Sie sind auf Seite 1von 87

Computer Science

PROGRAM FILE
&
MY SQL
2018-19

NAME:ABDUL BASIT ALAM


CLASS:XII
BOARD ROLL NO.9196936
1
Page

1
INDEX

Serial no. Program Page Teacher’s


no. Signature

Classes and Objects

1. Program to illustrate the function 1-2


definition inside the class

2. Program to illustrate the function


definition outside the class 3-4

Program to illustrate the use of object


3. arrays by storing details of 2 students in 5-6
an array

4. Menu driven C++ program using class to 7-9


perform all arithmetic operations (+,-,*,/)

Program to illustrate the concept of


5. passing objects as reference for adding 10-11
two complex numbers

6. Program to illustrate the use of static data


members and member functions 12

Illustrating the concept of passing and


7. retuning parameters into member 13
functions using another class

8. Illustrating searching record of a student


on the basis of roll number, name, using 14-15
array of objecs.
2
Page

2
Function Overloading
9. Illustrating the concept of overloading by
using the function volume() 16
(cube, cylinder and cuboid)
without class

10. Illustrating the concept of passing default 17


parameters values.

Data file handling

11.
Program to input lines and write them to text 18
file .

12. Program for displaying the contents from text 19


file.

Program to read and display the number of


13. times the word “the” occurs as an 20
independent word in text file

Handling of multiple files simultaneously to


14. copy lines of text which stars with uppercase 21
characters from a text file a.txt to b..txt

15. Consider the class student and perform all 22-25


binary operations like creation , display,
modification and deletion.

Array

16. Bubble Sort 26-27

17. Selection Sort 28-29

18. Linear Search 30-31


3
Page

3
19. Binary Search 32-33

20. Insertion of an element in array using function 34-35

21. Deletion of an element in array using function 36-37

22. Merging of two array in one array 38-39

Constructor and Destructor

23. Program to illustrate the use of different 40-41


constructor, i.e default, parametrized and
copy constructor.

24. Illustrating the concept of constructor 42-43


overloading.

25. Program to illustrate the order of constructor 44


overloading

26. Use of destructor within a program. 45-46

4
Page

4
Inheritance

27. Program to illustrate the access control in 47-48


public derivative of a class

28. Program to illustrate the access control of 49-50


inherited member in the privately derived
class.

29. Program to check working of constructor and 51-52


destructor in multiple inheritance.

30. Program to illustrate multiple base classes and 53


ambiguity generate.

31. Program to show working of virtual base class 54-55


to resolve ambiguity in multiple inheritance.

Stacks

33. Illustrating push and pop operations through a 56-58


menu driven program using arrays in stack.

34. Illustrating the concept of stack using linked 59-61


list.

Queue

Illustrating the concept of queue using


35. linked list through a menu driven program. 62-64

36. Illustrating the concept of queue using arrays 65-66


through a menu driven program
5
Page

5
SQL PRACTICALS

38. Practical-1 67-69

39. Practical-2 70-73

40. Practical-3 74-76

41. Practical-4 77-79

42. Practical-5 80-81

. PROGRAM/T

6
Page

6
// Q1: PROGRAM TO DEMONSTRATE THE FUNCTION DEFINITION INSIDE
THE CLASS

#include<iostream.h>
#include<conio.h>
class vol
{
float s ,area ;
public:
void cal()

{
area=s*s;
}
void input()
{
cout<<"enter the value of side : "<<endl;
cin>>s;
}
void output()
{
cout<<"area of square is : "<<endl;
cout<<area;
}
};
void main()
{
clrscr();
vol v;
v.input();
v.cal();
v.output();
getch();
};
7
Page

7
OUTPUT

8
Page

8
//Q2- PROGRAM TO DEMONSTRATE THE FUNCTION DEFINITION OUTSIDE
THE CLASS

#include<iostream.h>
#include<conio.h>
class vol
{
float s,area;
public:
void input();
void cal();
void output();
};
void vol::input()
{
cout<<" enter the value of s : ";
cin>>s;
}
void vol::cal()
{
area=s*s;
}
void vol::output()
{
cout<<" area of square is : ";
cout<<area;
}
void main()
{
clrscr();
vol v;
v.input();
v.cal();
v.output();
getch();
9
Page

};
9
OUTPUT

10
Page

10
//Q3.PROGRAM TO DEMONSTRATE THE USE OF OBJECT ARRAYS BY
STORING DETAILS OF 2 STUDENTS IN AN ARRAY

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class school
{
int admno;
char name[15];
public:
void input()
{
cout<<"Enter admno of student = ";
cin>>admno;
cout<<"Enter name of student = ";
gets(name);
}
void output()
{
cout<<"\nAdmno of student is :\n "<<admno;
cout<<"\nName of student is :\n "<<(name);
}
};
void main()
{
clrscr();
int i;
school s[15];
cout<<"Enter student details below : "<<endl;
for(i=0;i<2;i++)
{
s[i].input();
}
cout<<"\nDetails of student are as follows : "<<endl;
for(i=0;i<2;i++)
{
s[i].output();
}
getch();
};
11
Page

