Documente Academic
Documente Profesional
Documente Cultură
COMPUTER SCIENCE
C++ WORKFILE
SUBMITTED TO SUBMITTED BY
MS. HARSHITA AGARWAL HARSH CHAK
1
ACKOWLEDGEMENT
2
INDEX
S. NO. CONTENT PAGE
1 PROGRAM 1 5
2 PROGRAM 2 8
3 PROGRAM 3 12
4 PROGRAM 4 15
5 PROGRAM 5 18
6 PROGRAM 6 21
7 PROGRAM 7 24
8 PROGRAM 8 27
9 PROGRAM 9 34
10 PROGRAM 10 36
11 PROGRAM 11 40
12 PROGRAM 12 45
13 PROGRAM 13 50
14 PROGRAM 14 55
15 PROGRAM 15 61
16 PROGRAM 16 63
17 PROGRAM 17 65
18 PROGRAM 18 69
19 PROGRAM 19 72
20 PROGRAM 20 74
21 TABLE 1 77
22 TABLE 2 79
23 TABLE 3 81
3
C++
PROGRAMS
4
PROGRAM 1
#include<iostream.h>
#include<conio.h>
class A1
public:
A1() /* Constructor 1 */
~A1() /* Destructor 2 */
};
class A2
public:
A2() /* Constructor 2 */
~A2() /* Destructor 2 */
5
}
};
A2 Ob2;
A1 ob2;
void main()
clrscr();
A1 ob1;
crobj();
/* Constructor 1 gets called for the second time and constructor 2 gets
A2 Ob1;
getch();
6
main() to destroy remaining objects*/
OUTPUT:
7
PROGRAM 2
#include<iostream.h>
#include<conio.h>
class A /* Class 1 */
protected:
/* These can be accessed by the member function of this class and the
int c;
fun2();
private:
int b;
b=a*c;
public:
8
/* These can be accessed from any part of the program */
int a;
cin>>a;
c=a*10;
fun1();
};
public:
void dis()
void fun4()
9
c=a+10; /* Values updation */
};
void main()
clrscr();
/* Objects */
A ob1;
B ob2;
/* Call of functions */
ob1.fun3();
/* Call of functions */
ob2.fun4();
ob1.disp();
ob2.dis();
getch();
10
OUTPUT
11
PROGRAM 3
#include<iostream.h>
#include<conio.h>
float x, y;
protected:
float ar;
ar=x*y;
public:
members */
x=a;
y=b;
};
12
{
t_cs=cs*ar;
public:
calc_ar();
tot_cos();
};
void main()
clrscr();
/* Input values */
float a, b;
cin>>a>>b;
13
cost ob1;
Derived class */
ob1.disp();
getch();
OUTPUT
14
PROGRAM 4
#include<iostream.h>
#include<math.h>
#include<conio.h>
class ser
long int i, j, n;
ft=1;
ft*=j;
res=0;
fact(i);
15
}
public:
cin>>x;
cin>>n;
calc();
};
void main()
clrscr();
ser ob;
getch();
16
OUTPUT
17
PROGRAM 5
#include<iostream.h>
#include<conio.h>
#include<math.h>
class arm
int i, d;
sum=0;
sum+=pow(dig[i], 3);
if(sum==num)
else
public:
cin>>num;
18
int dum=num;
d=0;
dum =dum/10;
d++;
dum=num;
i=d-1;
dig[i]=dum%10;
dum=dum/10;
i--;
check();
};
void main()
clrscr();
arm ob;
getch();
19
OUTPUT
20
PROGRAM 6
#include<iostream.h>
#include<conio.h>
class c1
public:
};
class c2
int a, b;
public:
a=x;
b=y;
};
21
class c3
int a, b;
public:
c3(int x, int y)
a=x;
b=y;
a=ob.a+1;
b=ob.b-1;
};
void main()
clrscr();
22
c1 ob1;/* Default constructor called */
constructor is defined */
c3 ob4(ob3);
c3 ob5=ob4;
c3 ob6(1, 2);
ob6=ob4;
getch();
OUTPUT:
23
PROGRAM 7
#include<iostream.h>
#include<conio.h>
<<”\tRate: “<<rate
24
<<”\tRate: “<<rate
void main()
clrscr();
cout<<”\nCase 1”;
amt(2000);
cout<<”\nCase 2”;
amt(2500.0, 3);
cout<<”\nCase 3”;
amt(2300, 3, 0.11);
cout<<”\nCase 4”;
amt(2, 0.12);
25
/* Calling function 4*/
cout<<”\nCase 5”;
amt(6, 0.07);
getch();
OUTPUT
26
PROGRAM 8
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
class menu
int i, j;
res[i][j]=arr1[i][j]+arr2[i][j]; /* Addition of
matrix elements */
cout<<endl;
27
}
res[i][j]=arr1[i][j]-arr2[i][j]; /* Subtraction of
array element */
cout<<endl;
res[i][j]=0;
28
for(int k=0; k<3; k++)
res[i][j]+=arr1[i][k]+arr2[k][j]; /* Matrix
Multiplication */
cout<<endl;
void disp()
clrscr();
cout<<"Array 1: "<<endl;
cout<<endl;
29
cout<<"\nArray 2: "<<endl;
cout<<endl;
public:
menu()
cout<<"Array 1: "<<endl;
cin>>arr1[i][j];
cin>>arr2[i][j];
30
clrscr();
cout<<"\n Operations:"
<<"\n 1-Addition"
<<"\n 2-Subtraction"
<<"\n 3-Multiplication"<<endl;
int ch;
cin>>ch;
switch(ch)
case 1: disp();
add();
break;
case 2: disp();
sub();
break;
case 3: disp();
mul();
break;
default: break;
};
void main()
31
char ch;
again:
clrscr();
menu ob;
cin>>ch;
if(ch=='y' || ch=='Y')
goto again;
else
cout<<"\n EXITING....";
delay(200);
exit(0);
32
OUTPUT
ADDITION OF MATRIX
SUBTRACTION OF MATRIX
MULTIPLICATION OF MATRIX
33
PROGRAM 9
#include<iostream.h>
#include<conio.h>
<<"\nRate : "<<r
<<"\nRate : "<<r
void main()
34
clrscr();
cout<<"\nCase 1 :";
cout<<"\nCase 2 :";
cout<<"\nCase 3: ";
getch();
OUTPUT
35
PROGRAM 10
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class stat_stack
char ch;
cout<<"Overflow";
exit(0);
top++;
the stack */
36
{
cout<<"Underflow";
exit(0);
cout<<"Deleted "<<a[top];
top--;
for(int i=0;i<=top;i++)
cout<<a[i]<<endl;
public:
stat_stack()
top=-1;
clrscr();
cout<<"\nExit: 4 "<<endl;
int k;
37
cin>>k;
switch(k)
case 1: clrscr();
push();
break;
case 2: clrscr();
pop();
break;
case 3: clrscr();
display();
break;
case 4: exit(0);
cin>>ch;
}while(ch=='Y' || ch=='y');
};
void main()
38
clrscr();
stat_stack ob1;
getch();
OUTPUT
PUSHING AN ELEMENT
POPPING AN ELEMENT
39
PROGRAM 11
#include<iostream.h>
#include<process.h>
#include<conio.h>
struct node
int info;
node *next;
ptr=new node;
return ptr;
void push(node *np)/* Function pushes a new node into the linked stack */
if(top==NULL)
top=np;
else
save=top;
top=np;
np -> next=save;
40
}
if(top==NULL)
getch();
exit(0);
else
ptr=top;
delete ptr;
while(np != NULL)
cout<<np->info<<" ";
np=np->next;
cout<<endl;
void main()
41
{
clrscr();
top=NULL;
int inf;
char ch='y';
cin>>inf;
newptr=New(inf);
if(newptr==NULL)
getch();
exit(1);
push(newptr);
cin>>ch;
clrscr();
disp(top);
42
getch();
cin>>ch;
if(ch=='y' || ch=='Y')
pop();
}while(ch=='y' || ch=='Y');
getch();
43
OUTPUT
44
PROGRAM 12
#include<iostream.h>
#include<process.h>
#include<conio.h>
class stat_que
cin>>it;
cout<<”\nOVERFLOW!!!”;
getch();
exit(0);
fr=rr=0;
q[rr]=it;
rr++;
q[rr]=it;
45
}
getch();
exit(0);
cout<<q[i]<<” “;
cout<<”\nUNDERFLOW!!!”;
getch();
exit(0);
else if(fr==rr)
46
fr=rr=-1;
public:
stat_que()
fr=rr=-1;
char ch;
clrscr();
cout<<”\nExit: 4 “<<endl;
int k;
cin>>k;
switch(k)
case 1: clrscr();
insert();
break;
case 2: clrscr();
47
del();
break;
case 3: clrscr();
disp();
break;
case 4: exit(0);
default: break;
cin>>ch;
}while(ch==’Y’ || ch==’y’);
};
void main()
clrscr();
stat_que ob1;
getch();
48
OUTPUT
DISPLAYING QUEUE
49
PROGRAM 13
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
int info;
node *next;
ptr=new node;
return ptr;
if(front==NULL)
front=rear=np;
else
rear=np;
50
}
cout<<"\n UNDERFLOW!!!";
getch();
exit(0);
else
ptr=front;
delete ptr;
while(np != NULL)
cout<<np->info<<" ";
np=np->next;
cout<<endl;
void main()
51
clrscr();
front=rear=NULL;
int inf;
char ch='y';
cin>>inf;
newptr=New(inf);
if(newptr==NULL)
getch();
exit(1);
ins(newptr);
cin>>ch;
clrscr();
do /* Deleting nodes */
52
cout<<"\n Delete first item??(Y/N): ";
cin>>ch;
if(ch=='y' || ch=='Y')
del();
}while(ch=='y' || ch=='Y');
getch();
53
OUTPUT
54
PROGRAM 14
#include<iostream.h>
#include<limits.h>
#include<conio.h>
class sort
t=x[j];
x[j+1]=t;
cout<<x[i]<<" ";
55
}
t=x[i];
j=i-1;
j--;
cout<<x[i]<<" ";
56
for(i=0; i<sz-1; i++)
sml=x[i];
pos=i;
if( x[j]<sml)
sml=x[j];
pos=j;
t=x[i];
x[i]=x[pos];
x[pos]=t;
cout<<x[i]<<" ";
public:
sort()
57
cin>>sz;
cin>>x[i];
int ch;
cin>>ch;
re:
switch(ch)
case 1: selsort();
break;
case 2: bubsort();
break;
case 3: inssort();
break;
58
cin>>ch;
goto re;
};
void main()
clrscr();
sort ob;
getch();
OUTPUT:
59
60
PROGRAM 15
#include<iostream.h>
#include<conio.h>
class pnt_test
int a, b, *c;
int *swap_big(int *x, int *y) /* Funtion which recieves and returns
pointer */
int t;
*x=*y;
*y=t;
return(x);
else
return(y);
public:
pnt_test()
cin>>a>>b;
61
c=swap_big(&a, &b);
};
void main()
clrscr();
pnt_test ob1;
getch();
OUTPUT:
62
PROGRAM 16
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
void main()
clrscr();
getch();
63
OUTPUT:
64
PROGRAM 17
#include<stdio.h>
#include<dos.h>
#include<iostream.h>
#include<conio.h>
class patt
char elem;
void print()
delay(5);
cout<<" ";
delay(5);
cout<<" ";
65
}
cout<<endl;
space--;
cout<<" ";
delay(5);
cout<<" ";
cout<<endl;
space++;
66
public:
patt()
int dum;
cin>>rows;
space=rows;
cin>>dum;
elem=dum;
clrscr();
print();
};
void main()
clrscr();
patt ob;
getch();
67
OUTPUT:
68
PROGRAM 18
#include<iostream.h>
#include<conio.h>
#include<dos.h>
class psc
double res=1;
long ct=1;
do
res*=ct;
ct++;
}while(ct<=n);
return(res);
spaces=rows;
69
{
delay(10);
cout<<" ";
of num in series*/
delay(10);
spaces--;
cout<<endl;
public:
psc()
cin>>rows;
draw();
};
void main()
clrscr();
70
psc h;
getch();
OUTPUT:
71
PROGRAM 19
#include<iostream.h>
#include<conio.h>
class tri_ar
double area;
cin>>base;
cin>>height;
input();
area=0.5*base*height;
public:
72
calc();
};
void main()
clrscr();
tri_ar ob1;
ob1.output();
getch();
OUTPUT:
73
PROGRAM 20
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
void main ()
clrscr();
if(mf)
else
mf.close();
fstream fin;
char ch;
int c1=0,c2=0;
while(fin)
fin.get(ch);
74
cout<<ch;
if(ch==' ')
getch();
OUTPUT:
75
SQL
QUERIES
76
TABLE 1
TABLE: SENDER
TABLE: RECIPIENT
77
QUERIES
(i) To display name of all receiver from Mangalore:
(V) To Display Names and Address of all senders from Mangalore and
Bangalore:
78
TABLE 2
TABLE: CONSIGNER
TABLE: CONSIGNEE
79
QUERIES
80
TABLE 3
TABLE: CLASS_A
1 Raj Chemistry 78
2 Ayush English 65
3 Adya Chemistry 87
4 Parth Chemistry 19
5 Harsh Physics 54
TABLE: CLASS_B
1 Divya English 76
2 Pranav English 59
3 Akshay Physics 81
4 Sameer Physics 79
5 Surya Chemistry 67
81
QUERIES
82
83