Professional Documents
Culture Documents
My C Project
My C Project
++
Documentation-1
_______________________________________
Aim –
To store price list of 50 items and to print the
largest price as well as the sum of all prices.
Functions used –
ITEM::initialize()
ITEM::largest()
ITEM::sum()
ITEM::display_items()
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1.Define a class named ITEM with following
specification:-
Data Members:
Integer itemcode[50]
Floating it_price[50]
Member functions:
#include<stdlib.h>
float it_price[50];
public:
void initialize(void);
float largest(void);
float sum(void);
void display_items(void);
};
void ITEM::initialize(void)
{ for(int i=0;i<50;i++)
{ cout<<"\n"<<"item No:"<<(i+1);
cin>>itemcode[i];
cin>>it_price[i];
cout<<"\n";
float ITEM::largest(void)
{ float large= it_price[0];
for(int i=1;i<50;i++)
{ if(large<it_price[i])
large=it_price[i];
return large;
float ITEM::sum(void)
{ float sum=0;
for(int i=0;i<50;i++)
{ cout<<"\n"<<itemcode[i];
cout<<" "<<it_price[i];
cout<<"\n";
int main()
{ ITEM order;
order.initialize();
float total,biggest;
int ch=0;
system("cls");
do
{ cout<<"\nMain Menu.\n";
cout<<"\n1.Display largest price.";
cin>>ch;
switch(ch)
{ case 1 :biggest=order.largest();
break;
case 2 :total=order.sum();
break;
case 3 :order.display_item();
break;
default:cout<<"\nWrong choice!\n";
break;
}while(ch>=1&&ch<=3);
return 0;
}
Output-1
Main Menu.
Code price
101 23
102 44
103 98
104 67
105 66
Documentation-2
_______________________________________
Aim –
Program to illustrate the order of constructor
invocation.
Functions used –
Student::printsub()
Student::getval()
Student::print()
Student::print()
clrscr()
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
Student stud
Admission()
void print()
Admission adm
Print back in main
Source code -2
#include<iostream.h>
#include<stdlib.h>
int subjectno;
public:
void printsub(void)
{ cout<<"Subject No:"<<subjectno;
cout<<"\n"<<"Days:"<<days<<"\n"; }
};
{ cout<<"Constructing Subject\n";
days=d;
subjectno=sn;
float marks;
public:
Student()
{ cout<<"Constructing Students\n;
rollno=0;
marks=0.0;
void getval(void)
cin>>rollno>>marks;
cout<<"\n";
void print(void)
{ cout<<"Roll no:"<<rollno;
cout<<"\n"<<"Marks:"<<marks<<"\n";
};
Student stud;
float fees;
public:
Admission()
{ cout<<"Constructing Admission\n";
fees=0.0;
void print(void)
{ stud.print();
sub.printsub();
cout<<"Fees:"<<fees<<"\n";
};
int main()
System("cls";
Admission adm;
cout<<"\nBack in main()\n";
return 0;
}
Output-2
Constructing Subject
Constructing Student
Constructing Admission
Back in main ()
Documentation-3
_______________________________________
Aim –
To illustrate access control of inherited members
in the privately derived class.
Functions used –
employee::getdata()
employee::putdata()
employee::getbasic()
manager::getdata()
manager::getdata()
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1.Define class employee which will act as a base
class of class manager with following
specification:
Character name[25]
Floating basic
Void getbasic()
Void getdata()
Void putdata()
Void putdata ()
Character title[25]
Void getdata()
Void putdata()
3.Manager m1,m2
End
Source code -3
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
char name[LEN];
public:
void getdata()
{ cout<<"Enter Name:";
gets(name);
cin>>enumb;
void putdata()
{ cout<<"Name:"<<name<<"\t";
cout<<"Emp.Number:"<<enumb<<"\t";
cout<<"Basic salary:"<<basic;
protected:
float basic;
void getbasic()
};
private:
char title[LEN];
public:
void getdata()
Employee::getdata();
getbasic();
cout<<"Enter Title:";
get(title);
cout<<"\n";
void putdata()
{ Employee::putdata();
cout<<"\tTitle:"<<title<<"\n";
};
int main()
{ Manager m1,m2;
cout<<"Manager1\n";
m1.getdata();
cout<<"Manager2\n";
m2.getdata();
cout<<"\t\tManager1 Details\n";
m1.putdata();
cout<<"\t\tManager2 Details\n";
m2.putdata();
return 0;
}
Output -3
Manager 1
Manager 2
Manager 1 Details
Manager 2 Details
Functions used –
Void main()
Void getdata()
Void putdata()
accept()
display()
clrscr()
input()
output()
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. Create a class person.
6. END.
Source code-4
#include<iostream.h>
#include<conio.h>
int age;
char add[40];
public:
void getdata()
cout<<"\n"<<"ENTER AGE:";
cin>>age;
void putdata()
{ cout<<"\n"<<"NAME:"<<nm<<"\n"
<<"AGE:"<<age<<"\n"
<<"ADDRESS:"<<add<<"\n";
};
{ int rno;
int cl;
char sec;
public:
void accept()
{ getdata();
cout<<"\n"<<"ENTER ROLL
NUMBER:"; cin>>rno;
cout<<"\n"<<"ENTER
CLASS:"; cin>>cl;
cout<<"\n"<<"ENTER
SECTION:"; cin>>sec;
void display()
{ putdata();
cout<<"ROLL
NUMBER:"<<rno<<"\n"
<<"CLASS:"<<cl<<"\n"
<<"SECTION:"<<sec<<"\n";
};
{ char sub1[10],sub2[10];
float m1,m2;
public:
void input()
{ accept();
cout<<"\n"<<"ENTER
SUBJECT 1:"; cin>>sub1;
cout<<"\n"<<"ENTER
MARKS OF SUBJECT 1:"; cin>>m1;
cout<<"\n"<<"ENTER
SUBJECT 2:"; cin>>sub2;
cout<<"\n"<<"ENTER
MARKS OF SUBJECT 2:"; cin>>m2;
void output()
{ display();
cout<<"SUBJECT
1:"<<sub1<<"\n"
<<"MARKS:"<<m1<<"\n"
<<"SUBJECT:"<<sub2<<"\n"
<<"MARKS:"<<m2<<"\n"; }
};
void main()
{clrscr();
subject s1;
s1.input();
s1.output();
}
Output -4
ENTER NAME:DEV
ENTER AGE:17
ENTER ADDRESS:BHOPAL
ENTER CLASS:12
ENTER SECTION:C
NAME:DEV
AGE:17
ADDRESS:BHOPAL
ROLL NUMBER:12
CLASS:12
SECTION:C
SUBJECT 1:ENGLISH
MARKS:60
SUBJECT:COMPUTER
MARKS:65
Documentation-5
_______________________________________
Aim – Program to create a single file and then
display its contents.
fstream.h
Functions used –
fin.close(),fin.open()
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. Open file using ofstream.
7. END.
Source code-5
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
int main()
{ system ("cls");
ofstream fout("student",ios::out);
char name[30],ch;
float marks=0.0;
for(int i=0;i<5;i++)
{ cout<<"student"<<(i+1)<<":\tName:";
cin.get(name,30);
cout<<"\t\Marks:";
cin>>marks; cin.get(ch);
fout<<name<<'\n'<<marks<<'\n';
fout.close();
ifstream fin("student",ios::in);
fin.seekg(0);
cout<<"\n";
for(i=0;i<5;i++)
{ fin.get(name,30);
fin.get(ch);
fin>>marks;
fin.get(ch);
cout<<"Student Name:"<<name;
fin.close();
return 0;
}
Output -5
Student 1 : Name : Raju shah
Marks : 88
Marks : 90
Marks : 78
Marks : 67
Marks : 73
fstream.h
Functions used –
filin1.close();, filin2.close();,
filin2.open, filin1.open
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. Create file stunames .
4. Print it.
6. Print it.
8. END.
Source code- 6
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
int main()
{ system ("cls");
ifstream filin1,filin2;
filin1.open("Stunames",ios::in);
filin2.open("Stumarks",ios::in);
char line[80];
cout<<"the contents of Stunames and Stumarks are
given below.\n";
filin1.getline(line,80);
cout<<line<<"\n";
filin2.getline(line,80);
cout<<line<<"\n";
filin1.getline(line,80);
cout<<line<<"\n";
filin2.getline(line,80);
cout<<line<<"\n";
filin1.getline(line,80);
cout<<line<<"\n";
filin2.getline(line,80);
cout<<line<<"\n";
filin1.close();
filin2.close();
return 0;
}
Output -6
The contents of Stunames and Stumarks are given below.
Devyani
78.92
Monica Patrick
72.17
Neil banarjee
69.33
Documentation-7
_______________________________________
Aim –
Program to write and read a structure using write()
and read() function using a binary files.
string.h ,fstream.h
Functions used –
Void selsort(int[],int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
The is a structure named customer contains name and
balance
End of if
12.Close file
13.EXIT
Source code -7
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
float balance; };
int main()
{ system("cls" );
customer savac;
savac.balance=21310.75;
ofstream fout;
fout.open("saving",ios::out|ios::binary);
if(!fout)
return 1;
fout.write((char*)&savac,sizeof(customer));
fout.close();
ifstream fin;
fin.open("saving",ios::in|ios::binary);
fin.read((char*)&savac,sizeof(customer));
cout<<savac.name;
fin.close();
return 0 ;
}
Output-7
Tina Marshall has the balance amount of Rs.21310.75
Documentation-8
_______________________________________
Aim –
Program for reading and writing class objects.
string.h ,fstream.h
Functions used –
Void selsort(int[],int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. Create a class student.
4. Using fout.write((char*)&s1[i],sizeof(s1[i]))
i. write the information to file.
5. Using fin.write((char*)&s1[i],sizeof[i]))
i. read the information from the file.
7. END.
Source code-8
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
char grade;
float marks;
public:
void getdata();
void display();
};
void student::getdata()
void student::display()
{cout<<"\n"<<"NAME:"<<nm;
cout<<"\n"<<"GRADE:"<<grade;
cout<<"\n"<<"MARKS:"<<marks;
void main()
{clrscr();
student s1[3];
fstream filin;
filin.open("stu.dat",ios::in|ios::out);
if(!filin)
getch();
exit(0); }
for(int i=0;i<3;++i)
{cout<<"\n"<<"ENTER DETAILS OF
STUDENT:"<<i+1<<"\n";
s1[i].getdata();
filin.write((char*)&s1[i],sizeof(s1[i]));
filin.seekg(0);
for(i=0;i<3;++i)
{cout<<"\n"<<"\n"<<"STUDENT:"<<i+1<<"\n";
filin.read((char*)&s1[i],sizeof(s1[i]));
s1[i].display(); }
filin.close();
getch();
}
Output-8
ENTER DETAILS OF STUDENT:1
ENTER NAME:DARPAN
ENTER GRADE:A
ENTER MARKS:95
STUDENT:2
NAME:MANIT
GRADE:B
MARKS:66
STUDENT:3
NAME:DEV
GRADE:B
MARKS:67
Documentation-9
_______________________________________
Aim –
Program to append data in a file.
Functions used –
Void main()
Void getdata()
Void putdata()
close()
clrscr()
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
/* the class with required specifications is
already defined */
3. END.
Source code -9
#include<fstream.h>
#include<conio.h>
char nm[40];
int cl;
char sec;
float mks;
char grade;
public:
void getdata()
if(mks>=75) grade='A';
else grade='D';
void putdata()
{ cout<<"\n"<<"ROLL NUMBER:"<<rno<<"\n";
cout<<"\n"<<"NAME:"<<nm<<"\n";
cout<<"\n"<<"CLASS:"<<cl<<"\n";
cout<<"\n"<<"MARKS:"<<mks<<"\n";
cout<<"\n"<<"GRADE:"<<grade<<"\n";
}s1;
void main()
{ clrscr();
ofstream fout("stu.dat",ios::app);
char ans='y';
while(ans=='y')
{ s1.getdata();
fout.write((char*)&s1,sizeof(s1));
cin>>ans;
fout.close();
}
Output-9
ENTER ROLL NUMBER:10
ENTER CLASS:12
ENTER MARKS:80
N
Documentation -10
_______________________________________
Aim –
Linear search in array.
Functions used –
Lsearch(int [] ,int,int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
/* Initialise counter by assigning lower bound
value of array */
break
/* go out of loop */
Step.4 : ctr=ctr+1
/* end of repeat */
Step.6 : END
Source code-10
#include<iostream.h>
#include<conio.h>
int lsearch(int[],int,int);
void main()
{ clrscr();
int ar[50],item,N,index;
cin>>N;
for(int i=0;i<N;++i)
{cin>>ar[i];}
index=lsearch(ar,N,item);
if(index==-1)
{cout<<"\n"<<"SORRY GIVEN ELEMENT COULD NOT
BE FOUND"<<"\n";}
else
<<",POSITION:"<<index+1<<"\n";
}
int lsearch(int ar[],int size,int ITEM)
{ for(int i=0;i<size;++i)
{ if(ar[i]==ITEM) return i;
return-1;
}
Output -10
ENTER DESIRED ARRAY SIZE(max.50):5
_______________________________________
Aim –
Binary search in an array.
Functions used –
Void selsort(int[],int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. Let us assume that given array is AR[n]
Beg=0, last=n.
4. mid= (beg+last)/2
5. if AR[mid]==value
Pos=mid
Print pos
Break
6. if x[mid], value
Beg=mid+1
Else last=mid-1
8. end
Source code 11
#include<iostream.h>
int Bsearch(int[],int,int);
int main()
{ intAE[50],ITEM,N,index;
cin>>N;
for(int i=0;i<N;i++)
cin>>AR[i];
cin>>ITEM;
index=Bsearch(AR,N,ITEM);
if(index==-1)
else
return 0 ;
beg=0; last=size-1;
while(beg<=last)
{ mid=(beg+last)/2;
if(item==AR[mid])retun mid ;
else lasrt=mid-1;
return -1;
}
Output-11
Enter desired array size(max.50)……7
2 5 7 8 9 10 15
Functions used –
findpos(int [] ,int,int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
/* First the appropriate position for ITEM is to be
determined i.e.,if the appropriate position is i+1
then ar[i]<= ITEM <=ar[i+1],LST specifies maximum
possible index in array,u specifies index of last
element in array */
2. if LST =U then
{ print”overflow:”
3. if ar[ctr]>ITEM then
Pos = 1
else
{ pos = ctr+1
break
6. ctr = ctr + 1
/*end of repeat here*/
7. if ctr = U then
pos = U+1
10. { ar[ctr+1]=ar[ctr]
11. ctr=ctr-1
}
13. END
Source code-12
#include<iostream.h>
#include<process.h>
#include<conio.h>
int findpos(int[],int,int);
void main()
{ int ar[50],item,N,index;
cin>>N;
for(int i=0;i<N;++i)
cin>>ar[i];
char ch='y';
while(ch=='y'||ch=='Y')
{ cout<<"\n"<<"ENTER ELEMENT TO BE
INSERTED...";
cin>>item;
if(N==50)
{ cout<<"OVERFLOW"<<"\n";
exit(1);}
index=findpos(ar,N,item);
for(i=N;i>index;--i)
ar[i]=ar[i-1];
ar[index]=item;
N+=1;
cout<<"\n"<<"WANT TO INSERT MORE
ELEMENTS(y/n)...";
cin>>ch;
for(i=0;i<N;++i)
cout<<ar[i]<<" "<<"\n";
{ int pos;
if(ITEM<ar[0]) pos=0;
else
{ for(int i=0;i<size;++i)
{ if(ar[i]<=ITEM&&ITEM<ar[i+1])
{ pos=i+1; break;
} }
if(i==size-1) pos=size; }
return pos;
}
Output-12
ENTER NUMBER OF ELEMENTS OF ARRAY(MAX.50....6
10
12
15
10
11
12
15
Documentation -13
_______________________________________
Aim –
selection sort in array .
Functions used –
Void selsort(int[],int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
Small=AR[L]
For I=L TO do
Small=AR[I],pos=I
For J=I TO U do
if AR[J]<small then
{ small=AR[I]
Pos=J
J=J+1
temp=AR[I]
AR[I]=small
AR[pos}=temp
END.
Source code -13
#include<iostream.h>
Void selsort(int[],int);
int main()
{int AR[50],ITEM,N,index;
cin>>N;
for(int i=0;i<n;i++)
cin>>AR[i];
selsort(AR,N);
for(int i=0;i<N;i++)
cout<<AR[i]<<” “;
cout<<endl;
{ int small,pos,tmp;
for(int i=0;i<size;i++)
{ small=AR[i];
for(int j=i+1;j<size;j++)
{ if(AR[j]<small)
{ small=AR[j];
Pos=j;}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
For(j=0;j<size;j++)
Cout<<AR[j]<<” “;
}
Output-13
How many element do U want to create array with
?( maximum = 50)----6
1 2 3 4 5 6 8
Documentation-14
_______________________________________
Aim –
Bubble sort in array.
Functions used –
Void Bubblesort(int[],int)
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
for I=L TO U
{ if AR[J]>AR[J+1]then
Temp= AR[J]
AR[J]=AR[J+1]
AR[J+1]=temp
END.
Source code -14
#include<iostream.h>
Void Bubblesort(int[],int);
int main()
{ int AR[50],ITEM,N,index;
cin>>N;
for(int i=0;i<n;i++)
cin>>AR[i];
Bubblesort(AR,N);
for(int i=0;i<N;i++)
cout<<AR[i]<<” “;
cout<<endl;
return0 ;
{ int tmp,crt=0;
for(int i=0;i<size;i++)
{for(int j=0;j<(size-1),--i,j++)
{ if(AR[j]>AR[j+1])
{tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp;}
For(int k=0;k<size;k++)
Cout<<AR[k]<<” “;
Cout<<endl;
}
Output-14
How many element do U want to create array with
?( maximum = 50)----5
9 7 4 6 1
1 4 6 7 9
Documentation- 15
_______________________________________
Aim –
Insertion in the beginning of the list.
process.h
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
/* this algorithm deals with insertion in the
beginning of linked list */
Ptr =START
NEWPTR=new Node
If NEWPTR=NULL
Else
NEMPTR->INFP=ITEM
NEMPTR->LINK=NULL
If START=NEWPTR
Else
Save=START
*/
START=NEWPTR
NEWPTR->LINK=Save
*/ }
END.
Source code- 15
#include<iostream.h>
#include<process.h>
Node*next;
}*start,*newptr,*save,*ptr;
Node*create_New_Node(int);
Void Insert_Beg(Node*);
Int main()
{ start=NULL;
while(ch==’y’||ch==’y’)
{ system(“cls”);
Cin>>inf;
if( newptr!=NULL)
System(“pause”);
else
{cout<<”\n Cannot create new node!!!\n”;
system(“pause”);
exit(1);
System(“pause”);
Insert_beg(newptr);
Display(start);
cin>>ch;
return 0;
Node*Create_New _Node(int n)
Ptr->info=n;
Ptr->next=NULL;
return ptr ;
Void Insert_Beg(Node*np)
{if(start==NULL)
Start=np;
else
{ save=start;
Start=np;
np ->next=save;
Void Display(Node*np)
{while(np!=NULL)
{cout<<np->info<<”->“;
np=np->next;
cout<<”!!!\n”;
}
Output-15
ENTER INFOrmation for the new node…9
9 -> !!!
N
Documentation-16
_______________________________________
Aim –
Insertion in the End of the list.
process.h
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. Declare pointers START,PTR,NEWPTR REAR
2. ptr=START
3. NEWPTR=new Node
4. IF NEWPTR = NULL
6. Exit
7. ELSE
9. IF START=NULLTHEN
10. START=NEWPTR
11. REAR=NEWPTR
13. REAR=NEWPTR
14. END
Source code- 16
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
Node*next;
}*start,*newptr,*save,*ptr,*rear;
Node*create_New_Node(int);
Void Insert_End(Node*);
Void Display(Node*);
int main()
{ start=rear=NULL;
while(ch==’y’||ch==’y’)
{ system(“cls”);
cin>>inf;
if( newptr!=NULL)
System(“pause”);
}
else
exit(1);
System(“pause”);
Insert_End(newptr);
Display(start);
cin>>ch;
return 0;
Ptr->info=n;
Ptr->next=NULL;
return ptr ;
}
Void Insert_End(Node*np)
{if(start==NULL)
Start=rear=np;
else
rear=np;
Void Display(Node*np)
{ while(np!=NULL)
{ cout<<np->info<<”->“;
np=np->next;
cout<<”!!!\n”;
}
Output-16
ENTER INFOrmation for the new node… 9
9 -> !!!
N
Documentation-17
_______________________________________
Aim –
Deletion from the beginning of the list.
process.h
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1.If START = NULL THEN
2. Print “UNDERFLOW”
3. else
4. { ptr = start
5. Start = ptr -> LINK
6. Delete ptr }
7. END
Source code-17
# include<iostream.h>
# include<stdlib.h>
# include<process.h>
Node * next;
}
*start,*newptr,*save,*ptr,*rear;
Node*Create_New_Node(int);
void Display(Node*);
void DelNode();
int main()
int inf;
char ch =’y’;
while(ch==’y’||ch==’Y’)
{ system (“cls”);
if ( newptr == NULL )
{ cout <<”\nCannot create new node !!! Aborting!!”;
Exit(1);
Insert( newptr);
cin>>ch;
system( “cls”);
do
if ( ch ==’y’||ch == ‘Y’)
Delnode( );
return 0;
Node*Create_New_Node( int n )
return ptr ;
}
else
rear = np ;
Void DelNode ()
Else
{ ptr = start ;
delete ptr ;
np = np -> next ; }
cout <<”!!!!\n”;
}
Outputs-17
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
Firstly , check for underflow condition
4.Else
5.print stack(top)
6. top = top-1 /*top moved , so that the
topmost
element
becomes*/
/*inaccessible which is a
sort of a deletion*/
7.END
Source code-18
# include<iostream.h>
# include<process.h>
int main ( )
char ch = ’y’ ;
while ( ch == ‘y’|| ch == ‘ Y’ )
cin >>Item ;
if ( res == -1 )
exit (1) ;
Display(Stack,top);
cin >> ch ;
}
ch = ‘y’ ;
If ( res == -1 )
exit (1) ;
else
{ cout<< “\n Elements deleted is
:”<<res<<endl;
Display(Stack , top);
return 0 ;
else
{ top++ ;
Stack[top] = ele ;
return 0 ;
int ret ;
else
top -- ;
return ret ;
{ if ( top == -1 ) return ;
}
Outputs-18
Enter ITEM for insertion : 9
9 <--
6 <--
3 <--
Element deleted is : 3
6 <--
9 <--
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
Get new node for ITEM to be popped
4.top = newptr
5. else
7.top = newptr
8.end
Source code-19
# include<iostream.h>
# include<stdlib.h>
# include<process.h>
Node * next ;
} * top ,*newptr,*save,
*ptr;
void Pop( ) ;
int main ( )
{ top = NULL ;
if ( newptr == NULL )
Exit (1) ;
}
Push ( newptr ) ;
cin >> ch ;
system ( “cls” ) ;
do
cin >> ch ;
return 0 ;
return ptr ;
else
{ save = top ; top =np ;
void Pop ( )
else
delete ptr ;
{ while ( np ! = NULL )
np = np -> next ;
}
Output -19
Enter INFOrmation for the new node ....6
8 -> 6 -> ! ! !
6 -> ! ! !
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. If rear = NULL Then
{
2. Rear = front = 0
3. QUEUE[0] = ITEM
{
7. QUEUE [rear +1] = ITEM
8. rear = rear+1
}
9. END.
Source code-20
# include<iostream.h>
# include<stdlib.h>
# include<process.h>
int main( )
system ( “cls” ) ;
if ( res == -1 )
cin >> ch ;
}
return 0 ;
{ front = rear = 0 ;
Queue[rear] = ele ;
else
{ rear++ ;
Queue[rear] = ele ;
return 0 ;
{ if ( front == -1 ) return ;
}
Output -20
Enter ITEM for insertion : 3
3<-6
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. NEWPTR= new Node
5. Rear= NEWPTR
}
6. Else
{
7. Rear->LINK= NEWPTR
8. Rear= NEWPTR
}
9. END
Source code- 21
#include<iostream.h>
#include<process.h>
Node*next;
}*front,*newptr,*save,*ptr,*rear;
Node*create_New_Node( int) ;
int main()
{ front=rear=NULL;
while(ch=='y'||ch=='y')
cin>>inf;
newptr=create_New_Node(inf);
if(newptr==NULL)
Insert_End ( newptr);
Display ( front ) ;
cout<<"\n Press Y to enter more nodes.N to
exit...";
cin>>ch;
return 0;
Node*Create_New_Node( int n)
{ ptr=new Node;
ptr->info=n; ptr->next=NULL;
return ptr; }
{ if(front==NULL)front=rear=np;
else
{ rear->next=np;
rear=np; }
void Display(Node*np)
{ while(np!=NULL)
{cout<<np->info<<"->";
np=np->next;
cout<<"!!!\n";
}
Output- 21
5->!!!!
5->12->!!!!
Version of C++ -
Turbo C++ 3.o
Computer system –
Windows 7
Algorithm
1. If front= NULL Then
3. Else
{
4. ITEM= front->INFO
6. Front=rear=NULL
}
7. Else
8. Front=front->LINK
}
9. END
Source code- 22
#include<iostream.h>
#include<process.h>
Node*next;
}*front,*newptr,*save,*ptr,*rear;
Node*Create_New_Node(int) ;
void Insert(Node*);
void Display(node*);
void DelNode_Q();
int main()
{ front=rear=NULL;
while(ch=='y'||ch=='y')
cin>>inf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
Insert(newptr);
system("cls");
do
{ cout<<"\n The Linked-Queue now is
(Front...to...Rear):L\n";
Display(front) ;
cin>>ch;
if(ch=='y'||ch=='Y')
DelNode_Q();
} while(ch==’y’||ch==’Y’);
Return 0;
Node*Create_New_Node( int n)
return ptr; }
{ if(front==NULL){front=rear=np;}
else
{ rear->next=np;
rear=np; }
}
Void DelNode_q()
delete ptr ;}
void Display(Node*np)
{ while (np!=NULL)
{cout<<np->info<<"->";
np=np->next;
cout<<"!!!\n";
}
Output- 22
Enter INFOrmation for the new node… 15
3-<4->8->9->15!!!!
4->8->9->15!!!!!
8->9->15!!!!
Relation Student
No. Name Age Department Date of Fee Sex
Adm.
1. Apnkaj 24 Computer 10/01/97 120 M
2. Shalini 21 History 24/03/98 200 F
3. Sanjay 22 Hindi 12/12/96 300 M
4. Sudha 25 History 01/07/99 400 F
5. Rakesh 22 Hindi 05/09/97 250 M
6. Shakeel 30 History 27/06/98 300 M
7. Surya 34 Computer 25/02/97 210 M
8. shikha 23 hindi 31/07/97 200 F
SOLUTION :
VALUES(,”Zaheer”,36,”computer”,{12/03/97},230,”M);
HOSPITAL
No. Name Age Department Date of Fee Sex
Adm.
1. Sandeep 65 Surgery 23/02/98300 M
2. Ravina 24 Orthopedia 20/01/98200 F
3. Karan 45 Orthopedia 19/02/98200 M
4. Tarun 12 Surgery 01/01/98300 M
5. Zubin 36 ENT 12/01/98250 M
6. Kratika 16 ENT 24/02/98300 F
7. Ankita 29 Cardiology 20/02/98800 F
8. Zareen 45 Gynecology 22/02/98300 F
9. Kush 19 Cardiology 13/01/98800 M
10. shadilya 31 Nuclear 19/02/98400 F
medicine
(a) To show all information about the patients of
Cardiology Department.
(b) To list names of female patients who are in
Orthopedia department.
(c) To list names of all patients with their date of
admission in ascending order.
(d) To display patients name,charge,age for only male
patients.
(e) To count the number of patients with Age > 30 .
(f) To insert a new row in the HOSPITAL table with
the following data:
11,”Mustafa”,37,”ENT”<{25/2/98}’250,”M”;
SOLUTION:
ORDER BY DateofAdm;
BOOKS
Book Book_name Author_name Publishers Price Type Qt
_Id y
C0001 Fast cook Lata kapoor EPB 355 cookery 5
F0001 The tears William First 650 Fiction 20
publisher
T0001 My first c++ Brain EPB 350 Text 10
brooke
T0002 C++ brain A.W.Rossaie TDH 350 Text 15
works
F0002 Thunderboltt Anna First 750 fiction 50
roberts publisher
ISSUED
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2