Vous êtes sur la page 1sur 50

INDEX

Sr. TOPIC TEACHE


no RS
. SIGN
1. LINEAR SEARCH IN ARRAY
2 TRANSPOSE OF MATRIX
3. MENU DRIVEN PROGRAM USING CLASS AND
OBJECTS
4. STACKS AS AN ARRAY
5. BINARY SEARCH USING AN ARRAY
6. DATA FILE HANDLING OF STUDENTS
RECORDS
7. CREATE & COUNT TEXT USING DATA FILE
HANDLING
8. SORTING AN ARRAY(BUBBLE,SELECTION
SORT)
9. QUEUE AS AN ARRAY
10. MERGING OF ARRAY
11. CREATE FILE USING DATA FILE HANDLING
12. MULTIPLE INHERITANCE
13. TELEPHONE DIRECTORY ( DATA FILE
HANDLING )
14. PROGRAM TO WRITE, SEARCH AND DISPLAY
DIFFERENT BLODD GROUPS IN BLOOD BANK
15. ASSIGN VALUES USING CLASS
16. QUEUE AS AN LINKED LIST
17. STACK AS AN LINKED LIST
18. CIRCULAR QUEUE
19. PROGRAM FOR CONSTRUCTOR AND
DESTRUCTOR
20. DATA FILE HANDLING USING STRUCTURES
21. SQL COMMANDS
PROGRAM-1
Program for linear search in array
#include<iostream.h>
#include<conio.h>
int linear_search(int [],int,int);
main()
{clrscr();
constint array_size=10;
int array[array_size]={0};
cout<<"\n Enter the contents of the array are : "<<endl;
cout<<"\n Elements :"<<"\t\t Value:"<<endl;
for(int count=0;count<array_size;count++)
{ cout<<"\t"<<" array ["<<count<<"]"<<"\t\t";
cin>>array[count]; }
int searching_element=0;
int flag=0;
cout<<"\n\n Enter the element you want to find = ";
cin>>searching_element;
flag=linear_search(array,array_size,searching_element);
if(flag!=-1)
cout<<"\n The given element is found at the position array["<<
flag<<"]"<<endl;
else
cout<<"\n The given element is not found. "<<endl;
getch();
return 0;
}
int linear_search(int array[],int size,int element)
{ for(int count=0;count<size;count++)
{ if(element==array[count])
{ return count; }
} return -1;
}

OUTPUT:
PROGRAM-2
Program to transpose in matrix

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int arr[3][3], i, j, arrt[3][3];
cout<<"Enter 3*3 Array Elements : ";
for(i=0; i<3; i++)
{for(j=0; j<3; j++)
{ cin>>arr[i][j]; }
}
cout<<"Transposing Array...\n";
for(i=0; i<3; i++)
{for(j=0; j<3; j++)
{ arrt[i][j]=arr[j][i]; }
}
cout<<"Transpose of the Matrix is :\n";
for(i=0; i<3; i++)
{for(j=0; j<3; j++)
{cout<<arrt[i][j]; }
cout<<"\n";
}
getch();
}

OUTPUT:
PROGRAM-3
Menu driven program to list all records of report card

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{ clrscr();
char *name[50],*nm;
int rno[50],m1[50],m2[50],m3[50],tot[50],i,n,trn;
cout<<"Enter no. of records: ";
cin>>n;
for(i=0;i<n;i++)
{ cout<<"Enter Name of Student "<<i<<": ";
gets(name[i]);
cout<<"Enter Roll No. of Student "<<i<<": ";
cin>>rno[i];
cout<<"Enter Mark1 of Student "<<i<<": ";
cin>>(m1[i]);
cout<<"Enter Mark2 of Student "<<i<<": ";
cin>>(m2[i]);
cout<<"Enter Mark3 of Student "<<i<<": ";
cin>>(m3[i]);
tot[i]=m1[i]+m2[i]+m3[i];
}
char ch,ch1;
int flag=0;
cout<<"\n\t1.Report card for particular student"
"\n\t2.List all records\n\t3.Exit";
cin>>ch;
do
{ switch(ch)
{ case '1':
cout<<"\nEnter the Roll no.";
cin>>trn;
flag=0;
for(i=0;i<n;i++)
if(trn==rno[i])
{ cout<<"\n Name: "<<name[i]<<"\t";
cout<<"Roll No.: "<<rno[i];
cout<<"\nMark1: "<<m1[i];
cout<<"\nMark2: "<<m2[i];
cout<<"\nMark3: "<<m3[i];
cout<<"\n----------";
cout<<"\nTotal: "<<tot[i];
flag=1;}
if(flag==0)
cout<<"Record not found";
break;
case '2':cout<<"\nRollno\tName
\tMark1\tMark2\tMark3";
cout<<"\tTotal";
cout<<"\n------\t----------\t----\t----\t----";
cout<<"\t-----";
for(i=0;i<n;i++)
{cout<<"\n"<<rno[i]<<"\t"<<name[i]<<"\t"
<<m1[i]<<"\t"<<m2[i]<<"\t"<<m3[i]<<"\t"
<<tot[i];
}
break;
}
cout<<"\n\t1.Report card for particular student"
"\n\t2.List all records\n\t3.Exit";
cin>>ch;
}while(ch!='3');
getch();
}

OUTPUT:
PROGRAM-4
Program for stack as an array

