Question 1.
#include <iostream>
using namespace std;
class course
{
protected:
int course_code;
string course_name;
course(int cc, string cn)
{
course_code = cc;
course_name = cn;
}
void displayCourseInfo()
{
cout<<"Course code: "<<course_code<<endl;
cout<<"Course name: "<<course_name<<endl;
}
};
class studentCourse:public course
{
public:
int id;
string grade;
studentCourse(int cc, string cn, int ID, string Grade):course(cc, cn)
{
id = ID;
grade = Grade;
}
void displayStudentInfo()
{
displayCourseInfo();
cout<<"ID: "<<id<<endl;
cout<<"Grade: "<<grade<<endl;
}
};
int main()
{
studentCourse s1(202,"OOP II", 20021212, "A");
s1.displayStudentInfo();
cout<<endl;
studentCourse s2(201, "Software Design", 210209327, "A");
s2.displayStudentInfo();
return 0;
}
//OUTPUT:
Course code: 202
Course name: OOP II
ID: 20021212
Grade: A
Course code: 201
Course name: Software Design
ID: 210209327
Grade: A
Question 2.
#include <iostream>
#include <string>
using namespace std;
class Vehicle
{
public:
int max_speed;
int num_wheels;
Vehicle(int speed, int wheels)
{
max_speed = speed;
num_wheels = wheels;
}
void vehicle_info()
{
cout<<"Vehicle Max Speed: "<<max_speed<<endl;
cout<<"Vehicle Wheels: "<<num_wheels<<endl;
}
};
class Car:public Vehicle
{
public:
string car_name;
string car_model;
Car(int speed, int wheels, string cname, string cmodel): Vehicle(speed, wheels)
{
car_name = cname;
car_model = cmodel;
}
void car_info()
{
vehicle_info();
cout<<"Car Name: "<<car_name<<endl;
cout<<"Car Model: "<<car_model<<endl;
}
};
class Motorcycle:public Vehicle
{
public:
string mcar_name;
string mcar_model;
Motorcycle(int speed, int wheels, string mcname, string mcmodel): Vehicle(speed, wheels)
{
mcar_name = mcname;
mcar_model = mcmodel;
}
void Motorcycle_info()
{
vehicle_info();
cout<<"Motorcycle Name: "<<mcar_name<<endl;
cout<<"Motorcycle Model: "<<mcar_model<<endl;
}
};
class ConvertibleCar: public Car, public Motorcycle
{
public:
ConvertibleCar(int speed, int wheels, string cname, string cmodel, string mcname, string mcmodel):
Car(speed, wheels, cname, cmodel), Motorcycle(speed, wheels, mcname, mcmodel)
{}
void ConvertibleCar_info()
{
car_info();
cout<<endl;
Motorcycle_info();
}
};
int main()
{
Car car(200, 4, "Honda", "Sedan");
Motorcycle bike(180, 2, "Vespa", "Sport");
ConvertibleCar convertible(220, 4, "Convertible Car", "Sport Car", "Convertible Motocycle", "Vespa");
cout << "Car Information:" << endl;
car.car_info();
cout << endl;
cout << "Motorcycle Information:" << endl;
bike.Motorcycle_info();
cout << endl;
cout << "Convertible Car Information:" << endl;
convertible.ConvertibleCar_info();
return 0;
}
//OUTPUT:
Car Information:
Vehicle Max Speed: 200
Vehicle Wheels: 4
Car Name: Honda
Car Model: Sedan
Motorcycle Information:
Vehicle Max Speed: 180
Vehicle Wheels: 2
Motorcycle Name: Vespa
Motorcycle Model: Sport
Convertible Car Information:
Vehicle Max Speed: 220
Vehicle Wheels: 4
Car Name: Convertible Car
Car Model: Sport Car
Vehicle Max Speed: 220
Vehicle Wheels: 4
Motorcycle Name: Convertible Motocycle
Motorcycle Model: Vespa