You are on page 1of 9

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154
/*Write a program in c++ for the use of object array*/ #include<iostream.h> #include<conio.h> #include<iomanip.h> class student { public: int rollno; char sname[20]; void getdata(); void display(); }; void student::getdata() { cout<<"Enter the roll number"<<endl; cin>>rollno; cout<<"Enter the name"<<endl; cin>>sname; } void student::display() { cout<<"RollNo:"<<rollno<<endl; cout<<"Name:"<<sname<<endl; } const int size=3; void main() { clrscr(); student s[size]; for(int i=0;i<size;i++) { cout<<"\nDetails of student"<<i+1<<"\n"; s[i].getdata(); } cout<<"\n"; for(i=0;i<size;i++) {

Date: Semester: III

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154
cout<<"Details of student"<<i+1<<"\n"; s[i].display(); } getch(); } OUTPUT-

Date: Semester: III

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154 Date: Semester: III

/*Write a program in c++ for the use of Friend function*/ #include<iostream.h> #include<conio.h> class sample { int a; int b; public: void setvalue() {a=25;b=40;} friend float mean(sample s); }; float mean(sample s) { return float(s.a+s.b)/2; } int main() { sample x; clrscr(); x.setvalue(); cout<<"mean value:"<<mean(x); getch(); return 0; } OUTPUT-

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154
/*Write a program in c++ for function overloading*/ #include<iostream.h> #include<conio.h> #include<iomanip.h> class sample { public: int volume(int); double volume(double,int); long volume(long,int,int); }; int sample::volume(int s)//cube { return(s*s*s); } double sample::volume(double r,int h)//cylinder { return(3.14*r*r*h); } long sample::volume(long l,int b,int h)//rectangle { return(l*b*h); } void main() { clrscr(); sample s; cout<<Volume of cube=<<s.volume(10)<<"\n"; cout<<Volume of cylinder is=<<s.volume(2.5,8)<<"\n"; cout<<Volume of rectangle is=<<s.volume(100,75,15)<"\n"; getch(); } OUTPUT-

Date: Semester: III

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154 Date: Semester: III

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154 Date: Semester: III

/*Write a program in c++ to illustrate use of objects as arguments*/ #include<iostream.h> #include<conio.h> #include<iomanip.h> class time { public: int hours,mins; void gettime(int h,int m) { hours=h; mins=m; } void puttime() { cout<<hours<<" hours and"; cout<<mins<<" minutes"<<"\n"; } void sum(time,time); }; void time::sum(time t1,time t2)//cube { mins=t1.mins+t2.mins; hours=mins/60; mins=mins%60; hours=hours+t1.hours+t2.hours; } void main() { clrscr(); time t1,t2,t; t1.gettime(2,45); t2.gettime(3,30); t.sum(t1,t2); cout<<"T1=";t1.puttime(); cout<<"T2=";t2.puttime(); cout<<"T=";t.puttime(); getch(); }

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154 Date: Semester: III

OUTPUT-

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154 Date: Semester: III

/*Write a program in c++ to illustrate how an object returned to another function*/ #include<iostream.h> #include<conio.h> class complex { float x; float y; public: void getdata(float real,float imag) {x=real;y=imag; } complex sum(complex,complex); void display(complex); }; complex complex::sum(complex c1,complex c2) { complex c3; c3.x=c1.x+c2.x; c3.y=c1.y+c2.y; return(c3); } void complex::display(complex c) { cout<<c.x<<"+i"<<c.y<<"\n"; } void main() { complex c1,c2,c3; c1.complex(2.7,3.5); c2.complex(2.1,1.2); c3=c3.sum(c1,c2); clrscr(); cout<<"c1:";c1.display(c1); cout<<"c2:";c2.display(c2); cout<<"c3:";c3.display(c3); getch(); }

Jawahar education societys

A.C.PATIL COLLEGE OF ENGINEERING, MANAGEMENT STUDIES & RESEARCH KHARGHAR Master In Computer Application Department
Subject Practical: Computer Graphics Name: Om B. Thacker Roll No:10154
OUTPUT-

Date: Semester: III