11
OUTPUT:

12
Page

12
/ /Q4.MENU DRIVEN C++ PROGRAM USING CLASS TO PERFORM ALL
ARITHMETIC OPERATIONS

#include<iostream.h>
#include<conio.h>
class calci
{
float a,b;
float sum;
float div,mul,sub;
public:
void input()
{
cout<<"Enter first number = ";
cin>>a;
cout<<"Enter second number = ";
cin>>b;
}
void addi()
{
sum=a+b;
cout<<" Result is = "<<sum;
}
void subt()
{
sub=a-b;
cout<<" Result is = "<<sub;
}
void divi()
{
div=a/b;
cout<<" Result = "<<div;
}
void mult()
{
mul=a*b;
cout<<" Result is = "<<mul;
}
};
void main()
{
clrscr();
calci c;
c.input();
int ch,i;
13

cout<<"1)Addition"<<endl;
cout<<"2)subtraction"<<endl;
Page

cout<<"3)division"<<endl;
13
cout<<"4)multiplication"<<endl;
cout<<"Enter your choice : "<<endl;

cin>>ch;
{
switch(ch)
{
case 1:
c.addi();
break;
case 2:
c.subt();
break;
case 3:
c.divi();
break;
}
case 4:
c.mult();
break;
}
}
getch();
}
};

OUTPUT:

14
Page

14
15
Page 15
//Q5-PROGRAM TO DEMONSTRATE THE CONCEPT OF PASSING OBJECT
AS REFERENCE FOR ADDING TWO COMPLEX NUMBERS

#include<iostream.h>
#include<conio.h>
class comp
{
int a,r,sum1,sum2;
public:
void input()
{
cout<<"\nEnter the imaginary number = ";
cin>>a;
cout<<"\nEnter the real part = ";
cin>>r;
}
void output()
{
cout<<"Complex number is = "<<r<<"+"<<a<<"i";
}
void cal(comp x1,comp x2)
{
sum1=x1.r+x2.r;
sum2=x1.a+x2.a;
}
void result()
{
cout<<"\nSum of complex no.s is = "
<<sum1<<"+"<<sum2<<"i";
}
};
void main()
{
clrscr();
comp x1,x2,x3;
x1.input();
x1.output();
x2.input();
x2.output();
x3.cal(x1,x2);
x3.result();
getch();
};
16
Page

16
OUTPUT:

17
Page

17
//Q6-PROGRAM TO ILLUSTRATE THE USE OF STATIC DATA MEMBERS
AND STATIC MEMBER FUNCTIONS

#include<iostream.h>
#include<conio.h>
class test
{
static int count;
public:
test();
static void display();
};
int test::count=0;
test::test()
{
++count;
}
void test::display()
{
cout<<"\nCounter Values = "<<count<<endl;
}
void main()
{
clrscr();
test::display();
test obj1,obj2,obj3;
test::display();
getch();
}

OUTPUT:

18
Page

18
//Q7-ILLUSTRATING THE CONCEPT OF PASSING AND RETURNING
ARGUMENTS INTO MEMBER FUNCTIONS USING ANOTHER CLASS

#include<iostream.h>
#include<conio.h>
class account
{
int accno;
char type;
float balance;
public:
void deposit(float amt)
{
balance=balance+amt;
}
void disp_acc()
{
cout<<"\nBALANCE = \t"<<balance;
}
void withdraw(float amt)
{
balance=balance-amt;
}
};
void main()
{
clrscr();
account a;
float dep_amt=0,withd_amt=0;
cout<<"\nEnter amount to be deposited ";
cin>>dep_amt;
a.deposit(dep_amt);
a.withdraw(5000);
a.disp_acc();
getch();
}

OUTPUT:
19
Page

19
//Q8-ILLUSTRATING SEARCHING RECORD OF A STUDENT ON THE
BASIS OF ROLL NUMBER, NAME USING ARRAY OF OBJECTS.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class search
{
int bno;
char bname[15];
public:
void input()
{
cout<<"Enter the book number = " ;
cin>>bno;
cout<<"Enter book name = ";
gets(bname);
}
void output()
{
cout<<"Name of the book is = ";
}
int match()
{
return(bno);
}
};
void main()
{
clrscr();
int i;
int bno;
search x[5];
cout<<"Enter the book details : ";
for(i=0;i<3;i++)
{
x[i].input();
}
cout<<"\nEnter the book no you want to search ";
cin>>bno;
for(i=0;i<3;i++)
{
if(bno==x[i].match())
{
x.output();
20

}
else
Page

20
{
cout<<"Incorrect book no !!! ";

}
}
getch();
};

OUTPUT:

21
Page

21
//Q9-ILLUSTRATING THE CONCEPT OF OVERLOADING BY USING THE
FUNCTION VOLUME (CUBE, CYLINDER, CUBOID) [WITHOUT CLASS]

