You are on page 1of 15

ASSIGNMENT # 1

OBJECT ORIENTED PROGRAMMIG

SUBMITTED BY: Dr. AYESHA SULMAN

SUBMITTED TO: M. UZAIR ASHRAF


(191953)
PROBLEM :
We want to store the information of different vehicles. Create a class named
Vehicle with two data member named mileage and price. Create its two subclasses:
*Car with data members to store ownership cost, warranty (by years), seating
capacity and fuel type (diesel or petrol). *Bike with data members to store the
number of cylinders, number of gears, cooling type(air, liquid or oil), wheel
type(alloys or spokes) and fuel tank size(in inches) Make another two subclasses
Corolla and Honda of Car, each having a data member to store the model type.
Next, make two subclasses Yamaha and TVS, each having a data member to
store the make-type. Now, store and print the information of a Corolla and a Honda
car (i.e. model type, ownershipcost, warranty, seating capacity, fuel type, mileage
and price.) Do the same for a Yamaha and a TVS bike.

SOURCE CODE :
#include <iostream>
#include <string.h>
using namespace std;

class vehicle{
protected:
double mileage, price;
public:
vehicle(){
cout << "CLASS :: vehicle ( defualt constructor )" << endl;
}
double Miles(int a);
double VehiclePrice(int b);
};

class car: public vehicle{


protected:
double OwnershipCost;
int warranty, seatingCapacity;
public:
string fuel;
car(){
cout << "CLASS :: car ( defualt constructor )" << endl;
}
double Miles(int a){
mileage = a;
return mileage;
}

double VehiclePrice(int b){


price = b;
return price;
}
int Cost_of_Ownership(int c){
OwnershipCost = c;
return OwnershipCost;
}
int Car_warranty(int d){
warranty = d;
return warranty;
}

int total_seats(int e){


seatingCapacity = e;
return seatingCapacity;
}

string FuelType(){
string f;
cout << "Fuel type (petrol, diesel): ";
cin >> f;
fuel = f;
return fuel;
}
void car_info();

};

class bike: public vehicle{


protected:
int cylinders, gears;
int fuelTank_size;
public:
string coolingType;
string wheelType;

bike(){
cout << "CLASS :: bike ( defualt constructor )" << endl;
}

double Miles(int a){


mileage = a;
return mileage;
}

double VehiclePrice(int b){


price = b;
return price;
}
int totalCylinders(int i){
cylinders = i;
return cylinders;
}

int totalgear(int j){


gears = j;
return gears;
}

int fuelTankSize(int l){


fuelTank_size = l;
return fuelTank_size;
}

string Cooling_Type(){
string ct;
cout << "Cooling Type (air, liquid, oil) : ";
cin >> ct;
coolingType = ct;
return coolingType;
}

string Wheel_Type(){
string wt;
cout << "Wheel type (Alloy, Spokes) : ";
cin >> wt;
wheelType = wt;
return wheelType;
}
void bike_info();

};
class Honda: public car{
public:
int model;
Honda(){
cout << "CLASS :: Honda ( defualt constructor )" << endl;
}

int setmodel(int z){


model = z;
return model;
}
void car_info(){
cout << "\n\nHonda Car Information\n";
cout << "Price : Rs." << price << endl;
cout << "Mileage : " << mileage <<" km "<< endl;
cout << "Ownership cost : " << OwnershipCost << endl;
cout << "Warranty : " << warranty << " years"<< endl;
cout << "Seats : " << seatingCapacity << endl;
cout << "Fuel type (petrol, diesel) : " << fuel << endl;
cout << "Model : " <<model;
cout << "\n\n";
}
};
class corolla: public car{
public:
int model;
corolla(){
cout << "CLASS :: corolla ( defualt constructor )" << endl;
}

int setmodel(int z){


model = z;
return model;
}
void car_info(){
cout << "\n\nCorolla Car Information\n";
cout << "Price : Rs. " << price << endl;
cout << "Mileage : " << mileage <<" km "<< endl;
cout << "Ownership cost : " << OwnershipCost << endl;
cout << "Warranty : " << warranty << " years"<< endl;
cout << "Seats : " << seatingCapacity << endl;
cout << "Fuel type (petrol, diesel) : " << fuel << endl;
cout << "Model : " <<model;
cout << "\n\n";
}
};

class Yamaha: public bike{


public:
string makeType;
Yamaha(){
cout << "CLASS :: Yamaha ( defualt constructor )" << endl;
}

string setmakeType(){
string g;
cout << "Make type of a bike : ";
cin >> g;
makeType = g;
return makeType;
}

void bike_info(){
cout <<"\n\nYamaha Bike Information\n";
cout << "Price : Rs. " << price << endl;
cout << "Mileage : " << mileage <<" km "<< endl;
cout << "Cylinders : " << cylinders <<endl;
cout << "Gears : " << gears << endl;
cout << "Fuel tank size : " << fuelTank_size << endl;
cout << "Cooling Type (air, liquid, oil) : " << coolingType <<endl;
cout << "Wheel type (Alloy, Spokes) : " << wheelType << endl;
cout << "Make type : " << makeType;
cout << "\n\n";
}
};

class TVS: public bike{


public:
string makeType;
TVS(){
cout << "CLASS :: TVS ( defualt constructor )" << endl;
}

string setmakeType(){
string g;
cout << "Make type of a bike : ";
cin >> g;
makeType = g;
return makeType;
}

void bike_info(){
cout <<"\n\nTVS Bike Information\n";
cout << "Price : Rs. " << price << endl;
cout << "Mileage : " << mileage <<" km "<< endl;
cout << "Cylinders : " << cylinders <<endl;
cout << "Gears : " << gears << endl;
cout << "Fuel tank size : " << fuelTank_size << endl;
cout << "Cooling Type (air, liquid, oil) : " << coolingType <<endl;
cout << "Wheel type (Alloy, Spokes) : " << wheelType << endl;
cout << "Make type : " << makeType;
cout << "\n\n";
}
};
int main(){
int x;
int y;
do{
cout << "Select option for information"<<endl;
cout << "1. HONDA \n";
cout << "2. COROLLA\n";
cout << "3. YAMAHA\n";
cout << "4. TVS Bike\n";
cout << "5. EXIt\n";
cout << "\n SELECT FROM 1 - 5 :: ";
cin >>x;
switch(x){
case 1:{
Honda h;
h.VehiclePrice(150000);
h.Miles(25000);
h.Cost_of_Ownership(60000);
h.Car_warranty(3);
h.total_seats(5);
h.FuelType();
h.setmodel(19);
h.car_info();
break;
}
case 2:{
corolla c;
c.VehiclePrice(140000);
c.Miles(25000);
c.Cost_of_Ownership(450000);
c.Car_warranty(5);
c.total_seats(5);
c.FuelType();
c.setmodel(19);
c.car_info();
break;
}
case 3:{
Yamaha y;
y.VehiclePrice(90000);
y.Miles(1600);
y.fuelTankSize(12);
y.Cooling_Type();
y.totalCylinders(2);
y.Wheel_Type();
y.totalgear(5);
y.setmakeType();
y.bike_info();
break;
}
case 4:{
TVS a;
a.VehiclePrice(70000);
a.Miles(30000);
a.fuelTankSize(14);
a.Cooling_Type();
a.totalCylinders(3);
a.Wheel_Type();
a.totalgear(5);
a.setmakeType();
a.bike_info();
break;
}

}while(x<=4);
return 0;

OUTPUT :

You might also like