EEE III year oops lab manual
-
Upload
ayyanaprabu -
Category
Documents
-
view
141 -
download
1
description
Transcript of EEE III year oops lab manual
![Page 1: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/1.jpg)
THENI KAMMAVAR SANGAM COLLEGE OF TECHNOLOGY
Electrical & Electronics Engineering
OBJECT ORIENTED PROGRAMMING
RECORD NOTE
![Page 2: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/2.jpg)
NAMEREGISTRATION NUMBER
THENI KAMMAVAR SANGAM COLLEGE OF TECHNOLOGY
KODUVILARPATTI, THENI DISTRICT-625534
BONAFIDE CERTIFICATE
NAMEREGISTRATION NUMBERSEMESTERDEPARTMERTSUBJECTSUBJECT CODE
Certified that this is the bonafide record of work done by the above student
in Object Oriented Programming Laboratory during the year 2010-2011.
LAB-IN CHARGE HEAD OF THE DEPARTMENT
(Mr.J.Ayyana prabu) (Mr.K.Vel kumar)
Submitted for the Pratical Examination held on 27.10.2010
![Page 3: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/3.jpg)
INTERNAL EXAMINER EXTERNAL EXAMINER
EX NO DATE CONTENTS PAGE NO STAFFSIGNATURE
1 Simple Interest
2 Enumeration Datatype
3 Function Invocation
4 Function Overloading
5 Array
6 Call by Reference
7 Assertions
8 Structure
9 Structure pointer operator
10 Union
11 Diff b/t Structure and Union
12 Class
13 Constructor
14 Destructor
15 Static Member
16 This Pointer
17 ADT Conversions
18 Unary Operator Overloading
19 Binary Operator Overloading
![Page 4: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/4.jpg)
20 Function Selection
EX NO DATE CONTENTS PAGE NO STAFF
SIGNATURE21 Pointer Operators
22 Derived Class
23 Virtual Function
24 Exception Handling
25 Class Template
26 Function Template
27 Formatted I/O Operations
28 Unformatted I/O operations
29 Predefined Manipulators
30 User Defined Manipulators
31 File Modes
32 File Pointer and Manipulators
33 File I/O
![Page 5: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/5.jpg)
Ex.No: Date:
SIMPLE INTEREST
AIM:
ALGORITHM:
![Page 6: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/6.jpg)
PROGRAM:
//Program for Simple Interest
#include<iostream.h>#include<conio.h> void main() {
int p,q,r,i;clrscr();cout<<" Program for simple Interest "<<"\n";cout<<"==============================="<<"\n";cout<<" Enter the values of P, Q and R "<<"\n";cin>>p>>q>>r;i=(p*q*r)/100;cout<<"Simple Interest="<<i;getch();
}
![Page 7: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/7.jpg)
![Page 8: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/8.jpg)
OUTPUT:
RESULT:
![Page 9: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/9.jpg)
Ex.No: Date:
ENUMERATION DATATYPE
AIM:
ALGORITHM:
![Page 10: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/10.jpg)
PROGRAM:
//Program for Enumeration Datatype
#include<iostream.h>#include<conio.h>void main(){clrscr();
enum day
{sunday,monday,tuesday,wednesday,thursday,friday,saturday
};
day theday;
int j; cout<<" Program for Enumerators "<<"\n"; cout<<"====================================="<<"\n"; cout<<"Please enter the day of a week(0-6):"; cin>>j; theday=day(j); if(theday==sunday||theday==saturday) {
cout<<"Answer:Holiday"; } else {
cout<<"Answer:Working day"; } getch();}
![Page 11: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/11.jpg)
OUTPUT:
RESULT:
![Page 12: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/12.jpg)
Ex.No: Date:
FUNCTION INVOCATION
AIM:
ALGORITHM:
![Page 13: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/13.jpg)
PROGRAM:
//Program for Function Invocation
#include<iostream.h>#include<conio.h> void swap(int a,int b) {
int c;cout<<"Before swaping:";cout<<"a="<<a<<" "<<"b="<<b<<"\n";c=a;a=b;b=c;cout<<"After swaping:";cout<<"a="<<a<<" "<<"b="<<b;
}void main() {
int a,b;clrscr();cout<<" Program for Function Invocation "<<"\n";cout<<"==============================="<<"\n";cout<<"Enter the values of a and b "<<"\n";cin>>a>>b;
swap(a,b);
getch(); }
![Page 14: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/14.jpg)
OUTPUT:
RESULT:
![Page 15: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/15.jpg)
Ex.No: Date:
FUNCTION OVERLOADING
AIM:
ALGORITHM:
![Page 16: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/16.jpg)
PROGRAM:
//Program for Function Overloading
#include<iostream.h>#include<conio.h>void volume(int a) {
int c; cout<<"First Function"<<"\n"; c=a+a+a;
cout<<"Answer c="<<c<<"\n"; }void volume(double a,int b) {
int c; cout<<"Second Function"<<"\n"; c=3.14*a*a*b; cout<<"Answer c="<<c<<"\n"; }void volume(long l,int b,int h) {
int c; cout<<"Third Function"<<"\n"; c=l+b+h; cout<<"Answer c="<<c<<"\n"; }void main() { clrscr(); cout<<" Program for Function Overloading "<<"\n"; cout<<"================================"<<"\n"; volume(10); volume(2.5,8); volume(100,85,15);
getch(); }
![Page 17: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/17.jpg)
OUTPUT:
RESULT:
![Page 18: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/18.jpg)
Ex.No: Date:
ARRAY
AIM:
ALGORITHM:
![Page 19: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/19.jpg)
PROGRAM: //Program for Array
#include<iostream.h>#include<conio.h>void main() {
clrscr();int a[5][5],b[5][5],c[5][5],m,n,i,j;cout<<" Program for Array "<<"\n";cout<<"============================================="<<"\n";cout<<"Enter the row & column size for first matrix:"<<"\n";cin>>m>>n;cout<<"Enter the elements:"<<"\n";for(i=0;i<m;i++) { for(j=0;j<n;j++) { cin>>a[i][j]; }
}cout<<"Enter the row & column size for second matrix:"<<"\n";cin>>m>>n;cout<<"Enter the elements:"<<"\n";for(i=0;i<m;i++) { for(j=0;j<n;j++) { cin>>b[i][j]; } }cout<<"The added matrix is:"<<"\n";for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=a[i][j]+b[i][j]; cout<<"\t "<<c[i][j]; } cout<<"\n"; }getch();
}
![Page 20: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/20.jpg)
OUTPUT:
RESULT:
![Page 21: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/21.jpg)
Ex.No:Date:
CALL BY REFERENCE
AIM:
ALGORITHM:
![Page 22: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/22.jpg)
PROGRAM:
//Program for Call by Reference
#include<iostream.h>#include<conio.h>void swap(int *a,int *b) {
int c;cout<<"Before swaping:";cout<<"a="<<*a<<" "<<"b="<<*b<<"\n";c=*a;*a=*b;*b=c;cout<<"After swaping:";cout<<"a="<<*a<<" "<<"b="<<*b;
}void main() {
int a,b;clrscr();cout<<" Program for Call By Reference "<<"\n";cout<<"============================="<<"\n";cout<<"Enter the values of a and b "<<"\n";cin>>a>>b;swap(&a,&b);getch();
}
![Page 23: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/23.jpg)
OUTPUT:
RESULT:
![Page 24: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/24.jpg)
Ex.No:Date:
ASSERTIONS
AIM:
ALGORITHM:
![Page 25: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/25.jpg)
PROGRAM:
//Program for Assertion
#include<iostream.h>#include<conio.h>#include<assert.h> void post(int e,int f) { int g; cout<<"Checking for post condition"<<"\n"; g=e; e=f; f=g; assert((f==g)&&(f!=e)); cout<<"Post condition checked"<<"\n"; cout<<"The value of a and b after swaping"<<"\n"; cout<<"__________________________________"<<"\n"; cout<<"The Value of a is:"<<e<<"\n"; cout<<"The Value of b is:"<<f<<"\n"; } void pre(int c,int d) { int e; cout<<"Checking for precondition"<<"\n"; assert(c!=d); cout<<"Precondition checked"<<"\n"; post(c,d); }void main() { clrscr(); cout<<" Program for swaping using assert() "<<"\n"; cout<<"=================================="<<"\n"; int a,b; cout<<"Enter the value of a:"; cin>>a; cout<<"enter the value of b:"; cin>>b; pre(a,b); getch(); }
![Page 26: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/26.jpg)
OUTPUT:
RESULT:
![Page 27: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/27.jpg)
Ex.No:Date:
STRUCTURE
AIM:
ALGORITHM:
![Page 28: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/28.jpg)
PROGRAM:
//Program for Structure
#include<iostream.h>#include<conio.h>struct student {
int rollno;char name[25];char branch[15];int marks;
};void main() {
clrscr();student s1;cout<<” Program for structure ”<<”\n”;cout<<”==================”<<”\n”;cout<<"Enter the data of student";cout<<"Roll no:";cin>>s1.rollno;cout<<"Name:";cin>>s1.name;cout<<"Branch:";cin>>s1.branch;cout<<"Marks";cin>>s1.marks;cout<<"Student report:"<<"\n";cout<<"_____________"<<"\n";cout<<"Roll no:"<<s1.rollno<<"\n";cout<<"Name:"<<s1.name<<"\n";cout<<"Branch:"<<s1.branch<<"\n";cout<<"Percentage:"<<s1.marks/5<<"\n";getch();
}
![Page 29: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/29.jpg)
OUTPUT:
RESULT:
![Page 30: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/30.jpg)
Ex.No:Date:
STRUCTURE POINTER OPERATOR
AIM:
ALGORITHM:
![Page 31: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/31.jpg)
PROGRAM:
//Program for Structure Pointer Operator
#include<iostream.h>#include<conio.h>void main() {
clrscr();struct date { int month;
int day;int year;
};struct date *date_ptr;date_ptr->month=12;date_ptr->day=12;date_ptr->year=1987;cout<<" Program for Structure Pointer Operator "<<"\n";cout<<"======================================"<<"\n";cout<<"Month:"<<date_ptr->month<<"\n";cout<<"Day:"<<date_ptr->day<<"\n";cout<<"Year:"<<date_ptr->year<<"\n";getch();
}
![Page 32: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/32.jpg)
OUTPUT:
RESULT:
![Page 33: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/33.jpg)
Ex.No:Date:
UNION
AIM:
ALGORITHM:
![Page 34: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/34.jpg)
PROGRAM:
//Program for Union
#include<iostream.h>#include<conio.h>union student {
int rollno;char name[25];char branch[15];int marks;
};void main() {
clrscr();student s1,s2,s3,s4;cout<<” Program for Union ”<<”\n”;cout<<”==================”<<”\n”;cout<<"Enter the data of student";cout<<"Roll no:";cin>>s1.rollno;cout<<"Name:";cin>>s2.name;cout<<"Branch:";cin>>s3.branch;cout<<"Marks";cin>>s4.marks;cout<<"Student report:"<<"\n";cout<<"_____________"<<"\n";cout<<"Roll no:"<<s1.rollno<<"\n";cout<<"Name:"<<s2.name<<"\n";cout<<"Branch:"<<s3.branch<<"\n";cout<<"Percentage:"<<s4.marks/5<<"\n";getch();
}
![Page 35: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/35.jpg)
OUTPUT:
RESULT:
![Page 36: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/36.jpg)
Ex.No:Date:
DIFF B/T STRUCTURE AND UNION
AIM:
ALGORITHM:
![Page 37: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/37.jpg)
PROGRAM:
//Program for Diff B/T Structure and Union
#include<iostream.h>#include<conio.h>struct boy { char name[25]; int id; }st;union girl { char name[25]; int id; }un;void main() {
clrscr();cout<<" Program for Diff B/T Structure and Union "<<"\n";cout<<"========================================="<<"\n";cout<<" The Size of Structure is "<<sizeof(st)<<" Bytes"<<"\n";cout<<" The Size of Union is "<<sizeof(un)<<" Bytes"<<"\n";getch();
}
![Page 38: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/38.jpg)
OUTPUT:
RESULT:
![Page 39: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/39.jpg)
Ex.No:Date:
CLASS
AIM:
ALGORITHM:
![Page 40: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/40.jpg)
PROGRAM:
//Program for Class
#include<iostream.h>#include<conio.h>class item{
int number;float cost;public: void getdata(int a,float b) { number=a; cost=b; } void putdata() { cout<<"No:"<<number<<"\n" ; cout<<"Cost:"<<cost<<"\n"; }
};void main(){ clrscr(); item x; cout<<" Program for class "<<"\n"; cout<<"================="<<"\n"; cout<<"object x"<<"\n"; x.getdata(100,45.5); x.putdata(); item y; cout<<"object y"<<"\n"; y.getdata(200,75.5); y.putdata(); getch();}
![Page 41: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/41.jpg)
OUTPUT:
RESULT:
![Page 42: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/42.jpg)
Ex.No:Date:
CONSTRUCTOR
AIM:
ALGORITHM:
![Page 43: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/43.jpg)
PROGRAM:
//Program for Constructor
#include<iostream.h>#include<conio.h>class Bag {
private: int contents[25]; int itemcount;
public:Bag() {
itemcount=0; }void put(int item) {
contents[itemcount++]=item; }void show() {
for(int i=0;i<itemcount;i++)cout<<contents[i]<<" ";cout<<"\n";
} };void main() {
clrscr();cout<<" Program for Constructor "<<"\n";cout<<"===================================="<<"\n";int item;Bag bag;while(1) {
cout<<"Enter the item number put into bag:";cin>>item;if(item==0)break;bag.put(item);cout<<"Items in bag";bag.show();
} }
![Page 44: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/44.jpg)
OUTPUT:
RESULT:
![Page 45: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/45.jpg)
Ex.No:Date:
DESTRUCTOR
AIM:
ALGORITHM:
![Page 46: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/46.jpg)
PROGRAM:
//Program for Destructor
#include<iostream.h>#include<conio.h>class test {
public:test();~test();
};test::test() {
cout<<"constructor of class test called"<<"\n"; }test::~test() {
cout<<"destructor of class test called"<<"\n"; }void main() {
clrscr();cout<<" Program For Desructor "<<"\n";cout<<"==============================="<<"\n";test x;cout<<"terminating main()"<<"\n";getch();
}
![Page 47: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/47.jpg)
OUTPUT:
RESULT:
![Page 48: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/48.jpg)
Ex.No:Date:
STATIC MEMBER
AIM:
ALGORITHM:
![Page 49: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/49.jpg)
PROGRAM:
//Program for Static Member
#include<iostream.h>#include<conio.h>class test{
int code;static int count;public: void setcode() { code=++count; } void showcode() { cout<<"Object Number:"<<code<<"\n"; } static void showcount() { cout<<"count="<<count<<"\n"; }
};int test::count;void main(){
clrscr();cout<<”Program fot static Member”<<”\n”;cout<<”==================== ”<<”\n”;test t1,t2;t1.setcode();t2.setcode();test::showcount();test t3;t3.setcode();test::showcount();t1.showcode();t2.showcode();t3.showcode();getch();
}
![Page 50: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/50.jpg)
OUTPUT:
RESULT:
![Page 51: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/51.jpg)
Ex.No:Date:
THIS POINTER
AIM:
ALGORITHM:
![Page 52: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/52.jpg)
PROGRAM:
//Program for this pointer
#include<iostream.h>#include<conio.h>class student { private: int a,b; public: void setdata(int a) { b=a; cout<<"Address of my object:"<<this<<"\n"; this->showdata(); } void showdata() { cout<<"Data accessed in normal way:"<<b<<"\n"; cout<<"Data accessed by using this pointer:"<<this->b<<"\n"; } }; void main()
{ clrscr(); cout<<" Program for this pointer "<<"\n"; cout<<"====================================="<<"\n"; student N; N.setdata(25); getch();
}
![Page 53: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/53.jpg)
OUTPUT:
RESULT:
![Page 54: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/54.jpg)
Ex.No:Date:
ADT CONVERSIONS
AIM:
ALGORITHM:
![Page 55: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/55.jpg)
PROGRAM:
//Program for ADT Conversions
#include<iostream.h>#include<conio.h>void main() {
clrscr();int a=20000,b=20000,c;cout<<" Program for ADT Conversions "<<"\n";cout<<"==========================="<<"\n";cout<<"Implicit Type Conversion"<<"\n";c=a+b;cout<<"Answer:"<<c<<"\n";cout<<"Explicit Type Conversion"<<"\n";;int x=20000,y=20000;unsigned int z=(unsigned int) x + (unsigned int )y;cout<<"Answer:"<<z;getch();
}
![Page 56: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/56.jpg)
OUTPUT:
RESULT:
![Page 57: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/57.jpg)
Ex.No: Date:
UNARY OPERATOR OVERLOADING
AIM:
ALGORITHM:
![Page 58: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/58.jpg)
PROGRAM:
//Program for Unary Operator Overloading
#include<iostream.h>#include<conio.h>class space{
private: int x,y,z;
public: void getdata(int a,int b) { x=a; y=b; } void display() { cout<<"x="<<x<<"\n"; cout<<"y="<<y<<"\n"; } void operator++() { x=++x; y=++y;
} void operator--() { x=--x; y=--y; }};
void main() { clrscr(); space s;
cout<<" Program for Unary Operator Overloading "<<"\n"; cout<<"======================================"<<"\n";
cout<<"UNARYPLUS OPERATOR"<<"\n"; cout<<"======================"<<"\n";
cout<<"Initial values of x and y"<<"\n"; s.getdata(10,-20); s.display(); ++s;
![Page 59: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/59.jpg)
cout<<"Final values of x and y "<<"\n"; s.display(); cout<<"UNARY MINUS OPERATOR"<<"\n"; cout<<"======================="<<"\n"; cout<<"Initial Values of x and y"<<"\n"; s.getdata(10,-20);
s.display(); --s; cout<<"Final values of x and y "<<"\n"; s.display(); getch(); }
![Page 60: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/60.jpg)
OUTPUT:
RESULT:
![Page 61: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/61.jpg)
Ex.No:Date:
BINARY OPERATOR OVERLOADING
AIM:
ALGORITHM:
![Page 62: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/62.jpg)
PROGRAM:
//Program for Binary Operator Overloading
#include<iostream.h>#include<conio.h>class complex {
private: float real; float imag; public: complex() { real=imag=0.0; } void getdata()
{ cout<<"Real part:"; cin>>real; cout<<"Imag part:"; cin>>imag; }
void outdata() { cout<<"The Final Answer is:"; cout<<"("<<real; cout<<","<<imag<<")"; } complex operator+(complex c2)
{ real=real+c2.real; imag=imag+c2.imag; return *this;
} };
void main() {
clrscr(); complex c1,c2,c3; cout<<" Program for Binary operator Overloading "<<"\n"; cout<<"======================================="<<"\n"; cout<<"Enter the complex no c1"<<"\n"; c1.getdata();
![Page 63: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/63.jpg)
cout<<"Enter the complex no c2"<<"\n"; c2.getdata(); c3=c1+c2; c3.outdata(); getch(); }
OUTPUT:
RESULT:
![Page 64: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/64.jpg)
Ex.No: Date:
FUNCTION SELECTION
AIM:
ALGORITHM:
![Page 65: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/65.jpg)
PROGRAM:
//Program for Function Selection
#include<iostream.h>#include<conio.h>void volume(int a) { int c;
cout<<"1)Exact Match"<<"\n"; c=a+a+a; cout<<"Answer:"<<c<<"\n"; }void volume(float b,int d) { int c; cout<<"2)Standard Type Promotion"<<"\n";
c=b+d; cout<<"Answer:"<<c<<"\n"; }void volume(long d,double e,double f) { int c; cout<<"3)Standard Type Conversion"<<"\n"; c=d+e+f; cout<<"Answer:"<<c<<"\n"; }void main() { clrscr(); cout<<" Program for Function Selection Algorithm "<<"\n"; cout<<"========================================"<<"\n"; volume(65);
volume(5.5,65500);volume(10L,85,100);getch();
}
![Page 66: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/66.jpg)
OUTPUT:
RESULT:
![Page 67: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/67.jpg)
Ex.No:Date:
POINTER OPERATORS
AIM:
ALGORITHM:
![Page 68: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/68.jpg)
PROGRAM:
//Program for Pointer Operators
#include<iostream.h>#include<conio.h>void main() {
clrscr();int a ,*ptr;cout<<" Program for pointer operators "<<"\n";cout<<"======================================="<<"\n";cout<<"Enter the value of a:";cin>>a;ptr=&a;cout<<"The Value of variable a is:"<<a<<"\n";cout<<"The Address of variable a is:"<<ptr<<"\n";*ptr=(*ptr)/2;cout<<"Now The Value of a is:"<<(*ptr)<<"\n";getch();
}
![Page 69: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/69.jpg)
OUTPUT:
RESULT:
![Page 70: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/70.jpg)
Ex.No:Date:
DERIVED CLASS
AIM:
ALGORITHM:
![Page 71: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/71.jpg)
PROGRAM:
//Program for Derived Class(Inheritance)
#include<iostream.h>#include<conio.h>class student {
protected: int rollno,percentage;
public:void getmarks(int a,int b) {
rollno=a;percentage=b;
} };class girl:public student {
public:void display() {
cout<<"rollno:"<<rollno<<"\n";cout<<"percentage:"<<percentage<<"\n";
} };class boy:public student {
public:void display() {cout<<"rollno:"<<rollno<<"\n";cout<<"percentage:"<<percentage<<"\n"; }
};
void main() {
clrscr();girl s;boy t;cout<<"program for derived class"<<"\n";s.getmarks(1990,98);t.getmarks(1991,99);
![Page 72: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/72.jpg)
cout<<"anna university result"<<"\n";s.display();t.display();getch();
}
OUTPUT:
RESULT:
![Page 73: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/73.jpg)
Ex.No:Date:
VIRTUAL FUNCTIONS
AIM:
ALGORITHM:
![Page 74: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/74.jpg)
PROGRAM:
//Program for Virtual Function
#include<iostream.h>#include<conio.h>class base {
public:virtual void display() {
cout<<"Display base"<<"\n"; }virtual void show() {
cout<<"Show base"<<"\n"; }
};class derived:public base {
public:void display() {
cout<<"Display derived"<<"\n"; }void show() {
cout<<"Show derived"<<"\n"; }
};
void main() {
clrscr();base B;derived D;base *point;cout<<" Program for Virtual functions "<<"\n";cout<<"============================="<<"\n";cout<<"Pointer points Base class object"<<"\n";point=&B;point->display();point->show();
![Page 75: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/75.jpg)
cout<<"Pointer points Derived class object"<<"\n";point=&D;point->display();point->show();getch();
}
OUTPUT:
RESULT:
![Page 76: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/76.jpg)
Ex.No: Date:
EXCEPTION HANDLING
AIM:
ALGORITHM:
![Page 77: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/77.jpg)
PROGRAM:
//Program for Exception Handling
#include<iostream.h>#include<conio.h>#include<exception.h>void divide(int x,int y,int z){
cout<<"We are inside the function"<<"\n";if((x-y)!=0) {
int r=z/(x-y);cout<<"Result="<<r<<endl;
}else {
throw(x-y); }
}void main(){
cout<<" Program For Exception Handling "<<"\n";cout<<"=============================="<<"\n";try {
cout<<"We are inside the try block"<<"\n";divide(10,20,30);divide(10,10,20);
}catch(int i) {
cout<<"Caught the Exception"<<"\n"; }getch();
}
![Page 78: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/78.jpg)
OUTPUT:
RESULT:
![Page 79: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/79.jpg)
Ex.No:Date:
CLASS TEMPLATE
AIM:
ALGORITHM:
![Page 80: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/80.jpg)
PROGRAM:
//Program for Class Template
#include<iostream.h>#include<conio.h>template<class t1,class t2>class test {
private: t1 a; t2 b; public: test(t1 x,t2 y) { a=x;
b=y; } void show() { cout<<"Answer:"<<"a="<<a <<" and "<<"b="<<b<<"\n"; } }; void main() { clrscr(); cout<<" Program for Class Template "<<"\n"; cout<<"=========================="<<"\n"; test<float,int> test1(1.23,123); test<int,char> test2(100,'w'); test1.show(); test2.show(); getch(); }
![Page 81: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/81.jpg)
OUTPUT:
RESULT:
![Page 82: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/82.jpg)
Ex.No:Date:
FUNCTION TEMPLATE
AIM:
ALGORITHM:
![Page 83: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/83.jpg)
PROGRAM:
//Program for Function Template
#include<iostream.h>#include<conio.h>template<class T>void swap(T &x,T &y) {
T temp =x;x=y;y=temp;
}void fun(int m,int n,float a,float b) {
cout<<"Values of m and n before swap:"<<m<<" "<<n<<"\n";swap(m,n);cout<<"Values of m and n after swap:"<<m<<" "<<n<<"\n";cout<<"Values of a and b before swap:"<<a<<" "<<b<<"\n";swap(a,b);cout<<"Values of a and b after swap:"<<a<<" "<<b<<"\n";
}void main() {
clrscr();cout<<" Program for Function Template "<<"\n";cout<<"=========================================="<<"\n";fun(100,200,11.22,22.33);getch();
}
![Page 84: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/84.jpg)
OUTPUT:
RESULT:
![Page 85: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/85.jpg)
Ex.No:Date:
FORMATTED I/O OPERATION
AIM:
ALGORITHM:
![Page 86: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/86.jpg)
PROGRAM:
//Program for Formatted I/O Operations
#include<iostream.h>#include<conio.h>void main() {
clrscr();char *name[5]={"Ram","Raj","Raju "};float cut[5]={195.253,196.642,197.582};cout<<" Students Cutoff Marks "<<"\n";cout<<"========================="<<"\n";cout<<"Name "<<" "<<" Result "<<"\n";cout<<"========================="<<"\n";for(int i=0;i<3;i++) {
cout.setf(ios::left,ios::adjustfield);cout.fill('*');cout.width(12);cout<<name[i];cout<<" ";cout.fill('*');cout.precision(2);cout.width(12);cout<<cut[i]<<"\n";
}cout<<"========================="<<"\n";getch();
}
![Page 87: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/87.jpg)
OUTPUT:
RESULT:
![Page 88: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/88.jpg)
Ex.No:Date:
UNFORMATTED I/O OPERATIONS
AIM:
ALGORITHM:
![Page 89: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/89.jpg)
PROGRAM:
//Program for Unformatted I/O Operations
#include<iostream.h>#include<conio.h>#include<string.h>void main() {
clrscr();cout<<" Program for Unfomatted I/O Operations "<<"\n";cout<<"====================================="<<"\n";int count=0;char c,test[40];cout<<"Enter your Name:";cin.get(c);cout<<"My name is ";while(c!='\n') {
cout.put(c);count++;cin.get(c);
}cout<<"\n";cout<<"Enter Your Native Place:";cin.getline(test,40);cout<<"My Native Place is ";int len=strlen(test);cout.write(test,len);cout<<"\n";getch();
}
![Page 90: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/90.jpg)
OUTPUT:
RESULT:
![Page 91: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/91.jpg)
Ex.No:Date :
STANDARD MANIPULATOR
AIM:
ALGORITHM:
![Page 92: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/92.jpg)
PROGRAM:
//Program for Standard Manipulator
#include<iostream.h>#include<conio.h>#include<iomanip.h>void main() {
clrscr();char *name[5]={"Raj","Ram","Rajesh"};float cut[5]={195.253,196.642,197.582};cout<<" Program for standard manipulators "<<"\n";cout<<"================================="<<"\n";cout<<" students cutoff marks "<<"\n";cout<<"================================="<<”\n”;cout<<" name "<<" "<<" result "<<"\n";cout<<"================================="<<”\n”;for(int i=0;i<3;i++) {
cout<<setw(10)<<setfill('*')<<name[i]<<" " << setw(10)<<setprecision(2)<<cut[i]<<”\n”;
}cout<<"================================="<<"\n";getch();
}
![Page 93: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/93.jpg)
OUTPUT:
RESULT:
![Page 94: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/94.jpg)
Ex.No:Date:
USER DEFINED MANIPULATOR
AIM:
ALGORITHM:
![Page 95: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/95.jpg)
PROGRAM:
//Program for Userdefined Manipulatots
#include<iostream.h>#include<conio.h>ostream & sp(ostream & os) {
os<<" ";return os;
}void main() {
clrscr();int w=1,x=2,y=3,z=4;cout<<" Program for User Defined Manipulator "<<"\n";cout<<"===================================="<<"\n";cout<<"Answer:";cout<<"w="<<w<<sp<<"x="<<x<<sp<<"y="<<y<<sp<<"z="<<z<<sp<<"\n";getch();
}
![Page 96: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/96.jpg)
OUTPUT:
RESULT:
![Page 97: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/97.jpg)
Ex.No:Date:
FILE MODES
AIM:
ALGORITHM:
![Page 98: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/98.jpg)
PROGRAM:
//Program for Filemodes
#include<iostream.h>#include<conio.h>#include<iomanip.h>#include<fstream.h>void main() {
clrscr();char *name[5]={"Sachin","Ramesh","Tendulkar"};float cut[5]={195.253,196.642,197.582};ofstream outfile("prabu.txt",ios::out);outfile<<" program for file modes "<<"\n";outfile<<"======================"<<"\n";outfile<<" students cutoff marks "<<"\n";outfile<<"======================"<<"\n";outfile<<" name "<<" "<<" result "<<"\n";outfile<<"======================"<<"\n";for(int i=0;i<3;i++) {
outfile<<setw(10)<<setfill('*')<<name[i]<<"" <<setw(10)<<setprecision(2)<<cut[i]<<”\n”; }outfile<<"======================"<<"\n";getch();
}
![Page 99: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/99.jpg)
OUTPUT:
cse.txtProgram for File Modes ==================Students cut off Marks================== Name Result ================== Sachin 195.25Ramesh 196.64Tendulkar 197.58 ==================
RESULT:
![Page 100: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/100.jpg)
Ex.No:Date:
FILE POINTER AND MANIPULATIONS
AIM:
ALGORITHM:
![Page 101: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/101.jpg)
PROGRAM:
//Program for FilePointer and Manipulations
a)Program for seekg() and tellg()
#include<iostream.h>#include<fstream.h>#include<conio.h>void main () { clrscr(); cout<<" Program for seekg() and tellg() "<<"\n"; cout<<"==============================="<<"\n"; ifstream myfile("eee.txt"); myfile.seekg(0,ios::end); cout<<"The size of Input File is:"<<myfile.tellg()<<"\n"; getch(); }
Input File:
eee.txtWe are EEE Rockers
OUTPUT:
![Page 102: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/102.jpg)
b)Program for seekp() and tellp()
#include<iostream.h>#include <fstream.h>void main () { int pos; ofstream outfile; outfile.open ("123.txt"); outfile.write ("This is an apple",16); pos=outfile.tellp(); outfile.seekp (pos-7); outfile.write (" sam",4); outfile.close(); }
Output File:
123.txtThis is a sample
RESULT:
![Page 103: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/103.jpg)
Ex.No:Date:
FILE I/O OPERATIONS
AIM:
ALGORITHM:
![Page 104: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/104.jpg)
PROGRAM:
//Program for File I/O Operations
#include<iostream.h>#include<conio.h>#include<fstream.h>void main() {
fstream infile,outfile;int i,count,percentage;char name[30];infile.open("eee.txt",ios::in);outfile.open("cse.txt",ios::out);infile>>count;outfile<<" Anna University Results "<<"\n";outfile<<"======================="<<"\n";outfile<<" Name "<<" "<<" Result "<<"\n";outfile<<"======================="<<"\n";for(i=0;i<count;i++) {
infile>>name;infile>>percentage;outfile<< name <<" "<<percentage<<"\n";
}outfile<<"======================="<<"\n";infile.close();outfile.close();
}
![Page 105: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/105.jpg)
OUTPUT:
Input File:eee.txt3Sachin 97Ramesh 98Tendulkar 99
Output File:cse.txtAnna University Results =================== Name Result ================== Sachin 97Ramesh 98Tendulkar 99 ==================
RESULT:
![Page 106: EEE III year oops lab manual](https://reader034.fdocuments.in/reader034/viewer/2022052212/53f7c9fedab5caf01c8b4f17/html5/thumbnails/106.jpg)