#include<iostream.h>
#include<conio.h>

int volume(int s)
{
return s*s*s;
}
float volume(float r,float h)
{
return 3.14*r*r*h;
}
int volume(int l,int b,int h)
{
return l*b*h;
}
void main()
{
clrscr();
cout<<"Volume : ";
cout<<"\nVolume of Cube = "<<volume(10);
cout<<"\nVolume of Cylinder = "<<volume(1.5,3.0);
cout<<"\nVolume of Cuboid = "<<volume(2,3,4);
getch();
};

OUTPUT:

22
Page

22
//Q10 –ILLUSTRATE THE CONCEPT OF PASSING DEFAULT PARAMETER
VALUES

#include<iostream.h>
#include<conio.h>
void amount(float princ,int time=2,float rate=0.08);
void amount(float princ,int time,float rate)
{
float interest;
cout<<"\nPrincipal amount = "<<princ;
cout<<"\nTime = "<<time<<"years";
cout<<"\n Rate = "<<rate;
interest=princ*time*rate;
cout<<"\n Interest Amount = "<<interest<<endl;
}
void main()
{
clrscr();
cout<<"Case 1 : ";
amount(2500);
cout<<"Case 2 : ";
amount(2500,3);
cout<<"Case 3 : ";
amount(2500,3,0.2);
getch();
}

OUTPUT:

23
Page

23
//Q11-PROGRAM TO INPUT LINES AND WRITE THEM TO TEXT FILE

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char str[20];
cout<<"Enter the text : "<<endl;
gets(str);
ofstream fout;
fout.open("A.TXT");
fout<<str;
fout.close();
}

OUTPUT:

24
Page

24
//Q12-PROGRAM TO DISPLAY THE CONTENTS FROM TEXT FILE

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char input[20];
ifstream fin;
fin.open("B.TXT");
while(!fin.eof())
{
fin.getline(input,20);
cout<<input;
}
getch();
};

OUTPUT

25
Page

25
//Q13-PROGRAM TO READ AND DISPLAY THE NUMBER OF TIMES
THE WORD “THE” OCCURS AS AN INDEPENDENT WORD IN TEXT
FILE “A.TXT”

#include<fstream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
char str[30];
int count=0;
ifstream fin;
fin.open("A.txt");
while(!fin.eof())
{
fin>>str;
if (strcmp(str,"THE")==0)
count++;
}
cout<<"No of times ""the"" is found = "<<count;
fin.close();
getch();
};

OUTPUT:

26
Page

26
//Q14-HANDLING OF MULTIPLE SIMULATANEOUSLY TO COPY LINES OF
TEXT WHICH STARTS WITH UPPERCASE CHARACTERS FROM A TEXT
FILE WHICH STARTS WITH UPPERCASE CHARACTERS FROM A TEXT
FILE “A.TXT” TO ANOTHER FILE ”B.TXT”

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
void main()
{
clrscr();
ifstream fin;
fin.open("A.txt");
ofstream fout;
fout.open("B.txt");

char str[20];
while(!fin.eof())
{
fin.getline(str,20);
if(isupper(str[0]))
fout<<str;
}
fin.close();
fout.close();
getch();
}

OUTPUT:

27
Page

27
//Q15-CONSIDER THE CLASS STUDENT AND PERFORM ALL THE BINARY
OPERATIONS LIKE CREATION, DISPLAY, MODIFICATIONS AND
DELETION.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class student
{
int rno;
char name[30];
int a;
public:
void getdata()
{
cout<<"Enter roll number ";
cin>>rno;
cout<<"\nEnter name ";
gets(name);
cout<<"\nEnter class ";
cin>>a;
}
void showdata()
{
cout<<"\nRoll\tName\tClass";
cout<<endl<<rno<<"\t"<<name<<"\t"<<a;
}
int retroll()
{
return rno;
}
}s1;
void create()
{
ofstream fout("pq.dat",ios::binary);
s1.getdata();
fout.write((char*) & s1,sizeof (s1));
fout.close();
}
void display()
{
ifstream fin("pq.dat",ios::binary);
while(fin.read((char*) & s1,sizeof(s1)))
{
28

s1.showdata();
}
Page

fin.close();
28
}
void modify()

{
fstream f1("pq.dat",ios::binary|ios::in|ios::out);
int r1;
cout<<"\nEnter the roll no to modify ";
cin>>r1;
while(f1.read((char*)& s1,sizeof (s1)))
{
if(r1==s1.retroll())
s1.getdata();
f1.seekg(f1.tellg()-sizeof(s1));
f1.write((char*)& s1,sizeof (s1));
}
f1.close();
}
void Delete()

