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 |
Recommended : All Subjects Final term Papers solved by Moaaz
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");
}
You Can Also Download Solved Final Term Papers, Short Notes, Assignment Solutions, Lecture Wise Questions Answers Files, Solved MCQs, Solved Quiz , Solved Final Term Subjective Papers , Solved Final Term Objective Papers from Virtual Study Solutions For Preparation of Final Term Papers.
For any query about the assignment, contact at CS304@vu.edu.pk
CS304 assignment Objective
The objective of the assignment is to give you the idea of practical implementation of Polymorphism.CS304 assignment Instructions:
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:
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
Recommended : Student Management System Project in C++
Car, SUV and HDV are concrete classes as opposed to Vehicle with a pure virtual function.
You are required to implement polymorphism in the above scenario by writing a complete C++ program with the mentioned data members and member functions.
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:
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.
You are required to implement polymorphism in the above scenario by writing a complete C++ program with the mentioned data members and member functions.
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:
---Sample Output---Good Luck.
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");
}
CS304 Previous Assignments:
Please subscribe us below or like us on Facebook. Thank you.
Post a Comment