B.SC Computer Science 1st Sem C Lab Record
B.SC Computer Science 1st Sem C Lab Record
B.SC Computer Science 1st Sem C Lab Record
UNIVERSITY OF KERALA
REGIONAL CENTRE YEROOR
:. :. :. :.
Design @ Crazy
CERTIFICATE
Certified that this is a bonafide record of the practical work done by....Reg.No:....in the Computer Laboratory for Programming Lab-II during the academic year 2011-14 and submitted for the II Semester B.Sc Computer Science Examination held at UIT Centre, Yeroor on . . .. . . . . . . . . .
LECTURER IN CHARGE :
PRINCIPAL
EXAMINERS: 1) 2)
Design @ Crazy
INDEX
Sl.No 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Program Name Page No Date
Largest and smallest number Square of a number Factorial of a number Sum of digits of a number Reverse of a number Fibonacci series Prime or not Factorial of a number (class concept) Prime numbers (class concept) Bank transactions (class concept) Mark list (class concept) Copy constructor concept Function overloading concept Inline function program Default constructor program
Design @ Crazy
16 17 18
Parameterized constructor program Single inheritance concept Multilevel inheritance concept Multiple inheritance concept Hierarchical inheritance concept Hybrid inheritance concept Operator overloading concept Friend function concept Pure virtual function concept Function template concept Class template program Exception handling program File(Write program using file) File Accessing(Write program using file)
19
20 21 22 23 24 25 26 27 28 29
Design @ Crazy
PageNo..
Algorithm 1.Start 2.Print the number of terms 3.Read n 4.print the elements 5.for i=0 to n 6.read a[i] 7.for i=0 to n 8.if a[i]>l l=a[i] 9.if a[i]<s s=a[i] 10.End for 11.End for 12.Print the largest element I 13.Print the smallest element s 14.Stop
Design@Crazy
PageNo..
Title: Largest and smallest number Aim: Program to find the largest and smallest number Program #include<iostream.h> #include<conio.h> void main() { int a[50],i,n,l=0,s=100; clrscr(); cout<<"Enter the limit:"; cin>>n; cout<<"Enter the elements:"; for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n;i++) { if(a[i]>l) { l=a[i]; } if(a[i]<s) s=a[i]; } cout<<"\nThe largest element is:"<<l; cout<<"\nThe smallest elemet is:"<<s; getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Output Enter the limit:10 Enter the elements:20 35 12 4 0 85 77 6 28 100 The largest element is:100 The smallest elemet is:0
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Title Aim
Program #include<iostream.h> #include<conio.h> Void main() { int n,s; clrscr(); cout<<Enter the number:; cin>>n; s=n*n; cout<<square=:<<s; getch(); }
Design@Crazy
PageNo..
Algorithm 1.start 2.declare variables n,i,f 3. initialize f=1 4. read n 5. initialize i=1 6. if i<=n go to step 6 otherwise go to step8 7.calculate f=f*i 8. i=i+1 and go to step 5 9. display f 10. stop
Design@Crazy
PageNo..
#include<iostream.h> #include<conio.h> void main() { int n,i,f; f=1; clrscr(); cout<<"Enter the number:\n"; cin>>n; for(i=1;i<=n;i++) { f=f*i; } cout<<"The factorial="<<f; getch(); } Result: The program is tested and verified
Design@Crazy
PageNo..
Algorithm 1. Start 2. Read n 3. Initialize I,s=0 4. if(n>0)go to next step else go to step7 5. d=n%10,s=s+r,n=n/10 6. print s 7. stop
Design@Crazy
PageNo..
#include<stdio.h> #include<conio.h> void main() { int n,s=0,d; clrscr(); printf("Enter a number:"); scanf("%d",&n); while(n>0) { d=n%10; s=s+d; n=n/10; } printf("Sum=%d",s); getch(); }
Design@Crazy
PageNo..
Algorithm 1:start 2:initialize r=0 3:read n 4:if n>0 go to step 5 otherwise go to step 8 5.d=n%10 6.r=(r*10)+d 7.n=n/10 Go to step 4 8:display r 9:stop
Design@Crazy
PageNo..
#include<stdio.h> #include<conio.h> void main() { int n,r=0,d; clrscr(); printf("Enter a number:"); scanf("%d",&n); while(n>0) { d=n%10; r=(r*10)+d; n=n/10; } printf("Reverse=%d",r); getch(); }
Design@Crazy
PageNo..
Algorithm 1:start 2:initialize s=0,f0=0,f1=1 3:read n 4:display f0 and f1 5:initialize i=0 6:if i<n go to step 7 otherwise go to step 11 7:calculate s=f0+f1 8:display s 9:set f0=f1 and f1=s 10:=i+go to step 6 11:stop
Design@Crazy
PageNo..
#include<stdio.h> #include<conio.h> void main() { int f0,f1,s=0,n,i; clrscr(); f0=0; f1=1; printf("Enter the limit:"); scanf("%d",&n); printf("%d\n%d",f0,f1); for(i=0;i<n;i++) { s=f0+f1; printf("\n%d",s); f0=f1; f1=s; } getch(); } Result:The program is tested and verified
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Algorithm 1:start 2:declare variables n,i,z 3:read n 4:initialize i=2 5:if i<n go to step 6 6:if n%i =0 go to step 7 7: set z=1 8:set i=i+1 go to step 5 9: if z=1 go to step 10 ,otherwise go to step 11 10: Print the number is prime. Go to step 12 11: printNot prime number.go to step 12 12:stop
Design@Crazy
PageNo..
#include<stdio.h> #include<conio.h> void main() { int n,i,z; clrscr(); printf("Enter the number:"); scanf("%d",&n); if(n==1) exit(0); i=2; while(i<n) { if(n%i==0) { z=1; } i=i+1; } printf("The number is.."); if(z==1) { printf("Not a prime number"); } else { printf("....a prime number"); } getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Algorithm 1.Class defenition 1.1: declare f,i,n 1.2: public member function void getdata() 1.3: public member function void show() 1.4: end of class definition 2: void getdata() function 2.1:accept n 2.2: initialize f=1 and calculate f=f*i 3: void show() function 3.1: display f 4: main() function 4.1: create the object of class 4.2:call void getdata() function 4.3: call void show() function 4.4: end
Design@Crazy
PageNo..
#include<iostream.h> #include<conio.h> class fact { public: int f,i,n; void getdata(); void show(); }; void fact::getdata() { cout<<"Enter the number:"; cin>>n; f=1; for(i=1;i<=n;i++) f=f*i; } void fact::show() { cout<<"Factorial="<<f; } void main() { fact d; clrscr(); d.getdata(); d.show(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Algorithm 1: class definition 1.1: declare n,p,I,j,f,c; 1.2: public member function void generate() 1.3: end of class definition 2: void getdata() function 2.1: initialize c=0 2.2: accept n and initialize i=2 2.3: : if i<=n go to step 2.5 2.4 initialize f=0 2.5: initialize j=2 2.6: if j<i go to step 2.7 2.7: if i%j=0 go to step 2.8 2.8: f=f+1 go to step 2.9 2.9: if f=0, c=c+1 and print c 3: main() function 3.1: create the object of the class 3.2: call generate() function 3.3: end
Design@Crazy
PageNo..
#include<iostream.h> #include<conio.h> class prime { public: int n,p,i,j,f,c; void generate(); }; void prime::generate() { c=0; cout<<"Enter the limit of numbers:"; cin>>n; clrscr(); cout<<"\t\tPrime Numbers\n"; cout<<"\t\t........................\n"; cout<<"\n\tSl.No\tPrime Number\t\t\n"; cout<<"\n\t.......\t...............\n"; for(i=2;i<=n;i++) { f=0; for(j=2;j<i;j++) { if(i%j==0) {f++; } } if(f==0) { c++;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Result:The program is tested and verified Output Enter the limit of numbers: 10 Prime Numbers ........................ Sl.No: Prime Number ....... 1 2 3 4 ................. 2 3 5 7
Design@Crazy
PageNo..
Algorithm 1:class definition 1.1: declare variables dpt, wdrw, bal, temp,name[20],type[10] 1.2: public member function void initial() 1.3: public member function void deposit() 1.4: public member function void withdraw() 1.5: public member function void display() 1.6: end of class definition 2: void initial() function 2.1: accept name 2.2: accept account type 2.3: set balance=fxd 3: void deposit () function 3.1: accept deposit amount 3.2: set bal=fxd+dpt 3.3: display current balance 4: void withdraw() function 4.1: set temp=0 4.2: accept withdraw amount 4.3: if ((wdrw<bal)&&(wdrw>500)) go to step 4.4 Otherwise go to step 4.5 4.4: set temp=bal-wdrw; set bal=temp; 4.5: display current balance 5: void display() function 5.1: display name and balance 6: main() function 6.1: if choice=1,accept account number and call initial() function 6.2: if choice=1,accept account number and call deposit() function 6.3: if choice=1,accept account number and call withdraw() function 6.4: if choice=1,accept account number and call display() function 6.5: if choice=5, end
Design@Crazy
PageNo..
#include <iostream.h> #include <conio.h> int fxd=500; class bank { private: char name[20],type[10]; int dpt,wdrw,bal,temp; public: void initial(); void deposit(); void withdraw(); void display(); }m[10]; void bank::initial() { cout<<"\nEnter your name :"; cin>>name; cout<<"\nEnter the type of accound :"; cin>>type; bal=fxd; } void bank::deposit() { cout<<"\nEnter the amount for deposit :"; cin>>dpt; bal=fxd+dpt;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
cout<<"\nYour current balance is Rs :"<<bal <<"/-"; } void bank::withdraw() { temp=0; cout<<"\nEnter the amound for withdraw :"; cin>>wdrw; if ((wdrw<bal)&&(wdrw>500)) { temp=bal-wdrw; bal=temp; } else cout<<"\nSorry...! Your accound balance is "<<bal <<"only"; } void bank::display() { cout<<"\nName :"<<name; cout<<"\nCurrent balance :"<<bal; } void main() { int i,n; clrscr(); do { cout<<"\n1:Create an account"; cout<<"\n2:Deposit"; cout<<"\n3:Withdraw";
Design@Crazy
PageNo..
Design@Crazy
PageNo..
cout<<"\n4:Balance"; cout<<"\n5:Exit"; cout<<"\n\n\n\t\t\tEnter your choice"; cout<<"\n\n\n"; cin>>n; switch(n) { case 1: cout<<"Enter the account number (b/w 1 & 10) :"; cin>>i; m[i].initial(); break; case 2: cout<<"Enter your account number :"; cin>>i; m[i].deposit(); break; case 3: cout<<"Enter uour account number :"; cin>>i; m[i].withdraw(); break; case 4: cout<<"Enter uour account number :"; cin>>i; m[i].display(); break; case 5: void exit(); break; default: cout<<"wrong case"; break;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
} }while(n<5); getch(); } Result: The program is tested and verified Output 1:Create an account 2:Deposit 3:Withdraw 4:Balance 5:Exit Enter your choice 1 Enter the account number (b/w 1 & 10) :1 Enter your name :ARUN Enter the type of account: Simple 1:Create an account 2:Deposit 3:Withdraw 4:Balance 5:Exit Enter your choice 2 Enter your account number :1 Enter the amount for deposit :500 Your current balance is Rs :1000/
Design@Crazy
PageNo..
Algorithm 1: class definition 1.1: private data members name,grade,reg no m1,m2 ,m3,m4,m5,tot,per 1.2: public member function void getdata() 1.3: public member function void calc() 1.4: public member function void display() 2: void getdata() function 2.1:accept name 2.2: accept regno 2.3: accept m1,m2,m3,m4,m5 3: void calc() function 3.1: calculate total 3.2: calculate percentage 3.3: if percentage>=80 ,otherwise go to step 3.4 Set grade=A 3.4:if per>=60 and per<80, otherwise go to step 3.5 Set grade=B 3.5: if per>=50 and per<60, otherwise go to step 3.6 Set grade=C 3.6: if per>=40 and per<50, otherwise go to step 3.7 Set grade=D 3.7: Set grade=E 4: void display() function 4.1: display name,register number 4.2: display m1,m2,m3,m4,m5 4.3: display total,percentage,grade 5:main() function 5.1: initialize i=0 5.2: if i<n go to step 5.3 5.3: call to getdata() function 5.4:i=i+1 ,go to step 5.2 5.5: initialize i=0
Design@Crazy
PageNo..
#include <iostream.h> #include <conio.h> class students { private: char name[20],grade; int regno,m1,m2,m3,m4,m5,tot; float per; public: void getdata(); void calc(); void display(); }s[40]; void students::getdata() { cout<<"\n\nEnter the name of student :"; cin>>name; cout<<"\nEnter the register number :"; cin>>regno; cout<<"\nEnter the mark of 5 subjects :"; cin>>m1>>m2>>m3>>m4>>m5; } void students::calc() { tot=m1+m2+m3+m4+m5; per=tot/5; if(per>=80) { grade='A'; }
Design@Crazy
PageNo..
5.6: if i<n go to step 5.7 5.7: call to calc() function Call to display() function 5.8:i=i+1 ,go to step 5.6 5.9: end
Design@Crazy
PageNo..
else if((per>=60)&&(per<80)) { grade='B'; } else if((per>=50)&&(per<60)) { grade='C'; } else if((per>=40)&&(per<50)) { grade='D'; } else { grade='E'; } }
void students::display() {
cout<<"\n\n"<<name<<"\t"<<regno<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<m4 <<"\t"<<m5<<"\t"<<tot<<"\t"<<per<<"\t"<<grade<<"\n"; } void main() { int n,i,j; clrscr(); cout<<"\t\t ................DATA INPUT .................\n"; cout<<"\n\nEnter the number of students :";
Design@Crazy
PageNo..
Design@Crazy
PageNo..
cin>>n; for (i=0;i<n;i++) { s[i].getdata(); } clrscr(); cout<<"\t\t..........STUDENTS DETAILS...........\n\n"; cout<<"\n\nREG.NO:\tNAME\tSUB1\tSUB2\tSUB3\tSUB4\tSUB5\tTOTAL\tPER: (%)\tGRADE\n"; cout<<".................................................................................\n"; for (i=0;i<n;i++) { s[i].calc(); s[i].display(); } getch(); } Result: The program is tested and verified Output ................DATA INPUT ................. Enter the number of students :2 Enter the name of student :ANJU Enter the register number :17524 Enter the mark of 5 subjects :98 75 88 92 88 Enter the name of student :ANU
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Enter the register number :17379 Enter the mark of 5 subjects :80 52 63 54 90 ..........STUDENTS DETAILS........... REG.NO: NAME GRADE ............................................................................................................................ 17524 17379 ANJU ANU 98 80 75 52 88 63 92 54 88 90 441 339 88 67 A B SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PER:(%)
Design@Crazy
PageNo..
Algorithm 1:class definition 1.1: private data member id 1.2: constructor member functions declaration and definition 1.3: copy constructor member function definition 1.4: public member function void display(void) 1.5: end of class definition 2:main function() 2.1:object A is created and initialized 2.2: copy constructor called 2.3: copy constructor called again 2.4: D is created ,not initialized 2.5: D=A 2.6: call the functions A.display() B.display() C.display() D.display()
Design@Crazy
PageNo..
#include<iostream.h> #include<conio.h> class code { int id; public: code(){ } //constructor //copy constructor code(int a) { id=a;} //constructor again code(code &x) { id=x.id; } void display(void) { cout<<id; } }; int main() { code A(100); code B(A); code C=A; code D; clrscr(); D=A; cout<<"\n id of A:"; A.display(); cout<<"\n id of B:"; B.display(); cout<<"\n id of C:"; C.display(); cout<<"\n id of D:"; D.display(); getch(); return 0; }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Algorithm 1:start main() function 2: pass volume (10) to int volume(int s) function and display volume 3: pass volume (2.5,8) to double volume(double r,int h) function and display volume 4: pass volume(100l,75,15) to long volume(long l,int b,int h) function and display volume 5: int volume(int s) function return(s*s*s) 6:double volume(double r,int h) return(3.14519*r*r*h) 7: long volume(long l,int b,int h) return(l*b*h) 8: stop
Design@Crazy
PageNo..
#include<iostream.h> #include<conio.h> class area { public: int l,b,a,r,m,n; float pi,result; void findarea(float,int); void findarea(int,int); void findarea(int); }; void area::findarea(float p,int x) { x=p; r=x; a=x*r*r; cout<<"Area of circle="<<a; } void area::findarea(int l,int b) { m=l; n=b; a=m*n; cout<<"Area of rectangle="<<a; } void area::findarea(int s) { a=s; a=a*a; cout<<"Area of square="<<a;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
} void main() { area g; clrscr(); g.findarea(3.14,5); g.findarea(5,4); g.findarea(6); getch(); } Result: The program is tested and verified Output Area of cube:1000 Area of cylinder:157.2595 Area of rectangular box:112500
Design@Crazy
PageNo..
Algorithm 1: class definition 1.1: private data member r 1.2: public member function void getdata( int a) 1.3: public member function float area() 1.4: public member function float vol() 1.5: public member function void disp() 1.6: end of class definition 2: definition of getdata( int a) function as inline 3: definition of area() function as inline 4: definition of vol() function as inline 5: definition of disp()function as inline 6: main() function 6.1: create object of the class 6.2: call the function getdata(a) 6.3: call the function disp() 6.4: end
Design@Crazy
PageNo..
#include<iostream.h> #include<conio.h> class circle { int r; public: void getdata( int a); float area(); float vol(); void disp(); }; inline void circle::getdata(int a) { r=a; } inline float circle::area() { return 3.14*r*r; } inline float circle ::vol() { return area()*r; } inline void circle::disp() { cout<<"\n\n\tThe area is............\n\n\t"; cout<<area(); cout<<"\n\n\tThe volume is............\n\n\t"; cout<<vol(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
void main() { clrscr(); int a; circle d; cout<<"\n\n\tThe radius of circle is.........\n\n\t"; cin>>a; d.getdata(a); d.disp(); getch(); } Result: The program is tested and verified Output The radius of circle is......... 5 The area is............ 78.5 The volume is............ 392.5
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.declare the class sum 3.Defining constructor sum() as s=0 4.Defining the function findsum() 5.display value of a and b 6.Display the sum c 7.Stop Algorithm for main 1.Start 2.Create the object of class sum 3.Call the function findsum() with object a 4.Stop
Design@Crazy
PageNo..
Title :Default constructor Aim : Write program using default constructor Program //Program of default constructor #include<iostream.h> #include<conio.h> class sum { public: int a,b,s; sum() { s=0; } void findsum() { cout<<"Enter two number\n"; cin>>a>>b; s=a+b; cout<<"Sum="<<s; } }; void main() { sum a; clrscr(); a.findsum(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.declare the class factorial with member n,I,f and function findfact() 3.Defining constructor with 1 argument and assign it to x 4.Defing function findfact() and fin the factorial with for loop 5.Stop
Algorithm for main 1.Start 2.Calling constructor with 1 argument 3.display the value 4.Stop
Design@Crazy
PageNo..
Title :Parameterized constructor Aim : Write program using paramerterized constructor Program #include<iostream.h> #include<conio.h> class factorial { public: int n,i,f; factorial(int); void findfact(); }; factorial::factorial(int x) { n=x; } void factorial::findfact() { f=1; for(i=n;i>0;i--) { f=f*i; } cout<<"Factorial="<<f; } void main() { factorial f(5); clrscr(); f.findfact(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
OUTPUT Factorial=120
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.Create class staff with data members as no,bp,ta,da,hra,pf,name,designand function calculation() 3.Create class employe as derived class of staff with function getdata()for reading information and display()for printing data 4.stop Algorithm for main function 1.Start 2.Create object of class employe 3.Call function getdata()with object e 4.Call function display() with object e 5.stop
Design@Crazy
PageNo..
Title : Single inheritance Aim : Write program using single inheritance Program /*Single inheritance*/ #include<iostream.h> #include<conio.h> class staff { public: int bp,ta,da,hra,pf,no; char name[20],desig[20]; void getdata() { cout<<"Enter the roll number of employe:"; cin>>no; cout<<"Enter the name of the employe:"; cin>>name; cout<<"Enter the designation of the employe:"; cin>>desig; cout<<"Enter basic pay:"; cin>>bp; cout<<"Enter the ta :"; cin>>ta; cout<<"Enter the da:"; cin>>da; cout<<"Enter the hra:"; cin>>hra; cout<<"Enter the pf:"; cin>>pf; } }; class employe:public staff
Design@Crazy
PageNo..
Design@Crazy
PageNo..
{ public: int total,net; void calculation() { total=bp+ta+da+hra; net=total-pf; } void dispaly() { cout<<no<<"\t"<<name<<"\t"<<desig<<"\t"<<bp<<"\t"<<ta<<"\t"<<da<<"\t"<<hra <<"\t"<<pf<<"\t"<<total<<"\t"<<net<<"\n"; } }; void main() { employe e; clrscr(); e.getdata(); e.calculation(); cout<<"no\tname\tdesi\tbp\tta\tda\thra\tpf\total\tent\n"; cout<<"------------------------------------------------------\n"; e.dispaly(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
OUTPUT Enter the roll number of employe:1 Enter the name of the employe:Suresh Enter the designation of the employe:Kollam Enter basic pay:5000 Enter the ta :0 Enter the da:510 Enter the hra:310 Enter the pf:1500 no 1 name desi bp Suresh Kola 5000 ta 0 da 510 hra 310 pf total net -----------------------------------------------------------1500 total net -----------5820 4320
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.create class first with data member id,name and function getstudent() 3.Create class second with data member s,cname and function getcourse() 4.Create class third with data member tm s1,s2,s3 and function getresult()and getdetails() 5.Stop Algorithm for main function 1.Start 2.create object r for class third 3.Call function getstudent()with object r 4.Call function getcourse()with object r 5.call function getresult and getdetails with object r 6.Stop
Design@Crazy
PageNo..
Title :Multilevel inheritance Aim : Write program using multilevel inheritance Program #include<iostream.h> #include<conio.h> class student { public: int id,total; char name[10]; void getstudent() { cout<<"Enter the student id:"; cin>>id; cout<<"Enter the name of the student:"; cin>>name; } }; class course:public student { public: int s; char cname[20]; void getcourse() { cout<<"Enter the semester:"; cin>>s; cout<<"Enter the name of the course:"; cin>>cname; } };
Design@Crazy
PageNo..
Design@Crazy
PageNo..
class result:public course { public: int tm,s1,s2,s3; void getresult() { cout<<"Enter the mark of s1:"; cin>>s1; cout<<"Enter the mark of s2:"; cin>>s2; cout<<"Enter the mark of s3:"; cin>>s3; tm=s1+s2+s3; } void getdetails() { cout<<id<<"\t"<<name<<"\t"<<s<<"\t"<<cname<<"\t"<<tm<<"\n"; } }; void main() { result r; clrscr(); r.getstudent(); r.getcourse(); r.getresult(); cout<<"\t\tSTUDENT DETAILS\n"; cout<<"\t\t----------------------\n"; cout<<"ID\tname\tsemester\tcoursename\ttotalmark\n"; cout<<"-------------------------------------------------------\n"; r.getdetails(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Output Enter the student id:1 Enter the name of the student:Asha Enter the semester:1 Enter the name of the course:Bsccomputerscience Enter the mark of s1:85 Enter the mark of s2:95 Enter the mark of s3:99 STUDENT DETAILS ---------------------ID 1 name semester Asha 1 course name Bsc 279 total ------------------------------------------------------
Design@Crazy
PageNo..
Algorithm for class 1.start 2.Create class A with data member a and function geta() 3.Create class B with data member b and function getb() 4.Create class C as derived class of A and B with member c and function getresult() 5.Stop Algorithm for main 1.Start 2.Create object of C class 3.Call function geta() and getb() with object d 4.Stop
Design@Crazy
PageNo..
Title :Multiple inheritance Aim : Write program using multiple inheritance Program #include<iostream.h> #include<conio.h> class A { public: int a; void geta() { cout<<"Enter the value of a:"; cin>>a; } }; class B { public: int b; void getb() { cout<<"Enter the value of b:"; cin>>b; } }; class C:public A,public B { public: int c; void getresult() { geta();
Design@Crazy
PageNo..
Design@Crazy
PageNo..
getb(); c=a+b; cout<<"The value of c="<<c; } }; void main() { C d; clrscr(); d.getresult(); getch(); }
Output Enter the value of a:2 Enter the value of b:5 The value of c=7
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.create class A with member a and function geta() 3.Create class B as derived class of A with member b and function getb() 4.Create class C as derived class of A with member c and function getc() 5.Stop Algorithm for main 1.Start 2.Create object for class A 3.Create object for class B 4.Call function geta(),getb()and getsum() with object p 5.Call function geta(), getb() and getmul() with object q 6.Stop
Design@Crazy
PageNo..
Title :Heirarchial inheritance Aim : Write program using Herirarchial inheritance Program #include<iostream.h> #include<conio.h> class A { public: int a; void geta() { cout<<"Enter the value of a:"; cin>>a; } }; class B:public A { public: int b,c; void getb() { cout<<"Enter the value of b:"; cin>>b; } void getsum() { c=a+b; cout<<"Sum="<<c; } }; class C:public A { public:
Design@Crazy
PageNo..
Design@Crazy
PageNo..
int d,b,c; void getd() { cout<<"\nEnter the value of d:"; cin>>d; } void getmul() { c=a*d; cout<<"Product="<<c; } }; void main() { B p; C q; clrscr(); p.geta(); p.getb(); p.getsum(); q.geta(); q.getd(); q.getmul(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Output Enter the value of a:2 Enter the value of b:5 Sum=7Enter the value of a:6 Enter the value of d:7 Product=42
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.Create class player with member name,gender,age 3.Create class test as derived class of player with member height,weight 4.Create class sports with member sname and function getitem() 5.Create class result as derived class of test and player with function display() 6.Stop Algorithm for main 1.Start 2.Create object of class result 3.Call function getitem() and getitem()and display() with object r 4.stop
Design@Crazy
PageNo..
Title :hybrid inheritance Aim : Write program using hybrid inheritance Program #include<iostream.h> #include<conio.h> class student { public: int no; char name[10],desig[10]; void getstudent() { cout<<"Enter the roll number of the student:"; cin>>no; cout<<"Enter the name of the student:"; cin>>name; cout<<"Enter the designation of the student:"; cin>>desig; } }; class test:public student { public: int m1,m2,m3,total; void gettest() { cout<<"Enter the mark of english:"; cin>>m1; cout<<"Enter the mark of mathematics:"; cin>>m2; cout<<"Enter the mark of science:"; cin>>m3;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
total=m1+m2+m3; } }; class sports { public: char sname[20]; void getitem() { cout<<"Enter your favouraite sports item:"; cin>>sname; } }; class result:public test,public sports { public: void display() { cout<<"\t\tstudent details\n"; cout<<"\t\t-----------------------\n"; cout<<"\t\tNumber:"<<no<<"\n"; cout<<"\t\tName:"<<name<<"\n"; cout<<"\t\tDesignation:"<<desig<<"\n"; cout<<"\t\tMark of English:"<<m1<<"\n"; cout<<"\t\tMark of Mathematics:"<<m2<<"\n"; cout<<"\t\tMark of science:"<<m3<<"\n"; cout<<"\t\total="<<total<<"\n"; cout<<"\t\tfavouraite sports item:"<<sname<<"\n"; } }; void main() { result r;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Result: The program is tested and verified Output Enter the roll number of the student:1 Enter the name of the student:Manu Enter the designation of the student:Ayoor Enter the mark of english:85 Enter the mark of mathematics:60 Enter the mark of science:73 Enter your favouraite sports item:Cricket student details ----------------------Number:1 Name:Manu Designation:Ayoor Mark of English:85 Mark of Mathematics:60 Mark of science:73 total=218 favouraite sports item:Cricket
Design@Crazy
PageNo..
Algorithm for class 1.start 2.Create class demo with member x,y,z 3.Define function getdata()with 3 argument 4.define function operator() and display() 5.stop
Algorithm for main 1.Start 2.Create object for class demo 3.Call Function with object d 4.Stop
Design@Crazy
PageNo..
Title :Operator overloading Aim : Write program using operator overloading Program #include<iostream.h> #include<conio.h> class demo { public: int x,y,z; void getdata(int a,int b,int c); void operator -(); void display(); }; void demo::getdata(int a,int b,int c) { x=a; y=b; z=c; } void demo::operator -() { x=-x; y=-y; z=-z; } void demo::display() { cout<<"x="<<x<<"\n"; cout<<"y="<<y<<"\n"; cout<<"z="<<z<<"\n"; } void main()
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Result: The program is tested and verified Output x=-10 y=20 z=-30
Design@Crazy
PageNo..
Algorithm for Class 1.Start 2.Create class multiply with data members a,b and function getvalue() 3.Declare a friend function product 4.define friend function and print the product 5.Stop Algorithm for main 1.Start 2.Create object d 3.Call function getvalue() with object d 4.Call friend function product 5.Stop
Design@Crazy
PageNo..
Title :Friend function Aim : Write program using friend function Program #include<iostream.h> #include<conio.h> class multiply { int a,b; public: void getvalues() { cout<<"Enter two number:"; cin>>a>>b; } friend int product(multiply m) }; int product(multiply m) { int c; c=m.a*m.b; return(c); } void main() { multiply d; clrscr(); d.getvalues(); cout<<"Product of two numbers="<<product(d); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.Create class first with member b 3.Define the function first()as b=10 4.Define the class display as virtual and print b 5.Create class second as derived class of first with data member d and function second() 5.Define the function display()print the value of d 6.Stop Algorithm for main 1.Start 2.Create object s of second 3.create object *p of first 4.call function display()with p 5.Stop
Design@Crazy
PageNo..
Title :Pure virtual function Aim : Write program using pure virtual function Program #include<iostream.h> #include<conio.h> class first { public: int b; first() { b=10; } virtual void dispaly() { cout<<"Value of b="<<b; } }; class second:public first { public: int d; second() { d=20; } void display() { cout<<"Value of d="<<d; } }; void main()
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Result: The program is tested and verified Output Value of b=10 Value of d=20
Design@Crazy
PageNo..
Algorithm for template function 1.Start 2.Define function template sum to add two elements 3.Stop Algorithm for main function 1.Start 2.set x,y and hx,fy 3.z=call function sum with argument as x and y 4.fz=call function sum with argument as fx and fy 5.print z and fz 6.Stop
Design@Crazy
PageNo..
Title :Function template Aim : Write program using function template Program #include<iostream.h> #include<conio.h> template<class T> T addition(T a, T b) { T s; s=a+b; return(s); } void main() { int x,y,z; float fx,fy,fz; clrscr(); cout<<"Enter two integer number:"; cin>>x>>y; z=addition(x,y); cout<<"Sum="<<z; cout<<"Enter two real number:"; cin>>fx>>fy; fz=addition(fx,fy); cout<<"Sum="<<fz; getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Output Enter two integer number:2 3 Sum=5 Enter two real number:3.5 2.5 Sum=6
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.Create class template with data members pointer variable v 3.Create constructor function with no arguments 4.Create constructor function with *a as argument 5.Oerload operator* 6.Stop Algorithm for main function 1.Start 2.Create two arrays x and y with three element 3.Create template variables 4.v1=x and v2=y 5.Do operation between v1 and v2 with overload operator * and assign the result to r 6.Print r 7.Stop
Design@Crazy
PageNo..
Title : Class template Aim : Write program using class template Program #include<iostream.h> #include<conio.h> const size=3; template<class T> class vector { T *v; public: vector() { v=new T[size]; for(int i=0;i<size;i++) { v[i]=0; } } vector(T *a) { for(int i=0;i<size;i++) { v[i]=a[i]; } } T operator *(vector &y) { T sum=0; for(int i=0;i<size;i++) { sum+=this->v[i]*y.v[i]; }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
return(sum); } }; int main() { int x[3]={1,2,3}; int y[3]={1,2,3}; vector<int>v1; vector<int>v2; v1=x; v2=y; int r=v1*v2; cout<<"\nR="<<r; return 0; }
Output R=32
Design@Crazy
PageNo..
1.Start 2.Define function test() 3.Try block if x==1 Throw x if x=0 Throw x if x=-1 Throw 1.0 4.Catch block if x is integer printCaught integer If x is character print Caught character If x is double print Caught double 5.Stop
Algorithm for main function 1.Start 2.call function test()with argument as 1 3.Call function test ()with argument as 0 4.Call function test()with argument as -1 5.Call function test()with argument as 2 6.Stop
Design@Crazy
PageNo..
Title: Exception handling Aim : Write program using Exception hanling Program #include<iostream.h> #include<conio.h> void test(int x) { try { if(x==1) throw x; else if(x==0) throw'x'; else if(x==1) throw 1.0; } catch(char c) { cout<<"\nCought a charactor"; } catch(int m) { cout<<"\nCought an integer"; } catch(double d) { cout<<"\nCought a double"; } } int main() { clrscr(); cout<<"\nm=1;
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Result: The program is tested and varified Output m=1 caught an integer m=0 caught a chracter m=-1 caught a double m=2
Design@Crazy
PageNo..
ALGORITHM FOR CLASS: 1.Start 2.Create class tele withdata members fnm[23],dno[20],stm[10],city[20]and pno and with member function get()for reading and showwall() for printing data 3.Stop Algorithm for main function: 1.Start 2.Create object t for class tele 3.Create object f for fstream 4.Assign character ch==y 5.open file address.dat using object f in input mode 6.If ch==y Call function get()using t Write fetched data to file Read value of ch Repeat step 6 7.Seek file pointer to begning of file 8.call function showwall()using t 9.Close file address.dat 10.Stop
Design@Crazy
PageNo..
Title: File Aim :Write program using file Program /*Write and read operation using file*/ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<fstream.h> #include<string.h> class tele { char fnm[20]; char dno[10],stnm[20]; char road[20],city[10]; long pno; public: void get(); void showwall(); }; void tele::get() { cout<<"\nEnter full name:"; gets(fnm); cout<<"\nEnter door No:"; cin>>dno; cout<<"\nEnter street name:"; gets(stnm); cout<<"\nEnter road name:"; gets(road); cout<<"\nEnter city:"; gets(city); cout<<"Enter phone No:";
Design@Crazy
PageNo..
Design@Crazy
PageNo..
cin>>pno; } void tele::showwall() { cout<<"\nFull Name:"<<fnm; cout<<"\nDorr No:"<<dno; cout<<"\nStreet Name:"<<stnm; cout<<"\nRoad Name:"<<road; cout<<"\nCity:"<<city; cout<<"\nPhone No:"<<pno; } void main() { clrscr(); tele t; fstream f; char ch='y'; int c=0; f.open("address,dat",ios::in); while(ch=='y') { t.get(); f.write((char*)&t,sizeof(t)); cout<<"\nDo you want to continue?(y/n)"; cin>>ch; f.seekg(0); while(f.read((char*)&t,sizeof(t))); { cout<<"\n\n"<<++c<<"Information"; t.showwall(); } f.close(); getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Result: The program is tested and varified Output Enter full name:Asha suresh Enter door No:20 Enter street name:SPG complex Enter road name:Dwarka Enter city:Delhi Enter phone No:065897231 Do you want to continue?(y/n)n Information Full Name:Asha suresh Dorr No:20 Street Name:SPG complex Road Name:Dwarka City:Delhi Phone No:53
Design@Crazy
PageNo..
Algorithm for class 1.Start 2.Create class book with member bnm[20],author[30],peges,price and member function as get()for reading data and list() for printing data 3.Stop Algorithm for main 1.Start 2.Create array of object b[3] of books 3.Create object k of book 4.Create object f1 for fstream 5.Open file book.data in input mode 6.for i=0 to 2 7.Call function get()with b[i] 8.Writw data read by b[i]to file 9.End for i 10.Seek file pointer f1 to beginning of file 11.for i=0 to 2 12.Read data from file 13.Call function list()with b[i] 14.End for i 15.Stop
Design@Crazy
PageNo..
Title: File Accessing Aim :Write program using file Program #include<iostream.h> #include<conio.h> #include<stdio.h> #include<fstream.h> class book { char bnm[20],author[30]; int pages,price; public: void get(); void list(); }; void book::get() { cout<<"\nEnter book name:"; gets(bnm); cout<<"\nEnter author name:"; gets(author); cout<<"\nEnter pages:"; cin>>pages; price=pages*float(0.40); } void book::list() { cout<<"\nBook name:"<<bnm; cout<<"\nAuthor name:"<<author; cout<<"\nPages:"<<pages; cout<<"\nPrice:"<<price; }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
void main() { int i; book b[3],k; fstream f1; clrscr(); f1.open("book.dat.",ios::in); for(i=0;i<3;i++) { b[i].get(); f1.write((char*)&b[i],sizeof(b[i])); } f1.seekg(0); for(i=0;i<3;i++) { f1.read((char*)&b[i],sizeof(b[i])); b[i].list(); } getch(); }
Design@Crazy
PageNo..
Design@Crazy
PageNo..
Output Enter book name:Harrypotter Enter author name:JKRowling Enter pages:1000 Enter book name:Computerorganization Enter author name:Williamstalling Enter pages:826 Enter book name:Earthmagnetism Enter author name:WallaceHall Enter pages:100 Book name:Harrypotter Author name:JKRowling Pages:1000 Price:400 Book name:ComputerorganizationWilliamstalling Author name:Williamstalling Pages:826 Price:330 Book name:Earthmagnetism Author name:WallaceHall Pages:100 Price:40
Design@Crazy