Comsats University of Science and Technology Islamabad


                              LAB WORK 4

Name:
           Muhammad Tahir
Roll No:
           Sp11-Bcs-107
Subject:
           Object Oriented Programming (Oop)
Section:
           3A
Submitted To:
           Mam NusratShaheen


                                                          Date:27/03/2012
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;

                }
};

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()
{

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;
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)

           {
}

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();
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;

           }
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;

}
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{
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();}

Oop lab report

  • 1.
    Comsats University ofScience and Technology Islamabad LAB WORK 4 Name: Muhammad Tahir Roll No: Sp11-Bcs-107 Subject: Object Oriented Programming (Oop) Section: 3A Submitted To: Mam NusratShaheen Date:27/03/2012
  • 2.
    Program No:01 #include<iostream> #include<conio.h> using namespacestd; 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(); return0; } 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<<"Entertitle"<<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: intcount; 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 voidroll(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();}