{
ifstream fin("pq.dat",ios::binary);
ofstream fout("temp.dat",ios::binary);
int r2;
cout<<"\nEnter roll to delete ";
cin>>r2;
while(fin.read((char*)&s1,sizeof (s1)))
{
if(s1.retroll()!=r2)
fout.write((char*)&s1,sizeof (s1));
}
fout.close();
fin.close();
delete("abc.dat");
rename("temp.dat","abc.dat");
}
void main()
{
clrscr();
int ch;
char c;
do{
cout<<"\n1.Create\n2.Display\n3.Modification
\n4.delete\n";
cout<<"Enter your choice ";
cin>>ch;
29

switch(ch)
{
Page

29
case 1:create();
break;
case 2:display();
break;
case 3:modify();
break;
case 4:Delete();
break;
}
cout<<"\ndo you want to continue(y/n)\n";
cin>>c;
}while(c=='Y'||c=='Y');
getch();
}

OUTPUT:

30
Page

30
31
Page 31
//Q16-BUBBLE SORT

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n, i, arr[50], j, temp;
cout<<"Enter total number of elements :";
cin>>n;
cout<<"Enter "<<n<<" numbers :";
for(i=0; i<n; i++)
{
cin>>arr[i];
}
cout<<"Sorting array using bubble sort technique...\n";
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
cout<<"Elements sorted successfully..!!\n";
cout<<"Sorted list in ascending order :\n";
for(i=0; i<n; i++)
{
cout<<arr[i]<<" ";
}
getch();
}
32
Page

32
OUTPUT:

33
Page

33
//Q17-SELECTION SORT

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int size, arr[50], i, j, temp;
cout<<"Enter Array Size : ";
cin>>size;
cout<<"Enter Array Elements : ";
for(i=0; i<size; i++)
{
cin>>arr[i];
}
cout<<"Sorting array using selection sort...\n";
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
cout<<"Array after sorting is :\n";
for(i=0; i<size; i++)
{
cout<<arr[i]<<" ";
}
getch();

}
34
Page

34
OUTPUT:

35
Page

35
//Q18-LINEAR SEARCH

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5],ele,pos,found=0;
cout<<"Enter the array elements :- "<<endl;
for(int i=0;i<5;i++)
{
cin>>a[i];
}
cout<<"Enter the element to be searched = ";
cin>>ele;
for(i=0;i<5;i++)
{
if(ele==a[i])
{
found=1;
pos=i;
break;
}
}
if(found==0)
{
cout<<"Number not found !!! "<<endl;
}
else
{
cout<<"Found at position = "<<pos;
}
getch();
};
36
Page

36
OUTPUT:

37
Page

37
//Q19-BINARY SEARCH

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,a[30],srch,first,last,middle;
cout<<"\nEnter size of array : ";
cin>>n;
cout<<"\nEnter the elements of array : "<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nEnter a number to be found = ";
cin>>srch;
first=0;last=n-1;
while(first<=last)
{
middle=(first+last)/2;
if(a[middle]<srch)
{
first=middle+1;
}
else if(a[middle]==srch)
{
cout<<"\n"<<"Found at position = "<<middle;
break;
}
else
{
last=middle-1;
}
}
if(first<last)
{
cout<<"not found !!! "<<srch<<"Is not present in the
array ";
}
getch();
}
38
Page

38
OUTPUT:

39
Page

39
//Q20-INSERTION OF AN ELEMENT IN ARRAY USING FUNCTION

#include<iostream.h>
#include<conio.h>
void insert(int a[],int &n,int x)
{
n++;
a[n-1]=x;
}
void main()
{
clrscr();
int A[50],size,a;
cout<<"Enter Size of array : ";
cin>>size;
cout<<"\nEnter the array elements = "<<endl;
for(int i=0;i<size;i++)
{
cin>>A[i];
}
cout<<"\nEnter element to be inserted = ";
cin>>a;
insert(A,size,a);
cout<<"\nThe new array is : "<<endl;
for(i=0;i<size;i++)
{
cout<<A[i];
}
getch();
};

40
Page

40
OUTPUT:

41
Page

41
//Q21-DELETION OF AN ELEMENT IN ARRAY USING FUNCTION

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],size,i,del,count=0;
cout<<"Enter array size = ";
cin>>size;
cout<<"Enter array elements : "<<endl;
for(i=0;i<size;i++)
{
cin>>a[i];
}
cout<<"Enter element to be deleted = ";
cin>>del;
for(i=0;i<size;i++)
{
if(a[i]==del)
{
for(int j=i;j<(size-1);j++)
{
a[j]=a[j+1];
}
count++;
break;
}
}
if(count==0)
{
cout<<"Element not found !!! ";
}
else
{
cout<<"Element deleted successfully "<<endl;
}
cout<<"New array is : "<<endl;
for(i=0;i<(size-1);i++)
{
cout<<a[i]<<endl;
getch();
}
42
Page

42
OUTPUT:

43
Page

