SlideShare uma empresa Scribd logo
1 de 87
Baixar para ler offline
/* Write a program to find out the two digit numbers in an array? */
#include<iostream.h>
#include<conio.h>
void twodigit(int a[10][10],int m,int n)
{
int i,j,flag=0;
cout<<"The Two digit Numbers are: ";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(a[i][j]>=10&&a[i][j]<=99)
{
cout<<a[i][j]<<ends;
flag=1;
}
}
if(flag==0)
cout<<"None";
}
void main()
{
clrscr();
int a[10][10],i,j,m,n;
cout<<"n EnterNo. of rows: ";
cin>>m;
cout<<"nEnter the no. of columns: ";
cin>>n;
cout<<"nEnter the Elements of the array: ";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
twodigit(a,m,n);
getch();
}
/***********************OUTPUT***********************************
EnterNo. of rows: 2
Enter the no. of columns: 2
Enter the Elements of the array: 1 2 3
4 5 6
The Two digit Numbers are: None
**************************************** */
/* WAP to find the stream of engineering a student goes (Using OOP). According to following guidelines:
marks>=96 computer sc
marks>=91&marks<=95 Electronics
marks>=86&marks<=90 Mechanical
marks>=81&marks<=85 Electrical
marks>=76&marks<=80 Chemical
marks>=71&marks<=75 Civil
marks<70 none */
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.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<<"nt1.Add recordsnt2.Show Recordsnt3.Exit";
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<<"nNametRollnotMarkstStream";
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<<"nt DO U want to continue ";
cin>>ch1;
}while(ch1=='Y');
getch();
}
/********************** OUTPUT *********************************
1.Add records
2.Show Records
3.Exit
2
Name Rollno Marks Stream
Ayshkant 5 90 Mechanical
Shuvam 6 70 none
Bhabesh 1 78 Chemical
DO U want to continue n
*********************************************** */
/* WAP to enter and display the following details of employee in tabular form (in class)
Employee No.
Employee Name
Salary */
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<iomanip.h>
class employee
{
int eno;
char name[30];
float salary;
public :
void input()
{
cout << "Enter Employee Number ";
cin >>eno;
cout << "Enter name ";
gets(name);
cout << "Enter salary ";
cin >>salary;
}
void show()
{
cout << eno << setw(20)<<name<<setw(20)<<salary<<endl;
}
float rt_sal()
{
return salary;
}
}emp[10];
main()
{
int n,ch,i,j;
char choice;
do
{
clrscr();
cout << "1. For enter "<<endl;
cout << "2. For tabular report"<<endl;
cout << "3. For exit";
cin >> ch;
switch(ch)
{
case 1: cout << "Enter how many employees ";
cin >>n;
for(i=0;i<n;i++)
{
emp[i].input();
}
break;
case 2:
employee temp;
for (i=0;i<n;i++)
{
for(j=i;j<n-1;j++)
{
if (emp[j].rt_sal()>emp[j+1].rt_sal())
{
temp = emp[j];
emp[j]=emp[j+1];
emp[j+1]=temp;
}
}
}
gotoxy(6,6);
cout <<"Employee Number ";
gotoxy(26,6);
cout <<"Name";
gotoxy(46,6);
cout <<"Salary"<<endl;
int r = 8;
for(i=0;i<n;i++)
{ emp[i].show();
r++;
}
break;
case 3: exit(0);
}
cout << "n Do U want to continue";
cin>>choice;
}while(choice == 'Y' ||choice =='y');
}
/******************************** OUTPUT *******************************
1. For enter
2. For tabular report
3. For exit
2
Employee Number Name Salary
1 Dan 700
2 Nick 900
Do U want to continue n
*************************************************************** */
/* WAP to find the no. of words, vowels, numbers in a given 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<<"nt1.Create Textnt2.Count vowels/words/digitsnt3.Show Textnt4.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<<"nt DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/********************* OUTPUT ************************************
1.Create Text
2.Count vowels/words/digits /*
3.Show Text
4.Exit
1
Enter The Text india
DO U want to continue y
1.Create Text
2.Count vowels/words/digits
3.Show Text
4.Exit
2
No of Vowels: 3
No of digits: 1
No of words: 0
DO U want to continue y
1.Create Text
2.Count vowels/words/digits
3.Show Text
4.Exit
3
Formatted text: indiaÿÿ
DO U want to continue n
******************************************************** */
/* WAP to create a text and find the upper case and lower case constants and vowels? */
#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<<"nt1.Create Textnt2.Read from Filent3.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;
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 << "n Lower case vowel "<<tmp1;
else
cout<<"n Lower case consonants "<<tmp1;
}
if (isupper(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<<"nt DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/******************* OUTPUT **************************************
1.Creat Text
2.Read from file
3.creat another file
4.Exit
1
Enter The Text I am the King
DO U want to continue Y
1.Create Text
2.Read from File
3.create another file
4.Exit
2
Upper case vowel I
Lower case vowel a
Lower case consonants m
Lower case consonants t
Lower case consonants h
Lower case vowel e
Lower case consonants K
Lower case vowel i
Lower case consonants n
Lower case consonants g
DO U want to continue n
********************************************************** */
/* WAP to append record and search in a telephone directory? */
# include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.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;
// Function to append the records in file
void append()
{
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();
}
// Function to search a record in the file
void display()
{
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;
cout << " 1. For append record ";
cout <<"n 2. For search ";
cout << "n 3. For exit";
cin >> ch;
switch (ch)
{
case 1: append();
break;
case 2: display();
break;
case 3 : exit(0);
}
}
/***************************OUTPUT***************************
1. For append record
2. For search
3. For exit
1
Enter how many customers 2
Enter the name Dan
Enter address KNAGAR
Enter the telephone number 223344
Enter the name mak
Enter address MNAGAR
Enter the telephone number 334455
Do Yoy want to cotinue y
1. For append record
2. For search
3. For Exit
2Enter the number to be searched 556677
Record does not exist
Do you want to continue n
********************************************************* */
/* WAP to record the blood donor’s name, address and blood group and search by the blood group when
required? */
#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<<"nt1.Add recordsnt2.Search Recordsnt3.List Recordsnt4.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<<"nt DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/**********************OUTPUT***************************************
1.Add records
2.Search Records
3.List Records
4.Exit
1
Enter no. of records to be Entered: 2
Enter Donor Name: Ayashkant
Enter Address: pl no. 820
Enter Blood Group: B+
Enter Donor Name: Swaraj
Enter Address: Pl. 98
Enter Blood Group: A+
DO U want to continue y
1.Add records
2.Search Records
3.List Records
4.Exit
2
Enter Blood Group to be searched: O+
No record Found
DO U want to continue
N
****************************************** */
/* WAP in C++ to record the book no., book name and price and search by its number when required (USING
CLASS)? */
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class book
{
char bname[30];
int bno;
float price;
public:
void input()
{
cout<<"nEnter Book Name: ";
gets(bname);
cout<<"Enter BOOK No.: ";
cin>>bno;
cout<<"Enter Price";
cin>>price;
}
void setprice()
{
cout<<"nEnter Price";
cin>>price;
}
void display()
{
cout<<"nBook Name: "<<bname<<"tBook No.: "<<bno<<"tPrice: "<<price<<"t";
}
int getbno()
{
return bno;
}
};
void main()
{
clrscr();
book b;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do{
cout<<"nt1.Add recordsnt2.Search Recordsnt3.Modify Recordsnt4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("bk.dat",ios::out|ios::binary);
cout<<"nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
b.input();
ofile.write((char*)&b,sizeof(book));
}
ofile.close();
break;
case '2' : cout<<"nEnter Book No. to be searched: ";
int bn,flag=0;
cin>>bn;
afile.open("bk.dat",ios::in);
while(afile)
{
afile.read((char *)&b,sizeof(book));
if(!afile)
break;
if (bn==b.getbno())
{
b.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"n No record Found";
afile.close();
break;
case '3' :
cout<<"nEnter Book No. to be modified ";
int bn1,flag1=0,r=0;
cin>>bn1;
afile.open("bk.dat",ios::in|ios::out|ios::binary);
while(afile)
{
afile.read((char *)&b,sizeof(book));
if(!afile)
break;
if (bn1==b.getbno())
{
b.setprice();
afile.seekp(r*sizeof(b),ios::beg);
afile.write((char *)&b,sizeof(book));
flag1=1;
break;
}
r++;
}
if(flag1==0)
cout<<"n No record Found";
afile.close();
break;
case '4' : exit(0);
}
cout<<"nt DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/****************************OUTPUT**********************
1.Add records
2.Search Records
3.Modify Records
4.Exit
1
Enter no. of records to be Entered: 2
Enter Book Name: The Wolf Of The Wallstreet
Enter BOOK No.: 34
Enter Price 50
Enter Book Name: The Oath Of The Vayuputra
Enter BOOK No.: 47
Enter Price 8
DO U want to continue y
1.Add records
2.Search Records
3.Modify Records
4.Exit
2
Enter Book No. to be searched: 34
Book Name: The Wolf Of The Wallstreet Book No.: 34 Price: 50
DO U want to continue n
****************************************************** */
/* WAP to record the student name, roll no. and fees and display its details when searched by roll no.? */
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class students
{
char sname[30];
int sno;
float fees;
public:
void input()
{
cout<<"nEnter Student Name: ";
gets(sname);
cout<<"Enter Roll No.: ";
cin>>sno;
cout<<"Enter Fees: ";
cin>>fees;
}
void display()
{
cout<<"nStudent Name: "<<sname<<"tRoll No.: "<<sno<<"tFees: "<<fees<<"t";
}
int getsno()
{
return sno;}
};
void main()
{
clrscr();
students s;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"nt1.Add recordsnt2.Search Recordsnt3.Delete Recordsnt4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("std.dat",ios::out|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(students));
}
ofile.close();
break;
case '2' : cout<<"nEnter Roll No. to be searched: ";
int sn,flag=0;
cin>>sn;
afile.open("std.dat",ios::in);
while(afile)
{
afile.read((char *)&s,sizeof(students));
if(!afile)
break;
if (sn==s.getsno())
{
s.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"n No record Found";
afile.close();
break;
case '3' :
cout<<"nEnter Roll No. to be Deleted ";
int sn1,flag1=0;
cin>>sn1;
afile.open("std.dat",ios::in|ios::binary);
ofile.open("tmpstd.dat",ios::out|ios::binary);
while(afile)
{
afile.read((char *)&s,sizeof(students));
if(!afile)
break;
if (sn1==s.getsno())
{
flag1=1;
}
else
{
ofile.write((char *)&s,sizeof(students));
}
}
if(flag1==0)
cout<<"n No record Found";
afile.close();
ofile.close();
afile.open("tmpstd.dat",ios::in|ios::binary);
ofile.open("std.dat",ios::out|ios::binary);
while(afile)
{
afile.read((char *)&s,sizeof(students));
ofile.write((char *)&s,sizeof(students));
}
afile.close();
ofile.close();
break;
case '4' : exit(0);
}
cout<<"nt DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/************************OUTPUT*******************************
1.Add records
2.Search Records
3.Delet Records
4.Exit
1
Enter no. of records to be Entered: 2
Enter Student Name: Daniel
Enter Roll No.: 23
Enter Fees: 1200
Enter Student Name: Max
Enter Roll No.: 56
Enter Fees: 7890
DO U want to continue y
1.Add records
2.Search Records
3.Delete Records
4.Exit
2
Enter Roll No. to be searched: 23
Student Name: Daniel Roll No.: 23 Fees: 1200
DO U want to continue n
********************************************************* */
// This program illustrates the basic operation of add queue, delete queue and show queue
// using linked list.
#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 << "ntt Main Menu";
cout << "nt1. Addition of Queue";
cout << "nt2. Deletion from Queue";
cout << "nt3. Traverse of Queue";
cout << "nt4. Exit from Menu";
cout << "nnEnter 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);
}
// Function body to add queue elements
node *add_Q(node *rear, int val, float val1)
{
node *temp;
temp = new node;
temp->Eno = val;
temp->Salary = val1;
temp->link = NULL;
rear->link = temp;
rear = temp;
return (rear);
}
// Function body to delete queue elements
node *del_Q(node *front, int &val, float &val1)
{
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********************************
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 1
Enter the value to be added in the queue 234
567
Do you want to add more element <Y/N> n
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 2
The Queue values are
ENO : 234
Salary : 567
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 4
********************************************************************** */
/* WAP to add, delete and transverse stacks? */
#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 << "ntt Main Menu";
cout << "nt1. Addition of Stack";
cout << "nt2. Deletion from Stack";
cout << "nt3. Traverse of Stack";
cout << "“nt4. Exit from Menu";
cout << "nnEnter 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 << "ntPopped Roll Number is : " << temp->roll;
cout << "ntPopped 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***********************************
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack“
4. Exit from Menu
Enter your choice from above 1
Enter the roll no. : 1
Enter age : 15
Do you want to add more elements <Y/N> ? y
Enter the roll no. : 2
Enter age : 17
Do you want to add more elements <Y/N> ? n
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu
Enter your choice from above 3
The values are
2 17
1 15
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack“
4. Exit from Menu
Enter your choice from above 4
*********************************************************** */
/*This program illustrates the basic operation of circular to add queue, delete queue and show queue using
array. The queue contains data of type character. */
#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
ront = -1;
clrscr();
do
{
cout << "ntt Main Menu";
cout << "nt1. Addition of Queue";
cout << "nt2. Deletion from Queue";
cout << "nt3. Traverse of Queue";
cout << "nt4. Exit from Menu";
cout << "nnEnter 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);
}
// Function body to add circular queue with array of character
void add_Q(char queue[], int front, char val, int &rear)
{
if ((rear + 1) % MAX == front)
{
cout << "Queue Full ";
}
else
{
rear = (rear + 1) % MAX;
queue[rear] = val;
}
}
// Function body to delete circular queue with array of character
char del_Q(char queue[], int &front, int rear)
{
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************************************************ Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 1
Enter the value to be added in the queue 3
Do you want to add more element <Y/N>? n
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 4
**************************************************************************** */
/* Program to define the classes PERSON, GAME and STUDENT & to access the essential data using multiple
inheritance.*/
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class person{ char name[21];
int age;
public:
void indata()
{cout<<"nnEnter the name of Student: " ;
gets(name);
cout<<"nnEnter the age : ";
cin>>age;
}
void outdata();
};
void person::outdata() // since the function contains loop so it is not made inline
{
cout<<"nn";
for(int i=0; i<79; i++)
cout<<"-";
cout<<"nnName of the student is: "<<name;
cout<<"nnAge of the student is : "<<age;
}
class game {
char game_name[20];
public:
void input()
{
cout<<"nnEnter the game name : ";
cin.get();cin.getline(game_name,20);
}
void output()
{
cout<<"nnGame 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<<"nnEnter the roll number: "; cin>>rollno;
input(); // input() of class game called here
cout<<"nnEnter total marks (out of 100) : ";
cin>>Tmarks;
}
void display()
{
outdata();
cout<<"nnRoll number : "<<rollno;
output();
cout<<"nnTotal marks are : "<<Tmarks;
cout<<"nnGrade = "<<calgrade();
}
};
void main()
{ clrscr();
student A;
A.enter();
A.display();
getch();
}
/**************************OUTPUT*********************************
Enter the name of Student: Ayashkant Mishta
Enter the age : 16
Enter the roll number: 01
Enter the game name : Kabbadi
Enter total marks (out of 100) : 95
--------------------------------------------------------------------------------------------------------------------------------------------------------
------------
Name of the student is: Ayashkant Mishra
Age of the student is : 16
Roll number : 34
Game opted by the student is : Kabbadi
Total marks are : 95
Grade = A
****************************************************************** */
/* Wap in c++ to implement stack as an array */
#include<iostream.h>
#include<conio.h>
#include<process.h>
int pop(int[],int&);
int push(int[],int&,int);
void display(int[],int);
const int size=50;
void main()
{
clrscr();
char m,ch;
int k,stack[size],item,top=-1,res;
do
{ cout<<"nChoose from the following : nn"
<<"n 1. Push"
<<"n 2. Pop"
<<"n 3. Display"
<<"n 4. Exit"
<<"nnEnter your choice : "; cin>>k;
switch(k)
{
case 1: ch='y';
while(ch=='y'||ch=='Y')
{ cout<<"nEnter the element : ";
cin>>item;
res=push(stack,top,item);
if(res==-1)
{cout<<"nOverflow !!!!";
exit(1); }
cout<<"nThe stack formed is : nn";
display(stack,top);
cout<<"nnnWant to enter again ?: ";
cin>>ch;
}
break;
case 2: ch='y';
while(ch=='y'||ch=='Y')
{ res=pop(stack,top);
if(res==-1)
{
cout<<"nUnderflow !!!!";
exit(1);
}
else
{
cout<<"nThe deleted Element is : "<<res<<endl;
cout<<"nThe resultant stack is : nn";
display(stack,top); }
cout<<"nWant to delete again ? : ";
cin>>ch;
}
break;
case 3: cout<<"nThe resultant stack is : ";
display(stack,top);
break;
case 4: exit(0);
break;
default: cout<<"nPlease enter desired keyword : ";
} // end of switch
cout<<"nnChoose from the menu again ? : ";
cin>>m;
}while(m=='y'||m=='Y'); // end of do-while loop
getch();
} // end of main()
int push(int stack[],int &top,int el)
{
if(top==size-1)
return -1;
else
{
top++;
stack[top]=el;
return 0;
}
}
int pop(int stack[],int &top)
{
int ret;
if(top==-1)
return -1;
else
{
ret=stack[top];
top--;
return ret;
}
}
void display(int stack[],int top)
{
cout<<stack[top]<<"<--";
for(int i=top-1;i>=0;i--)
cout<<stack[i]<<"<--";
}
/************************************OUTPUT********************************************
Choose from the following :
1. Push
2. Pop
3. Display
4. Exit
Enter your choice : 1
Enter the element : 1
The stack formed is :
1 
Want to enter again ?: y
Enter the element : 2
The stack formed is :
2  1 
Want to enter again ?: y
Enter the element : 3
The stack formed is :
3 2  1 
Want to enter again ?: y
Enter the element : 4
The stack formed is :
4  3  2  1 
Want to enter again ?: N
Choose from the menu again ? : y
Choose from the following :
1. Push
2. Pop
3. Display
4. Exit
Enter your choice : 2
The deleted Element is : 4
The resultant stack is :
3  2  1 
Want to delete again ? : y
The deleted Element is : 3
The resultant stack is :
2  1 
Want to delete again ? : n
Choose from the menu again ? : y
Choose from the following :
1. Push
2. Pop
3. Display
4. Exit
Enter your choice : 3
The resultant stack is :
2 1 
Choose from the menu again ? : n
********************************************************************************** */
/* Wap to implement stack as a linked list */
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node {
int roll;
node* next;
}*top,*save,*ptr,*newptr,*np;
node *create(int a)
{
ptr=new node;
ptr->roll=a;
ptr->next=NULL;
return ptr;
}
void push(node *np)
{
if(top==NULL)
top=np;
else
{
save=top;
top=np;
np->next=save;
}
}
void pop()
{
if(top==NULL)
cout<<"n Underflow!!!!";
else
{
ptr=top;
top=top->next;
delete ptr;
}
}
void display(node *np)
{
while(np!=NULL)
{
cout<<np->roll<<" -> ";
np=np->next;
}
}
void main()
{
clrscr();
top=NULL;
int n,m;
char k,ch;
do {
cout<<"nChoose from the menu :n"
<<"n 1. Push."
<<"n 2. Pop."
<<"n 3. Display."
<<"n 4. Quit."
<<"nnEnter your choice : ";
cin>>n;
switch(n)
{
case 1: k='y';
while(k=='y'||k=='Y')
{
cout<<"n Enter element to be inserted .";
cin>>m;
newptr=create(m);
if(newptr==NULL)
cout<<"n Cannot create !!!!";
push(newptr);
cout<<"n The Stack formed is : ";
display(top);
cout<<"nn Want to enter again ?: ";
cin>>k;
}
break;
case 2: k='y';
while(k=='y'||k=='Y')
{
pop();
cout<<"n The Stack formed is : nn";
display(top);
cout<<"nn Want to delete again ?: ";
cin>>k;
}
break;
case 3: cout<<"n The Stack formed is : ";
display(top);
break;
case 4: exit(0);
break;
default: cout<<"n Please enter desired keyword : ";
}
cout<<"n Do you want to continue..? : ";
cin>>ch;
}while(ch=='y'||ch=='Y');
getch();
}
/*********************************************OUTPUT*****************************************
*****
Choose from the menu :
1. Push.
2. Pop.
3. Display.
4. Quit.
Enter your choice : 1
Enter element to be inserted : 1
The Stack formed is :
1 ->
Want to enter again ?: y
Enter element to be inserted : 2
The Stack formed is :
2 -> 1 ->
Want to enter again ?: y
Enter element to be inserted : 3
The Stack formed is :
3 -> 2 -> 1 ->
Want to enter again ?: n
Do you want to continue..? : y
Choose from the menu :
1. Push.
2. Pop.
3. Display.
4. Quit.
Enter your choice : 2
The Stack formed is :
2 -> 1 ->
Want to delete again ?: y
The Stack formed is :
1 ->
Want to delete again ?: N
Do you want to continue..? : y
Choose from the menu :
1. Push.
2. Pop.
3. Display.
4. Quit.
Enter your choice : 3
The Stack formed is :
1 ->
Do you want to continue..? : y
Choose from the menu :
1. Push.
2. Pop.
3. Display.
4. Quit.
Enter your choice : 4
*********************************************************************************** */
/* Wap in C++ to read file “sports.dat” and copy only those records where event name is ATHLETIC using the
concept of Data file handling. */
#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<<"nnEnter the name of Event : ";
cin.getline(s[i].event,20);
cout<<"nnEnter the total number of participants in Event "<<s[i].event<<" : ";
cin>>s[i].no_of_participants;
cout<<"nnEnter 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<<"nnnWant to Enter Details of Another Event (Y/N) : ";
cin>>choice;
i++;
} while(choice=='y'||choice=='Y');
cout<<"nnnnn******************************************************************************
******************************nn";
copy(ob);
cout<<"nn***********************************************************************************
******************************nnn";
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));
n=1;
break;
}
c++;
}
if(n==0)
{
cout<<"nnUnsuccessful 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<<"nnThe Records of file are : nn";
cout<<"nnEvent = "<<sp.event;
cout<<"nnnnThe Participants are : nn";
for(int i=0; i<sp.no_of_participants; i++)
{
cout<<sp.participants[i]<<"nn";
}
oo.close();
remove("athletic.dat");
remove("sports.dat");
}
/**************************************OUTPUT************************************************
**
Enter the name of Event : Cricket
Enter the total number of participants in Event Cricket : 3
Enter the name of Praticipants :
Rahul verma
Shivam
Siddharth
Want to Enter Details of Another Event (Y/N) : y
Enter the name of Event : athleltic
Enter the total number of participants in Event atlhletic : 2
Enter the name of Praticipants :
Mohak
Vikas
Want to Enter Details of Another Event (Y/N) : y
Enter the name of Event : Football
Enter the total number of participants in Event Football : 2
Enter the name of Praticipants :
Arsh
Ashu
Want to Enter Details of Another Event (Y/N) : n
*********************************************************************************************
************************************
The Records of file are :
Event = athletic
The Participants are :
Mohak
Vikas
*********************************************************************************************
************************************ */
/* Wap to print and find the sum of Fibonacci series using recursion. */
#include<iostream.h>
#include<conio.h>
int fibonacci(int n);
void main()
{
clrscr();
int n;
cout<<"nn Enter the number of terms upto which you want the sum of fibonnaci series : ";
cin>>n;
cout<<"nnThe fibonacci series generated is : nn";
cout<<"1 1 ";
int s=fibonacci(n);
cout<<"nnThe sum of fibonacci series for "<<n<<" terms = "<<s;
getch();
}
int first=1;
int second=1;
int third;
int i=2;
int sum=0;
int fibonacci(int n)
{ if(n==1)
sum=1;
else if(n==2)
sum=2;
// n = 1 2 3 4 5
else if(n>1 && i!=n) // num = 1 1 2 3 5
{
third=first+second;
cout<<third<<” “;
if(i==2)
sum+=first+second+third;
else
sum+=third;
first=second;
second=third;
++i;
fibonacci(n);
}
return sum;
}
/*****************************OUTPUT*******************************************
Enter the number of terms upto which you want the sum of fibonnaci series : 5
The fibonacci series generated is :
1 1 2 3 5
The sum of fibonacci series for 5 terms = 12
**************************************************************************************** */
/* Wap in C++ to print and find the sum of even /odd numbers using recursion.*/
#include<iostream.h>
#include<conio.h>
int sum_even(int );
int sum_odd(int );
int sum=0;
int num=0;
void main()
{ clrscr();
int n;
int s_e, s_o;
cout<<"nnEnter the number upto which you want the sum of even/odd numbers : ";
cin>>n;
cout<<"nn The list of integers is : nn";
for(int l=1; l<=n; l++)
cout<<l<<"n";
s_e=sum_even(n);
s_o=sum_odd(n);
cout<<"nnThe sum of even numbers upto "<<n<<" = "<<s_e;
cout<<"nnThe sum of odd numbers upto "<<n<<" = "<<s_o;
getch();
}
int sum_even(int n){
if(num%2==0)
sum=sum+num;
if(num!=n && num<n)
{
++num;
sum_even(n);
}
return sum;
}
int sum_2=0;
int num_2=0;
int sum_odd(int n)
{
if(num_2%2!=0)
sum_2=sum_2+num_2;
if(num_2!=n)
{
num_2++;
sum_odd(n);
}
return sum_2;
}
/*********************************OUTPUT**********************************************
Enter the number upto which you want the sum of even/odd numbers : 10
The list of integers is :
1
2
3
4
5
6
7
8
9
10
The sum of even numbers upto 10 = 30
The sum of odd numbers upto 10 = 25
**************************************************************************** */
/* WAP in c++ using pointers to find the smallest and the largest element in a dynamically created array?*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int *array, smallest, largest, n;
cout<<"nnEnter the number of elements : ";
cin>>n;
array=new[n];
cout<<"nnEnter the elements : nn";
for(int i=0; i<n; i++)
cin>>array[i];
i=0;
cout<<"nnThe array formed is : nn";
while(i!=n)
{
cout<<array[i]<<" ";
i++;
}
smallest=array[0];
for(i=0; i<n; i++)
{
if(array[i]<=smallest)
smallest=array[i];
}
largest=array[0];
for(i=0; i<n; i++)
{
if(array[i]>=largest)
largest=array[i];
}
cout<<"nnThe smallest element is : "<<smallest<<"nnThe largest element is : "<<largest;
getch();
}
/*********************************************OUTPUT*****************************************
*****************
Enter the number of elements : 5
Enter the elements :
1
9
2
8
6
The array formed is : 1 9 2 8 6
The smallest element is : 1
The largest element is : 9
************************************************************************************** */
/* Wap using pointers to swap two integers. */
#include<iostream.h>
#include<conio.h>
void swap_using_pointers(int *, int *);
void main()
{
clrscr();
int a,b;
cout<<"nnEnter first integer : "; cin>>a;
cout<<"nnEnter second integer : "; cin>>b;
swap_using_pointers(&a,&b);
cout<<"nnNow value of first integer = "<<a;
cout<<"nnNow value of second integer = "<<b;
getch();
}
void swap_using_pointers(int *a,int *b)
{
int temp;
temp=*a; *a=*b; *b=temp;
}
/*****************************************OUTPUT*********************************************
***
Enter first integer : 1
Enter second integer : 100
Now value of first integer = 100
Now value of second integer = 1
**************************************************************************** */
/* Wap using pointers to swap two integers. */
#include<iostream.h>
#include<conio.h>
void swap_using_pointers(int *, int *);
void main()
{
clrscr();
int a,b;
cout<<"nnEnter first integer : "; cin>>a;
cout<<"nnEnter second integer : "; cin>>b;
swap_using_pointers(&a,&b);
cout<<"nnNow value of first integer = "<<a;
cout<<"nnNow value of second integer = "<<b;
getch();
}
void swap_using_pointers(int *a,int *b)
{
int temp;
*a=*b; *b=temp; temp=*a;
}
/*****************************************OUTPUT*****************************
Enter first integer : 1
Enter second integer : 100
Now value of first integer = 100
Now value of second integer = 1
******************************************************************** */
/* WAP to create a text file(.txt) and display number of words, alphabets, vowels and consonants and number
of lowercase and uppercase letters using the concept of DATA FILE HANDLING? */
#include<fstream.h>
#include<string.h>
#include<ctype.h>
#include<conio.h>
void main()
{
clrscr();
char a[80];
int words=0, upper_letters=0, lower_letters=0, alpha=0, vowels=0,consonants=0;
ofstream string("str.txt");
cout<<"nnEnter the string : ";
cin.getline(a,79);
string<<"The string is : "<<a<<"nn";
for(int i=0; i<strlen(a); i++)
{
if(a[i]==' ')
while(a[i]==' ')
{
i++;
}
if(isalnum(a[i]))
{
while(a[i]!=' ')
{
i++;
}
words++;
}
}
string<<"nnThe number of words in string are : "<<words;
string<<"nnnAlphabets in string are : nn";
for(i=0; i<strlen(a); i++)
{
if(isalpha(a[i]))
{
alpha++;
string<<a[i]<<" ";
}
}
string<<"nnTotal number of alphabets in string => "<<alpha;
string<<"nnnUppercase letters in string are : nn";
for(i=0; i<strlen(a); i++)
{
if(isupper(a[i]))
{
upper_letters++;
string<<a[i]<<" ";
}
}
string<<"nnTotal number of uppercase letters in string => "<<upper_letters;
string<<"nnnLowercase letters in string are : nn";
for(i=0; i<strlen(a); i++)
{
if(islower(a[i]))
{
lower_letters++;
string<<a[i]<<" ";
}
}
string<<"nnTotal number of Lowercase letters in string => "<<lower_letters;
string<<"nnnVowels in string are : nn";
for(i=0; i<strlen(a); i++)
{
if(isalpha(a[i]))
{
if(a[i]=='a'||a[i]=='A'||a[i]=='e'||a[i]=='E'||a[i]=='i'||a[i]=='I'||a[i]=='o'||a[i]=='O'||a[i]=='u'||a[i]=='U')
{
vowels++;
string<<a[i]<<" ";
}
}
}
string<<"nnTotal number of vowels in string => "<<vowels;
string<<"nnnConsonants in string are : nn";
for(i=0; i<strlen(a); i++)
{
if(isalpha(a[i]))
{
if(a[i]!='a'&&a[i]!='A'&&(a[i]!='e'&&a[i]!='E'&&a[i]!='i'&&a[i]!='I'&&(a[i]!='o'&&a[i]!='O')&&a[i]!='u'&&a[i]!='U')
{
consonants++;
string<<a[i]<<" ";
}
}
}
string<<"nnTotal number of vowels in string => "<<consonants;
getch();
}
/*****************************OUTPUT*************************************
Enter the string : Ayashkant Misha
Output of created text file:
The string is : Atashkant Mishra
The number of words in string are : 2
Alphabets in string are :
A y a s h k a n t M i s h r a
Total number of alphabets in string => 10
Uppercase letters in string are :
A M
Total number of uppercase letters in string => 2
y a s h k a n t i s h r a
Lowercase letters in string are :
Total number of Lowercase letters in string => 13
Vowels in string are :
a i
Total number of vowels in string => 2
Consonants in string are :
y s h k n t r s h
Total number of vowels in string => 8
************************************************************************ */
/* WAP Using Multiple Inheritance For The Classes Student, Game And Person? */
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class person{ char name[21];
int age;
public:
void indata()
{cout<<"nnEnter the name of Student: " ;
gets(name);
cout<<"nnEnter the age : ";
cin>>age;
}
void outdata();
};
void person::outdata()
{
cout<<"nn";
for(int i=0; i<79; i++)
cout<<"-";
cout<<"nnName of the student is: "<<name;
cout<<"nnAge of the student is : "<<age;
}
class game {
char game_name[20];
public:
void input()
{
cout<<"nnEnter the game name : ";
cin.get();cin.getline(game_name,20);
}
void output()
{
cout<<"nnGame 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();
cout<<"nnEnter the roll number: "; cin>>rollno;
input();
cout<<"nnEnter total marks (out of 100) : ";
cin>>Tmarks;
}
void display()
{
outdata();
cout<<"nnRoll number : "<<rollno;
output();
cout<<"nnTotal marks are : "<<Tmarks;
cout<<"nnGrade = "<<calgrade();
}
};
void main()
{ clrscr();
student A;
A.enter();
cout<<”nnstudent details are : nn”;
A.display();
getch();
}
/*********************************************OUTPUT*****************************************
**
Enter the name of student : Mahendra
Enter the age : 17
Enter the roll number: 21
Enter the game name : Cricket
Enter total marks (out of 100) : 99
Student Details are :
Name of the student is: Mahendra
Age of the student is : 17
Roll number : 21
Game opted by the student is : Cricket
Total marks are : 99
Grade = A
*********************************************************************************************
*********************** */
Computer practicals(part) Class 12
Computer practicals(part) Class 12

Mais conteúdo relacionado

Mais procurados

computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)Nitish Yadav
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12Abhishek Sinha
 
SALARY MANAGEMENT SYSTEM IN C++
SALARY MANAGEMENT SYSTEM IN C++SALARY MANAGEMENT SYSTEM IN C++
SALARY MANAGEMENT SYSTEM IN C++vikram mahendra
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2Chul Ju Hong
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2ang0123dev
 
The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189Mahmoud Samir Fayed
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesOXUS 20
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesAbdul Rahman Sherzad
 
CANTEEN MANAGEMENT SYSTEM IN PYTHON
CANTEEN MANAGEMENT SYSTEM IN PYTHONCANTEEN MANAGEMENT SYSTEM IN PYTHON
CANTEEN MANAGEMENT SYSTEM IN PYTHONvikram mahendra
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRsquared Academy
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.jsSarah Drasner
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with PipesRsquared Academy
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 

Mais procurados (18)

computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
 
SALARY MANAGEMENT SYSTEM IN C++
SALARY MANAGEMENT SYSTEM IN C++SALARY MANAGEMENT SYSTEM IN C++
SALARY MANAGEMENT SYSTEM IN C++
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
 
Groovy kind of test
Groovy kind of testGroovy kind of test
Groovy kind of test
 
wreewrer
wreewrerwreewrer
wreewrer
 
CANTEEN MANAGEMENT SYSTEM IN PYTHON
CANTEEN MANAGEMENT SYSTEM IN PYTHONCANTEEN MANAGEMENT SYSTEM IN PYTHON
CANTEEN MANAGEMENT SYSTEM IN PYTHON
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with Pipes
 
Final_Project
Final_ProjectFinal_Project
Final_Project
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
 
Explore Data using dplyr
Explore Data using dplyrExplore Data using dplyr
Explore Data using dplyr
 

Semelhante a Computer practicals(part) Class 12

java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdfDngTin307322
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfezzi97
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management foSunny Singhania
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing Swakriti Rathore
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
Railway reservation
Railway reservationRailway reservation
Railway reservationSwarup Boro
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control StructureMohammad Shaker
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docxajoy21
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Aman Deep
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Aman Deep
 

Semelhante a Computer practicals(part) Class 12 (20)

C program
C programC program
C program
 
Java
JavaJava
Java
 
java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdf
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdf
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management fo
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
Lab Question
Lab QuestionLab Question
Lab Question
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
Writeable CTEs: The Next Big Thing
Writeable CTEs: The Next Big ThingWriteable CTEs: The Next Big Thing
Writeable CTEs: The Next Big Thing
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
 
c programming
c programmingc programming
c programming
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 

Último

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Último (20)

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Computer practicals(part) Class 12

  • 1. /* Write a program to find out the two digit numbers in an array? */ #include<iostream.h> #include<conio.h> void twodigit(int a[10][10],int m,int n) { int i,j,flag=0; cout<<"The Two digit Numbers are: "; for(i=0;i<m;i++) for(j=0;j<n;j++) { if(a[i][j]>=10&&a[i][j]<=99) { cout<<a[i][j]<<ends; flag=1; } } if(flag==0) cout<<"None"; } void main() { clrscr(); int a[10][10],i,j,m,n; cout<<"n EnterNo. of rows: "; cin>>m; cout<<"nEnter the no. of columns: ";
  • 2. cin>>n; cout<<"nEnter the Elements of the array: "; for(i=0;i<m;i++) for(j=0;j<n;j++) cin>>a[i][j]; twodigit(a,m,n); getch(); } /***********************OUTPUT*********************************** EnterNo. of rows: 2 Enter the no. of columns: 2 Enter the Elements of the array: 1 2 3 4 5 6 The Two digit Numbers are: None **************************************** */
  • 3. /* WAP to find the stream of engineering a student goes (Using OOP). According to following guidelines: marks>=96 computer sc marks>=91&marks<=95 Electronics marks>=86&marks<=90 Mechanical marks>=81&marks<=85 Electrical marks>=76&marks<=80 Chemical marks>=71&marks<=75 Civil marks<70 none */ #include<fstream.h> #include<stdio.h> #include<conio.h> #include<process.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;
  • 4. } 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;
  • 5. fstream ofile,afile; char ch,ch1; do { cout<<"nt1.Add recordsnt2.Show Recordsnt3.Exit"; 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<<"nNametRollnotMarkstStream"; afile.open("st.dat",ios::in); while(afile) { afile.read((char *)&s,sizeof(student)); if (!afile)
  • 6. break; s.display(); } afile.close(); break; case '3' : exit(0); } cout<<"nt DO U want to continue "; cin>>ch1; }while(ch1=='Y'); getch(); } /********************** OUTPUT ********************************* 1.Add records 2.Show Records 3.Exit 2 Name Rollno Marks Stream Ayshkant 5 90 Mechanical Shuvam 6 70 none Bhabesh 1 78 Chemical DO U want to continue n *********************************************** */
  • 7. /* WAP to enter and display the following details of employee in tabular form (in class) Employee No. Employee Name Salary */ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<process.h> #include<iomanip.h> class employee { int eno; char name[30]; float salary; public : void input() { cout << "Enter Employee Number "; cin >>eno; cout << "Enter name "; gets(name); cout << "Enter salary "; cin >>salary; } void show() { cout << eno << setw(20)<<name<<setw(20)<<salary<<endl;
  • 8. } float rt_sal() { return salary; } }emp[10]; main() { int n,ch,i,j; char choice; do { clrscr(); cout << "1. For enter "<<endl; cout << "2. For tabular report"<<endl; cout << "3. For exit"; cin >> ch; switch(ch) { case 1: cout << "Enter how many employees "; cin >>n; for(i=0;i<n;i++) { emp[i].input(); } break;
  • 9. case 2: employee temp; for (i=0;i<n;i++) { for(j=i;j<n-1;j++) { if (emp[j].rt_sal()>emp[j+1].rt_sal()) { temp = emp[j]; emp[j]=emp[j+1]; emp[j+1]=temp; } } } gotoxy(6,6); cout <<"Employee Number "; gotoxy(26,6); cout <<"Name"; gotoxy(46,6); cout <<"Salary"<<endl; int r = 8; for(i=0;i<n;i++) { emp[i].show(); r++; } break; case 3: exit(0);
  • 10. } cout << "n Do U want to continue"; cin>>choice; }while(choice == 'Y' ||choice =='y'); } /******************************** OUTPUT ******************************* 1. For enter 2. For tabular report 3. For exit 2 Employee Number Name Salary 1 Dan 700 2 Nick 900 Do U want to continue n *************************************************************** */
  • 11. /* WAP to find the no. of words, vowels, numbers in a given 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<<"nt1.Create Textnt2.Count vowels/words/digitsnt3.Show Textnt4.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;
  • 12. 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()) {
  • 14. getch(); } /********************* OUTPUT ************************************ 1.Create Text 2.Count vowels/words/digits /* 3.Show Text 4.Exit 1 Enter The Text india DO U want to continue y 1.Create Text 2.Count vowels/words/digits 3.Show Text 4.Exit 2 No of Vowels: 3 No of digits: 1 No of words: 0 DO U want to continue y 1.Create Text 2.Count vowels/words/digits 3.Show Text 4.Exit 3 Formatted text: indiaÿÿ DO U want to continue n ******************************************************** */
  • 15. /* WAP to create a text and find the upper case and lower case constants and vowels? */ #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<<"nt1.Create Textnt2.Read from Filent3.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;
  • 16. case '2' : char tmp1; 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 << "n Lower case vowel "<<tmp1; else cout<<"n Lower case consonants "<<tmp1; } if (isupper(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;
  • 17. 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<<"nt DO U want to continue "; cin>>ch1; }while(ch1=='Y'||ch1=='y'); getch(); } /******************* OUTPUT ************************************** 1.Creat Text 2.Read from file 3.creat another file 4.Exit 1
  • 18. Enter The Text I am the King DO U want to continue Y 1.Create Text 2.Read from File 3.create another file 4.Exit 2 Upper case vowel I Lower case vowel a Lower case consonants m Lower case consonants t Lower case consonants h Lower case vowel e Lower case consonants K Lower case vowel i Lower case consonants n Lower case consonants g DO U want to continue n ********************************************************** */
  • 19. /* WAP to append record and search in a telephone directory? */ # include <fstream.h> #include <conio.h> #include <string.h> #include <stdio.h> #include <stdlib.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()
  • 20. { return tno; } }tele; // Function to append the records in file void append() { 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(); } // Function to search a record in the file void display() { ifstream tfile; tfile.open("tele.dat",ios :: binary); int no,flag;
  • 21. 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; cout << " 1. For append record "; cout <<"n 2. For search "; cout << "n 3. For exit"; cin >> ch; switch (ch) {
  • 22. case 1: append(); break; case 2: display(); break; case 3 : exit(0); } } /***************************OUTPUT*************************** 1. For append record 2. For search 3. For exit 1 Enter how many customers 2 Enter the name Dan Enter address KNAGAR Enter the telephone number 223344 Enter the name mak Enter address MNAGAR Enter the telephone number 334455 Do Yoy want to cotinue y 1. For append record 2. For search 3. For Exit 2Enter the number to be searched 556677 Record does not exist Do you want to continue n ********************************************************* */
  • 23. /* WAP to record the blood donor’s name, address and blood group and search by the blood group when required? */ #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"; }
  • 24. char *getbgroup() { return bgroup; } }; void main() { clrscr(); donor d; int n,i,j; fstream ofile,afile; char ch,ch1; do { cout<<"nt1.Add recordsnt2.Search Recordsnt3.List Recordsnt4.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++) {
  • 25. 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);
  • 26. while(afile) { afile.read((char *)&d,sizeof(donor)); if(!afile) break; d.display(); } afile.close(); break; case '4' : exit(0); } cout<<"nt DO U want to continue "; cin>>ch1; }while(ch1=='Y'||ch1=='y'); getch(); } /**********************OUTPUT*************************************** 1.Add records 2.Search Records 3.List Records 4.Exit 1 Enter no. of records to be Entered: 2
  • 27. Enter Donor Name: Ayashkant Enter Address: pl no. 820 Enter Blood Group: B+ Enter Donor Name: Swaraj Enter Address: Pl. 98 Enter Blood Group: A+ DO U want to continue y 1.Add records 2.Search Records 3.List Records 4.Exit 2 Enter Blood Group to be searched: O+ No record Found DO U want to continue N ****************************************** */
  • 28. /* WAP in C++ to record the book no., book name and price and search by its number when required (USING CLASS)? */ #include<fstream.h> #include<stdio.h> #include<conio.h> #include<process.h> class book { char bname[30]; int bno; float price; public: void input() { cout<<"nEnter Book Name: "; gets(bname); cout<<"Enter BOOK No.: "; cin>>bno; cout<<"Enter Price"; cin>>price; } void setprice() { cout<<"nEnter Price"; cin>>price; } void display()
  • 29. { cout<<"nBook Name: "<<bname<<"tBook No.: "<<bno<<"tPrice: "<<price<<"t"; } int getbno() { return bno; } }; void main() { clrscr(); book b; int n,i,j; fstream ofile,afile; char ch,ch1; do{ cout<<"nt1.Add recordsnt2.Search Recordsnt3.Modify Recordsnt4.Exit"; cin>>ch; switch(ch) { case '1' : ofile.open("bk.dat",ios::out|ios::binary); cout<<"nEnter no. of records to be Entered: "; cin>>n; for(i=0;i<n;i++)
  • 30. { b.input(); ofile.write((char*)&b,sizeof(book)); } ofile.close(); break; case '2' : cout<<"nEnter Book No. to be searched: "; int bn,flag=0; cin>>bn; afile.open("bk.dat",ios::in); while(afile) { afile.read((char *)&b,sizeof(book)); if(!afile) break; if (bn==b.getbno()) { b.display(); flag=1; break; } } if(flag==0) cout<<"n No record Found"; afile.close(); break; case '3' :
  • 31. cout<<"nEnter Book No. to be modified "; int bn1,flag1=0,r=0; cin>>bn1; afile.open("bk.dat",ios::in|ios::out|ios::binary); while(afile) { afile.read((char *)&b,sizeof(book)); if(!afile) break; if (bn1==b.getbno()) { b.setprice(); afile.seekp(r*sizeof(b),ios::beg); afile.write((char *)&b,sizeof(book)); flag1=1; break; } r++; } if(flag1==0) cout<<"n No record Found"; afile.close(); break; case '4' : exit(0); } cout<<"nt DO U want to continue "; cin>>ch1;
  • 32. }while(ch1=='Y'||ch1=='y'); getch(); } /****************************OUTPUT********************** 1.Add records 2.Search Records 3.Modify Records 4.Exit 1 Enter no. of records to be Entered: 2 Enter Book Name: The Wolf Of The Wallstreet Enter BOOK No.: 34 Enter Price 50 Enter Book Name: The Oath Of The Vayuputra Enter BOOK No.: 47 Enter Price 8 DO U want to continue y 1.Add records 2.Search Records 3.Modify Records 4.Exit 2 Enter Book No. to be searched: 34 Book Name: The Wolf Of The Wallstreet Book No.: 34 Price: 50 DO U want to continue n ****************************************************** */
  • 33. /* WAP to record the student name, roll no. and fees and display its details when searched by roll no.? */ #include<fstream.h> #include<stdio.h> #include<conio.h> #include<process.h> class students { char sname[30]; int sno; float fees; public: void input() { cout<<"nEnter Student Name: "; gets(sname); cout<<"Enter Roll No.: "; cin>>sno; cout<<"Enter Fees: "; cin>>fees; } void display() { cout<<"nStudent Name: "<<sname<<"tRoll No.: "<<sno<<"tFees: "<<fees<<"t"; } int getsno() { return sno;}
  • 34. }; void main() { clrscr(); students s; int n,i,j; fstream ofile,afile; char ch,ch1; do { cout<<"nt1.Add recordsnt2.Search Recordsnt3.Delete Recordsnt4.Exit"; cin>>ch; switch(ch) { case '1' : ofile.open("std.dat",ios::out|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(students)); } ofile.close(); break; case '2' : cout<<"nEnter Roll No. to be searched: ";
  • 35. int sn,flag=0; cin>>sn; afile.open("std.dat",ios::in); while(afile) { afile.read((char *)&s,sizeof(students)); if(!afile) break; if (sn==s.getsno()) { s.display(); flag=1; break; } } if(flag==0) cout<<"n No record Found"; afile.close(); break; case '3' : cout<<"nEnter Roll No. to be Deleted "; int sn1,flag1=0; cin>>sn1; afile.open("std.dat",ios::in|ios::binary); ofile.open("tmpstd.dat",ios::out|ios::binary); while(afile) {
  • 36. afile.read((char *)&s,sizeof(students)); if(!afile) break; if (sn1==s.getsno()) { flag1=1; } else { ofile.write((char *)&s,sizeof(students)); } } if(flag1==0) cout<<"n No record Found"; afile.close(); ofile.close(); afile.open("tmpstd.dat",ios::in|ios::binary); ofile.open("std.dat",ios::out|ios::binary); while(afile) { afile.read((char *)&s,sizeof(students)); ofile.write((char *)&s,sizeof(students)); } afile.close();
  • 37. ofile.close(); break; case '4' : exit(0); } cout<<"nt DO U want to continue "; cin>>ch1; }while(ch1=='Y'||ch1=='y'); getch(); } /************************OUTPUT******************************* 1.Add records 2.Search Records 3.Delet Records 4.Exit 1 Enter no. of records to be Entered: 2 Enter Student Name: Daniel Enter Roll No.: 23 Enter Fees: 1200 Enter Student Name: Max
  • 38. Enter Roll No.: 56 Enter Fees: 7890 DO U want to continue y 1.Add records 2.Search Records 3.Delete Records 4.Exit 2 Enter Roll No. to be searched: 23 Student Name: Daniel Roll No.: 23 Fees: 1200 DO U want to continue n ********************************************************* */
  • 39. // This program illustrates the basic operation of add queue, delete queue and show queue // using linked list. #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
  • 40. front = rear = NULL; // Initialization of Queue clrscr(); do { cout << "ntt Main Menu"; cout << "nt1. Addition of Queue"; cout << "nt2. Deletion from Queue"; cout << "nt3. Traverse of Queue"; cout << "nt4. Exit from Menu"; cout << "nnEnter 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;
  • 41. 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); } // Function body to add queue elements node *add_Q(node *rear, int val, float val1) { node *temp;
  • 42. temp = new node; temp->Eno = val; temp->Salary = val1; temp->link = NULL; rear->link = temp; rear = temp; return (rear); } // Function body to delete queue elements node *del_Q(node *front, int &val, float &val1) { 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; }
  • 43. 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******************************** Main Menu 1. Addition of Queue 2. Deletion from Queue 3. Traverse of Queue 4. Exit from Menu Enter Your choice from above 1 Enter the value to be added in the queue 234 567
  • 44. Do you want to add more element <Y/N> n Main Menu 1. Addition of Queue 2. Deletion from Queue 3. Traverse of Queue 4. Exit from Menu Enter Your choice from above 2 The Queue values are ENO : 234 Salary : 567 Main Menu 1. Addition of Queue 2. Deletion from Queue 3. Traverse of Queue 4. Exit from Menu Enter Your choice from above 4 ********************************************************************** */
  • 45. /* WAP to add, delete and transverse stacks? */ #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 {
  • 46. cout << "ntt Main Menu"; cout << "nt1. Addition of Stack"; cout << "nt2. Deletion from Stack"; cout << "nt3. Traverse of Stack"; cout << "“nt4. Exit from Menu"; cout << "nnEnter 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)
  • 47. 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;
  • 48. 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 << "ntPopped Roll Number is : " << temp->roll; cout << "ntPopped Age is : " << temp->age; delete temp; } return (top);
  • 49. } // 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*********************************** Main Menu 1. Addition of Stack 2. Deletion from Stack 3. Traverse of Stack“ 4. Exit from Menu Enter your choice from above 1 Enter the roll no. : 1 Enter age : 15 Do you want to add more elements <Y/N> ? y
  • 50. Enter the roll no. : 2 Enter age : 17 Do you want to add more elements <Y/N> ? n Main Menu 1. Addition of Stack 2. Deletion from Stack 3. Traverse of Stack 4. Exit from Menu Enter your choice from above 3 The values are 2 17 1 15 Main Menu 1. Addition of Stack 2. Deletion from Stack 3. Traverse of Stack“ 4. Exit from Menu Enter your choice from above 4 *********************************************************** */
  • 51. /*This program illustrates the basic operation of circular to add queue, delete queue and show queue using array. The queue contains data of type character. */ #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 ront = -1; clrscr(); do { cout << "ntt Main Menu"; cout << "nt1. Addition of Queue"; cout << "nt2. Deletion from Queue";
  • 52. cout << "nt3. Traverse of Queue"; cout << "nt4. Exit from Menu"; cout << "nnEnter 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;
  • 53. case 3: show_Q(queue, front, rear); break; case 4: exit(0); } } while (choice != 4); } // Function body to add circular queue with array of character void add_Q(char queue[], int front, char val, int &rear) { if ((rear + 1) % MAX == front) { cout << "Queue Full "; } else { rear = (rear + 1) % MAX; queue[rear] = val; } } // Function body to delete circular queue with array of character char del_Q(char queue[], int &front, int rear) { char value; if (front == rear)
  • 54. { 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************************************************ Main Menu 1. Addition of Queue 2. Deletion from Queue 3. Traverse of Queue 4. Exit from Menu
  • 55. Enter Your choice from above 1 Enter the value to be added in the queue 3 Do you want to add more element <Y/N>? n Main Menu 1. Addition of Queue 2. Deletion from Queue 3. Traverse of Queue 4. Exit from Menu Enter Your choice from above 4 **************************************************************************** */
  • 56. /* Program to define the classes PERSON, GAME and STUDENT & to access the essential data using multiple inheritance.*/ #include<iostream.h> #include<stdio.h> #include<conio.h> class person{ char name[21]; int age; public: void indata() {cout<<"nnEnter the name of Student: " ; gets(name); cout<<"nnEnter the age : "; cin>>age; } void outdata(); }; void person::outdata() // since the function contains loop so it is not made inline { cout<<"nn"; for(int i=0; i<79; i++) cout<<"-"; cout<<"nnName of the student is: "<<name; cout<<"nnAge of the student is : "<<age; } class game { char game_name[20]; public: void input() { cout<<"nnEnter the game name : "; cin.get();cin.getline(game_name,20); } void output() { cout<<"nnGame 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';
  • 57. 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<<"nnEnter the roll number: "; cin>>rollno; input(); // input() of class game called here cout<<"nnEnter total marks (out of 100) : "; cin>>Tmarks; } void display() { outdata(); cout<<"nnRoll number : "<<rollno; output(); cout<<"nnTotal marks are : "<<Tmarks; cout<<"nnGrade = "<<calgrade(); } }; void main() { clrscr(); student A; A.enter(); A.display(); getch(); } /**************************OUTPUT********************************* Enter the name of Student: Ayashkant Mishta Enter the age : 16 Enter the roll number: 01 Enter the game name : Kabbadi Enter total marks (out of 100) : 95 -------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ Name of the student is: Ayashkant Mishra
  • 58. Age of the student is : 16 Roll number : 34 Game opted by the student is : Kabbadi Total marks are : 95 Grade = A ****************************************************************** */
  • 59. /* Wap in c++ to implement stack as an array */ #include<iostream.h> #include<conio.h> #include<process.h> int pop(int[],int&); int push(int[],int&,int); void display(int[],int); const int size=50; void main() { clrscr(); char m,ch; int k,stack[size],item,top=-1,res; do { cout<<"nChoose from the following : nn" <<"n 1. Push" <<"n 2. Pop" <<"n 3. Display" <<"n 4. Exit" <<"nnEnter your choice : "; cin>>k; switch(k) { case 1: ch='y'; while(ch=='y'||ch=='Y') { cout<<"nEnter the element : "; cin>>item; res=push(stack,top,item); if(res==-1) {cout<<"nOverflow !!!!"; exit(1); }
  • 60. cout<<"nThe stack formed is : nn"; display(stack,top); cout<<"nnnWant to enter again ?: "; cin>>ch; } break; case 2: ch='y'; while(ch=='y'||ch=='Y') { res=pop(stack,top); if(res==-1) { cout<<"nUnderflow !!!!"; exit(1); } else { cout<<"nThe deleted Element is : "<<res<<endl; cout<<"nThe resultant stack is : nn"; display(stack,top); } cout<<"nWant to delete again ? : "; cin>>ch; } break; case 3: cout<<"nThe resultant stack is : "; display(stack,top); break; case 4: exit(0); break; default: cout<<"nPlease enter desired keyword : "; } // end of switch
  • 61. cout<<"nnChoose from the menu again ? : "; cin>>m; }while(m=='y'||m=='Y'); // end of do-while loop getch(); } // end of main() int push(int stack[],int &top,int el) { if(top==size-1) return -1; else { top++; stack[top]=el; return 0; } } int pop(int stack[],int &top) { int ret; if(top==-1) return -1; else { ret=stack[top]; top--; return ret; } } void display(int stack[],int top) { cout<<stack[top]<<"<--";
  • 62. for(int i=top-1;i>=0;i--) cout<<stack[i]<<"<--"; } /************************************OUTPUT******************************************** Choose from the following : 1. Push 2. Pop 3. Display 4. Exit Enter your choice : 1 Enter the element : 1 The stack formed is : 1  Want to enter again ?: y Enter the element : 2 The stack formed is : 2  1  Want to enter again ?: y Enter the element : 3 The stack formed is : 3 2  1  Want to enter again ?: y Enter the element : 4 The stack formed is : 4  3  2  1 
  • 63. Want to enter again ?: N Choose from the menu again ? : y Choose from the following : 1. Push 2. Pop 3. Display 4. Exit Enter your choice : 2 The deleted Element is : 4 The resultant stack is : 3  2  1  Want to delete again ? : y The deleted Element is : 3 The resultant stack is : 2  1  Want to delete again ? : n Choose from the menu again ? : y Choose from the following : 1. Push 2. Pop 3. Display 4. Exit Enter your choice : 3 The resultant stack is : 2 1  Choose from the menu again ? : n ********************************************************************************** */
  • 64. /* Wap to implement stack as a linked list */ #include<iostream.h> #include<conio.h> #include<process.h> struct node { int roll; node* next; }*top,*save,*ptr,*newptr,*np; node *create(int a) { ptr=new node; ptr->roll=a; ptr->next=NULL; return ptr; } void push(node *np) { if(top==NULL) top=np; else { save=top; top=np; np->next=save; } } void pop() { if(top==NULL) cout<<"n Underflow!!!!"; else { ptr=top; top=top->next; delete ptr; } } void display(node *np) { while(np!=NULL) { cout<<np->roll<<" -> "; np=np->next; } }
  • 65. void main() { clrscr(); top=NULL; int n,m; char k,ch; do { cout<<"nChoose from the menu :n" <<"n 1. Push." <<"n 2. Pop." <<"n 3. Display." <<"n 4. Quit." <<"nnEnter your choice : "; cin>>n; switch(n) { case 1: k='y'; while(k=='y'||k=='Y') { cout<<"n Enter element to be inserted ."; cin>>m; newptr=create(m); if(newptr==NULL) cout<<"n Cannot create !!!!"; push(newptr); cout<<"n The Stack formed is : "; display(top); cout<<"nn Want to enter again ?: "; cin>>k; } break; case 2: k='y'; while(k=='y'||k=='Y') { pop(); cout<<"n The Stack formed is : nn"; display(top); cout<<"nn Want to delete again ?: "; cin>>k; } break; case 3: cout<<"n The Stack formed is : ";
  • 66. display(top); break; case 4: exit(0); break; default: cout<<"n Please enter desired keyword : "; } cout<<"n Do you want to continue..? : "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); } /*********************************************OUTPUT***************************************** ***** Choose from the menu : 1. Push. 2. Pop. 3. Display. 4. Quit. Enter your choice : 1 Enter element to be inserted : 1 The Stack formed is : 1 -> Want to enter again ?: y Enter element to be inserted : 2 The Stack formed is : 2 -> 1 -> Want to enter again ?: y Enter element to be inserted : 3 The Stack formed is :
  • 67. 3 -> 2 -> 1 -> Want to enter again ?: n Do you want to continue..? : y Choose from the menu : 1. Push. 2. Pop. 3. Display. 4. Quit. Enter your choice : 2 The Stack formed is : 2 -> 1 -> Want to delete again ?: y The Stack formed is : 1 -> Want to delete again ?: N Do you want to continue..? : y Choose from the menu : 1. Push. 2. Pop. 3. Display. 4. Quit. Enter your choice : 3 The Stack formed is : 1 -> Do you want to continue..? : y Choose from the menu : 1. Push. 2. Pop. 3. Display. 4. Quit. Enter your choice : 4 *********************************************************************************** */
  • 68. /* Wap in C++ to read file “sports.dat” and copy only those records where event name is ATHLETIC using the concept of Data file handling. */ #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<<"nnEnter the name of Event : "; cin.getline(s[i].event,20); cout<<"nnEnter the total number of participants in Event "<<s[i].event<<" : "; cin>>s[i].no_of_participants; cout<<"nnEnter 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<<"nnnWant to Enter Details of Another Event (Y/N) : "; cin>>choice; i++; } while(choice=='y'||choice=='Y');
  • 69. cout<<"nnnnn****************************************************************************** ******************************nn"; copy(ob); cout<<"nn*********************************************************************************** ******************************nnn"; 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)); n=1; break; } c++; } if(n==0) { cout<<"nnUnsuccessful Search."; getch(); exit(0); }o.close();
  • 70. file.close(); sports sp; ifstream oo; oo.open("athletic.dat",ios::binary); while(oo) { oo.read((char*)&sp, sizeof(sports)); } cout<<"nnThe Records of file are : nn"; cout<<"nnEvent = "<<sp.event; cout<<"nnnnThe Participants are : nn"; for(int i=0; i<sp.no_of_participants; i++) { cout<<sp.participants[i]<<"nn"; } oo.close(); remove("athletic.dat"); remove("sports.dat"); } /**************************************OUTPUT************************************************ ** Enter the name of Event : Cricket Enter the total number of participants in Event Cricket : 3 Enter the name of Praticipants : Rahul verma Shivam Siddharth Want to Enter Details of Another Event (Y/N) : y
  • 71. Enter the name of Event : athleltic Enter the total number of participants in Event atlhletic : 2 Enter the name of Praticipants : Mohak Vikas Want to Enter Details of Another Event (Y/N) : y Enter the name of Event : Football Enter the total number of participants in Event Football : 2 Enter the name of Praticipants : Arsh Ashu Want to Enter Details of Another Event (Y/N) : n ********************************************************************************************* ************************************ The Records of file are : Event = athletic The Participants are : Mohak Vikas ********************************************************************************************* ************************************ */
  • 72. /* Wap to print and find the sum of Fibonacci series using recursion. */ #include<iostream.h> #include<conio.h> int fibonacci(int n); void main() { clrscr(); int n; cout<<"nn Enter the number of terms upto which you want the sum of fibonnaci series : "; cin>>n; cout<<"nnThe fibonacci series generated is : nn"; cout<<"1 1 "; int s=fibonacci(n); cout<<"nnThe sum of fibonacci series for "<<n<<" terms = "<<s; getch(); } int first=1; int second=1; int third; int i=2; int sum=0; int fibonacci(int n) { if(n==1) sum=1;
  • 73. else if(n==2) sum=2; // n = 1 2 3 4 5 else if(n>1 && i!=n) // num = 1 1 2 3 5 { third=first+second; cout<<third<<” “; if(i==2) sum+=first+second+third; else sum+=third; first=second; second=third; ++i; fibonacci(n); } return sum; } /*****************************OUTPUT******************************************* Enter the number of terms upto which you want the sum of fibonnaci series : 5 The fibonacci series generated is : 1 1 2 3 5 The sum of fibonacci series for 5 terms = 12 **************************************************************************************** */
  • 74. /* Wap in C++ to print and find the sum of even /odd numbers using recursion.*/ #include<iostream.h> #include<conio.h> int sum_even(int ); int sum_odd(int ); int sum=0; int num=0; void main() { clrscr(); int n; int s_e, s_o; cout<<"nnEnter the number upto which you want the sum of even/odd numbers : "; cin>>n; cout<<"nn The list of integers is : nn"; for(int l=1; l<=n; l++) cout<<l<<"n"; s_e=sum_even(n); s_o=sum_odd(n); cout<<"nnThe sum of even numbers upto "<<n<<" = "<<s_e; cout<<"nnThe sum of odd numbers upto "<<n<<" = "<<s_o; getch(); } int sum_even(int n){ if(num%2==0) sum=sum+num; if(num!=n && num<n) { ++num; sum_even(n); } return sum; } int sum_2=0; int num_2=0;
  • 75. int sum_odd(int n) { if(num_2%2!=0) sum_2=sum_2+num_2; if(num_2!=n) { num_2++; sum_odd(n); } return sum_2; } /*********************************OUTPUT********************************************** Enter the number upto which you want the sum of even/odd numbers : 10 The list of integers is : 1 2 3 4 5 6 7 8 9 10 The sum of even numbers upto 10 = 30 The sum of odd numbers upto 10 = 25 **************************************************************************** */
  • 76. /* WAP in c++ using pointers to find the smallest and the largest element in a dynamically created array?*/ #include<iostream.h> #include<conio.h> void main() { clrscr(); int *array, smallest, largest, n; cout<<"nnEnter the number of elements : "; cin>>n; array=new[n]; cout<<"nnEnter the elements : nn"; for(int i=0; i<n; i++) cin>>array[i]; i=0; cout<<"nnThe array formed is : nn"; while(i!=n) { cout<<array[i]<<" "; i++; } smallest=array[0]; for(i=0; i<n; i++) { if(array[i]<=smallest) smallest=array[i]; }
  • 77. largest=array[0]; for(i=0; i<n; i++) { if(array[i]>=largest) largest=array[i]; } cout<<"nnThe smallest element is : "<<smallest<<"nnThe largest element is : "<<largest; getch(); } /*********************************************OUTPUT***************************************** ***************** Enter the number of elements : 5 Enter the elements : 1 9 2 8 6 The array formed is : 1 9 2 8 6 The smallest element is : 1 The largest element is : 9 ************************************************************************************** */
  • 78. /* Wap using pointers to swap two integers. */ #include<iostream.h> #include<conio.h> void swap_using_pointers(int *, int *); void main() { clrscr(); int a,b; cout<<"nnEnter first integer : "; cin>>a; cout<<"nnEnter second integer : "; cin>>b; swap_using_pointers(&a,&b); cout<<"nnNow value of first integer = "<<a; cout<<"nnNow value of second integer = "<<b; getch(); } void swap_using_pointers(int *a,int *b) { int temp; temp=*a; *a=*b; *b=temp; } /*****************************************OUTPUT********************************************* *** Enter first integer : 1 Enter second integer : 100 Now value of first integer = 100 Now value of second integer = 1 **************************************************************************** */
  • 79. /* Wap using pointers to swap two integers. */ #include<iostream.h> #include<conio.h> void swap_using_pointers(int *, int *); void main() { clrscr(); int a,b; cout<<"nnEnter first integer : "; cin>>a; cout<<"nnEnter second integer : "; cin>>b; swap_using_pointers(&a,&b); cout<<"nnNow value of first integer = "<<a; cout<<"nnNow value of second integer = "<<b; getch(); } void swap_using_pointers(int *a,int *b) { int temp; *a=*b; *b=temp; temp=*a; } /*****************************************OUTPUT***************************** Enter first integer : 1 Enter second integer : 100 Now value of first integer = 100 Now value of second integer = 1 ******************************************************************** */
  • 80. /* WAP to create a text file(.txt) and display number of words, alphabets, vowels and consonants and number of lowercase and uppercase letters using the concept of DATA FILE HANDLING? */ #include<fstream.h> #include<string.h> #include<ctype.h> #include<conio.h> void main() { clrscr(); char a[80]; int words=0, upper_letters=0, lower_letters=0, alpha=0, vowels=0,consonants=0; ofstream string("str.txt"); cout<<"nnEnter the string : "; cin.getline(a,79); string<<"The string is : "<<a<<"nn"; for(int i=0; i<strlen(a); i++) { if(a[i]==' ') while(a[i]==' ') { i++; } if(isalnum(a[i])) { while(a[i]!=' ') { i++; } words++; } } string<<"nnThe number of words in string are : "<<words; string<<"nnnAlphabets in string are : nn"; for(i=0; i<strlen(a); i++) { if(isalpha(a[i])) { alpha++; string<<a[i]<<" "; } } string<<"nnTotal number of alphabets in string => "<<alpha; string<<"nnnUppercase letters in string are : nn"; for(i=0; i<strlen(a); i++) { if(isupper(a[i])) { upper_letters++; string<<a[i]<<" ";
  • 81. } } string<<"nnTotal number of uppercase letters in string => "<<upper_letters; string<<"nnnLowercase letters in string are : nn"; for(i=0; i<strlen(a); i++) { if(islower(a[i])) { lower_letters++; string<<a[i]<<" "; } } string<<"nnTotal number of Lowercase letters in string => "<<lower_letters; string<<"nnnVowels in string are : nn"; for(i=0; i<strlen(a); i++) { if(isalpha(a[i])) { if(a[i]=='a'||a[i]=='A'||a[i]=='e'||a[i]=='E'||a[i]=='i'||a[i]=='I'||a[i]=='o'||a[i]=='O'||a[i]=='u'||a[i]=='U') { vowels++; string<<a[i]<<" "; } } } string<<"nnTotal number of vowels in string => "<<vowels; string<<"nnnConsonants in string are : nn"; for(i=0; i<strlen(a); i++) { if(isalpha(a[i])) { if(a[i]!='a'&&a[i]!='A'&&(a[i]!='e'&&a[i]!='E'&&a[i]!='i'&&a[i]!='I'&&(a[i]!='o'&&a[i]!='O')&&a[i]!='u'&&a[i]!='U') { consonants++; string<<a[i]<<" "; } } } string<<"nnTotal number of vowels in string => "<<consonants; getch(); } /*****************************OUTPUT************************************* Enter the string : Ayashkant Misha Output of created text file: The string is : Atashkant Mishra
  • 82. The number of words in string are : 2 Alphabets in string are : A y a s h k a n t M i s h r a Total number of alphabets in string => 10 Uppercase letters in string are : A M Total number of uppercase letters in string => 2 y a s h k a n t i s h r a Lowercase letters in string are : Total number of Lowercase letters in string => 13 Vowels in string are : a i Total number of vowels in string => 2 Consonants in string are : y s h k n t r s h Total number of vowels in string => 8 ************************************************************************ */
  • 83. /* WAP Using Multiple Inheritance For The Classes Student, Game And Person? */ #include<iostream.h> #include<stdio.h> #include<conio.h> class person{ char name[21]; int age; public: void indata() {cout<<"nnEnter the name of Student: " ; gets(name); cout<<"nnEnter the age : "; cin>>age; } void outdata(); }; void person::outdata() { cout<<"nn"; for(int i=0; i<79; i++) cout<<"-"; cout<<"nnName of the student is: "<<name; cout<<"nnAge of the student is : "<<age; } class game { char game_name[20]; public: void input() { cout<<"nnEnter the game name : "; cin.get();cin.getline(game_name,20); } void output() { cout<<"nnGame 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)
  • 84. return 'D'; else return 'E'; } void enter() { indata(); cout<<"nnEnter the roll number: "; cin>>rollno; input(); cout<<"nnEnter total marks (out of 100) : "; cin>>Tmarks; } void display() { outdata(); cout<<"nnRoll number : "<<rollno; output(); cout<<"nnTotal marks are : "<<Tmarks; cout<<"nnGrade = "<<calgrade(); } }; void main() { clrscr(); student A; A.enter(); cout<<”nnstudent details are : nn”; A.display(); getch(); } /*********************************************OUTPUT***************************************** ** Enter the name of student : Mahendra Enter the age : 17 Enter the roll number: 21 Enter the game name : Cricket Enter total marks (out of 100) : 99 Student Details are :
  • 85. Name of the student is: Mahendra Age of the student is : 17 Roll number : 21 Game opted by the student is : Cricket Total marks are : 99 Grade = A ********************************************************************************************* *********************** */