• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
989
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
45
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Comsats University of Science and Technology Islamabad LAB WORK 4Name: Muhammad TahirRoll No: Sp11-Bcs-107Subject: Object Oriented Programming (Oop)Section: 3ASubmitted To: Mam NusratShaheen Date:27/03/2012
  • 2. Program No:01#include<iostream>#include<conio.h>using namespace std;class book{private:int page;float price;string title;public:voidgetvalue() {cout<<"Enter pages"<<endl;cin>>page;cout<<"Enter price"<<endl;cin>>price;cout<<"Enter title"<<endl;cin>>title; }void display() {cout<<"Pages are= "<<page<<endl;cout<<"Price are="<<price<<endl;cout<<"Title is="<<title<<endl; }
  • 3. };main(){book b1,b2,b3;b1.getvalue();b2.getvalue();b3.getvalue();book b3=b1;b1.display();b2.display();b3.display();getch();return 0;} Program No: 02#include<iostream>#include<conio.h>using namespace std;class book{private:int page;float price;string title;public:voidgetvalue()
  • 4. {cout<<"Enter pages"<<endl;cin>>page;cout<<"Enter price"<<endl;cin>>price;cout<<"Enter title"<<endl;cin>>title; }voidsetvalue() { cout<<"Enter pages"<<endl;cin>>page;cout<<"Enter price"<<endl;cin>>price;cout<<"Enter title"<<endl;cin>>title; }void display() {cout<<"Pages are= "<<page<<endl;cout<<"Price are="<<price<<endl;cout<<"Title is="<<title<<endl; }};main(){book b1,b2,b3;
  • 5. b1.getvalue();b2.getvalue();b3.getvalue(); b3=b1;b1.display();b2.display();b3.display();b3.setvalue();b1.display();b2.display();b3.display();getch();return 0;} Program No: 03#include<iostream>#include<conio.h>using namespace std;class travel{private:float km;int h;public:travel():km(0),h(0) {
  • 6. }voidgetvalue() {cout<<"Enter kilometer"<<endl;cin>>km;cout<<"Enter hour"<<endl;cin>>h; }void show() {cout<<"Values are="<<km<<endl;cout<<"Values are="<<h<<ebdl; }void add(t1,t2) {float sum=0;sum=t1+t2;cout<<sum; }};main(){travel t1,t2,t3;t1.getvalue();t1.show();t2.getvalue();
  • 7. t2.show();t3.add(t1,t2);getch();return 0;} Program No: 04#include<iostream>#include<conio.h>using namespace std;class time{private:inthour,min,sec;public:time():km(0),h(0) { }voidgetvalue() {cout<<"Enter hours"<<endl;cin>>hour;cout<<"Enter minute"<<endl;cin>>min;cout<<"Enter second"<<endl;cin>>sec; }
  • 8. void show() {cout<<"Hours ="<<hour<<endl;cout<<"Minute ="<<min<<endl;cout<<"Second ="<<sec<<endl; }void add(hour,min,sec) {int sum=0;sum=hour+min+sec;cout<<"Addition of hours, minute and second is="<<sum; }};main(){travelh,m,s,su;h.getvalue();h.show();m.getvalue();m.show();s.getvalue();s.show();su.add(h,m,s);getch();return 0;}
  • 9. Program No: 05#include<iostream.h>#include<conio.h>classcountr{private:int count;public:countr(){count=0;}voidincr(){count++;}void display(){cout<<count;}};void main(){clrscr();countr c1;c1.incr();c1.display();c1.incr();c1.display();getch();} Program No: 06#include<iostream.h> #include<conio.h>class student{
  • 10. private:staticint a;public:static void roll(int);static void showroll();};int student::a=157;void student::roll(int roll){ a=roll;}void student::showroll(){cout<<"roll number is: "<<a<<"n";}void main(){clrscr(); student::roll(10); student::showroll(); student::roll(11); student::showroll(); student::roll(12); student::showroll();getch();}