Page

Air Reservation Ticket Booking System in C/C++

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main_menu();
void new_flight();
void search();
void list();
void ticket_booking();
typedef struct
{
char f_name[30];
char b_time[15];
char a_time[15];
char origin[30];
char dest[30];
int seat;
int f_no;
}flight;
typedef struct
{
char p_name[30];
char j_date[15];
char f_name[30];
int f_no;
int pnr;
int fare;
int seat_no;
char from[20];
char to[20];
}book;
FILE *fp,*fb;
int another;
void main()
{
clrscr();
gotoxy(25,10);
cprintf("Air Reservation Ticket Booking system");
gotoxy(35,12);
cprintf("By sourcecodernp.blogspot.com");
gotoxy(25,15);
textcolor(RED);
delay(6000);
main_menu();
getch();
}
void main_menu()
{
int ch;
clrscr();
gotoxy(30,6);
printf("Main Menu");
gotoxy(30,8);
printf("Add Flight          [1]");
gotoxy(30,10);
printf("Search Flight       [2]");
gotoxy(30,12);
printf("List of Flight      [3]");
gotoxy(30,14);
printf("Ticket Booking      [4]");
gotoxy(30,16);
printf("Exit                [5]");
gotoxy(30,18);
printf("Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
new_flight();
break;
case 2:
search();
break;
case 3:
list();
break;
case 4:
ticket_booking();
break;
case 5:
exit(1);
default:
main_menu();
break;
}
}
void new_flight()
{
flight f;
clrscr();
another='Y';
fp=fopen("flight.dat","ab");
while(another=='y'||another=='Y')
{
printf("Enter flight No:");
scanf("%d",&f.f_no);
fflush(stdin);
printf("Enter flight Name:");
gets(f.f_name);
fflush(stdin);
printf("Enter Bording Time");
gets(f.b_time);
fflush(stdin);
printf("Enter Arrival Time:");
gets(f.a_time);
fflush(stdin);
printf("Enter Origin:");
gets(f.origin);
fflush(stdin);
printf("Enter Destination:");
gets(f.dest);
fflush(stdin);
printf("\nEnter total seat:");
scanf("%d",&f.seat);
fwrite(&f,sizeof(f),1,fp);
cprintf("Data is inserted");
cprintf("You want to add another data:");
fflush(stdin);
another=getche();
}
fclose(fp);
getch();
main_menu();
}
void search()
{
int fno;
flight f1;
clrscr();
another='Y';
fp=fopen("flight.dat","rb");
if(fp==NULL)
{
printf("Database is Not Found");
}
printf("\nEnter Flight No:");
scanf("%d",&fno);
while(fread(&f1,sizeof(f1),1,fp)==1)
{
if(f1.f_no==fno)
{
printf("\n\nFlight is found");
printf("\n\n\tFlight No               :  %d",f1.f_no);
printf("\n\n\tFlight Name             :  %s",f1.f_name);
printf("\n\n\tBording Time            :  %s",f1.b_time);
printf("\n\n\tArrival Time            :  %s",f1.a_time);
printf("\n\n\tOrigin                  :  %s",f1.origin);
printf("\n\n\tDestination             :  %s",f1.dest);
printf("\n\n\tAvailable Seat          :  %d",f1.seat);
printf("\n\nYou want to search another flight(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='y'||another=='Y')
search();
else
{
fclose(fp);
exit(1);
}
}
}
printf("\n\nFlight is not available");
printf("\n\nDo you want to Search another medicine(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='Y'||another=='y')
search();
else
{
fclose(fp);
exit(1);
}
}
void list()
{
int p=3;
flight f2;
clrscr();
textcolor(YELLOW);
gotoxy(1,1);
cprintf("Flight No");
gotoxy(20,1);
cprintf("Flight Name");
gotoxy(45,1);
cprintf("Bording Time");
gotoxy(65,1);
cprintf("Arrival Time");
fp=fopen("flight.dat","rb");
if(fp==NULL)
{
printf("\n\nDatabase Not Found");
}
while(fread(&f2,sizeof(f2),1,fp)==1)
{
gotoxy(1,p);
printf("%d",f2.f_no);
gotoxy(20,p);
printf("%s",f2.f_name);
gotoxy(45,p);
printf("%s",f2.b_time);
gotoxy(65,p);
printf("%s",f2.a_time);
p+=2;
}
fclose(fp);
printf("\n\nPress any Key to go back Main Menu..........");
}
void ticket_booking()
{
book b;
clrscr();
another='Y';
fb=fopen("booking.dat","ab");
while(another=='y'||another=='Y')
{
printf("Enter flight No:");
scanf("%d",&b.f_no);
fflush(stdin);
printf("Enter flight Name:");
gets(b.f_name);
fflush(stdin);
printf("Passenger Name : ");
gets(b.p_name);
fflush(stdin);
printf("Enter Jounary Date:");
gets(b.j_date);
fflush(stdin);
printf("Enter Origin   :");
gets(b.from);
fflush(stdin);
printf("Enter Destination :");
gets(b.to);
fflush(stdin);
printf("Enter PNR No :");
scanf("%d",&b.pnr);
fflush(stdin);
printf("Enter Total amount :");
scanf("%d",&b.fare);
fflush(stdin);
printf("\nEnter Seat No:");
scanf("%d",&b.seat_no);
fwrite(&b,sizeof(b),1,fb);
cprintf("\nData is inserted");
cprintf("\nYou want to add another data:");
fflush(stdin);
another=getche();
}
fclose(fb);
getch();
main_menu();
}

How to Generate random rows in dataset using c#.net

 SqlConnection con = new SqlConnection("Your Connection String");
            con.Open();

            string str = "select * from StudentDetail";
            SqlCommand cmd =new SqlCommand(str,con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds =new DataSet();
            sda.Fill(ds);

            Random RandomNumber = new Random();
            int no = RandomNumber.Next(0,ds.Tables[0].Rows. Count);
            textBox1.Text = ds.Tables[0].Rows[no][0].ToString();

linked list program to create,insert and delete nodes


#include <stdio.h>
#include <stdlib.h>
#include "node.h"

struct node* CreateNode() {
        return malloc(sizeof(struct node));
}

void PrintList(struct node* head) {
        struct node* current = head;
        while(current != NULL) {
                printf("%d ", current->data);
                current = current->next;
        }
        printf("NULL\n");
}

struct node* InsertInFront(struct node* head, int value) {
        struct node* newNode = CreateNode();
        newNode->data = value;
        newNode->next = head;
        return newNode;
}

struct node* CreateList(int values[], int len) {
        // check for empty list
        if (len == 0) return NULL;
        struct node* head = NULL;
        int i;
        for(i=len; i>0; i--) {
                head = InsertInFront(head, values[i-1]);
        }
        return head;
}

int LinkedListLength(struct node* head) {
        struct node *temp = head;
        int i = 0;
        while(temp != NULL){
                temp = temp -> next;
                i++;
        }
        return i;
}

struct node* InsertAtEnd(struct node* head, int value) {
        struct node *temp = head;
        int i = 1;
        struct node *newNode;
        while (temp != NULL){
                if(temp -> next == NULL){
                        newNode = CreateNode();
                        newNode -> data = value;
                        newNode -> next = NULL;
                        return head;
                }
                temp = temp -> next;
                i++;
        }
        return head;
}

struct node* InsertAtN(struct node* head, int value, int N) {
        int i = 1;
        struct node *temp = head;
        if(N > LinkedListLength(head)){
                printf("ERROR: Node <N> does not exist");
        }
        if(N == 0){
                InsertInFront(head, value);
        }
        struct node *newNode;
        while (i <= N){
                if(i == N){
                        newNode = CreateNode();
                        newNode -> data = value;
                        newNode -> next = temp -> next;
                        temp = newNode;
                        return head;
                }
                temp = temp -> next;
                i++;
        }
        return head;
}

struct node* DeleteNode(struct node* head, int pos) {
        struct node *temp = head;
        if(pos > LinkedListLength(head)){
                printf("ERROR: Node does not exist");
        }
        int i = 1;
        struct node *newNode;
        while(i < pos){
                if(i+1 == pos){
                        temp = temp -> next -> next;
                        free(temp -> next);
                        return head;
                }
                temp = temp -> next;
                i++;
        }
        return newNode;
}

Student Record & Registration using LinkList in C/C++

#include<iostream>
#include<conio.h>
#include<string>
#include<stdlib.h>  
using namespace std;

bool register_student(struct student *stud,struct list *ls);
double calculate_aggregiate(struct student *);
void addToList(struct student *stud, struct list *l);
void showList(struct student *stud, struct list *l);

struct student
{
char name[20];
int metric_marks, fsc_marks, entryTest_marks;
student *next;

};

struct list
{
char name[20];
double aggr;
list *next;

};


int main()
{
student *s;
s = (struct student *) malloc(sizeof(struct student));

struct list *ls;
ls = (struct list *) malloc(sizeof(struct list));
strcpy(ls->name, "");
ls->aggr = 0;
ls->next= NULL;
do
{
cout<<"Write 1 to Register a new student\n";
cout<<"Write 2 to Display lists of students registered\n";
cout<<"Write 3 to Quit\n";
 
int input;
cin>>input;
if (input == 1)
{
register_student(s, ls);

}
else if (input == 2)
{
showList(s, ls);
}
else if (input == 3)
exit(0);
cout<<"\n";
} while(1);

getch();
}

bool register_student(struct student *stud,struct list *ls)
{
student *s = stud;
cout<<"Write name of student\n";
cin>>s->name;
cout<<"Enter metric percentage\n";
cin>>s->metric_marks;
cout<<"Enter fsc percentage\n";
cin>>s->fsc_marks;
cout<<"Enter entry test percentage\n";
cin>>s->entryTest_marks;

double aggregiate;
aggregiate = calculate_aggregiate(s);
cout<<"aggregiate percentage is "<< aggregiate<<"\n";
if (aggregiate >= 70)
{
cout<<"Student registered in Electrical\n";
addToList(s,ls);
return true;
}
else if (aggregiate >= 60)
{
cout<<"Student registered in Mechanical\n";
addToList(s,ls);
return true;
}
else if (aggregiate >=50)
{
cout<<"Student registered in CSE\n";
addToList(s,ls);
return true;
}
else
{
cout<<"Sorry, the student can't be registered in engineering\n";
return false;
}

}

double calculate_aggregiate(struct student *stud)
{
student *s = stud;
double aggr;
aggr = s->metric_marks * 10/100  + s->fsc_marks * 50/100 + 
   s->entryTest_marks * 40/100;
        
return aggr;

}


void addToList(struct student *stud, struct list *l)
{
list *pointer = l;
while (pointer->next != NULL)
{
pointer = pointer->next;
} 
pointer->next = (struct list *) malloc(sizeof(struct list));
pointer = pointer->next;
strcpy(pointer->name , stud->name);
pointer->aggr = calculate_aggregiate(stud);
pointer->next = NULL;


}

void showList(struct student *stud, struct list *l)
{
list *pointer = l;
if (pointer->next == NULL)
cout<<"No student registered yet!\n";
else
{
cout<<"Students statistics are: \n";
while (pointer->next != NULL)
{
pointer = pointer->next;
cout<<"Name of student is: "<<pointer->name<<"\n";
cout<<"Aggregiate of student is: "<<pointer->aggr<<"\n";
if (pointer->aggr >= 70)
cout<<"Student registered in Electrical\n";
else if(pointer->aggr >=60)
cout<<"Student registered in Mechanical\n";
else
cout<<"Student registered in CSE\n";
cout<<"\n";
}
}
}

How to submit a page to another page in asp.net

// Example.aspx //


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Example.aspx.cs" Inherits="_Example" %>  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  

<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>PostBackUrl Example: how to submit a page to another page in asp.net</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="DarkSlateBlue"></asp:Label>  
        <br />  
        <asp:Label ID="Label2" runat="server" Text="Your City" AssociatedControlID="TextBox1"></asp:Label>  
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Text="*"></asp:RequiredFieldValidator>  
        <br />  
        <asp:Button ID="Button1" runat="server" Text="Submit in this page" OnClick="Button1_Click" />  
        <asp:Button ID="Button2" runat="server" Text="Submit in city page" PostBackUrl="~/CityPage.aspx" />  
    </div>  
    </form>  
</body>  
</html>  


// Example.aspx.cs //

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

public partial class Example : System.Web.UI.Page
{

  protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button1_Click(object sender, System.EventArgs e)
 {  
        Label1.Text = "Your city name: " +  
            TextBox1.Text.ToString();  
    }  

}


// city.aspx //


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="city.aspx.cs" Inherits="_city" %>  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  

<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>City Page</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h1>City Page</h1>  
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson"></asp:Label>  
    </div>  
    </form>  
</body>  
</html>  

// city.aspx.cs //

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

public partial class city: System.Web.UI.Page
{


    protected void Page_Load(object sender, System.EventArgs e) 
{  
        TextBox PP_TextBox1;  
        PP_TextBox1 = (TextBox)PreviousPage.FindControl("TextBox1");  
        Label1.Text = "Your City: " +   PP_TextBox1.Text;  
    }  

    }