In: Computer Science
Task 1. Create class "Vehicle" with variables "company" and "year". LM 2. Create 3 derived classes: "Bus", "Car", and "Motorcycle". They should contain a variable storing number of seats (bus) / weight (car) / number of tires (motorcycle), constructor, destructor and a print_info function that will print all the information about the vehicle. PK 3. The constructors should take as parameters: company, year and number of seats / weight / number of tires. Inside it assign the company name and create an if / else condition that will throw an invalid_argument () exception with message "bus / car / motorcycle not produced yet" if the year is bigger than 2020, or assign the proper value. Additionally: a) for class "Bus": create if / else condition that throws an out of_range () exception with message "invalid number of seats" if that value is smaller than 8 and bigger than 70, or assign the proper value b) for class "Car": create if / else condition that throws an exception with message "car is too heavy" if that value is bigger than 3500, or assign the proper value c) for class "Motorcycle": create if / else condition that throws an exception with message "vehicle is not a motorcycle" if that value is different than 2, or assign the proper value
#include<iostream>
#include<string>
using namespace std;
class Vehicle
{
public:
int year;
string company;
Vechile(int year,string company)
{
if (year<=2020)
{
this.company=company;
this.year=year;}
else{
throw "bus / car / motorcycle not produced yet";}
}
}
class Bus:public Vehicle{
public:
void print_info(){
cout<<company;
cout<<year;
cout<<numberofseats;
}
int numberofseats;
Bus(int seats)
{
cin>>seats;
if(seats>=8 && seats<=70)
{this.numberofseats=seats;}
else
{
throw "invalid number of seats";
}
}
~Bus();
}
class Car:public Vehicle{
int weight;
public:
Car(int w){
if(w<=3500)
{
this.weight=w;
}
else{
throw "car is too heavy";
}
}
~Car();
void print_info(){
cout<<company;
cout<<year;
cout<<weight;
}
}
class Motorcycle:public Vehicle{
public:
int numberoftires;
Motorcycle(int t)
{
if(t==2)
{
this.numberoftires=t;
}
else
{
throw "vehicle is not a motorcycle";
}
}
~Motorcycle();
void print_info(){
cout<<company;
cout<<year;
cout<<numberoftires;
}
}