0% found this document useful (0 votes)
26 views8 pages

Abdullah

The document provides instructions for 4 programming tasks to practice object-oriented concepts in C++, including creating classes for vehicles, circles, books, and students that make use of methods, constructors, and manipulating object properties. Multiple objects are created for each class and data is stored, retrieved, and output for each task to demonstrate working with objects and classes.

Uploaded by

Saqib Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Abdullah

The document provides instructions for 4 programming tasks to practice object-oriented concepts in C++, including creating classes for vehicles, circles, books, and students that make use of methods, constructors, and manipulating object properties. Multiple objects are created for each class and data is stored, retrieved, and output for each task to demonstrate working with objects and classes.

Uploaded by

Saqib Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Object Oriented Programming Lab

Task No: 1
Create class car whose data members are brand, model and year. Do this task by
creating multiple objects by storing values in them.
#include<iostream>
using namespace std;
class car
{
public:
string brand;
string model;
int year;
};
int main()
{
car carobj1;
carobj1.brand="BMW";
carobj1.model="X5";
carobj1.year=2000;

car carobj2;
carobj2.brand="HONDA";
carobj2.model="X6";
carobj2.year=1998;

car carobj3;
carobj3.brand="CIVIC";
carobj3.model="X7";
carobj3.year=1995;
cout<<carobj1.brand<<endl;
cout<<carobj1.model<<endl;
cout<<carobj1.year<<endl;
cout<<carobj2.brand<<endl;
cout<<carobj2.model<<endl;
cout<<carobj2.year<<endl;
cout<<carobj3.brand<<endl;
cout<<carobj3.model<<endl;
cout<<carobj3.year<<endl;
return 0;
}

Output:

Task No: 2
Create class circle having compute area as member function.
#include<iostream>
using namespace std;
class circle
{
private:
double radius;
public:
int r;
void compute_area()
{
radius=r;
cout<<"enter radius"<<endl;
cin>>radius;
double area=3.14*radius*radius;
cout<<"radius is:"<<radius<<endl;
cout<<"area is:"<<area;
}
};
int main()
{
circle obj;
obj.compute_area();
return 0;
}

Output:
Task No 3:
Write program having get and show functions print atleast 5 information related to
books using copy constructor.
#include<iostream>
using namespace std;
class book
{
public:
string title;
int pagenumber;
int price;
string authorname;
int edition;
int get()
{
cout<<"enter title"<<endl;
cin>>title;
cout<<"enter pagenumber"<<endl;
cin>>pagenumber;
cout<<"enter price"<<endl;
cin>>price;
cout<<"authorname"<<endl;
cin>>authorname;
cout<<"edition"<<endl;
cin>>edition;
}
int show()
{
cout<<title<<endl;
cout<<pagenumber<<endl;
cout<<price<<endl;
cout<<authorname<<endl;
cout<<edition<<endl;
}
};
int main()
{
book b1;
book b2=b1;
cout<<"data of b1"<<endl;
b1.get();
cout<<"data of b2"<<endl;
b2.get();
cout<<"data of b1"<<endl;
b1.show();
cout<<"data of b2"<<endl;
b2.show();
return 0;
}
Output:

Task No: 4
Write your name, roll number, department and other information by using default
constructor in program.

#include<iostream>
using namespace std;
class student
{
public:
string name;
float rollnumber;
string department;
string section;
string batch;
string address;
};
int main()
{
student s;
cout<<"**************ENTER
INFORMATION***********"<<endl;
cout<<"enter name"<<endl;
cin>>s.name;
cout<<"enter rollnumber"<<endl;
cin>>s.rollnumber;
cout<<"enter department"<<endl;
cin>>s.department;
cout<<"enter section"<<endl;
cin>>s.section;
cout<<"batch"<<endl;
cin>>s.batch;
cout<<"address"<<endl;
cin>>s.address;
cout<<"*************DISPLAYING
INFORMATION************"<<endl;
cout<<"name:"<<s.name<<endl;
cout<<"rollnumber:"<<s.rollnumber<<endl;
cout<<"department:"<<s.department<<endl;
cout<<"section:"<<s.section<<endl;
cout<<"batch:"<<s.batch<<endl;
cout<<"address:"<<s.address<<endl;
return 0;
}
Output:

You might also like