43
// Q22-MERGING OF TWO ARRAY

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a1[10],a2[10],size1,size2,size,i,k,merge[20];
clrscr();
cout<<"Enter size of 1st array = ";
cin>>size1;
cout<<"\nEnter elements of 1st array : "<<endl;
for(i=0;i<size1;i++)
{
cin>>a1[i];
}
cout<<"\nEnter size of 2nd array = ";
cin>>size2;
cout<<"\nEnter elements of 2nd array : "<<endl;
for(i=0;i<size2;i++)
{
cin>>a2[i];
}
for(i=0;i<size1;i++)
{
merge[i]=a1[i];
}
size=size1+size2;
for(i=0,k=size1;k<size && i<size2;i++,k++)
{
merge[k]=a2[i];
}
cout<<"\nArray after merging : "<<endl;
for(i=0;i<size;i++)
{
cout<<merge[i];
}
getch();
}
44
Page

44
OUTPUT:

45
Page

45
//Q23-PROGRAM TO ILLUSTRATE THE USE OF DIFFERENT
CONSTRUCTOR , i.e DEFAULT, PARAMETRIZED AND COPY
CONSTRUCTOR.

#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
float perc;
public:
student()
{
rollno =10;
perc=80;
cout<<"Default constructor invoked"<<endl;
cout<<"Roll no = "<<rollno<<endl;
cout<<"Percentage = "<<perc<<endl;
}
student(int rno,float p)
{
rollno=rno;
perc=p;
cout<<"\nParametrized Constructor Invoked "<<endl;
cout<<"Roll No = "<<rollno<<endl;
cout<<"Percentage = "<<perc<<endl;
}
student(student &s2)
{
rollno=s2.rollno;
perc=s2.perc;
cout<<"\nCopy Constructor Invoked "<<endl;
cout<<"Roll no : "<<rollno<<endl;
cout<<"Percentage : "<<perc<<endl;
}
};
void main()
{
clrscr();
student s1,s2(1,70.5),s3(s2);
getch();
}
46
Page

46
OUTPUT:

47
Page

47
//Q24-ILLUSTRATING THE CONCEPT OF CONSTRUCTOR
OVERLOADING

#include<iostream.h>
#include<stdlib.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 r);
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*rate*time)/100;
}
void deposit::display(void)
{
cout<<"\nPrincipal amount = "<<principal;
cout<<"\nPeriod of investment = "<<time<<" years";
48

cout<<"\nRate of interest = "<<rate;


cout<<"\nTotal amount = "<<total_amt;
Page

48
}
void main()
{
clrscr();
deposit d1,d2(2000,2,0.07),d3(4000,1),d4(3000,0.12f);
d1.calc_amt();
d2.calc_amt();
d3.calc_amt();
d3.calc_amt();
d4.calc_amt();
cout<<"Object 1 : ";
d1.display();
cout<<"\n\nObject 2 : ";
d2.display();
cout<<"\n\nObject 3 : ";
d3.display();
cout<<"\n\nObject 4 : ";
d4.display();
getch();
};

OUTPUT:

49
Page

49
//Q25-PROGRAM TO ILLUSTRATE THE ORDER OF CONSTRUCTOR
OVERLOADING.

#include<iostream.h>
#include<conio.h>

class Parent //base class


{
public:
Parent()
{
cout << "Inside base class" << endl;
}
};

class child : public Parent //derived class


{
public:
child()
{
cout << "Inside sub class" << endl;
}
};
void main()
{
clrscr();
child obj;
getch();
}

OUTPUT:
50
Page

50
//Q26-USE OF DESTRUCTOR WITHIN A PROGRAM

#include<iostream.h>
#include<conio.h>
class A
{
public:
A()
{
cout<<"\nConstructor A\n ";
}
~A()
{
cout<<"\nDestructor A\n";
}
};
class B
{
public:
B()
{
cout<<"\nConstructor B\n";
}
~B()
{
cout<<"\nDestructor B\n";
}
};
class C
{
A ob1,ob2;
B ob3;
public:
C()
{
cout<<"\nConstructor C\n";
}
~C()
{
cout<<"\nDestructor C\n";
}
};
void main()
{
clrscr();
51

C oc;
B ob; A oa;
Page

51
OUTPUT :

OUTPUT:}

52
Page