#include<stdio.h>
#include<process.h>
#define MAXSIZE 10
void push();
int pop();
void traverse();
int stack[MAXSIZE];
int Top=-1;
int main()
{ int choice;
char ch;
do { printf("n1. PUSH ");
printf("n2. POP ");
printf("n3. TRAVERSE ");
printf("nEnter your choice ");
scanf("%d",&choice);
switch(choice)
{ case 1: push();
break;
case 2: printf("nThe deleted element is %d ",pop());
break;
case 3: traverse();
break;
default: printf("nYou Entered Wrong Choice");
}
printf("nDo You Wish To Continue (Y/N)");
fflush(stdin);
scanf("%c",&ch);
}
while(ch=='Y' || ch=='y');
return 0;
}
void push()
{ int item;
if(Top == MAXSIZE - 1)
{ printf("nThe Stack Is Full");
exit(0);
}
else
{ printf("Enter the element to be inserted ");
scanf("%d",&item);
Top= Top+1;
stack[Top] = item;
}
}
int pop()
{ int item;
if(Top == -1)
{ printf("The stack is Empty");
exit(0);
}
else
{ item = stack[Top];
Top = Top-1; }
return(item);
}
void traverse()
{ int i;
if(Top == -1)
{ printf("The Stack is Empty");
exit(0); }
else
{ for(i=Top;i>=0;i--)
{ printf("Traverse the element ");
printf("%dn",stack[i]);
}
}
}
OUTPUT:

PROGRAM-5
Menu driven program to enter, sort, search and display
array
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[20],n,i,j,temp;
char ch;
do
{cout<<"\n\t1.Enter Array\n\t2.Sort
Array\n\t3.Search\n\t4.Display\n\t5.Exit";
cin>>ch;
switch(ch)
{ case '1': cout<<"\nEnter no. of Elements (<=20): ";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
break;
case '2': cout<<"\nThe Array is Now Sorted";
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[j]>a[j+1])
{ temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
break;
case '3': cout<<"\nThe element to be searched";
int el;
cin>>el;
int first=0,last=n-1,mid=0,flag=0;
while(first<=last&&flag==0)
{ mid=(first+last)/2;
if(a[mid]==el)
{ flag=mid;
}
else if(a[mid]<el)
{ first=mid+1;
}
else
{ last=mid-1;
}
}
if(flag>0)
cout<<"\nThe Element is Found at: "<<++flag<<" in
the sorted array";
else
cout<<"\n No such Element";
break;
case '4': cout<<"\n";
for(i=0;i<n;i++)
cout<<a[i]<<ends;
}
}
while(ch!='5');
}

OUTPUT:

