CS304 assignment No 3
Dear Students, Here You can read and download CS304 - Object Oriented Programming assignment No 3 Solution Spring 2017. Assignment due date is July 19, 2017. Lectures Covered in this assignment are Lecture No 29 to 31. CS304 Assignment Total Marks are 20.![]() |
CS304 assignment No 3 Solution Spring 2017 |
CS304 assignment Objective
The objective of the assignment is to give you the idea of practical implementation of Polymorphism.CS304 assignment Instructions:
It should be clear that your assignment will not get any credit if:
- The assignment is submitted after the due date.
- The assignment is submitted via email.
- The assignment is copied from the internet or from any other student.
- The submitted assignment does not open or file is corrupt.
- It is in some format other than .cpp.
For any query about the assignment, contact at CS304@vu.edu.pk
Problem Statement:
In continuation of Assignment No. 1 and 2, we have the following part of class diagram:Car, SUV and HDV are concrete classes as opposed to Vehicle with a pure virtual function.
In the main function, create one object each of Car, SUV and HDV and call their respective showGears() function thus implementing the concept of polymorphism.
Following is the sample output that you need to print:
CS304 assignment No 3 Solution
![]() |
CS304 assignment No 3 Solution idea |
Assignment Solution
#include<iostream>using namespace std;
class vihicle{
protected:
string model,color, noofgear;
public:
void getmodel(string mod)
{
model = mod;
}
void getcolor(string c)
{
color = c;
}
void getnoofgear(string gear){
noofgear = gear;
}
virtual void showgear() = 0; //Pure virtual function.....
};
class car : public vihicle{
public:
void showgear()
{
getmodel("Corolla");
getcolor("White");
getnoofgear("4-6");
cout<<"Model of Vihicle: "<<model<<endl;
cout<<"Color of Vihicle: "<<color<<endl;
cout<<"There are "<<noofgear<<" Gears in a car"<<endl;
}
};
class SUV : public vihicle{
public:
void showgear()
{
getmodel("CRU");
getcolor("Green");
getnoofgear("6-8");
cout<<"Model of Vihicle: "<<model<<endl;
cout<<"Color of Vihicle: "<<color<<endl;
cout<<"There are "<<noofgear<<" Gears in a SUV"<<endl;
}
};
class HDV : public vihicle{
public:
void showgear()
{
getmodel("Truck");
getcolor("Red");
getnoofgear("8-16");
cout<<"Model of Vihicle: "<<model<<endl;
cout<<"Color of Vihicle: "<<color<<endl;
cout<<"There are "<<noofgear<<" Gears in a HDV"<<endl;
}
};
main()
{
car car;
car.showgear();
cout<<endl;
SUV suv;
suv.showgear();
cout<<endl;
HDV hdv;
hdv.showgear();
system("pause");
}
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.