SlideShare a Scribd company logo
1 of 89
Computer Science
(SESSION 20 - )
SUBITTED TO: SUBMITTED BY:
ROLL NO. :
Basic concept of OOP’S
 Data Abstraction
 Data Encapsulation
 Inheritance
 Modularity
 Polymorphism
DATA ABSTRACTION:
Abstraction refers to the act of representing essential
features without including the background details or
explanation.
Example:
You are driving a car. You only know the essential features to drive a car
e.g., gear handling, steering handling, use of clutch, accelerator, brakes etc.
But while you are driving do you get into internal details of the car like
wiring, motor working etc.? You just change the gears of apply the brakes
etc. What is happening is hidden from you. This is abstraction where you
only know the essential things to drive a car without including the
background details or explanation. Another example is of ‘switch board’.
You only press certain switches according to your requirement. What is
happening inside, how it is happening inside, how it is happening etc. you
needn’t know. Again, in this abstraction, you only know the essential things
to operate on the switch board without the knowledge the background
details of the switchboard.
DATA ENCAPSULAION:
The wrapping up of data and operation/function (that
operate on the data) into a single entity (called class) is
known as encapsulation.
Example:
In a big company, there are so many departments, sales, account, payroll,
purchase, production etc. each department has its own personnel that
maintain its data. Suppose an employee in the production dept. wants to
know how much raw material has been purchased for the next month. The
production dept. employee would not be allowed to himself go throughthe
purchase dept. files. Rather, he`ll issue a memo to the purchase dept.
requesting the desired information. Then some employee of the purchase
dept. will go through the data files for him and pertain to his requests. This
practice ensures that the data is accessed accurately and that it is not
corrupted by inept outsiders. Therefore, ‘Department data and department
employees are encapsulated into a single entity, the department.’
INHERITANCE:
Inheritance is the capability of one class of things to
inherit capabilities of properties from another class.
Example:
‘Humans’ certain properties, such as the ability to speak, breath, eat, drink,
etc. etc. But these properties are not unique to humans. The class ‘Human’
inherits these properties from the class ‘Mammal’ which again inherits some
of its properties from another “Animal’.The class “car” inherits some of its
properties from the class ‘Automobiles” which inherits some of its
properties from another class ‘Vehicles”. The capability to pass down
properties is a powerful one. It allows us to describe things in an
economical way. ‘Automobiles and ‘Pulled Vehicles’ are subclasses of
‘Vehicles’. ‘Vehicles are base class of ‘Automobiles’ and ‘Pulled Vehicles’.
MODULARITY:
Modularity is the property of a system that has been
decomposed into a set of cohesive and loosely coupled
modules.
Example:
You must have seen a complete music system. Let us assume that our
program represents the music system. The music system comprises of
speakers, cassette-player, record-player, cd-player, tuner etc. Now, these
parts are complete units in themselves, yet they are themselves, yet they
are a subpart of the music system. This is modularity. Similarly, we can
achieve modularity in programs also. A program can be divided into various
modules each representing speakers, cassette-player… etc. See each
module is a complete unit itself yet it works in accordance with other
modules in order to achieve one single goal i.e. music.
POLYMORPHISM:
Polymorphism is the ability for a message or data to be
processed in more than one form.
Example:
‘Human’ is a subclass of ‘Mammal’. Similarly ‘Dog’, ‘Cat’, are also subclasses
of ‘Mammals’. Mammals can see through day-light. So if a message ‘see
through day light’ is passed to all mammals, they will behave alike. Now if a
message ‘see through day light’is passes to all mammals, then humans and
dogs will not be able to see at night whereas cat will be able to see at night
also. Here cats behave differently than other mammals in response to a
message or action.
INDEX
S.No. PROGRAMES DATE SIGNAT
URE
1. WAP USING CLASSES AND OBJECTS TO CREATE CLASS BOOK.
2. WRITE A MENU DRIVEN PROGRAM TO CREATE CLASS BANK TO
INITIALISE DEPOSIT, WITHDRAW & DISPLAY DEETAILS OF THREE
CUSTOMERS.
3. WAP YO CREATE CLASS ADMISSION THAT GENERATE TWO RANDOM
ADMISSION NUMBER FROM THE LIST OF GIVEN ADMISSION
NUMBERS.
4. WAP TO SHOW WORKING OF CONSTRUCTOR AND DESTRUCTOR.
5. WAP TO MAINTAIN DETAILS OF COLLEGE STUDENTS AND PRINT
THEM (INHERITANCE).
6. WAP TO SHOW CONSTRUCTOR OVERLOADING.
7. WAP TO CREATE TEXT FILE WHICH PERFORM THE FOLLOWING
ACTIONS
i. COUNT NO. OF WORDS
ii. COUNT NO. OF LINES
iii. COUNT AND DISPLAY WORDS STARTING WITH VOWELS AND
STORE THEM IN A FILE
iv. COUNT AND DISPLAY WORDS STARTING WITH UPPERCASE
ALPHABETS
v. COUNT NO. OF BLANK SPACES
8. WAP TO CREATE BINARY FILES WITH FIVE RECORDS AND DISPLAY.
9. WAP TO SEARCH RECORD IN A BINARY FILE.
10. WAP TO APPEND A RECORD IN A BINARY FILE.
11. WAP TO INSERT DATA IN A BINARY FILE.
12. WAP TO DELETE A RECORD IN A BINARY FILE.
13. WAP TO MODIFY A RECORD IN A BINARY FILE.
14. WRITE A MENU DRIVEN PROGRAM FOR BINARY AND LINEAR
SEARCH IN A ARRAY.
15. CREATE A MENU DRIVEN INSERT & DELETE AN ELEMENT IN A
SORTED FILE.
16. WAP TO MERGE TWO ARRAYS A IN SACENDING ORDER, B IN
DESCENDING ORDER INTO THIRD ARRAY C INASCENDING ORDER.
17. CREATE MENU DRIVEN PROGRAM TO CHOOSE SORTING
TECHNIQUES SELECTION, BUBBLE.
18. WAP TO CONVERT I-D ARRAY TO 2-D ARRAY.
19. CREATE MENU DRIVEN PROGRAM FOR PUSH & POP IN STACK AS
LINKED LIST.
20. WAP TO SHOW INSERTION AND DELETION IN QUEUES.
21. QURIES OF SQL TABLE 1 STUDENT
22. QURIES OF SQL TABLE 2 HOSPITAL
23. QURIES OF SQL TABLE 3 TEACHER
24. QURIES OF SQL TABLE 4 FURNITURE AND ARRIVALS
25. QURIES OF SQL TABLE 5 INTERIORS AND NEWONES
Q.1) W.A.P. using classes and objects to create the class book.
#include<iostream.h>//for basic functions
#include<stdio.h> //for gets
#include<conio.h> //for clrscr()
class BOOK {int book_no;
char book_title[20]; //data members
float price;
float total_cost(int n) //member functions
{float total;
total=n*price;
return total;
}
public:
void INPUT() //member function
{cout<<"n Enter Book No.: ";
cin>>book_no;
cout<<"n Enter Book Title: ";
gets(book_title);
cout<<"n Enter Price: ";
cin>>price;
}
void PURCHASE()
{int n;
float TOT;
cout<<"n Enter no of
cin>>n;
TOT=total_cost(n);
cout<<"n Your total cost is: "<<TOT;
}
}//end of class book
;
void main() //start of main
{ clrscr();
BOOK buy; //creating object of class buy.INPUT();/*accessing member functions*/
buy.PURCHASE();
getch();
} //end of main
Output
Q.2) Write menu driven program to create class to initialize, deposit,
withdraw and display the details.
#include<iostream.h>
#include<ctype.h>
#include<conio.h>
class Account{ char name[31];
int acc_no;
char act;
float balance;
public:
void initial()
{ cout<<"n Name: ";
cin>>name;
cout<<"n Accoutn No.: ";
cin>>acc_no;
cout<<"n Enter Amount: ";
cin>>balance;
cout<<endl;
}
void deposit(float amt)
{balance+=amt;
cout<<" Amount Deposited";
}
void withdraw(float amt)
{if((amt-balance>=1000))
{ balance=amt-balance;
cout<<"n Amount Withdrawn";
}
else
{cout<<"n Min Bal should be 1000";
cout<<" You can withdraw only: "<<balance-1000;
}
}
void display()
{cout<<"nnttt !!Your Account Details!!";
cout<<"nn Account no.:"<<acc_no;
cout<<"n Accoutn Holder: ";
cout<<name;
cout<<"n Balance: "<<balance;
}
int getacno()
{ return acc_no;}
};
void main()
{ clrscr();
Account bank;
int choice;
cout<<"n Menu";
cout<<"n 1.For Deposit";
cout<<"n 2.For WithDraw";
cout<<"n Enter Choice(1/2): ";
cin>>choice;
switch(choice)
{ case 1:bank.initial();
bank.deposit(100000);
break;
case 2:bank.initial();
bank.withdraw(100000);
break;
default:cout<<"n !!Wrong Choice!!";
}
bank.display();
getch();
}
Output
Q.3) WAP to create the class ADMISSION that generates two random
admission nos. from the list of given admission nos.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
int i;
class ad{ int adno;
char name[10];
float fees;
int clas;
public:
void readdata();
void draw_nos();
int getadno()
{ return adno; } };
ad A1[5];
void ad::draw_nos()
{ int n1=0,n2=0;
randomize();
n1=random(4);
n2=random(4);
for(i=0;i<3;i++)
if((A1[i].getadno()==n1)||(A1[i].getadno()==n2));
cout<<"nRandomly generated admission nos are:"<<n1<<" and "<<n2;
}
void ad::readdata()
{ cout<<"nEnter admission no:"; cin>>adno;
cout<<"Name:"; cin>>name;
cout<<"Class:"; cin>>clas;
cout<<"Fees:"; cin>>fees; }
void main()
{clrscr();
for(i=0;i<3;i++)
{ A1[i].readdata(); }
A1[i-1].draw_nos();
getch();
}
OUTPUT
Q.4)WAP to show working of constructor and destructor in a class.
#include<iostream.h>
#include<conio.h>
class A{ public:
A()
{cout<<"n Constructor A";}
~A()
{cout<<"n Destructor A";}
};
class B{ public:
B()
{cout<<"n Constructor B";}
~B()
{cout<<"n Destructor B";}
};
class C{ public:
A ob1,ob2;
B ob3;
C()
{cout<<"n Constructor C";}
~C()
{cout<<"n Destructor C";}
};
void main()
{clrscr();
C oc;
B ob;
A oa;
getch();
}
Output
Q.5)Write a program to maintain the details of college students and
print them using inheritance.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
const int len = 25 ;
class person
{ char name[len];
int age;
public:
void readperson(void) ;
void displayperson(void)
{ cout<<"Name : ";
cout.write(name,len);
cout<<"t Age : " <<age<<"n";
}
};
void person::readperson(void)
{ for(int i=0;i<len;i++)
name[i]=' ';
cout<<"Enter name of the person :";
gets(name);
cout<<"Enter age :";
cin>>age;
}
class student: public person
{ int rollno;
float average ;
public:
void readstudent(void)
{ readperson();
cout<<"Enter roll no. : ";
cin>>rollno;
cout<<"Enter average marks : ";
cin>>average;
}
void disp_rollno(void)
{ cout<<"Roll no : "<<rollno<<"n";
}
float getaverage(void)
{ return average ;
}
};
class gradstudent :public student
{ char subject[len];
char working;
public :
void readit(void);
void displaysubject(void)
{ cout<<"Subject : " ;
cout.write(subject,len);
}
char workstatus(void)
{ return working;
}
};
void gradstudent::readit(void)
{ readstudent();
for(int i=0 ;i<len;i++)
subject[i]=' ';
cout<<"Enter main subject : ";
gets(subject);
cout<<"Working?(y/n) : ";
cin>>working;
}
void main()
{ clrscr();
const int size = 5 ;
gradstudent grad[size];
int year,num_working=0,non_working=0,div1=0,total=0;
float topscore = 0,score, number,wperc,nwperc;
cout<<"Enter year :";
cin>>year;
char ch=' ';
int i;
for(i=0;i<10;i++)
{ cout<<"Enter details for graduate "<<(i+1)<<" (maximum 10)n";
grad[i].readit();
total++;
if(grad[i].workstatus() =='y'||(grad[i].workstatus() == 'Y'))
num_working++;
else
non_working++;
score=grad[i].getaverage() ;
if(score>topscore)
{ topscore=score;
number=i;
}
if(score>=60.0)
div1++;
cout<<"Press y to see report and n to continue";
cin>>ch;
if(ch=='y'||ch=='Y')
break;
}
i=number;
cout<<"n"<<"ttttReport of the year " <<year<<"n";
cout<<"tttt-----------------------n";
cout<<"Working graduates : " <<num_working<<"n";
cout<<"Non working graduates : "<<non_working<<"n";
cout<<"Details of topper n";
grad[i].displayperson();
grad[i].displaysubject();
nwperc=((float)non_working/(float)total)*100;
wperc=((float)div1/(float)total)*100;
cout<<"Average marks : "<<grad[i].getaverage()<<"n";
cout<<nwperc<<"% of the graduates this year are non working and "<<wperc<<"% are
first divisionersn";
getch();
}
OUTPUT
Q.6) WAP to show constructor overloading.
#include<iostream.h>
#include<conio.h>
class Deposit{ long int principal;
int time;
float rate;
float total_amt;
public:
Deposit();
Deposit(long p,int t,float r);
Deposit(long p,int t);
Deposit(long p,float r);
void calc_amt(void);
void display(void); };
Deposit::Deposit()
{principal=time=rate=0.0;}
Deposit::Deposit(long p,int t,float r)
{principal=p;time=t;rate=r;}
Deposit::Deposit(long p,int t)
{principal=p;time=t;rate=0.08;}
Deposit::Deposit(long p,float r)
{principal=p;time=2;rate=r;}
void Deposit::calc_amt(void)
{ total_amt=principal+(principal*time*rate)/100;
}
void Deposit::display(void)
{ cout<<" Principal Amount: "<<principal;
cout<<"n Time Period: "<<time;
cout<<"n Rate of interest: "<<rate;
cout<<"n Total Amount: "<<total_amt<<"n";
}
void main()
{ clrscr();
Deposit D1,D2(2000,2,0.07f),D3(4000,1),D4(3000,0.12f);
D1.calc_amt(); D2.calc_amt();
D3.calc_amt(); D4.calc_amt();
cout<<"n Object1:n"; D1.display();
cout<<"n Object2:n"; D2.display();
cout<<"n Object3:n"; D3.display();
cout<<"n Object4:n"; D4.display();
getch();
}
Output
Q.7) Write a menu driven program to create the text file that
i. Count the no of words in a file.
ii. Count the no of lines a file.
iii. Count and display the words starting with the vowels.
iv. Count the words starting with uppercase alphabets.
v. Count the no of spaces.
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void file_content()
{ ofstream fout("xyz.txt");
char ch[200];
cout<<"nEnter the content of the file: ";
cin.getline(ch,200);
fout<<ch;
fout.close();
}
void vowel()
{ ifstream fin("xyz.txt");
char ch[20];
while(!fin.eof())
{ fin>>ch;
switch(ch[0])
{ case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
cout<<"nWords starting from vowels is: "<<ch<<"n";
}
}
}
void word_count()
{ ifstream fin ("xyz.txt");
char ch;
int count=0;
while (!fin.eof())
{ fin.get(ch);
if(ch==' ')
++count;
}
cout<<"nNo. of words are: "<<++count<<"n";
fin.close();
}
void count_spaces()
{ ifstream fin ("xyz.txt");
char ch;
int count=0;
while (!fin.eof())
{ fin.get(ch);
if(ch==' ')
++count;
}
cout<<"nNo. of spaces are: "<<count<<"n";
fin.close();
}
void count_lines()
{ char str[100];
int count=0;
ifstream fin("xyz.txt");
while(!fin.eof())
{ fin.getline(str,100);
++count;
}
cout<<"nNo. of lines are: "<<count<<"n";
}
void count_uppercase()
{ ifstream fin("xyz.txt");
int count=0;
char ch;
while(!fin.eof())
{ fin>>ch;
if(isupper(ch))
++count;
}
fin.close();
cout<<"nNo. of upper case alpahabets are: "<<count<<"n";
}
void main()
{ clrscr();
file_content();
word_count();
count_lines();
vowel();
count_uppercase();
count_spaces();
getch();
}
OUTPUT
Q.8) Write a program to create the binary file and display them.
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
class student
{ char name[50];
char grade;
float marks;
public: void getdata(void);
void display(void); };
void student::getdata(void)
{ char ch;
cin.get(ch);
cout<<"n"<<"ENTER NAME : - ";
cin>>name;
cout<<"n"<<"ENTER GRADE : - ";
cin>>grade;
cout<<"n"<<"ENTER MARKS : - ";
cin>>marks;
cout<<"n"; }
void student::display(void)
{cout<<"NAME : - "<<name<<"t";
cout<<"GRADE : - "<<grade<<"t";
cout<<"MARKS : - "<<marks<<"t"<<"n";}
int main()
{ clrscr();
student arts[5];
fstream filin ;
filin.open("stu.dat",ios::in|ios::out);
if(!filin)
{ cout<<"SORRY CAN NOT OPEN THE FILE"<<"n";
return 1; }
cout<<"ENTER DETAILS OF THE 2 STUDENTS : - "<<"n";
for(int i=0;i<2;i++)
{ arts[i].getdata();
filin.write((char*)&arts[i],sizeof(arts[i])); }
filin.seekg(0);
cout<<"n";
cout<<"THE CONTENTS OF THE STU.DAT IS AS SHOWN BELOW : - "<<"n";
for(i=0;i<2;i++)
{ filin.read((char*)&arts[i],sizeof(arts[i]));arts[i].display();}
filin.close();
getch(); }
Output
Q.9) Write a program to search a record in a file.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class stu
{ int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{ cout<<"ROLL NUMBER";
cin>>rollno;
cout<<"NAME";
cin>>name;
cout<<"CLASS";
cin>>Class;
cout<<"MARKS";
cin>>marks;
}
void putdata()
{ cout<<”Name-“<<name<<"Roll No-"<<rollno<<”Marks=”<<marks;
}
int getrno()
{ return rollno;
}
} s1;
void main()
{ clrscr();
int rn; char found='n';
ifstream fi("stu.dat",ios::in);
cout<<"ENTER ROLL NUMBER TO BE SEARCHED : - ";
cin>>rn;
while (!fi.eof())
{ fi.read((char*)&s1,sizeof(s1));
if(s1.getrno()==rn)
{ s1.putdata();
found='y';
break; }
} if(found=='n')
cout<<"ROLL NUMBER NOT FOUND IN THE FILE"<<endl;
fi.close();}
Output
Q.10)WAP to append data from file.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
class stu
{ clrscr();
int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{ cout<<"n Rollno: "; cin>>rollno;
cout<<"n Name: "; cin>>name;
cout<<"n Class: "; cin>>Class;
cout<<"n Marks: "; cin>>marks;
if(grade>=75) grade='A';
else if(grade>=60) grade='B';
else if(grade>=50) grade='C';
else if(grade>=40) grade='D';
else grade='F';
}
void putdata()
{ cout<<name<<"n Rollno "<<rollno<<"has"<<marks
<<"% Marks and "<<grade<<"Grade: "<<endl;
}
int getrno()
{ return rollno;
}
} s1;
void main()
{ ofstream fo("n stu.dat",ios::app);
char ans='y';
while(ans=='y')
{ s1.getdata();
fo.write((char*)&s1,sizeof(s1));
cout<<"n Record added to file.n";
cout<<"n Want to enter more records?(y/n)?: ";
cin>>ans;
}
fo.close();}
Output
Q.11) Write a program to insert data in a file.
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class stu
{ int rollno;
char name[25];
float marks;
public:
void getdata()
{ cout<<"ROLL NUMBER : - ";
cin>>rollno;
cout<<"NAME : - ";
gets(name);
cout<<"MARKS : - ";
cin>>marks;
}
void putdata()
{ cout<<"nName-"<<name<<"n";
cout<<"Roll No- "<<name<<"n";
cout<<"Marks= "<<marks<<"n";
}
int getrno()
{return rollno;
}
};
stu s1,stud;
void main()
{ clrscr();
ofstream f("stu.dat",ios::out|ios::app);
ifstream fi("stu.dat",ios::in|ios::app);
ofstream fo("temp.dat",ios::out|ios::app);
char last='y';
cout<<"enter the details of students whose record is to be insertedn";
s1.getdata();
while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
if(s1.getrno()<=stud.getrno())
{ fo.write((char*)&s1,sizeof(s1));
last='n';
break; }
else
fo.write((char*)&stud,sizeof(stud));
}
if(last=='y')
fo.write((char*)&s1,sizeof(s1));
else if(!fi.eof())
{ while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
fo.write((char*)&stud,sizeof(stud));
}
}
fi.close();
fo.close();
remove("stu.dat");
rename("temp.dat","stu.dat");
ifstream ko;
ko.open("stu.dat",ios::in);
cout<<"file now contains"<<endl;
while(!ko.eof())
{ ko.read((char*)&stud,sizeof(stud));
if(ko.eof())
break;
stud.putdata(); }
ko.close();
getch();
}
Output
Q.12) Write a program to delete data from a file.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class stu
{ int rollno;
char name[25];
char cls;
float marks;
public:
void getdata()
{ cout<<"ROLL NUMBER : - ";
cin>>rollno;
cout<<"NAME : - ";
gets(name);
cout<<"CLASS : - ";
cin>>cls;
cout<<"MARKS : - ";
cin>>marks;
}
void putdata()
{ cout<<"nName- "<<name<<"n";
cout<<"Roll No- "<<rollno<<"n";
cout<<"Marks="<<marks<<"n";
}
int getrno()
{ return rollno;
}
}s1,stud;
void main()
{ clrscr();
ifstream fi("STU.DAT",ios::in);
ofstream fo("TEMP.DAT",ios::out);
int rno;
char found='f',confirm='n';
cout<<"ENTER ROLL NUMBER OF STUDENT WHOSE RECORD IS TO BE
DELETED:-";
cout<<"n";
cin>>rno;
while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
if(s1.getrno()==rno)
{ s1.putdata();
found='t';
fo.write((char*)&s1,sizeof(s1));
}
else
fo.write((char*)&s1,sizeof(s1));
}
if(found=='n')
cout<<"SORRY RECOD NOT FOUND"<<endl;
fi.close();
fo.close();
remove("STU.DAT");
rename("TEMP.DAT","STU.DAT");
fi.open("STU.DAT",ios::in);
cout<<"FILE NOW CONTAINS : - "<<"n"<<endl;
while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
if(fi.eof())
break;
stud.putdata();
}
fi.close();
getch();
}
Output
Q.13) Write a program to modify data in a file.
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
class stu
{ int rollno;
char name[25];
char Class[4];
float marks;
public:
void getdata()
{ cout<<"Enter Name-";
cin>>name;
cout<<"Enter Roll No-";
cin>>rollno;
cout<<"Enter Marks ";cin>>marks;
}
int getrno()
{ return rollno ;
}
void modify() ;
};
s1,stud ;
void stu::modify()
{ cout<<"ROLL NUMBER : - "<<rollno<<endl;
cout<<"NAME : - "<<name<<"t";
cout<<"CLASS : - "<<Class<<"t";
cout<<"MARKS : - "<<marks<<endl;
cout<<"ENTER NEW DETAILS : - "<<endl;
char nm[20]=" ",cl[4]=" ";
float mks ;
cout<<”Enter Name-";
cin>>nm;
cout<<"Enter Roll No- ";
cin>>rn;
cout<<"Enter Marks= ";
cin>>mks;
if(strcmp(nm,".")!= 0)
strcpy(name, nm);
if(strcmp(cl,".")!=0)
strcpy(Class,cl);
if(mks!= -1)
{ marks=mks;
if(marks >= 75) }
}
void main()
{ clrscr();
fstream fio("stu.dat", ios::in|ios::out|ios::binary);
int rno; long pos; char found='f';
cout<<"ENTER ROLL NUMBER OF THE STUDENT WHOSE RECORD IS TO
MODIFY:-";
cout<<"n";
cin>>rno;
while(!fio.eof())
{ pos=fio.tellg();
fio.read((char*) &s1, sizeof(s1));
if (s1.getrno()==rno)
{ s1.modify();
fio.write((char*) &s1, sizeof(s1));
found='t';
break;
}
}
if(found=='f')
cout<<"SORRY RECORD NOT FOUND"<<"n";
fio.seekg(0);
fio.close();
getch();
}
Output
Q.14) Create a menu driven program to show searching operation in 1-
D array using (I)Lsearch (II) Bsearch
#include<iostream.h>
#include<conio.h>
int Lsearch(int[],int,int);
int Bsearch(int[],int,int);
void main()
{clrscr();
int n,AR[50],i,item,index;
int ch=0;
cout<<"n Menu: ";
cout<<"n 1.Linear Search";
cout<<"n 2.Binary Search";
cout<<"n Enter Choice(1/2): ";
cin>>ch;
cout<<"n Enter the Desired array size(Max.50): ";
cin>>n;
cout<<"n Enter Array elements ";
for(i=0;i<n;i++)
{ cin>>AR[i]; }
cout<<"n Enter Elements to be searched for: ";
cin>>item;
switch(ch)
{ case 1:{ index=Lsearch(AR,n,item);
if(index==-1)
cout<<"n Sorry!! Given element could not be found.";
else
cout<<"n Element found at index: "<<index;
cout<<"n Position: "<<index+1<<endl;
break;}
case 2:{ index=Bsearch(AR,n,item);
if(index==-1)
cout<<"n Sorry!! Given element could not be found.";
else
cout<<"n Element found at index: "<<index;
cout<<"n Position: "<<index+1<<endl;
break;}
default:{cout<<"n Wrong Choice";}
break;
}
getch();
}
int Lsearch(int arr[50],int size,int it)
{
for(int j=0;j<size;j++)
{if(arr[j]==it)
return j;
}
return-1;
};
int Bsearch(int arr[50],int size,int it)
{ int beg,last,mid;
beg=0;
last=size-1;
while(beg<=last)
{ mid=(beg+last)/2;
if(it==arr[mid])
return mid;
else if(it>arr[mid])
beg=mid+1;
else
last=mid-1;
}
return -1;
};
Output
Q.15)WAP menu driven program to insert & delete an element in a
sorted array.
#include<iostream.h>
#include<conio.h>
#include<process.h>
int FindPos(int[],int,int);
int Lsearch(int[],int,int);
int Insertion(int[],int);
int Deletion(int[],int);
void main()
{clrscr();
int AR[50],N,choice;
cout<<"n Enter size of array(Max.50): ";
cin>>N;
cout<<"n Enter array elements is ascending order:n";
for(int i=0;i<N;i++)
{ cin>>AR[i];}
cout<<"n Menu:";
cout<<"n 1.Insertion";
cout<<"n 2.Deletion";
cout<<"n Enter Choice(1/2): ";
cin>>choice;
switch(choice)
{case 1: Insertion(AR,N);
break;
case 2: Deletion(AR,N);
break;
default:cout<<"n !!Please enter either 1 or 2";
break;
}
getch();
}
int Insertion(int ar[],int y)
{char ch='y';
int item,index,i;
while(ch=='y'||ch=='Y')
{ cout<<"n Enter element to be inserted: ";
cin>>item;
if(y==50)
{ cout<<"n Overflow";
exit(1);
}
index=FindPos(ar,y,item);
for(i=y;i>index;i--)
{ ar[i]=ar[i-1];}
ar[index]=item;
y=y+1;
cout<<"n Want to insert more element(Y/N)?: ";
cin>>ch;
}
cout<<"n Array after insertion is: n";
for(i=0;i<y;i++)
{ cout<<ar[i]<<" ";}
}
int FindPos(int AR[],int size,int item)
{int pos;
if(item<AR[0]) pos=0;
else
{ for(int i=0;i<size-1;i++)
{ if(AR[i]<=item&&item<AR[i+1])
{ pos=i+1;
break;
} }
if(i==size-1) pos=size;
}
return pos;}
int Deletion(int AR[],int N)
{ char ch='y';
int item,index,i;
while(ch=='y'||'Y')
{ cout<<"n Enter element to be deleted: ";
cin>>item;
if(N==0)
{ cout<<"Underflow!!";
exit(1);
}
index=Lsearch(AR,N,item);
if(index!=-1)
AR[index]=0;
else
cout<<"n !!Sorry no such element is found";
for(i=index;i<N;i++)
{ AR[i]=AR[i+1];}
N=N-1;
cout<<"n Want to delete more(Y/N)?";
cin>>ch;
cout<<"n Array after deletion is: n";
for(i=0;i<N;i++)
cout<<AR[i]<<" ";
break;
}}
int Lsearch(int AR[],int size,int item)
{ int i;
for(i=0;i<size;i++)
{ if(AR[i]==item)
return i;
}
return -1;
}
Output
Q.16) Write a program to merge two 1-D arrays into third array.
#include<iostream.h>
#include<conio.h>
void Merge(int[],int,int[],int,int[]);
void main()
{ clrscr();
int A[20],B[20],C[40],m,n,mn=0;
cout<<"Enter no of element in first array in acs order";
cin>>m;
for(int i=0;i<m;i++)
cin>>A[i];
cout<<"Enter no of element in second array in desc order";
cin>>n;
for(i=0;i<n;i++)
cin>>B[i];
mn=m+n;
Merge(A,m,B,n,C);
cout<<"Resultant array is";
for(i=0;i<mn;i++)
cout<<C[i];
getch();
}
void Merge(int A[],int m,int B[],int n,int C[])
{ int a,b,c;
for(a=0,b=n-1,c=0;a<m&&b>=0;)
{ if(A[a]<=B[b])
C[c++]=A[a++];
else
C[c++]=B[b--];
}
}
Output
Q.17) Write a menu driven program to sort elements using selection
sort and bubble sort.
#include<iostream.h>
#include<conio.h>
void selsort(int[],int);
void bubblesort(int[],int);
void main()
{ clrscr();
int AR[50],ITEM,N,index,n;
cout<<"How many element you want to insert in array?(Max.50): ";
cin>>N;
cout<<"Enter element of array: ";
for(int i=0;i<N;i++)
cin>>AR[i];
cout<<"Menun"<<"1.Selection Sortn"<<"2.Bubble Sortn"<<"Enter Choice: ";
cin>>n;
switch(n)
{ case 1: selsort(AR,N);
break;
case 2: bubblesort(AR,N);
break;
default:cout<<"Enter Valid Choice";
break;
}
cout<<"nThe Sorted Array is shown below:n";
for(i=0;i<N;i++)
cout<<AR[i]<<" ";
cout<<endl;
getch();
}
void selsort(int AR[], int size)
{ int small,pos,tmp;
for(int i=0;i<size;i++)
{ small=AR[i];
for(int j=i+1;j<size;j++)
{ if(AR[j]<small)
{ small=AR[j];
pos=j;
}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
}
cout<<"nArray after pass:"<<i+1<<" is-n";
for(int k=0;k<size;k++)
cout<<AR[k]<<" ";
}
}
void bubblesort(int AR[],int size)
{ int tmp, ctr=0;
for(int i=0;i<size;i++)
{ for(int j=0;j<(size-1)-i;j++)
{ if(AR[j]>AR[j+1])
{ tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp;
}
}
cout<<"Array after iteration:"<<++ctr<<" is:n";
for(int k=0;k<size;k++)
cout<<AR[k]<<" ";
cout<<endl;
}
}
Output
Q.18) Write a program to convert 1D array into 2D array.
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int ar [20],arr[20][20];
int i,j,size;
cout<<"Enter size of arrayn";
cin>>size;
cout<<"Enter 1d-arrayn";
for(i=0;i<size;i++)
{ cin>>ar[i];
}
cout<<"Your array isn";
for(i=0;i<size;i++)
{ cout<<ar[i];
cout<<"t";
}
cout<<"n";
for(i=0;i<size;i++)
for(j=0;j<size;j++)
arr[i][j]=ar[j];
cout<<"Your required 2d array isn";
for(i=0;i<size;i++)
{ for(j=0;j<size;j++)
{ cout<<arr[i][j]<<"t";
}
cout<<"n";
}
getch();
}
Output
Q.19) Write a program for pushing and popping in a stack implemented
as linked list.
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int info;
node*next;
}*top,*newptr,*save,*ptr;
node*create_new_node(int);
void push(node*);
void display(node*);
void pop();
void main()
{ clrscr();
top=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"n Enter the information"<<"t";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{ cout<<"n cannot create new node!!!";
exit(1);
}
push(newptr);
cout<<"n press Y to enter more nodes, n to exit"<<" ";
cin>>ch;
}
clrscr();
do
{ cout<<"n stack is now:n";
display(top);
getch();
cout<<"n want to pop an element?(y/n)"<<" ";
cin>>ch;
if(ch=='y'||ch=='Y')
pop();
}while(ch=='y'||ch=='Y');
}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
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->info<<"->";
np=np->next;
} cout<<"!!!n";
}
Output
Q.20) Write a program to show insertion and deletion from linked
queue.
#include<iostream.h>
#include<conio.h>
struct node
{ int data;
node*next;
};
node*add(node*rear,int val);
node*delet(node*front);
void show(node*front);
void main()
{ node*front,*rear;
int val,choice;
front=rear=NULL;
clrscr();
do{
cout<<"nMenu";
cout<<"n 1. ADD";
cout<<"n 2. Delete";
cout<<"n 3. Show";
cout<<"n 4. Quit";
cout<<"n Enter your choice"<<" ";
cin>>choice;
switch(choice)
{
case 1:cout<<"n Enter the vlaue to be added"<<" ";
cin>>val;
rear=add(rear,val);
if(front==NULL)
front=rear;
break;
case 2:front=delet(front);
if(front==NULL)
rear=front;
break;
case 3:show(front);
break;
}
}
while(choice!=4);
}
node*add(node*rear,int val)
{ node*x;
x=new node;
x->data=val;
x->next=NULL;
if(rear!=NULL)
{
rear->next=x;
}
rear=x;
return(rear);
}
node*delet(node*front)
{
node*x;
int val;
if(front==NULL)
{ cout<<"nQueue is empty";
val=-999;
}
else
{
x=front;
front=front->next;
val=x->data;
delete x;
}
cout<<val;
return(front);
}
void show(node*front)
{
node*ptr;
ptr=front;
cout<<"nThe queue is:";
while(ptr!=NULL)
{
cout<<ptr->data<<" ";
ptr=ptr->next;
}
}
Output
21.) Write SQL command for (a) for (f) and write the output for (g)
on the basis of tables Student.
Table: Student
No. Name Age Department Dateofadm Fee Sex
1. Pankaj 24 Computer 10/01/97 120 M
2. Shalini 21 History 24/03/98 200 F
3. Sanjay 22 Hindi 12/12/96 300 M
4. Sudha 25 History 01/07/99 400 F
5. Rakesh 22 Hindi 05/09/97 250 M
6. Shakeel 30 History 27/06/98 300 M
7. Surya 34 Computer 25/02/97 210 M
8. Sikha 23 Hindi 31/07/97 200 F
a) To show all information about all students of the History
Department.
b) To list the names of female students who are of Hindi
department.
c) To list name of all students with their name in ascending order.
d) To display student’s name, fee, age for male students only.
e) To count the number of student with Age<23.
f) To isnert a new row in the STUDENT table with the following
data :
9, “Zaheer”, 36 , “Computer”, {12/03/97}, 230, ‘M’
g) Give the output of following SQL statements :
(i) Select COUNT (distinct departments) from STUDENT ;
(ii) Select MAX (Age) from STUDENT where Sex = ”F” ;
(iii) Select AVG (fee) form STUDENT where Dateofadm
<{01/01/98} ;
(iv) Select SUM (Fee) from STUDENT where Dateofadm
<{01/01/98} ;
Answers)
(a) SELECT * FROM Student
WHERE Depatment = “History”;
(b) SELECT Name FROM Student
WHERE sex =”F” and
Depatment = “History”;
(c) SELECT name FROM Student
ORDER BY Dateofadm;
(d) SELECT Name, Fee, Age
FROM Student
WHERE sex = “M”;
(e) SELECT COUNT (*) FROM Student
WHERE Age>23 ;
(f) INSERT INTO Student
VALUES (9, “Zaheer”, 36 , “Computer”, {12/03/97}, 230, ‘M’) ;
(i) 3 (ii)25 (iii)236 (iv) 1080
22.) Write SQL commands for (a) to (f) and Write to outputs for
(g) on the basis of table HOSPITAL.
Table: HOSPITAL
No. Name Age Department Dateofadm Charges Sex
1. Sandeep 62 Surgery 21/01/98 300 M
2. Ravina 22 ENT 12/12/97 250 F
3. Karan 32 Orthopedic 19/02/98 200 M
4. Tarun 12 Surgery 11/01/98 300 M
5. Zubin 30 ENT 12/01/98 250 M
6. Ketaki 16 ENT 24/02/98 250 F
7. Ankita 29 Cardiology 20/02/98 800 F
8. Zareen 45 Gynecology 22/05/98 300 F
9. Kush 19 Cariology 13/01/98 800 M
10. Shalya 23 Nuclaer Medicine 21/02/98 400 F
a) To select all information about all patient of the CARIOLOGY
Department.
b) To list the names of female patients who are in ENT
Department.
c) The list names of all patients with date date of admission in
ascending order.
d) To display Patient’s name, Charges, Age for only male patients.
e) To count the number of patients with Age<30.
f) To insert a new row in the HOSpital table with the following
date ;
11, “Mustafa” , 37, “ENT”, {25/02/98}, 250, “M”
g) Give the output of the following SQL statements :
(i) Select COUNT (distict department) from HOSPITAL ;
(ii) Select MAX( Age) from HOSPITAL where Sex =”M”
(iii)Select AVG (Charges) form HOSPITAL where Sex =”F”
(iv)Select SUM ( Charges) from HoSPITAL where Dateofadm<
{10/08/98}
Answers)
(a) SELECT * FROM Hospital
WHERE Depatment = “Cardiology”;
(b) SELECT Name FROM Hospital
WHERE sex =”F” and
Depatment = “Orthopedic”;
(c) SELECT name FROM Hospital
ORDER BY Dateofadm;
(d) SELECT Name, Charges, Age
FROM Hospital
WHERE sex = “M”;
(e) SELECT COUNT (*) FROM Hospital
WHERE Age<30 ;
(f) INSERT INTO Hospital
VALUES (11, “Mustafa”, 37 , “ENT”, {25/02/97}, 250, “M”) ;
(i) 6 (ii)65 (iii)400 (iv) 3850
23.) Write SQL commands for (a) to (f) and write output for (g) on
the basis of Teacher relation given below:
Table: Teacher
No. Name Age Department Date of join Salary Sex
1. Jugal 34 Computer 10/01/97 12000 M
2. Sharmila 31 History 24/03/98 20000 F
3. Sandeep 32 Maths 12/12/96 30000 M
4. Sangeeta 35 History 01/07/99 40000 F
5. Rakesh 42 Maths 05/09/97 25000 M
6. Shayam 50 History 27/06/98 30000 M
7. Shiv Ov 44 Computer 25/02/97 21000 M
8. Shalakha 33 Maths 31/07/97 20000 F
a) To select all information about all Teachers of the history
department.
b) To list the names of female Teachers who are in Hindi Department.
c) The list names of all Teachers with date of joining in ascending
order.
d) To display students’ Name, Fees, Age for only male teachers.
e) To count the number of patients with Age<23.
f) To insert a new row in the HOSPITAL table with the following date
;
11, “Raja” , 26, “Computer”, {13/05/95}, 2300, “M”.
g) Give the output of the following SQL statements :
(i) Select COUNT (distict department) from TEACHER ;
(ii) Select MAX( Age) from TEACHERS where Sex =”F”
(iii)Select AVG (Salary) form TEACHERS where
Dateofadm< {10/08/98}
(iv)Select SUM (Salary) from TEACHERS where
Dateofadm< {10/08/98
Answers)
(a) SELECT * FROM Teacher
WHERE Department = “History”;
(b) SELECT Name FROM Hospital
WHERE sex =”F” and
Department = “Hindi”;
(c) SELECT name FROM Teacher
ORDER BY Dateofadm;
(d) SELECT Name, Salary, Age
FROM Teacher
WHERE sex = “M” AND Age>23;
(e) SELECT COUNT(*) FROM Hospital
WHERE Age<23 ;
(f) INSERT INTO Teacher
VALUES (9, “Raja”, 26 , “Computer”, {13/02/95}, 2300, “M”) ;
(i) 3 (ii)35 (iii)23600 (iv) 2300
24.) Write SQL command for (a) for (f) and write the output for (g)
on the basis of tables FURNITURE and ARRIVALS.
Table: FURITURE
NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1
2
3
4
5
6
7
8
9
10
White Lotus
Pink Feather
Dolphin
Decent
Comfort zone
Donald
Royal Finish
Royal Tiger
Econo sitting
EatingParadise
Double Bed
Baby cot
Baby cot
OfficeTable
Double Bed
Baby cot
OfficeTable
Sofa
Sofa
Dining Table
23/02/02
20/01/02
19/02/02
01/01/02
12/01/02
24/01/02
20/02/02
22/02/02
13/13/01
19/02/02
30000
7000
9500
25000
25000
6500
18000
31000
90005
110005
25
20
20
30
25
15
30
30
25
25
Table: ARRIVALS
NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
11
12
13
Wood Comfort
Old Fox
Mickey
Double Bed
Sofa
Baby cot
23/03/03
20/02/03
21/02/03
25000
17000
7500
25
20
15
a) To show all info about the Baby cots from the FURNITURE
table.
b) To list the ITEMNAME which are priced at more than 15000
from the FURNITURE table.
c) To list ITEMNAME and TYPE of those items, in which
DATEOFSTOCK is before 22/01/02 from the FURNITURE table
in descending order of ITEMNAME.
d) To display ITEMNAME and DATEOFSTOCK of those items, in
which the DISCOUNT percentage is more than 25 from
FURNITURE table.
e) To count the number of items, whose TYPE is “Sofa” from the
FURNITURE table.
f) To insert a new row in the ARRIVALS table with the following
data:
14, ”Velvet Touch”, Double Bed, (25/03/03), 25000, 30
g) Give the output of the following statement:
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE, ARRIVALS;
(iii) Select AVG(DISCOUNT) from FURNITURE where
TYPE=”Baby cot”.
(iv) Select SUM(PRICE) from FURNITURE where
DATAOFSTOCK < (12/02/02).
Answer)
a) Select* From FURNITURE Where TYPE=”Baby cot”;
b) Select ITEMNAME From FURNITURE Where PRICE > 15000;
c) Select ITEMNAME, TYPE From FURINTURE;
Where DATEOFSTOCK < (22/01/02) Order by ITEMNAME;
d) Select ITEMNAME, DATEOFSTOCK From FURINTURE Where DISCOUNT >
25;
e) Select Count(*) From FURNITURE Where TYPE=”Sofa”;
f) Insert Into ARRIVALS Values(14, ”Velvet Touch”, Double Bed, (25/03/03),
25000, 30)
g) (i) 5 (ii)30 (iii)18.33 (iv)66500.
25.) Write the SQL command for (a) to (f) and write the output for
(g) on the basis of tables INTERIORS and NEWONES.
Table: INTERIORS
NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Red rose
Soft touch
Jerry’s home
Rough wood
Comfort zone
Jerry look
Lion king
Royal tiger
Park sitting
Dine Paradise
Double Bed
Baby cot
Baby cot
Office Table
Double Bed
Baby cot
Office Table
Sofa
Sofa
Dining Table
23/02/02
20/01/02
19/02/02
01/01/02
12/01/02
24/01/02
20/02/02
22/02/02
13/13/01
19/02/02
32000
9000
8500
20000
15000
7000
16000
30000
9000
11000
15
10
10
20
20
19
20
25
15
15
Table: NEWONES
NO. ITEMNAME TYPE DATEOFSTOCK Price DISCOUNT
11.
12.
13.
White wood
James 007
Tom look
Double Bed
Sofa
Baby cot
23/03.03
20/02/03
21/02/03
20000
15000
7000
20
15
10
a) To show all info about the Sofas from the INTERIORS table.
b) To list the ITEMNAME which are priced at more than 10000
from the INTERIORS table.
c) To list ITEMNAME and TYPE of those items, in which
DATEOFSTOCK is before 22/01/02 from the INTERIORS table
in decreasing order of ITEMNAME.
d) To display ITEMNAME and DATEOFSTOCK of those items, in
which the discount percentage is more than 15 from the
INTERIORS table.
e) To count the no of items whose type is “Double Bed” from the
table INTERIORS.
f) To insert a new tow in the NEWONES table with the following
data:
14,”True Indian”, “Office Table”, (28/03/03), 15000, 20.
g) Give the output of the following statement:
(i) Select COUNT(distinct TYPE) from INTERIORS;
(ii) Select AVG(DISCOUNT) from INTERIORS, where
DATEOFSTOCK<(12/02/02).
(iii) Select SUM(Price) form INTERIORS where
DATEOFSOCK<(12/02/02).
Answer)
a) Select* From INTERIORS Where PRICE>10000;
b) Select ITEMNAME, TYPE From INTERIORS
c) Select ITEMNAME, TYPE From INTERIORS
Where DATEOFSTOCK < (22/01/02) Order by ITEMNAME;
d) Select ITEMNAME, DATEOFSTOCK From INTERIORS Where
DICSOUNT>15;
e) Select Count(*) From INTERIORS Where TYPE=”Double Bed”;
f) Insert Into NEWONES Values
(14,”True Indian”, “Office Table”, (28/03/03), 15000, 20);
e) (i)5 (ii)13 (iii)43000
BIBLIOGRAPHY
1. COMPUTER SCIENCE text book
By: SUMITA ARORA
2. INTERNET and various websites.

More Related Content

What's hot

Types of function call
Types of function callTypes of function call
Types of function callArijitDhali
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data typesMohd Sajjad
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance pptNivegeetha
 
Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsFALLEE31188
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java yash jain
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 
PYTHON FEATURES.pptx
PYTHON FEATURES.pptxPYTHON FEATURES.pptx
PYTHON FEATURES.pptxMaheShiva
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS abhishek kumar
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++Sujan Mia
 

What's hot (20)

Types of function call
Types of function callTypes of function call
Types of function call
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
PYTHON FEATURES.pptx
PYTHON FEATURES.pptxPYTHON FEATURES.pptx
PYTHON FEATURES.pptx
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
This pointer
This pointerThis pointer
This pointer
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 

Similar to C++ 25 programs Class XII

CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory projectDIVYANSHU KUMAR
 
Intro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesIntro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesBlue Elephant Consulting
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Blue Elephant Consulting
 
Pandas tool for data scientist
Pandas tool for data scientist Pandas tool for data scientist
Pandas tool for data scientist MoTechInc
 
CSCI 383 Lecture 3 and 4: Abstraction
CSCI 383 Lecture 3 and 4: AbstractionCSCI 383 Lecture 3 and 4: Abstraction
CSCI 383 Lecture 3 and 4: AbstractionJI Ruan
 
Let's Peel Mangos
Let's Peel MangosLet's Peel Mangos
Let's Peel MangosSam Basu
 
ConSteel_14_User_Manual-351-359.pdf
ConSteel_14_User_Manual-351-359.pdfConSteel_14_User_Manual-351-359.pdf
ConSteel_14_User_Manual-351-359.pdfJuanUnafVargas
 
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AEBank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AEEngr. Md. Jamal Uddin Rayhan
 
Airflow - Insane power in a Tiny Box
Airflow - Insane power in a Tiny BoxAirflow - Insane power in a Tiny Box
Airflow - Insane power in a Tiny BoxDovy Paukstys
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioDurgesh Singh
 
Cw comp1661 211574_mo233_20131122_234918_1314
Cw comp1661 211574_mo233_20131122_234918_1314Cw comp1661 211574_mo233_20131122_234918_1314
Cw comp1661 211574_mo233_20131122_234918_1314Owen Muzi
 
CSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: AbstractionCSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: AbstractionJI Ruan
 

Similar to C++ 25 programs Class XII (20)

CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
 
Intro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesIntro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & Classes
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
Pandas tool for data scientist
Pandas tool for data scientist Pandas tool for data scientist
Pandas tool for data scientist
 
Intro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm ReviewIntro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm Review
 
CSCI 383 Lecture 3 and 4: Abstraction
CSCI 383 Lecture 3 and 4: AbstractionCSCI 383 Lecture 3 and 4: Abstraction
CSCI 383 Lecture 3 and 4: Abstraction
 
java tr.docx
java tr.docxjava tr.docx
java tr.docx
 
2 oop
2 oop2 oop
2 oop
 
Let's Peel Mangos
Let's Peel MangosLet's Peel Mangos
Let's Peel Mangos
 
ConSteel_14_User_Manual-351-359.pdf
ConSteel_14_User_Manual-351-359.pdfConSteel_14_User_Manual-351-359.pdf
ConSteel_14_User_Manual-351-359.pdf
 
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AEBank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
 
Airflow - Insane power in a Tiny Box
Airflow - Insane power in a Tiny BoxAirflow - Insane power in a Tiny Box
Airflow - Insane power in a Tiny Box
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World Scenario
 
Cw comp1661 211574_mo233_20131122_234918_1314
Cw comp1661 211574_mo233_20131122_234918_1314Cw comp1661 211574_mo233_20131122_234918_1314
Cw comp1661 211574_mo233_20131122_234918_1314
 
CSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: AbstractionCSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: Abstraction
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 

Recently uploaded

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 

Recently uploaded (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

C++ 25 programs Class XII

  • 1. Computer Science (SESSION 20 - ) SUBITTED TO: SUBMITTED BY: ROLL NO. :
  • 2. Basic concept of OOP’S  Data Abstraction  Data Encapsulation  Inheritance  Modularity  Polymorphism DATA ABSTRACTION: Abstraction refers to the act of representing essential features without including the background details or explanation. Example: You are driving a car. You only know the essential features to drive a car e.g., gear handling, steering handling, use of clutch, accelerator, brakes etc. But while you are driving do you get into internal details of the car like wiring, motor working etc.? You just change the gears of apply the brakes etc. What is happening is hidden from you. This is abstraction where you only know the essential things to drive a car without including the background details or explanation. Another example is of ‘switch board’. You only press certain switches according to your requirement. What is happening inside, how it is happening inside, how it is happening etc. you needn’t know. Again, in this abstraction, you only know the essential things to operate on the switch board without the knowledge the background details of the switchboard.
  • 3. DATA ENCAPSULAION: The wrapping up of data and operation/function (that operate on the data) into a single entity (called class) is known as encapsulation. Example: In a big company, there are so many departments, sales, account, payroll, purchase, production etc. each department has its own personnel that maintain its data. Suppose an employee in the production dept. wants to know how much raw material has been purchased for the next month. The production dept. employee would not be allowed to himself go throughthe purchase dept. files. Rather, he`ll issue a memo to the purchase dept. requesting the desired information. Then some employee of the purchase dept. will go through the data files for him and pertain to his requests. This practice ensures that the data is accessed accurately and that it is not corrupted by inept outsiders. Therefore, ‘Department data and department employees are encapsulated into a single entity, the department.’ INHERITANCE: Inheritance is the capability of one class of things to inherit capabilities of properties from another class. Example: ‘Humans’ certain properties, such as the ability to speak, breath, eat, drink, etc. etc. But these properties are not unique to humans. The class ‘Human’ inherits these properties from the class ‘Mammal’ which again inherits some of its properties from another “Animal’.The class “car” inherits some of its properties from the class ‘Automobiles” which inherits some of its properties from another class ‘Vehicles”. The capability to pass down properties is a powerful one. It allows us to describe things in an
  • 4. economical way. ‘Automobiles and ‘Pulled Vehicles’ are subclasses of ‘Vehicles’. ‘Vehicles are base class of ‘Automobiles’ and ‘Pulled Vehicles’. MODULARITY: Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules. Example: You must have seen a complete music system. Let us assume that our program represents the music system. The music system comprises of speakers, cassette-player, record-player, cd-player, tuner etc. Now, these parts are complete units in themselves, yet they are themselves, yet they are a subpart of the music system. This is modularity. Similarly, we can achieve modularity in programs also. A program can be divided into various modules each representing speakers, cassette-player… etc. See each module is a complete unit itself yet it works in accordance with other modules in order to achieve one single goal i.e. music. POLYMORPHISM: Polymorphism is the ability for a message or data to be processed in more than one form. Example: ‘Human’ is a subclass of ‘Mammal’. Similarly ‘Dog’, ‘Cat’, are also subclasses of ‘Mammals’. Mammals can see through day-light. So if a message ‘see through day light’ is passed to all mammals, they will behave alike. Now if a message ‘see through day light’is passes to all mammals, then humans and dogs will not be able to see at night whereas cat will be able to see at night also. Here cats behave differently than other mammals in response to a message or action.
  • 5. INDEX S.No. PROGRAMES DATE SIGNAT URE 1. WAP USING CLASSES AND OBJECTS TO CREATE CLASS BOOK. 2. WRITE A MENU DRIVEN PROGRAM TO CREATE CLASS BANK TO INITIALISE DEPOSIT, WITHDRAW & DISPLAY DEETAILS OF THREE CUSTOMERS. 3. WAP YO CREATE CLASS ADMISSION THAT GENERATE TWO RANDOM ADMISSION NUMBER FROM THE LIST OF GIVEN ADMISSION NUMBERS. 4. WAP TO SHOW WORKING OF CONSTRUCTOR AND DESTRUCTOR. 5. WAP TO MAINTAIN DETAILS OF COLLEGE STUDENTS AND PRINT THEM (INHERITANCE). 6. WAP TO SHOW CONSTRUCTOR OVERLOADING. 7. WAP TO CREATE TEXT FILE WHICH PERFORM THE FOLLOWING ACTIONS i. COUNT NO. OF WORDS ii. COUNT NO. OF LINES iii. COUNT AND DISPLAY WORDS STARTING WITH VOWELS AND STORE THEM IN A FILE iv. COUNT AND DISPLAY WORDS STARTING WITH UPPERCASE ALPHABETS v. COUNT NO. OF BLANK SPACES 8. WAP TO CREATE BINARY FILES WITH FIVE RECORDS AND DISPLAY. 9. WAP TO SEARCH RECORD IN A BINARY FILE. 10. WAP TO APPEND A RECORD IN A BINARY FILE. 11. WAP TO INSERT DATA IN A BINARY FILE. 12. WAP TO DELETE A RECORD IN A BINARY FILE. 13. WAP TO MODIFY A RECORD IN A BINARY FILE. 14. WRITE A MENU DRIVEN PROGRAM FOR BINARY AND LINEAR SEARCH IN A ARRAY. 15. CREATE A MENU DRIVEN INSERT & DELETE AN ELEMENT IN A SORTED FILE. 16. WAP TO MERGE TWO ARRAYS A IN SACENDING ORDER, B IN DESCENDING ORDER INTO THIRD ARRAY C INASCENDING ORDER. 17. CREATE MENU DRIVEN PROGRAM TO CHOOSE SORTING TECHNIQUES SELECTION, BUBBLE. 18. WAP TO CONVERT I-D ARRAY TO 2-D ARRAY. 19. CREATE MENU DRIVEN PROGRAM FOR PUSH & POP IN STACK AS LINKED LIST. 20. WAP TO SHOW INSERTION AND DELETION IN QUEUES. 21. QURIES OF SQL TABLE 1 STUDENT 22. QURIES OF SQL TABLE 2 HOSPITAL 23. QURIES OF SQL TABLE 3 TEACHER
  • 6. 24. QURIES OF SQL TABLE 4 FURNITURE AND ARRIVALS 25. QURIES OF SQL TABLE 5 INTERIORS AND NEWONES Q.1) W.A.P. using classes and objects to create the class book. #include<iostream.h>//for basic functions #include<stdio.h> //for gets #include<conio.h> //for clrscr() class BOOK {int book_no; char book_title[20]; //data members float price; float total_cost(int n) //member functions {float total; total=n*price; return total; } public: void INPUT() //member function {cout<<"n Enter Book No.: "; cin>>book_no; cout<<"n Enter Book Title: "; gets(book_title); cout<<"n Enter Price: "; cin>>price; } void PURCHASE() {int n;
  • 7. float TOT; cout<<"n Enter no of cin>>n; TOT=total_cost(n); cout<<"n Your total cost is: "<<TOT; } }//end of class book ; void main() //start of main { clrscr(); BOOK buy; //creating object of class buy.INPUT();/*accessing member functions*/ buy.PURCHASE(); getch(); } //end of main
  • 9. Q.2) Write menu driven program to create class to initialize, deposit, withdraw and display the details. #include<iostream.h> #include<ctype.h> #include<conio.h> class Account{ char name[31]; int acc_no; char act; float balance; public: void initial() { cout<<"n Name: "; cin>>name; cout<<"n Accoutn No.: "; cin>>acc_no; cout<<"n Enter Amount: "; cin>>balance; cout<<endl; } void deposit(float amt) {balance+=amt; cout<<" Amount Deposited"; } void withdraw(float amt) {if((amt-balance>=1000)) { balance=amt-balance; cout<<"n Amount Withdrawn"; } else {cout<<"n Min Bal should be 1000"; cout<<" You can withdraw only: "<<balance-1000; } } void display() {cout<<"nnttt !!Your Account Details!!"; cout<<"nn Account no.:"<<acc_no; cout<<"n Accoutn Holder: ";
  • 10. cout<<name; cout<<"n Balance: "<<balance; } int getacno() { return acc_no;} }; void main() { clrscr(); Account bank; int choice; cout<<"n Menu"; cout<<"n 1.For Deposit"; cout<<"n 2.For WithDraw"; cout<<"n Enter Choice(1/2): "; cin>>choice; switch(choice) { case 1:bank.initial(); bank.deposit(100000); break; case 2:bank.initial(); bank.withdraw(100000); break; default:cout<<"n !!Wrong Choice!!"; } bank.display(); getch(); }
  • 12. Q.3) WAP to create the class ADMISSION that generates two random admission nos. from the list of given admission nos. #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<stdio.h> int i; class ad{ int adno; char name[10]; float fees; int clas; public: void readdata(); void draw_nos(); int getadno() { return adno; } }; ad A1[5]; void ad::draw_nos() { int n1=0,n2=0; randomize(); n1=random(4); n2=random(4); for(i=0;i<3;i++) if((A1[i].getadno()==n1)||(A1[i].getadno()==n2));
  • 13. cout<<"nRandomly generated admission nos are:"<<n1<<" and "<<n2; } void ad::readdata() { cout<<"nEnter admission no:"; cin>>adno; cout<<"Name:"; cin>>name; cout<<"Class:"; cin>>clas; cout<<"Fees:"; cin>>fees; } void main() {clrscr(); for(i=0;i<3;i++) { A1[i].readdata(); } A1[i-1].draw_nos(); getch(); }
  • 15. Q.4)WAP to show working of constructor and destructor in a class. #include<iostream.h> #include<conio.h> class A{ public: A() {cout<<"n Constructor A";} ~A() {cout<<"n Destructor A";} }; class B{ public: B() {cout<<"n Constructor B";} ~B() {cout<<"n Destructor B";} }; class C{ public: A ob1,ob2; B ob3; C() {cout<<"n Constructor C";} ~C() {cout<<"n Destructor C";} }; void main()
  • 16. {clrscr(); C oc; B ob; A oa; getch(); }
  • 18. Q.5)Write a program to maintain the details of college students and print them using inheritance. #include<iostream.h> #include<stdio.h> #include<conio.h> const int len = 25 ; class person { char name[len]; int age; public: void readperson(void) ; void displayperson(void) { cout<<"Name : "; cout.write(name,len); cout<<"t Age : " <<age<<"n"; } }; void person::readperson(void) { for(int i=0;i<len;i++) name[i]=' '; cout<<"Enter name of the person :"; gets(name); cout<<"Enter age :"; cin>>age; } class student: public person { int rollno; float average ; public: void readstudent(void) { readperson(); cout<<"Enter roll no. : "; cin>>rollno; cout<<"Enter average marks : "; cin>>average; }
  • 19. void disp_rollno(void) { cout<<"Roll no : "<<rollno<<"n"; } float getaverage(void) { return average ; } }; class gradstudent :public student { char subject[len]; char working; public : void readit(void); void displaysubject(void) { cout<<"Subject : " ; cout.write(subject,len); } char workstatus(void) { return working; } }; void gradstudent::readit(void) { readstudent(); for(int i=0 ;i<len;i++) subject[i]=' '; cout<<"Enter main subject : "; gets(subject); cout<<"Working?(y/n) : "; cin>>working; } void main() { clrscr(); const int size = 5 ; gradstudent grad[size]; int year,num_working=0,non_working=0,div1=0,total=0; float topscore = 0,score, number,wperc,nwperc; cout<<"Enter year :"; cin>>year;
  • 20. char ch=' '; int i; for(i=0;i<10;i++) { cout<<"Enter details for graduate "<<(i+1)<<" (maximum 10)n"; grad[i].readit(); total++; if(grad[i].workstatus() =='y'||(grad[i].workstatus() == 'Y')) num_working++; else non_working++; score=grad[i].getaverage() ; if(score>topscore) { topscore=score; number=i; } if(score>=60.0) div1++; cout<<"Press y to see report and n to continue"; cin>>ch; if(ch=='y'||ch=='Y') break; } i=number; cout<<"n"<<"ttttReport of the year " <<year<<"n"; cout<<"tttt-----------------------n"; cout<<"Working graduates : " <<num_working<<"n"; cout<<"Non working graduates : "<<non_working<<"n"; cout<<"Details of topper n"; grad[i].displayperson(); grad[i].displaysubject(); nwperc=((float)non_working/(float)total)*100; wperc=((float)div1/(float)total)*100; cout<<"Average marks : "<<grad[i].getaverage()<<"n"; cout<<nwperc<<"% of the graduates this year are non working and "<<wperc<<"% are first divisionersn"; getch(); }
  • 22. Q.6) WAP to show constructor overloading. #include<iostream.h> #include<conio.h> class Deposit{ long int principal; int time; float rate; float total_amt; public: Deposit(); Deposit(long p,int t,float r); Deposit(long p,int t); Deposit(long p,float r); void calc_amt(void); void display(void); }; Deposit::Deposit() {principal=time=rate=0.0;} Deposit::Deposit(long p,int t,float r) {principal=p;time=t;rate=r;} Deposit::Deposit(long p,int t) {principal=p;time=t;rate=0.08;} Deposit::Deposit(long p,float r) {principal=p;time=2;rate=r;} void Deposit::calc_amt(void) { total_amt=principal+(principal*time*rate)/100;
  • 23. } void Deposit::display(void) { cout<<" Principal Amount: "<<principal; cout<<"n Time Period: "<<time; cout<<"n Rate of interest: "<<rate; cout<<"n Total Amount: "<<total_amt<<"n"; } void main() { clrscr(); Deposit D1,D2(2000,2,0.07f),D3(4000,1),D4(3000,0.12f); D1.calc_amt(); D2.calc_amt(); D3.calc_amt(); D4.calc_amt(); cout<<"n Object1:n"; D1.display(); cout<<"n Object2:n"; D2.display(); cout<<"n Object3:n"; D3.display(); cout<<"n Object4:n"; D4.display(); getch(); }
  • 25. Q.7) Write a menu driven program to create the text file that i. Count the no of words in a file. ii. Count the no of lines a file. iii. Count and display the words starting with the vowels. iv. Count the words starting with uppercase alphabets. v. Count the no of spaces. #include<fstream.h> #include<conio.h> #include<string.h> #include<ctype.h> void file_content() { ofstream fout("xyz.txt"); char ch[200]; cout<<"nEnter the content of the file: "; cin.getline(ch,200); fout<<ch; fout.close(); } void vowel() { ifstream fin("xyz.txt"); char ch[20]; while(!fin.eof()) { fin>>ch; switch(ch[0]) { case 'a':
  • 26. case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': cout<<"nWords starting from vowels is: "<<ch<<"n"; } } } void word_count() { ifstream fin ("xyz.txt"); char ch; int count=0; while (!fin.eof()) { fin.get(ch); if(ch==' ') ++count; } cout<<"nNo. of words are: "<<++count<<"n"; fin.close(); }
  • 27. void count_spaces() { ifstream fin ("xyz.txt"); char ch; int count=0; while (!fin.eof()) { fin.get(ch); if(ch==' ') ++count; } cout<<"nNo. of spaces are: "<<count<<"n"; fin.close(); } void count_lines() { char str[100]; int count=0; ifstream fin("xyz.txt"); while(!fin.eof()) { fin.getline(str,100); ++count; } cout<<"nNo. of lines are: "<<count<<"n"; } void count_uppercase() { ifstream fin("xyz.txt"); int count=0;
  • 28. char ch; while(!fin.eof()) { fin>>ch; if(isupper(ch)) ++count; } fin.close(); cout<<"nNo. of upper case alpahabets are: "<<count<<"n"; } void main() { clrscr(); file_content(); word_count(); count_lines(); vowel(); count_uppercase(); count_spaces(); getch(); }
  • 30. Q.8) Write a program to create the binary file and display them. #include<iostream.h> #include<fstream.h> #include<conio.h> class student { char name[50]; char grade; float marks; public: void getdata(void); void display(void); }; void student::getdata(void) { char ch; cin.get(ch); cout<<"n"<<"ENTER NAME : - "; cin>>name; cout<<"n"<<"ENTER GRADE : - "; cin>>grade; cout<<"n"<<"ENTER MARKS : - "; cin>>marks; cout<<"n"; } void student::display(void) {cout<<"NAME : - "<<name<<"t"; cout<<"GRADE : - "<<grade<<"t"; cout<<"MARKS : - "<<marks<<"t"<<"n";}
  • 31. int main() { clrscr(); student arts[5]; fstream filin ; filin.open("stu.dat",ios::in|ios::out); if(!filin) { cout<<"SORRY CAN NOT OPEN THE FILE"<<"n"; return 1; } cout<<"ENTER DETAILS OF THE 2 STUDENTS : - "<<"n"; for(int i=0;i<2;i++) { arts[i].getdata(); filin.write((char*)&arts[i],sizeof(arts[i])); } filin.seekg(0); cout<<"n"; cout<<"THE CONTENTS OF THE STU.DAT IS AS SHOWN BELOW : - "<<"n"; for(i=0;i<2;i++) { filin.read((char*)&arts[i],sizeof(arts[i]));arts[i].display();} filin.close(); getch(); }
  • 33. Q.9) Write a program to search a record in a file. #include<iostream.h> #include<conio.h> #include<fstream.h> class stu { int rollno; char name[25]; char Class[4]; float marks; char grade; public: void getdata() { cout<<"ROLL NUMBER"; cin>>rollno; cout<<"NAME"; cin>>name; cout<<"CLASS"; cin>>Class; cout<<"MARKS"; cin>>marks; } void putdata() { cout<<”Name-“<<name<<"Roll No-"<<rollno<<”Marks=”<<marks; }
  • 34. int getrno() { return rollno; } } s1; void main() { clrscr(); int rn; char found='n'; ifstream fi("stu.dat",ios::in); cout<<"ENTER ROLL NUMBER TO BE SEARCHED : - "; cin>>rn; while (!fi.eof()) { fi.read((char*)&s1,sizeof(s1)); if(s1.getrno()==rn) { s1.putdata(); found='y'; break; } } if(found=='n') cout<<"ROLL NUMBER NOT FOUND IN THE FILE"<<endl; fi.close();}
  • 36. Q.10)WAP to append data from file. #include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdio.h> class stu { clrscr(); int rollno; char name[25]; char Class[4]; float marks; char grade; public: void getdata() { cout<<"n Rollno: "; cin>>rollno; cout<<"n Name: "; cin>>name; cout<<"n Class: "; cin>>Class; cout<<"n Marks: "; cin>>marks; if(grade>=75) grade='A'; else if(grade>=60) grade='B'; else if(grade>=50) grade='C'; else if(grade>=40) grade='D'; else grade='F'; }
  • 37. void putdata() { cout<<name<<"n Rollno "<<rollno<<"has"<<marks <<"% Marks and "<<grade<<"Grade: "<<endl; } int getrno() { return rollno; } } s1; void main() { ofstream fo("n stu.dat",ios::app); char ans='y'; while(ans=='y') { s1.getdata(); fo.write((char*)&s1,sizeof(s1)); cout<<"n Record added to file.n"; cout<<"n Want to enter more records?(y/n)?: "; cin>>ans; } fo.close();}
  • 39. Q.11) Write a program to insert data in a file. #include<iostream.h> #include<fstream.h> #include<conio.h> #include<stdio.h> class stu { int rollno; char name[25]; float marks; public: void getdata() { cout<<"ROLL NUMBER : - "; cin>>rollno; cout<<"NAME : - "; gets(name); cout<<"MARKS : - "; cin>>marks; } void putdata() { cout<<"nName-"<<name<<"n"; cout<<"Roll No- "<<name<<"n"; cout<<"Marks= "<<marks<<"n"; } int getrno()
  • 40. {return rollno; } }; stu s1,stud; void main() { clrscr(); ofstream f("stu.dat",ios::out|ios::app); ifstream fi("stu.dat",ios::in|ios::app); ofstream fo("temp.dat",ios::out|ios::app); char last='y'; cout<<"enter the details of students whose record is to be insertedn"; s1.getdata(); while(!fi.eof()) { fi.read((char*)&stud,sizeof(stud)); if(s1.getrno()<=stud.getrno()) { fo.write((char*)&s1,sizeof(s1)); last='n'; break; } else fo.write((char*)&stud,sizeof(stud)); } if(last=='y') fo.write((char*)&s1,sizeof(s1)); else if(!fi.eof()) { while(!fi.eof())
  • 41. { fi.read((char*)&stud,sizeof(stud)); fo.write((char*)&stud,sizeof(stud)); } } fi.close(); fo.close(); remove("stu.dat"); rename("temp.dat","stu.dat"); ifstream ko; ko.open("stu.dat",ios::in); cout<<"file now contains"<<endl; while(!ko.eof()) { ko.read((char*)&stud,sizeof(stud)); if(ko.eof()) break; stud.putdata(); } ko.close(); getch(); }
  • 43. Q.12) Write a program to delete data from a file. #include<fstream.h> #include<conio.h> #include<stdio.h> class stu { int rollno; char name[25]; char cls; float marks; public: void getdata() { cout<<"ROLL NUMBER : - "; cin>>rollno; cout<<"NAME : - "; gets(name); cout<<"CLASS : - "; cin>>cls; cout<<"MARKS : - "; cin>>marks; } void putdata() { cout<<"nName- "<<name<<"n"; cout<<"Roll No- "<<rollno<<"n"; cout<<"Marks="<<marks<<"n";
  • 44. } int getrno() { return rollno; } }s1,stud; void main() { clrscr(); ifstream fi("STU.DAT",ios::in); ofstream fo("TEMP.DAT",ios::out); int rno; char found='f',confirm='n'; cout<<"ENTER ROLL NUMBER OF STUDENT WHOSE RECORD IS TO BE DELETED:-"; cout<<"n"; cin>>rno; while(!fi.eof()) { fi.read((char*)&stud,sizeof(stud)); if(s1.getrno()==rno) { s1.putdata(); found='t'; fo.write((char*)&s1,sizeof(s1)); } else fo.write((char*)&s1,sizeof(s1)); }
  • 45. if(found=='n') cout<<"SORRY RECOD NOT FOUND"<<endl; fi.close(); fo.close(); remove("STU.DAT"); rename("TEMP.DAT","STU.DAT"); fi.open("STU.DAT",ios::in); cout<<"FILE NOW CONTAINS : - "<<"n"<<endl; while(!fi.eof()) { fi.read((char*)&stud,sizeof(stud)); if(fi.eof()) break; stud.putdata(); } fi.close(); getch(); }
  • 47. Q.13) Write a program to modify data in a file. #include<iostream.h> #include<fstream.h> #include<stdio.h> #include<string.h> #include<conio.h> class stu { int rollno; char name[25]; char Class[4]; float marks; public: void getdata() { cout<<"Enter Name-"; cin>>name; cout<<"Enter Roll No-"; cin>>rollno; cout<<"Enter Marks ";cin>>marks; } int getrno() { return rollno ; } void modify() ; };
  • 48. s1,stud ; void stu::modify() { cout<<"ROLL NUMBER : - "<<rollno<<endl; cout<<"NAME : - "<<name<<"t"; cout<<"CLASS : - "<<Class<<"t"; cout<<"MARKS : - "<<marks<<endl; cout<<"ENTER NEW DETAILS : - "<<endl; char nm[20]=" ",cl[4]=" "; float mks ; cout<<”Enter Name-"; cin>>nm; cout<<"Enter Roll No- "; cin>>rn; cout<<"Enter Marks= "; cin>>mks; if(strcmp(nm,".")!= 0) strcpy(name, nm); if(strcmp(cl,".")!=0) strcpy(Class,cl); if(mks!= -1) { marks=mks; if(marks >= 75) } } void main() { clrscr();
  • 49. fstream fio("stu.dat", ios::in|ios::out|ios::binary); int rno; long pos; char found='f'; cout<<"ENTER ROLL NUMBER OF THE STUDENT WHOSE RECORD IS TO MODIFY:-"; cout<<"n"; cin>>rno; while(!fio.eof()) { pos=fio.tellg(); fio.read((char*) &s1, sizeof(s1)); if (s1.getrno()==rno) { s1.modify(); fio.write((char*) &s1, sizeof(s1)); found='t'; break; } } if(found=='f') cout<<"SORRY RECORD NOT FOUND"<<"n"; fio.seekg(0); fio.close(); getch(); }
  • 51. Q.14) Create a menu driven program to show searching operation in 1- D array using (I)Lsearch (II) Bsearch #include<iostream.h> #include<conio.h> int Lsearch(int[],int,int); int Bsearch(int[],int,int); void main() {clrscr(); int n,AR[50],i,item,index; int ch=0; cout<<"n Menu: "; cout<<"n 1.Linear Search"; cout<<"n 2.Binary Search"; cout<<"n Enter Choice(1/2): "; cin>>ch; cout<<"n Enter the Desired array size(Max.50): "; cin>>n; cout<<"n Enter Array elements "; for(i=0;i<n;i++) { cin>>AR[i]; } cout<<"n Enter Elements to be searched for: "; cin>>item; switch(ch)
  • 52. { case 1:{ index=Lsearch(AR,n,item); if(index==-1) cout<<"n Sorry!! Given element could not be found."; else cout<<"n Element found at index: "<<index; cout<<"n Position: "<<index+1<<endl; break;} case 2:{ index=Bsearch(AR,n,item); if(index==-1) cout<<"n Sorry!! Given element could not be found."; else cout<<"n Element found at index: "<<index; cout<<"n Position: "<<index+1<<endl; break;} default:{cout<<"n Wrong Choice";} break; } getch(); } int Lsearch(int arr[50],int size,int it) { for(int j=0;j<size;j++) {if(arr[j]==it) return j;
  • 53. } return-1; }; int Bsearch(int arr[50],int size,int it) { int beg,last,mid; beg=0; last=size-1; while(beg<=last) { mid=(beg+last)/2; if(it==arr[mid]) return mid; else if(it>arr[mid]) beg=mid+1; else last=mid-1; } return -1; };
  • 55. Q.15)WAP menu driven program to insert & delete an element in a sorted array. #include<iostream.h> #include<conio.h> #include<process.h> int FindPos(int[],int,int); int Lsearch(int[],int,int); int Insertion(int[],int); int Deletion(int[],int); void main() {clrscr(); int AR[50],N,choice; cout<<"n Enter size of array(Max.50): "; cin>>N; cout<<"n Enter array elements is ascending order:n"; for(int i=0;i<N;i++) { cin>>AR[i];} cout<<"n Menu:"; cout<<"n 1.Insertion"; cout<<"n 2.Deletion"; cout<<"n Enter Choice(1/2): "; cin>>choice; switch(choice) {case 1: Insertion(AR,N);
  • 56. break; case 2: Deletion(AR,N); break; default:cout<<"n !!Please enter either 1 or 2"; break; } getch(); } int Insertion(int ar[],int y) {char ch='y'; int item,index,i; while(ch=='y'||ch=='Y') { cout<<"n Enter element to be inserted: "; cin>>item; if(y==50) { cout<<"n Overflow"; exit(1); } index=FindPos(ar,y,item); for(i=y;i>index;i--) { ar[i]=ar[i-1];} ar[index]=item; y=y+1; cout<<"n Want to insert more element(Y/N)?: "; cin>>ch;
  • 57. } cout<<"n Array after insertion is: n"; for(i=0;i<y;i++) { cout<<ar[i]<<" ";} } int FindPos(int AR[],int size,int item) {int pos; if(item<AR[0]) pos=0; else { for(int i=0;i<size-1;i++) { if(AR[i]<=item&&item<AR[i+1]) { pos=i+1; break; } } if(i==size-1) pos=size; } return pos;} int Deletion(int AR[],int N) { char ch='y'; int item,index,i; while(ch=='y'||'Y') { cout<<"n Enter element to be deleted: "; cin>>item; if(N==0) { cout<<"Underflow!!";
  • 58. exit(1); } index=Lsearch(AR,N,item); if(index!=-1) AR[index]=0; else cout<<"n !!Sorry no such element is found"; for(i=index;i<N;i++) { AR[i]=AR[i+1];} N=N-1; cout<<"n Want to delete more(Y/N)?"; cin>>ch; cout<<"n Array after deletion is: n"; for(i=0;i<N;i++) cout<<AR[i]<<" "; break; }} int Lsearch(int AR[],int size,int item) { int i; for(i=0;i<size;i++) { if(AR[i]==item) return i; } return -1; }
  • 60. Q.16) Write a program to merge two 1-D arrays into third array. #include<iostream.h> #include<conio.h> void Merge(int[],int,int[],int,int[]); void main() { clrscr(); int A[20],B[20],C[40],m,n,mn=0; cout<<"Enter no of element in first array in acs order"; cin>>m; for(int i=0;i<m;i++) cin>>A[i]; cout<<"Enter no of element in second array in desc order"; cin>>n; for(i=0;i<n;i++) cin>>B[i]; mn=m+n; Merge(A,m,B,n,C); cout<<"Resultant array is"; for(i=0;i<mn;i++) cout<<C[i]; getch(); } void Merge(int A[],int m,int B[],int n,int C[])
  • 61. { int a,b,c; for(a=0,b=n-1,c=0;a<m&&b>=0;) { if(A[a]<=B[b]) C[c++]=A[a++]; else C[c++]=B[b--]; } }
  • 63. Q.17) Write a menu driven program to sort elements using selection sort and bubble sort. #include<iostream.h> #include<conio.h> void selsort(int[],int); void bubblesort(int[],int); void main() { clrscr(); int AR[50],ITEM,N,index,n; cout<<"How many element you want to insert in array?(Max.50): "; cin>>N; cout<<"Enter element of array: "; for(int i=0;i<N;i++) cin>>AR[i]; cout<<"Menun"<<"1.Selection Sortn"<<"2.Bubble Sortn"<<"Enter Choice: "; cin>>n; switch(n) { case 1: selsort(AR,N); break; case 2: bubblesort(AR,N); break; default:cout<<"Enter Valid Choice"; break; }
  • 64. cout<<"nThe Sorted Array is shown below:n"; for(i=0;i<N;i++) cout<<AR[i]<<" "; cout<<endl; getch(); } void selsort(int AR[], int size) { int small,pos,tmp; for(int i=0;i<size;i++) { small=AR[i]; for(int j=i+1;j<size;j++) { if(AR[j]<small) { small=AR[j]; pos=j; } tmp=AR[i]; AR[i]=AR[pos]; AR[pos]=tmp; } cout<<"nArray after pass:"<<i+1<<" is-n"; for(int k=0;k<size;k++) cout<<AR[k]<<" "; } }
  • 65. void bubblesort(int AR[],int size) { int tmp, ctr=0; for(int i=0;i<size;i++) { for(int j=0;j<(size-1)-i;j++) { if(AR[j]>AR[j+1]) { tmp=AR[j]; AR[j]=AR[j+1]; AR[j+1]=tmp; } } cout<<"Array after iteration:"<<++ctr<<" is:n"; for(int k=0;k<size;k++) cout<<AR[k]<<" "; cout<<endl; } }
  • 67. Q.18) Write a program to convert 1D array into 2D array. #include<iostream.h> #include<conio.h> void main() { clrscr(); int ar [20],arr[20][20]; int i,j,size; cout<<"Enter size of arrayn"; cin>>size; cout<<"Enter 1d-arrayn"; for(i=0;i<size;i++) { cin>>ar[i]; } cout<<"Your array isn"; for(i=0;i<size;i++) { cout<<ar[i]; cout<<"t"; } cout<<"n"; for(i=0;i<size;i++) for(j=0;j<size;j++) arr[i][j]=ar[j]; cout<<"Your required 2d array isn"; for(i=0;i<size;i++)
  • 70. Q.19) Write a program for pushing and popping in a stack implemented as linked list. #include<iostream.h> #include<conio.h> #include<process.h> struct node { int info; node*next; }*top,*newptr,*save,*ptr; node*create_new_node(int); void push(node*); void display(node*); void pop(); void main() { clrscr(); top=NULL; int inf; char ch='y'; while(ch=='y'||ch=='Y') { cout<<"n Enter the information"<<"t"; cin>>inf; newptr=create_new_node(inf);
  • 71. if(newptr==NULL) { cout<<"n cannot create new node!!!"; exit(1); } push(newptr); cout<<"n press Y to enter more nodes, n to exit"<<" "; cin>>ch; } clrscr(); do { cout<<"n stack is now:n"; display(top); getch(); cout<<"n want to pop an element?(y/n)"<<" "; cin>>ch; if(ch=='y'||ch=='Y') pop(); }while(ch=='y'||ch=='Y'); } node*create_new_node(int n) { ptr=new node; ptr->info=n; ptr->next=NULL; return ptr;
  • 72. } 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->info<<"->"; np=np->next; } cout<<"!!!n"; }
  • 74. Q.20) Write a program to show insertion and deletion from linked queue. #include<iostream.h> #include<conio.h> struct node { int data; node*next; }; node*add(node*rear,int val); node*delet(node*front); void show(node*front); void main() { node*front,*rear; int val,choice; front=rear=NULL; clrscr(); do{ cout<<"nMenu"; cout<<"n 1. ADD"; cout<<"n 2. Delete"; cout<<"n 3. Show"; cout<<"n 4. Quit"; cout<<"n Enter your choice"<<" "; cin>>choice;
  • 75. switch(choice) { case 1:cout<<"n Enter the vlaue to be added"<<" "; cin>>val; rear=add(rear,val); if(front==NULL) front=rear; break; case 2:front=delet(front); if(front==NULL) rear=front; break; case 3:show(front); break; } } while(choice!=4); } node*add(node*rear,int val) { node*x; x=new node; x->data=val; x->next=NULL;
  • 76. if(rear!=NULL) { rear->next=x; } rear=x; return(rear); } node*delet(node*front) { node*x; int val; if(front==NULL) { cout<<"nQueue is empty"; val=-999; } else { x=front; front=front->next; val=x->data; delete x; } cout<<val; return(front); }
  • 77. void show(node*front) { node*ptr; ptr=front; cout<<"nThe queue is:"; while(ptr!=NULL) { cout<<ptr->data<<" "; ptr=ptr->next; } }
  • 79. 21.) Write SQL command for (a) for (f) and write the output for (g) on the basis of tables Student. Table: Student No. Name Age Department Dateofadm Fee Sex 1. Pankaj 24 Computer 10/01/97 120 M 2. Shalini 21 History 24/03/98 200 F 3. Sanjay 22 Hindi 12/12/96 300 M 4. Sudha 25 History 01/07/99 400 F 5. Rakesh 22 Hindi 05/09/97 250 M 6. Shakeel 30 History 27/06/98 300 M 7. Surya 34 Computer 25/02/97 210 M 8. Sikha 23 Hindi 31/07/97 200 F a) To show all information about all students of the History Department. b) To list the names of female students who are of Hindi department. c) To list name of all students with their name in ascending order. d) To display student’s name, fee, age for male students only. e) To count the number of student with Age<23. f) To isnert a new row in the STUDENT table with the following data : 9, “Zaheer”, 36 , “Computer”, {12/03/97}, 230, ‘M’ g) Give the output of following SQL statements : (i) Select COUNT (distinct departments) from STUDENT ; (ii) Select MAX (Age) from STUDENT where Sex = ”F” ; (iii) Select AVG (fee) form STUDENT where Dateofadm <{01/01/98} ; (iv) Select SUM (Fee) from STUDENT where Dateofadm <{01/01/98} ;
  • 80. Answers) (a) SELECT * FROM Student WHERE Depatment = “History”; (b) SELECT Name FROM Student WHERE sex =”F” and Depatment = “History”; (c) SELECT name FROM Student ORDER BY Dateofadm; (d) SELECT Name, Fee, Age FROM Student WHERE sex = “M”; (e) SELECT COUNT (*) FROM Student WHERE Age>23 ; (f) INSERT INTO Student VALUES (9, “Zaheer”, 36 , “Computer”, {12/03/97}, 230, ‘M’) ; (i) 3 (ii)25 (iii)236 (iv) 1080
  • 81. 22.) Write SQL commands for (a) to (f) and Write to outputs for (g) on the basis of table HOSPITAL. Table: HOSPITAL No. Name Age Department Dateofadm Charges Sex 1. Sandeep 62 Surgery 21/01/98 300 M 2. Ravina 22 ENT 12/12/97 250 F 3. Karan 32 Orthopedic 19/02/98 200 M 4. Tarun 12 Surgery 11/01/98 300 M 5. Zubin 30 ENT 12/01/98 250 M 6. Ketaki 16 ENT 24/02/98 250 F 7. Ankita 29 Cardiology 20/02/98 800 F 8. Zareen 45 Gynecology 22/05/98 300 F 9. Kush 19 Cariology 13/01/98 800 M 10. Shalya 23 Nuclaer Medicine 21/02/98 400 F a) To select all information about all patient of the CARIOLOGY Department. b) To list the names of female patients who are in ENT Department. c) The list names of all patients with date date of admission in ascending order. d) To display Patient’s name, Charges, Age for only male patients. e) To count the number of patients with Age<30. f) To insert a new row in the HOSpital table with the following date ; 11, “Mustafa” , 37, “ENT”, {25/02/98}, 250, “M” g) Give the output of the following SQL statements : (i) Select COUNT (distict department) from HOSPITAL ; (ii) Select MAX( Age) from HOSPITAL where Sex =”M” (iii)Select AVG (Charges) form HOSPITAL where Sex =”F” (iv)Select SUM ( Charges) from HoSPITAL where Dateofadm< {10/08/98}
  • 82. Answers) (a) SELECT * FROM Hospital WHERE Depatment = “Cardiology”; (b) SELECT Name FROM Hospital WHERE sex =”F” and Depatment = “Orthopedic”; (c) SELECT name FROM Hospital ORDER BY Dateofadm; (d) SELECT Name, Charges, Age FROM Hospital WHERE sex = “M”; (e) SELECT COUNT (*) FROM Hospital WHERE Age<30 ; (f) INSERT INTO Hospital VALUES (11, “Mustafa”, 37 , “ENT”, {25/02/97}, 250, “M”) ; (i) 6 (ii)65 (iii)400 (iv) 3850
  • 83. 23.) Write SQL commands for (a) to (f) and write output for (g) on the basis of Teacher relation given below: Table: Teacher No. Name Age Department Date of join Salary Sex 1. Jugal 34 Computer 10/01/97 12000 M 2. Sharmila 31 History 24/03/98 20000 F 3. Sandeep 32 Maths 12/12/96 30000 M 4. Sangeeta 35 History 01/07/99 40000 F 5. Rakesh 42 Maths 05/09/97 25000 M 6. Shayam 50 History 27/06/98 30000 M 7. Shiv Ov 44 Computer 25/02/97 21000 M 8. Shalakha 33 Maths 31/07/97 20000 F a) To select all information about all Teachers of the history department. b) To list the names of female Teachers who are in Hindi Department. c) The list names of all Teachers with date of joining in ascending order. d) To display students’ Name, Fees, Age for only male teachers. e) To count the number of patients with Age<23. f) To insert a new row in the HOSPITAL table with the following date ; 11, “Raja” , 26, “Computer”, {13/05/95}, 2300, “M”. g) Give the output of the following SQL statements : (i) Select COUNT (distict department) from TEACHER ; (ii) Select MAX( Age) from TEACHERS where Sex =”F” (iii)Select AVG (Salary) form TEACHERS where Dateofadm< {10/08/98} (iv)Select SUM (Salary) from TEACHERS where Dateofadm< {10/08/98
  • 84. Answers) (a) SELECT * FROM Teacher WHERE Department = “History”; (b) SELECT Name FROM Hospital WHERE sex =”F” and Department = “Hindi”; (c) SELECT name FROM Teacher ORDER BY Dateofadm; (d) SELECT Name, Salary, Age FROM Teacher WHERE sex = “M” AND Age>23; (e) SELECT COUNT(*) FROM Hospital WHERE Age<23 ; (f) INSERT INTO Teacher VALUES (9, “Raja”, 26 , “Computer”, {13/02/95}, 2300, “M”) ; (i) 3 (ii)35 (iii)23600 (iv) 2300
  • 85. 24.) Write SQL command for (a) for (f) and write the output for (g) on the basis of tables FURNITURE and ARRIVALS. Table: FURITURE NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT 1 2 3 4 5 6 7 8 9 10 White Lotus Pink Feather Dolphin Decent Comfort zone Donald Royal Finish Royal Tiger Econo sitting EatingParadise Double Bed Baby cot Baby cot OfficeTable Double Bed Baby cot OfficeTable Sofa Sofa Dining Table 23/02/02 20/01/02 19/02/02 01/01/02 12/01/02 24/01/02 20/02/02 22/02/02 13/13/01 19/02/02 30000 7000 9500 25000 25000 6500 18000 31000 90005 110005 25 20 20 30 25 15 30 30 25 25 Table: ARRIVALS NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT 11 12 13 Wood Comfort Old Fox Mickey Double Bed Sofa Baby cot 23/03/03 20/02/03 21/02/03 25000 17000 7500 25 20 15 a) To show all info about the Baby cots from the FURNITURE table. b) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table. c) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from the FURNITURE table in descending order of ITEMNAME. d) To display ITEMNAME and DATEOFSTOCK of those items, in which the DISCOUNT percentage is more than 25 from FURNITURE table. e) To count the number of items, whose TYPE is “Sofa” from the FURNITURE table. f) To insert a new row in the ARRIVALS table with the following data: 14, ”Velvet Touch”, Double Bed, (25/03/03), 25000, 30
  • 86. g) Give the output of the following statement: (i) Select COUNT(distinct TYPE) from FURNITURE; (ii) Select MAX(DISCOUNT) from FURNITURE, ARRIVALS; (iii) Select AVG(DISCOUNT) from FURNITURE where TYPE=”Baby cot”. (iv) Select SUM(PRICE) from FURNITURE where DATAOFSTOCK < (12/02/02). Answer) a) Select* From FURNITURE Where TYPE=”Baby cot”; b) Select ITEMNAME From FURNITURE Where PRICE > 15000; c) Select ITEMNAME, TYPE From FURINTURE; Where DATEOFSTOCK < (22/01/02) Order by ITEMNAME; d) Select ITEMNAME, DATEOFSTOCK From FURINTURE Where DISCOUNT > 25; e) Select Count(*) From FURNITURE Where TYPE=”Sofa”; f) Insert Into ARRIVALS Values(14, ”Velvet Touch”, Double Bed, (25/03/03), 25000, 30) g) (i) 5 (ii)30 (iii)18.33 (iv)66500.
  • 87. 25.) Write the SQL command for (a) to (f) and write the output for (g) on the basis of tables INTERIORS and NEWONES. Table: INTERIORS NO. ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Red rose Soft touch Jerry’s home Rough wood Comfort zone Jerry look Lion king Royal tiger Park sitting Dine Paradise Double Bed Baby cot Baby cot Office Table Double Bed Baby cot Office Table Sofa Sofa Dining Table 23/02/02 20/01/02 19/02/02 01/01/02 12/01/02 24/01/02 20/02/02 22/02/02 13/13/01 19/02/02 32000 9000 8500 20000 15000 7000 16000 30000 9000 11000 15 10 10 20 20 19 20 25 15 15 Table: NEWONES NO. ITEMNAME TYPE DATEOFSTOCK Price DISCOUNT 11. 12. 13. White wood James 007 Tom look Double Bed Sofa Baby cot 23/03.03 20/02/03 21/02/03 20000 15000 7000 20 15 10 a) To show all info about the Sofas from the INTERIORS table. b) To list the ITEMNAME which are priced at more than 10000 from the INTERIORS table. c) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from the INTERIORS table in decreasing order of ITEMNAME. d) To display ITEMNAME and DATEOFSTOCK of those items, in which the discount percentage is more than 15 from the INTERIORS table. e) To count the no of items whose type is “Double Bed” from the table INTERIORS. f) To insert a new tow in the NEWONES table with the following data: 14,”True Indian”, “Office Table”, (28/03/03), 15000, 20. g) Give the output of the following statement:
  • 88. (i) Select COUNT(distinct TYPE) from INTERIORS; (ii) Select AVG(DISCOUNT) from INTERIORS, where DATEOFSTOCK<(12/02/02). (iii) Select SUM(Price) form INTERIORS where DATEOFSOCK<(12/02/02). Answer) a) Select* From INTERIORS Where PRICE>10000; b) Select ITEMNAME, TYPE From INTERIORS c) Select ITEMNAME, TYPE From INTERIORS Where DATEOFSTOCK < (22/01/02) Order by ITEMNAME; d) Select ITEMNAME, DATEOFSTOCK From INTERIORS Where DICSOUNT>15; e) Select Count(*) From INTERIORS Where TYPE=”Double Bed”; f) Insert Into NEWONES Values (14,”True Indian”, “Office Table”, (28/03/03), 15000, 20); e) (i)5 (ii)13 (iii)43000
  • 89. BIBLIOGRAPHY 1. COMPUTER SCIENCE text book By: SUMITA ARORA 2. INTERNET and various websites.