PROGRAM-6
Menu driven program to add and show the records of
students
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>
class student
{ char name[30];
int rollno;
int marks;
public:
void input()
{
cout<<"\nEnter Name: ";
gets(name);
cout<<"Enter Rollno.: ";
cin>>rollno;
cout<<"enter marks";
cin>>marks;
}
void display()
{ cout<<"\n"<<name<<"\t"<<rollno<<"\t"<<marks<<"\t";
if(marks>=96)
cout<<"computer sc.";
else if(marks>=91&&marks<=95)
cout<<"Electronics";
else if(marks>=86&&marks<=90)
cout<<"Mechanical";
else if(marks>=81&&marks<=85)
cout<<"Electrical";
else if(marks>=76&&marks<=80)
cout<<"Chemical";
else if(marks>=71&&marks<=75)
cout<<"Civil";
else
cout<<"none";
}
};
void main()
{ clrscr();
student s;
int n,i,j;
fstream ofile,afile;

char ch,ch1;
do
{ cout<<"\n\t1.Add records\n\t2.Show Records\n\t3.Exit\n";
cout<<"Enter your choice: ";
cin>>ch;
switch(ch)
{ case '1' : ofile.open("st.dat",ios::app|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{ s.input();
ofile.write((char*)&s,sizeof(student));
}
ofile.close();
break;
case '2' : cout<<"\nName\tRollno\tMarks\tStream";
afile.open("st.dat",ios::in);
while(afile)
{ afile.read((char *)&s,sizeof(student));
if (!afile)
break;
s.display(); }
afile.close();
break;
case '3' : exit(0);
}
cout<<"\n\t DO U want to continue <Y/N>: ";
cin>>ch1;
}while(tolower(ch1)!='n');
getch();
}

OUTPUT:

PROGRAM-7
Menu driven program to create text, count words/digits &
show text
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{ clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;
do
{cout<<"\n\t1.Create Text\n\t2.Count vowels/words/digits\n\t3.Show
Text\n\t4.Exit";
cin>>ch;
switch(ch)
{ case '1' : ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
break;
case '2' : char tmp1;
int v=0,d=0,w=0;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{afile.get(tmp1);
if(tmp1=='a'||tmp1=='e'||tmp1=='i'||tmp1=='o'||
tmp1=='u')
v++;
if(isdigit(tmp1))
d++;
if(tmp1==' '||tmp1=='.')
w++;

}
afile.close();
cout<<"\n No of Vowels: "<<v;
cout<<"\n No of digits: "<<d+1;
cout<<"\n No of words: "<<w;
break;
case '3' : char tmp2;
afile.open("smp.txt",ios::in);
ofile.open("spl.txt",ios::out);
while(!afile.eof())
{ afile.get(tmp2);
if(tmp2==' ')
{ ofile<<'#'; }
else
{ ofile<<tmp2;
}
}
afile.close();
ofile.close();
cout<<"\nFormatted text:\t";
afile.open("spl.txt",ios::in);
while(afile)
{ afile.get(ch);
cout<<ch;
}
afile.close();
break;
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
OUTPUT:

PROGRAM-8
Menu driven program for selection, bubble, exchange,
insertion sort
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{ clrscr();
int ch;
int i,j,x,k,z,l,m,n,o,p,a[50],small;
cout<<"Enter the choice 1:Selection\n
2:Bubble\n
3:Exchange Selection\n
4:Insertion\n
5:Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the limit "<<endl;
cin>>n;
cout<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{ cin>>a[i];
cout<<endl; }
for(j=0;j<n;j++)
{ small=a[j];
p=j;
for(i=j;i<n;i++)
{ if(small>a[i])
{ small=a[i];
p=i; } }
for(k=p;k>j;k--)
{ a[k]=a[k-1]; }
a[j]=small; }
cout<<"Result:";
for(z=0;z<n;z++)
{ cout<<a[z];
cout<<endl; }
goto q;

case 2: cout<<"Enter the limit"<<endl;


cin>>n;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
for(j=0;j<n;j++)
{ for(i=0;i<n-1;i++)
{ if (a[i]>a[i+1])
{ x=a[i+1];
a[i+1]=a[i];
a[i]=x;
}
}
}
cout<<"Result"<<endl;
for (i=0;i<n;i++)
{ cout<<a[i];
cout<<endl; }
break;
case 3 : cout<<"Enter the limit "<<endl;
cin>>n;
cout<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{ cin>>a[i];
cout<<endl; }
for(j=0;j<n;j++)
{ small=a[j];
p=j;
for(i=j;i<n;i++)
{ if(small>a[i])
{ small=a[i]; p=i; }
} a[p]=a[j];
a[j]=small;
} cout<<"Result"<<endl;
for(z=0;z<n;z++)
{ cout<<a[z];
cout<<endl; }
goto q;
case 4 : int m=-32767;
cout<<"enter the no. of elements"<<endl;
cin>>n;
cout<<"enter the array"<<endl;
for(i=1;i<=n;i++)
{cin>>a[i];}
a[0]=m;
for(i=1;i<=n;i++)
{for(j=0;j<i;j++)
{if(a[i]<a[j])
{p=a[i];
for(k=i-1;k>=j;k--)
{a[k+1]=a[k];}
a[j]=p;}}}
for(i=1;i<=n;i++)
{cout<<a[i];}
goto q;
case 5: exit(0);
default: cout<<"Wrong choice";
goto q; }
getch();
}

OUTPUT:

PROGRAM-9
Program for queue as an array

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class queue
{ int queue1[5];
int rear,front;
public: queue()
{ rear=-1;
front=-1;
}
void insert(int x)
{ if(rear > 4)
{ cout <<"queue over flow";
front=rear=-1;
return;
}
queue1[++rear]=x;
cout <<"inserted" <<x;
}
void delet()
{ if(front==rear)
{ cout <<"queue under flow";
return;
}
cout <<"deleted" <<queue1[++front];
}
void display()
{ if(rear==front)
{ cout <<" queue empty";
return;
}
for(int i=front+1;i<=rear;i++)
cout <<queue1[i]<<" ";
} };
main()
{ int ch;
queue qu;
while(1)
{ cout <<"\n1.insert 2.delet 3.display 4.exit\nEnter ur choice";
cin >> ch;
switch(ch)
{ case 1: cout <<"enter the element";
cin >> ch;
qu.insert(ch);
break;
case 2: qu.delet(); break;
case 3: qu.display();break;
case 4: exit(0);
}
}
return (0);
}
OUTPUT:

PROGRAM-10
Program for merging in array
#include<iostream>
using namespace std;
void merge_sort(int [],int ,int );
void merge(int [],int,int ,int );
int main()
{ int n;
cout<<"Enter the size of the array"<<endl;
cin>>n;
int a[n];
cout<<"Enter the elements in the array"<<endl;
for(int i=1;i<=n;i++)
{ cin>>a[i]; }
cout<<"sorting using merge sort"<<endl;
int p=1,r=n;
merge_sort(a,p,r);
cout<<"sorted form"<<endl;
for(int i=1;i<=n;i++)
{ cout<<"a["<<i<<"]="<<a[i]<<endl; }
return 0;
}
void merge_sort(int a[],int p,int r)
{ int q;
if(p<r)
{ q=(p+r)/2;
merge_sort(a,p,q);
merge_sort(a,q+1,r);
merge(a,p,q,r);
}
}
void merge(int a[],int p,int q,int r)
{ cout<<"Entered merge"<<endl;
int n1=q-p+1;
int n2=r-q;
int L[n1+1];
int R[n2+1];
for(int i=1;i<=n1;i++)
{ L[i]=a[p+i-1]; }
for(int j=1;j<=n2;j++)
{ R[j]=a[q+j]; }
L[n1+1]=999;
R[n2+1]=999;
int i=1, j=1;
for(int k=p;k<=r;k++)
{ if(L[i]<=R[j])
{ a[k]=L[i];
i=i+1;
}
else
{ a[k]=R[j];
j=j+1;
}
}
}
OUTPUT:

PROGRAM-11
Menu driven program to create, read and write in another
program

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{ clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;
do
{ cout<<"\n\t1.Create Text\n\t2.Read from File\n\t3.create another file";
cout << "\n 4.Exit ";
cin>>ch;
switch(ch)
{
case '1' : ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
break;
case '2' : char tmp1;
<< "\n Lower case vowel "<<tmp1;
else
cout<<"\n Lower case consonants "<<tmp1;
}
if (isupper(afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);
if(isalpha(tmp1))
{
if (islower(tmp1))
{ if (tmp1=='a'||tmp1=='e'||tmp1=='i'||
tmp1=='o'||tmp1=='u')
cout <<tmp1))
{ if (tmp1=='A'||tmp1=='E'||tmp1=='I'||
tmp1=='O'||tmp1=='U')
cout << "\n Upper case vowel "<<tmp1;
else
cout<<"\n Lower case consonants "<<tmp1;
}
}
}
afile.close();
break;
case '3' : ofile.open("smp.txt",ios::in);
afile.open("smp1.txt",ios::out);
char c;
while(ofile)
{ ofile.get(c);
c = tolower(c);
if (c=='a'||c=='i'||c=='e'||c=='o'||c=='u')
afile.put(c);
}
ofile.close();
afile.close();
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}

OUTPUT:

PROGRAM-12
Menu driven program to define the various classes to
access data
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class person{ char name[21];
int age;
public:
void indata()
{cout<<"\nEnter the name of Student: " ;
gets(name);
cout<<"\nEnter the age : ";
cin>>age;
}
void outdata();
};
void person::outdata() // since the function contains loop so it is not made
inline
{ cout<<"\n\n";
for(int i=0; i<79; i++)
cout<<"-";
cout<<"\nName of the student is: "<<name;
cout<<"\nAge of the student is : "<<age;
}
class game {
char game_name[20];
public:
void input()
{ cout<<"\nEnter the game name : ";
cin.get();cin.getline(game_name,20);
}
void output()
{ cout<<"\nGame opted by the student is : "<<game_name;
}
};
class student: public person, public game
{ float Tmarks;
int rollno;
public:
char calgrade()
{if(Tmarks>90)
return 'A';
else if(Tmarks>80&&Tmarks<=90)
return 'B';
else if(Tmarks>70&&Tmarks<=80)
return 'C';
else if(Tmarks>60&&Tmarks<=70)
return 'D';
else
return 'E';
} void enter()
{ indata(); // indata() of class
person called here
cout<<"\nEnter the roll number: "; cin>>rollno;
input(); // input() of class
game called here
cout<<"\nEnter total marks (out of 100) : ";
cin>>Tmarks;
}
void display()
{ outdata();
cout<<"\nRoll number : "<<rollno;
output();
cout<<"\nTotal marks are : "<<Tmarks;
cout<<"\nGrade = "<<calgrade();
}
};
void main()
{ clrscr();
student A;
A.enter();
A.display();
getch();
}
OUTPUT:

PROGRAM-13
Menu driven program of telephone directory using data
handling
# include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
class telephone
{ char name[30];
char address[50];
double tno;
public :
void input()
{ cout<<"\n Enter the name ";
gets(name);
cout << "\n Enter address ";
gets(address);
cout<<"\n Enter the telephone number ";
cin>>tno;
}
void show()
{ cout << "\n Name "<<name;
cout << "\n Address "<<address;
}
double rt_tno()
{return tno;
}
}tele;
void append() // Function to append the
records in file
{ ofstream tfile;
telephone tele;
tfile.open("tele.dat", ios :: app);
int n,i;
cout<< "Enter how many customers ";
cin>>n;
for (i =0; i<n ;i++)
{ tele.input();
tfile.write((char *)& tele,sizeof(tele)); }
tfile.close();
}
void display() // Function to search a record in the
file
{ ifstream tfile;
tfile.open("tele.dat",ios :: binary);
int no,flag;
flag = 0;
cout<< "\n Enter telephone number to be searched ";
cin>>no;
while(tfile)
{ tfile.read((char *)&tele , sizeof(tele));
if(!tfile)
break;
if (tele.rt_tno() == no)
{ tele.show();
flag = 1; }
}if (flag == 0)
cout<< "\n Record does not exist ";
}
void main()
{ clrscr();
int ch;
char ch1;
do { cout << "1. For append record ";
cout <<"\n2. For search ";
cout << "\n3. For exit";
cout<<"Enter your choice: ";
cin >> ch;
switch (ch)
{ case 1: append();
break;
case 2: display();
break;
case 3 : exit(0);
}cout<<"\n\t DO U want to continue <Y/N>: ";
cin>>ch1;
}while(tolower(ch1)!='n');}

OUTPUT:

PROGRAM-14
Menu driven program of blood bank using data handling

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
class donor
{
char name[30];
char address[30];
char bgroup[5];
public:
void input()
{
cout<<"\nEnter Donor Name: ";
gets(name);
cout<<"Enter Address: ";
gets(address);
cout<<"Enter Blood Group: ";
gets(bgroup);
}
void display()
{
cout<<"\nDonor Name: "<<name<<"\tAddress:
"<<address<<"\tBlood Group: "<<bgroup<<"\t";

}
char *getbgroup()
{
return bgroup;
}

};
void main()
{
clrscr();
donor d;
int n,i,j;
fstream ofile,afile;

char ch,ch1;

do
{
cout<<"\n\t1.Add records\n\t2.Search Records\n\t3.List
Records\n\t4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("dnr.dat",ios::out|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
d.input();
ofile.write((char*)&d,sizeof(donor));
}
ofile.close();
break;
case '2' : cout<<"\nEnter Blood Group to be searched: ";
char bg[5],flag=0;
gets(bg);
afile.open("dnr.dat",ios::in);
while(afile)
{
afile.read((char *)&d,sizeof(donor));
if(!afile)
break;
if (strcmp(bg,d.getbgroup())==0)
{
d.display();
flag=1;

}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
afile.open("dnr.dat",ios::in);
while(afile)
{afile.read((char *)&d,sizeof(donor));
if(!afile)
break;
d.display();
}
afile.close();
break;

case '4' : exit(0);


}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}

OUTPUT:
PROGRAM-15
Menu driven program to define class assign values
respectively

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
class Clothing
{ char Code[15];
char Type[15];
int Size;
char Material[20];
float Price;
public:
Clothing() // Constructor to assign initial
values
{ strcpy(Code, "NOT ASSIGNED");
strcpy(Type, "NOT ASSIGNED");
strcpy(Material, "NOT ASSIGNED");
Size = 0;
Price = 0;
}
void CalPrice() // Function to calculate value
{ if (strcmp(Material, "COTTON") == 0)
{ Price = 1500;
}
else
if (strcmp(Material, "SHIRT") == 0)
{ Price = 1200 - (1200 * (25/100));
}
}
void Enter() //Function to input the values
{
cout << "Enter code : ";
gets(Code);
cout << "Enter type : ";
gets(Type);
cout << "Enter size : ";
cin >> Size;
cout << "Enter Material : ";
gets(Material);
CalPrice();
}
void Show()// Function to display values
{ cout << "Code : ";
puts(Code);
cout << "Type : ";
puts(Type);
cout << "Size : " << Size << endl;
cout << "Material : ";
puts(Material);
cout << "Price : " << Price;
}
};
void main()
{ clrscr();
Clothing C;
C.Enter();
C.Show();
}

OUTPUT:

PROGRAM-16
Menu driven program to add queue, delete and show
queue
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
// Declares a queue structure
struct node
{
int Eno;
float Salary;
node *link;
};
// Functions prototype to add queue, delete queue, and show queue
node *add_Q(node *rear, int val,float val1); // Add queue
node *del_Q(node *front, int &val, float &val1);// Delete queue
void show_Q(node *front); // Show queue
// Main programming logic
void main()
{
node *front, *rear;
int val;
float val1;
int choice;
char opt = 'Y'; // To continue the do loop in case
front = rear = NULL; // Initialization of Queue
clrscr();
do
{
cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Queue";
cout << "\n\t2. Deletion from Queue";
cout << "\n\t3. Traverse of Queue";
cout << "\n\t4. Exit from Menu";
cout << "\n\nEnter Your choice from above ";
cin >> choice;
switch (choice)
{case 1: do
{cout << "Enter the value to be added in the queue ";
cin >> val;
cin >> val1;
rear = add_Q(rear, val,val1);
if (front == NULL)
front = rear;
cout << "\nDo you want to add more element <Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2: opt = 'Y'; // Initialize for the second loop
do
{front = del_Q(front, val, val1);
if (front == NULL)
rear = front;
if (val != -1)
cout << "Value deleted from Queue is " << val;
cout << "\nDo you want to delete more element <Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3: show_Q(front);
break;
case 4:
exit(0);
}
} while (choice != 4);

node *add_Q(node *rear, int val, float val1) // Function body to add queue
elements
{ node *temp;
temp = new node;
temp->Eno = val;
temp->Salary = val1;
temp->link = NULL;
rear->link = temp;
rear = temp;
return (rear);
}
node *del_Q(node *front, int &val, float &val1) //Function body to delete
queue elements
{ node *temp;
clrscr();
if (front == NULL)
{ cout << "Queue Empty ";
val = -1;
}
else
{ temp = front;
front = front->link;
val = temp->Eno;
val1 = temp->Salary;
temp->link = NULL;
delete temp;
}
return (front);
}
// Function body to show queue elements
void show_Q(node *front)
{ node *temp;
temp = front;
clrscr();
cout << "The Queue values are";
while (temp != NULL)
{ cout <<"\nENO : "<< temp->Eno;
cout <<"\nSalary : "<<temp->Salary;
temp = temp->link;
}
}
OUTPUT:

PROGRAM-17
Menu driven program to add stack, delete and show stack
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
// Declares a stack structure
struct node
{ int roll;
int age;
node *link;
};
// Function prototype declaration for add stack, delete stack, and show stack
node *push(node *top, int val, int tage); // Add stack
node *pop(node *top); // Delete stack
void show_Stack(node *top); // Show stack
// Main programming logic
void main()
{ node *top;
int troll, tage, choice;
char opt = 'Y'; // To continue the do loop in case
top = NULL; // Initialization of Stack
clrscr();
do
{ cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Stack";
cout << "\n\t2. Deletion from Stack";
cout << "\n\t3. Traverse of Stack";
cout << "\n\t4. Exit from Menu";
cout << "\n\nEnter your choice from above ";
cin >> choice;
switch (choice)
{case 1:
do
{cout << "Enter the roll no. : ";
cin >> troll;
cout << "Enter age : ";
cin >> tage;
top = push(top, troll, tage);
cout << "\nDo you want to add more elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y'; // Initialize for the second loop
do
{top = pop(top);
if (troll != -1)
cout << "Value deleted from Stack is " << troll;
cout << "\nDo you want to delete more elements <Y/N> ?
";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3: show_Stack(top);
break;
case 4: exit(0);
}
}
while (choice != 4);
}
// Function body for adds stack elements
node *push(node *top, int val, int tage)
{ node *temp;
temp = new node;
temp->roll = val;
temp->age = tage;
temp->link = NULL;
if(top ==NULL)
top = temp;
else
{
temp->link = top;
top = temp;
}
return(top);
}
// Function body for delete stack elements
node *pop(node *top)
{ node *temp;
int tage, troll;
clrscr();
if (top == NULL )
{ cout << "Stack Empty ";
troll = -1;
}
else
{ temp = top;
top = top->link;
troll = temp->roll;
tage = temp->age;
temp->link = NULL;
cout << "\n\tPopped Roll Number is : " << temp->roll;
cout << "\n\tPopped Age is : " << temp->age;
delete temp;
}
return (top);
}
// Function body for show stack elements
void show_Stack(node *top)
{ node *temp;
temp = top;
clrscr();
cout << "The values are \n";
while (temp != NULL)
{ cout << "\n" << temp->roll << "\t" << temp->age;
temp = temp->link;
}
}

OUTPUT:

PROGRAM-18
Menu driven program to add, delete and show circular
queue
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 20 // Show maximum array length
char queue[MAX]; // Declares array global variable
int front, rear; // Declares integer front and read
// Function prototypes to add queue, delete queue and show queue in array
implementation
void add_Q(char queue[], int front, char val, int &rear); // Add queue
char del_Q(char queue[], int &front, int rear); // Delete queue
void show_Q(char queue[], int front, int rear); // Show queue
void main()
{int choice;
char val;
char opt = 'Y'; // To continue the do loop in case
rear = -1; // Initialization of Queue
front = -1;
clrscr();
do{ cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Queue";
cout << "\n\t2. Deletion from Queue";
cout << "\n\t3. Traverse of Queue";
cout << "\n\t4. Exit from Menu";
cout << "\n\nEnter Your choice from above ";
cin >> choice;
switch (choice)
{case 1: do
{cout << "Enter the value to be added in the queue ";
cin >> val;
add_Q(queue, front, val, rear);
cout << "Do you want to add more element <Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2: opt = 'Y'; // Initialize for the second loop
do
{val = del_Q(queue, front, rear);
if (val != -1)
cout << "Value deleted from Queue is " << val;
cout << "\nDo you want to delete more element <Y/N>? ";
cin >> opt;
}while (toupper(opt) == 'Y');
break;
case 3: show_Q(queue, front, rear);
break;
case 4:exit(0);
}
while (choice != 4);
}
void add_Q // Function body to add circular queue with array of
character
if ((rear + 1) % MAX == front) (char queue[], int front, char val, int
&rear)
{ cout << "Queue Full ";
}
else
{ rear = (rear + 1) % MAX;
queue[rear] = val;
}
}
char del_Q(char queue[], int &front, int rear) // Function body to delete
circular queue { char value;
if (front == rear)
{
cout << "Queue Empty ";
value = -1;
}
else
{
front = (front + 1) % MAX;
value = queue[front];
}
return (value);
}
// Function body to show circular queue with array
void show_Q(char queue[], int front, int rear)
{ clrscr();
cout << "The values are ";
do
{ front = (front + 1) % MAX;
cout << "\n" << queue[front];
}while(front != rear);
}

OUTPUT:
PROGRAM-19
Program to define a class employee and call it using constructor
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
const int LEN=25;
class employee{ char name[LEN];
unsigned long enumb;
public:
void getdata()
{ cout<<"Enter the name : ";
cin.get();cin.getline(name,LEN);
cout<<"\n\nEnter the employee number :";
cin>>enumb;
}
employee()
{delay(1000);cout<<"\n\nCalling Constructor of base class .";}
~employee()
{ delay(1000);cout<<"\n\nDeallocating the object of base
class.";getch();}
void putdata()
{ cout<<"\n\nName : "<<name;
cout<<"\n\nEmployee number : "<<enumb;
cout<<"\n\nBasic salary : "<<basic;
}
protected:
float basic;
void getbasic()
{cout<<"\n\nEnter basic : "; cin>>basic;
}
};

class manager : public employee { char title[LEN];


public:
void getdata()
{ employee::getdata();
getbasic();
cout<<"\n\nEnter title : ";
cin.get();cin.getline(title,80);
}
manager()
{delay(1000);cout<<"\n\nCalling constructor in
derived class";
}

~manager()
{ delay(1000);
cout<<"\n\nDeallocating the object of
derived class."; }
void putdata ()
{ employee::putdata();
cout<<"\n\nTitle : "<<title;
}
};
void main()
{ clrscr();
manager m1,m2;
cout<<"\n\nManager 1 : \n"; m1.getdata();
cout<<"\n\nManager 2 : \n"; m2.getdata();
cout<<"\n\n\n\nManager 1 Details :\n"; m1.putdata();
cout<<"\n\n\n\nManager 2 Details :\n"; m2.putdata();
getch();}

OUTPUT:

PROGRAM-20
Menu driven program to read file and copy in another file
#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct sports { char event[20];
char participants[10][30];
int no_of_participants;
} s[20], s2[20];
void copy(fstream &ob);
int i=0;
void main()
{clrscr();
char choice;
fstream ob("sports.dat",ios::binary|ios::in|ios::out);
do{if(i>0)
cin.get();
cout<<"\n\nEnter the name of Event : ";
cin.getline(s[i].event,20);
cout<<"\n\nEnter the total number of participants in Event "<<s[i].event<<" : ";
cin>>s[i].no_of_participants;
cout<<"\n\nEnter the name of Praticipants : \n";
cin.get();
for(int j=0; j<s[i].no_of_participants; j++)
cin.getline(s[i].participants[j],30);
ob.write((char*)&s[i], sizeof(sports));
cout<<"\n\n\nWant to Enter Details of Another Event (Y/N) : ";
cin>>choice;
i++;
} while(choice=='y'||choice=='Y');
cout<<"\n\n\n\n\n***********************************************\n\n";
copy(ob);
cout<<"\n\n****************************************************\n\n\n";
getch();}
void copy(fstream &o)
{sports s[20];
o.seekg(0);
ofstream file;
file.open("athletic.dat",ios::binary);
file.seekp(0);
int j,n=0;
int c=0;
while(o)
{ o.read((char*)&s[c], sizeof(sports));
if(strcmp("athletic",s[c].event)==0)
file.write((char*)&s[c], sizeof(sports));
break;}
c++;
}
if(n==0)
{cout<<"\n\nUnsuccessful Search.";
getch();
exit(0);
}
o.close();
file.close();
sports sp;
ifstream oo;
oo.open("athletic.dat",ios::binary);
while(oo)
{oo.read((char*)&sp, sizeof(sports));
}
cout<<"\n\nThe Records of file are : \n\n";
cout<<"\n\nEvent = "<<sp.event;
cout<<"\n\n\n\nThe Participants are : \n\n";
for(int i=0; i<sp.no_of_participants; i++)
{cout<<sp.participants[i]<<"\n\n";
}
oo.close();
remove("athletic.dat");
remove("sports.dat");
}

OUTPUT:

SQL COMMANDS:
1. TO CREATE TABLE SENDER1

CREATE TABLE SENDER1


(SENDERID CHAR(10) PRIMARY KEY,
SENDERNAME CHAR(10) NOT NULL,
SENDERADDRESS CHAR(20) NOT NULL,
SENDERCITY CHAR(10) NOT NULL);

2. TO INSERT VALUES IN SENDER1 AND RECIPIENT1

INSERT INTO SENDER1


VALUES('ND01','R JAIN','2,ABC APPTS','NEW DELHI');

INSERT INTO SENDER1


VALUES('MU02','H SINHA','12,NEW TOWN','MUMBAI')
INSERT INTO SENDER1
VALUES('MU15','S JHA','27/A PARK STREET','MUMBAI')
INSERT INTO SENDER1
VALUES('ND50','T PRASAD','122-K,SDA','NEW DELHI')

==================================================
================
OUTPUT:

SENDERID SENDERNAME SENDERADDRESS SENDERCITY


---------- ---------- -------------------- ----------
ND01 R JAIN 2,ABC APPTS NEW DELHI
MU02 H SINHA 12,NEW TOWN MUMBAI
MU15 S JHA 27/A PARK STREET MUMBAI
ND50 T PRASAD 122-K,SDA NEW DELHI

==================================================
================
INSERT INTO RECIPIENT1
VALUES('KO05','ND01','R BAJPAYEE','5,CENTRAL AVENUE','KOLKATA');

INSERT INTO RECIPIENT1


VALUES('ND08','MU02','S MAHAJAN','116,A VIHAR','NEW DELHI')

INSERT INTO RECIPIENT1


VALUES('MU19','ND01','H SINGH','2A,ANDHERI EAST','MUMBAI')

INSERT INTO RECIPIENT1


VALUES('MU32','MU15','P K SWAMY','B5,C S TERMINUS','MUMBAI')

INSERT INTO RECIPIENT1


VALUES('ND48','ND50','S TRIPATHI','13,MAYUR VIHAR','NEW DELHI')

INSERT INTO RECIPIENT1


VALUES('KO05','ND01','R BAJPAYEE','5,CENTRAL AVENUE','KOLKATA');
==================================================
================
OUTPUT:
RECID SENDERID RECNAME RECADDRESS RECCITY
----- ---------- ---------- -------------------- ----------
KO05 ND01 R BAJPAYEE 5,CENTRAL AVENUE KOLKATA
ND08 MU02 S MAHAJAN 116,A VIHAR NEW DELHI
MU19 ND01 H SINGH 2A,ANDHERI EAST MUMBAI
MU32 MU15 P K SWAMY B5,C S TERMINUS MUMBAI
ND48 ND50 S TRIPATHI 13,MAYUR VIHAR NEW DELHI
3. TO DISPLAY SENDERNAME WHOSE CITY IS MUMBAI

SELECT SENDERNAME FROM SENDER


WHERE SENDERCITY='MUMBAI';

OUTPUT:
SENDERNAME
----------
H SINHA
S JHA
==================================================
=================
4. TO DISPLAY RECID, SENDERNAME, SENDER ADDRESS,
RECNAME, RECADDRESS

SELECT RECID,SENDERNAME,SENDERADDRESS,RECNAME,RECADDRESS
FROM SENDER1,RECIPIENT1
WHERE SENDER1.SENDERID=RECIPIENT1.SENDERID

OUTPUT:

RECID SENDERNAME SENDERADDRESS RECNAME RECADDRESS


----- ---------- -------------------- ---------- -----------------
KO05 R JAIN 2,ABC APPTS R BAJPAYEE 5,CENTRAL AVENUE
ND08 H SINHA 12,NEW TOWN S MAHAJAN 116,A VIHAR
MU19 R JAIN 2,ABC APPTS H SINGH 2A,ANDHERI EAST
MU32 S JHA 27/A PARK STREET P K SWAMY B5,C S TERMINUS
ND48 T PRASAD 122-K,SDA S TRIPATHI 13,MAYUR VIHAR

5. TO DISPLAY ALL DETAILS IN ASCENDING ORDER


SELECT * FROM RECIPIENT1
ORDER BY RECNAME;
OUTPUT:
RECID SENDERID RECNAME RECADDRESS RECCITY
----- ---------- ---------- -------------------- ----------
MU19 ND01 H SINGH 2A,ANDHERI EAST MUMBAI
MU32 MU15 P K SWAMY B5,C S TERMINUS MUMBAI
KO05 ND01 R BAJPAYEE 5,CENTRAL AVENUE KOLKATA
ND08 MU02 S MAHAJAN 116,A VIHAR NEW DELHI
ND48 ND50 S TRIPATHI 13,MAYUR VIHAR NEW DELHI
==================================================
==================
6. TO COUNT CITY FROM RECIPIENT1
SELECT RECCITY,COUNT(RECCITY) FROM RECIPIENT1
GROUP BY RECCITY
OUTPUT:
RECCITY COUNT(RECCITY)
---------- --------------
KOLKATA 1
MUMBAI 2
NEW DELHI 2
==================================================
==================
7. TO DISPLAY ALL DETAILS WHOSE SENDERID IS ND50
SELECT * FROM SENDER1
WHERE SENDERID='ND50'

OUTPUT:
SENDERID SENDERNAME SENDERADDRESS SENDERCITY
---------- ---------- -------------------- ----------
ND50 T PRASAD 122-K,SDA NEW DELHI
==================================================
==================
8. TO DELETE RECORDS WHOSE SENDERID IS MU15
DELETE FROM SENDER1
WHERE SENDERID='MU15';
SELECT * FROM SENDER1;
OUTPUT:
SENDERID SENDERNAME SENDERADDRESS SENDERCITY
---------- ---------- -------------------- ----------
ND01 R JAIN 2,ABC APPTS NEW DELHI
MU02 H SINHA 12,NEW TOWN MUMBAI
ND50 T PRASAD 122-K,SDA NEW DELHI

==================================================
=================

9. TO DISPLAY DISTINCT CITY FROM SENDER1


SELECT DISTINCT SENDERCITY FROM SENDER1;

OUTPUT:
SENDERCITY
----------
MUMBAI
NEW DELHI
==================================================
==================
10. TO DISPLAY NAME FROM SENDER1,RECIPIENT1 WHOSE
CITY IS MUMBAI

SELECT A.SENDERNAME,B.RECNAME FROM SENDER1 A,RECIPIENT1 B


WHERE A.SENDERID=B.SENDERID AND B.RECCITY='MUMBAI'

OUTPUT:
SENDERNAME RECNAME
---------- ----------
R JAIN H SINGH
==================================================
==================
11. TO DISPLAY NAME AND ADDRESS WHOSE CITY IS NOT IN
MUMBAI AND KOLKATA

SELECT RECNAME,RECADDRESS FROM RECIPIENT1


WHERE RECCITY NOT IN('MUMBAI','KOLKATA')

OUTPUT:
RECNAME RECADDRESS
---------- --------------------
S MAHAJAN 116,A VIHAR
S TRIPATHI 13,MAYUR VIHAR
==================================================
==================
12. TO DISPLAY ID AND NAME FROM RECIPIENT1 WHOSE ID IS
BETWEEN MU02 AND ND50
SELECT RECID,RECNAME FROM RECIPIENT1
WHERE SENDERID='MU02' OR SENDERID='ND50';

OUTPUT:
RECID RECNAME
----- ----------
ND08 S MAHAJAN
ND48 S TRIPATHI
==================================================
==================
13. TO COUNT THE NUMBER OF CITY FROM SENDER1

SELECT SENDERCITY,COUNT(*) FROM SENDER1


GROUP BY SENDERCITY;
OUTPUT:
SENDERCITY COUNT(*)
---------- ----------
MUMBAI 1
NEW DELHI 2

==================================================
==================
14. TO UPDATE THE CITY TO AHMEDABAD WHOSE ID IS
MU02

UPDATE SENDER1
SET SENDERCITY='AHMEDABAD'
WHERE SENDERID='MU02';
OUTPUT:
SELECT * FROM SENDER1;

SENDERID SENDERNAME SENDERADDRESS SENDERCITY


---------- ---------- -------------------- ----------
ND01 R JAIN 2,ABC APPTS NEW DELHI
MU02 H SINHA 12,NEW TOWN AHMEDABAD
ND50 T PRASAD 122-K,SDA NEW DELHI
==================================================
=================
15. TO DELETE THE TABLE
16.
DROP TABLE SENDER1;

OUTPUT:

Table dropped.

==================================================
=================