52
//Q27-PROGRAM TO ILLUSTRATE THE ACCESS CONTROL IN PUBLIC
DERIVATIVE OF A CLASS

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
const int len=25;
class employee
{
char name[25];
double Enum;
public:
void getdata()
{
cout<<"Enter name = ";
gets(name);
cout<<"Enter employee number = ";
cin>>Enum;
}
void putdata()
{
cout<<"Name = "<<name<<endl;
cout<<"Employee number = "<<endl;
cout<<"Basic salary : "<<basic;
}
protected:
float basic;
void getbasic()
{
cout<<"Enter basic = ";
cin>>basic;
}
};
class manager:public employee
{
private:
char title[len];
public:
void getdata()
{
employee::getdata();
getbasic();
cout<<"Enter title = ";
gets(title);
53

}
Page

53
void putdata()
{
employee::putdata();

cout<<"Title = \n";

cout<<title;

OUTPUT:

54
Page

54
//Q28-PROGRAM TO ILLUSTRATE THE ACCESS OF INHERITED
MEMBERS IN THE PRIVATELY DERIVED CLASS

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
const int len=25;
class employee
{
private:
char name[len];
int Enum;
public:
void getdata()
{
cout<<"Enter Name = ";
gets(name);
cout<<"Enter Employee Number = ";
cin>>Enum;
}
void putdata()
{
cout<<"Name = "<<name<<endl;
cout<<"Employee Number = "<<Enum<<endl;
cout<<"Basic Salary = "<<basic<<endl;
}
protected:
float basic;
void getbasic()
{
cout<<"Enter Basic = " ;
cin>>basic;
}
};
class manager:private employee
{
private:
char title[len];
public:
void getdata()
{
employee::getdata();
getbasic();
cout<<"Enter Title = ";
55

gets(title);
Page

55
void putdata()
{
employee::putdata();
cout<<"Title = ";
cout<<title;
}
};
void main()
{
clrscr();
manager m1,m2;
cout<<"Manager-1 : \n";
m1.getdata();
cout<<"Manager-2 : \n";
m2.getdata();
cout<<"\nManager 1 details : \n";
m1.putdata();
cout<<"\n\nManager 2 details : \n";
m2.putdata();
getch();
};

OUTPUT :

56
Page

56
//Q29-PROGRAM TO CHECK WORKING OF CONSTRUCTOR AND
DESTRUCTOR IN MULTIPLE INHERITANCE

#include<iostream.h>
#include<conio.h>
class A
{
public:
A()
{
cout<<"Constructor of base class A "<<endl;
}
~A()
{
cout<<"Destructor of class A "<<endl;
}
};
class B
{
public:
B()
{
cout<<"Constructor of base class B "<<endl;
}
~B()
{
cout<<"Destructor of class B "<<endl;
}
};
class c:public A , public B
{
public:
c()
{
cout<<"Constructor of base class C "<<endl;
}
~c()
{
cout<<"Destructor of class C "<<endl;
}
};
void main()
{
clrscr();
c obj;
57

}
Page

57
OUTPUT:

58
Page

58
//Q30-PROGRAM TO ILLUSTRATE THE MULTIPLE BASE CLASSES
INHERITED AND AMBIGUITY GENERATE

#include<iostream.h>
#include<conio.h>
class A
{
public:
void show()
{
cout<<"Class A ";
}
};
class B
{
public:
void show()
{
cout<<"Class B ";
}
};
class C:public A, public B
{
};
void main()
{
C obj;
obj.show();
getch();
};

OUTPUT:
59
Page

59
//Q31-PROGRAM TO SHOW WORKING OF VIRTUAL BASE CLASS AND
RESOLVE THE AMBIGITY IN MULTIPLE INHERITANCE

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class base
{
public:
int a;
};
class c1:virtual public base
{
public:
int b;
};
class c2:virtual public base
{
public:
int c;
};
class c3:public c1,public c2
{
public:
int total;
};
void main()
{
clrscr();
c3 obj;
obj.a=30;
obj.b=60;
obj.c=90;
obj.total=obj.a+obj.b+obj.c;
cout<<"\n"<<obj.a<<"\t"<<obj.b<<"\t"<<obj.c<<"\n";
cout<<"Sum of three numbers = "<<obj.total;
getch();
}
60
Page

60
OUTPUT:

61
Page

61
//Q32-ILLUSTRATING PUSH AND POP OPERATIONS THROUGH A
MENU DRIVEN PROGRAM USING ARRAY IN STACK

#include<iostream.h>
#include<conio.h>
#include<process.h>
class stack
{
int stk[5];
int top;
public:
stack()
{
top=-1;
}
void push(int x)
{
if(top > 4)
{
cout<<"Stack overflow";
}
else
{
stk[++top]=x;
cout<<"inserted"<<x<<endl;
}
}
void pop()
{
if(top < 0)
{
cout<<"stack underflow"<<endl;
}
else
{
cout<<"deleted"<<stk[top--]<<endl;
}
}
void display()
{
if(top < 0)
{
cout<<"Stack empty"<<endl;
}
62

else
Page

62
{
for(int i=top;i>=0;i--)
cout<<" "<<stk[i]<<" "<<endl;
}
}
};
void main()
{
clrscr();
int ch;
stack st;
while(1)
{
cout<<"1)Push "<<endl;
cout<<"2)Pop "<<endl;
cout<<"3)Display "<<endl;
cout<<"Enter your choice = ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"enter the element ";
cin>>ch;
st.push(ch);
break;

case 2:
st.pop();
break;

case 3:
st.display();
break;

case 4:
exit(0);
}
}
getch();
}
63
Page

63
OUTPUT:

64
Page

64
//Q33-ILLUSTRATING THE CONCEPT OF STACK USING LINKED LIST

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
#include<stdio.h>
struct node
{
char data[15];
node *next;
};
class stack
{
node *top, *back;
public:
stack()
{
top=back=NULL;
}
void push();
void pop();
void display();
}stk;
void stack::push()
{
node *temp=new node;
cout<<"Enter data ";
cin>>temp->data;
temp->next=NULL;
if(top==NULL)
{
top=temp;
}
else
{
temp->next=top;
top=temp;
}
}
void stack::pop()
{
node *temp=top;
if(top==NULL)
65

cout<<"Stack Underflow";
else
Page

65
{
cout<<"Data"<<temp->data<<"deleted "<<endl;

if(top->next==NULL)
{
top=NULL;
}
top=top->next;
}
delete temp;
}
void stack::display()
{
node *temp=top;
if(top==NULL)
cout<<"Stack is empty"<<endl;
cout<<"Stack data : ";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}
void main()
{
clrscr();
int a;
do
{
cout<<"1)Push"<<endl;
cout<<"2)Pop"<<endl;
cout<<"3)Display"<<endl;
cout<<"4)Exit"<<endl;
cout<<"Enter your choice = ";
cin>>a;
switch(a)
{
case 1:
stk.push();
break;
case 2:
stk.pop();
break;
stk.display();
break;
66

case 4:
{
Page

66
exit(0);
defautlt:
cout<<"\nInvalid choice.....";

}
}

} while(a!=5);
getch();
}

OUTPUT:

67
Page

67
//Q34-ILLUSTRATING THE CONCEPT OF QUEUE USING LINKED LIST

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
struct node
{
int no;
node *next;
};
class queue
{
private:
node *front, *rear;
public:
queue()
{
front=rear=NULL;
}
void insert();
void del();
void display();
}
;
void queue::insert()
{
node *temp;
temp=new node;
cout<<"Enter number ";
cin>>temp->no;
temp->next=NULL;
if(front==NULL)
{
front=rear=temp;
}
else
{
rear->next=temp;
rear=temp;
}
}
void queue::del()
{
if(front==NULL)
68

{
cout<<"Queue empty";
Page

68
return;
}
node *temp=front;
front=temp->next;
cout<<"\n"<<temp->no;
cout<<"Deleted";
delete(temp);
}
void queue: {
if(front==NULL)
{
cout<<"Empty";
return;
}
node *temp=front;
while(temp!=NULL)
{
cout<<"\n"<<temp->no;
cout<<endl;
temp=temp->next;
}
}
void main()
{
clrscr();
queue q;
int ch;
while(1)
{
cout<<"1)Insert";
cout<<"2)delete";
cout<<"3)display";
cout<<"4)exit";
cout<<"Enter your choice ";
cin>>ch;
switch(ch)
{
case 1:
q.insert();
break;
case 2:
q.del();
break;
case 3:
q.display();
69

break;
case 4:
Page

69
exit(0);
default:
cout<<"Invalid choice";
}
getch();
}
};

70
Page

70
//Q35-ILLUSTRATING THE CONCEPT OF QUEUE USING ARRAYS
THROUGH A MENU DRIVEN PROGRAM.

#include <iostream.h>
#include<stdio.h>
#include<conio.h>
int queue[100], n = 100, front = - 1, rear = - 1;
void Insert() {
int val;
if (rear == n - 1)
cout<<"Queue Overflow"<<endl;
else {
if (front == - 1)
front = 0;
cout<<"Insert the element in queue : "<<endl;
cin>>val;
rear++;
queue[rear] = val;
}
}
void Delete() {
if (front == - 1 || front > rear) {
cout<<"Queue Underflow ";
return ;
} else {
cout<<"Element deleted from queue is : "<< queue[front] <<endl;
front++;;
}
}
void Display() {
if (front == - 1)
cout<<"Queue is empty"<<endl;
else {
cout<<"Queue elements are : ";
for (int i = front; i <= rear; i++)
cout<<queue[i]<<" ";
cout<<endl;
}
}
void main()
{
clrscr();
int ch;
cout<<"1) Insert element to queue"<<endl;
71

cout<<"2) Delete element from queue"<<endl;


cout<<"3) Display all the elements of queue"<<endl;
Page

cout<<"4) Exit"<<endl;
71
do {
cout<<"Enter your choice : "<<endl;
cin>>ch;
switch (ch) {
case 1: Insert();
break;
case 2: Delete();
break;
case 3: Display();
break;
case 4: cout<<"Exit"<<endl;
break;
default: cout<<"Invalid choice"<<endl;
}
} while(ch!=4);
getch();
}

OUTPUT:

72
Page

72
DATABASE AND MY SQL

PRACTICAL-1

Consider the following tables BOOKS and ISSUED and write SQL commands
for the following statements.

Table : BOOKS

Book_Id Book_Name Author_Name Publishers Price Type Qty


F0001 The Tears William First publ. 750 Fiction 10
Hopkins
F0001 Thunderbolts Anna Roberts First publ. 700 Fiction 5
T0001 My First Brian and EPB 250 Text 10
C++ Brooke
T0002 C++ A.W.Rossaine TDH 325 Text 5
Brainworks
C0001 Fast Cooks Lata Kapoor EPB 350 Cookery 8

Table: ISSUED

Book_Id Quantity_Issued
F0001 3
T0001 1
C0001 5

1. To create tables BOOKS and ISSUED with suitable data types

73
Page

73
2. To display the names and prices of the books in descending order of their
price.

3. To show book name, Author name and price of books of EPB publishers.

4. To display the book id, book_name, and quantity issued for all books which
have been issued.

74
Page

74
5. To increase the price of all books of first publishers by 50.

6. To display the records of BOOKS and ISSUED table

75
Page

75
PRACTICAL-2

Consider the following tables WORKERS and DESIG and write SQL
commands for the following statements.

Table: WORKERS

W_Id Firstname Lastname Address City


102 Sam Tones 33 Elm St. Paris
105 Sarah Ackerman 440 U.S. 110 New York
144 Manila Sengupta 24FriendsStreet New Delhi
210 George Smith 83 First Street Howard
255 Mary Jones 842 Vine Ave. Ville
300 Robert Samuel 9 Fifth Cross Washington
335 Henry Williams 12 MooreStreet Boston
403 Rony Lee 121 Harrison St New York
451 Pat Thompson 11 Red Road Paris

Table: DESIG

W_Id Salary Benefits Designation


102 75000 15000 Manager
105 85000 25000 Director
144 70000 15000 Manager
210 75000 12500 Manager
255 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 75000 Salesman
451 28000 75000 Salesman

76
Page

76
1.To create table WORKERS and DESIG with suitable data types

2. To Display all information from WORKERS


77
Page

77
3.To display all information from DESIG.

4. To display W_Id , Firstname, Address, City from WORKERS whose City is


New York.

5.To display all information from WORKERS and order by Firstname.

78
Page

78
6. To display Firstname, Total Salary, from Workers , Desig where W_Id is
same and Designation is CLERK.

7. To display DESIGNATION,MAX SALARY from DESIG and group them by


designation having designation MANAGER and CLERK.

79
Page

79
PRACTICAL-3

Consider the following table DRESS and MATERIAL and write the SQL
commands for the following statements.

Table:DRESS

Dcode Description Price MCode


10001 Formal Shirt 1250 M001
10002 Frock 750 M002
10003 Informal Shirt 1450 M003
10004 Tulip Skirt 850 M004
10005 Pencil Skirt 1250 M005
10006 Informal Pant 1400 M006

Table: MATERIAL

MCode Type
M001 Terelene
M002 Cotton
M003 Silk
M004 Polyester

1. To create table DRESS and MATERIAL

2.To display the details of DRESS and MATERIAL


80
Page

80
3.To display DCode and Description of each dress in ascending order of DCode

4.To display the average Price of the dresses which are made up of the material
with MCode as M003

5.To display material wise the highest and lowest prices of dresses from DRESS
table

6.To display the sum of price from DRESS where MCode is M001
81
Page

81
7. To display Description , Type from DRESS, MATERIAL where MCode is
same and Price is above 700

82
Page

82
PRACTICAL 4

Consider the following table SALARY and SALARY and write SQL commands
for the following statements.

Table: DOCTOR

Id Name Dept Gender Experience


101 John ENT M 12
107 George Cardiology M 12
114 Lara Skin F 3
109 K George Medicine F 9
105 Johnson Orthopedic M 10
117 Lucy ENT F 3
111 Bill Medicine F 12
130 Morphy Orthopedic M 15

Table: SALARY

Id Basic Allowance Consultance


101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 100
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300

1.To Create tables DOCTOR and SALARY 83


Page

83
2.To display the details of DOCTOR and SALARY

3. To display name of all the doctors who are in “ENT” having more than 10
Years of experience from the table DOCTOR.

4. To display average salary of all doctors working in “ENT” department using


the table DOCTOR and SALARY (Salary=Basic+Allowance)

5. To display the minimum ALLOWANCE of female doctors


84
Page

84
6.To display highest consulatation fee amount for all male doctors

85
Page

85
Practical 5

Consider the following tables GAMES and PLAYER and write SQL command
for the given queries.

Table: GAMES

Gcode GameName Type Number PrizeMoney ScheduleDate


101 CarromBoard Indoor 2 5000 23-Jan-2004
102 Badminton Outdoor 2 11000 13-Dec-2003
103 Table Tennis Indoor 4 8000 01-Feb-2004
105 Chess Indoor 2 9000 01-Jan-2004
108 Lawn Tennis Outdoor 4 25000 19-Mar-2004

Table: PLAYER

Pcode Name Gcode


1 Nabi Ahmed 101
2 Ravi Shah 108
3 Jatin 101
4 Nazneen 103

1. To create Table GAMES and PLAYER

2. To display the details of GAMES and PLAYER


86
Page

86
3. To count different number from GAMES table

4. To display maximum and minimum Schedule dates from GAMES

5. To display name and Gname from GAMES and PLAYER whose Gcodes are
equal and Prie money is greater than 10000

6. To display different Gcodes from PLAYER

87
Page

87

Das könnte Ihnen auch gefallen