Question

In: Computer Science

Task 1. Create class "Vehicle" with variables "company" and "year". LM 2. Create 3 derived classes:...

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

Solutions

Expert Solution

#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;

}

}


Related Solutions

C++ Code Vehicle Class The vehicle class is the parent class of a derived class: locomotive....
C++ Code Vehicle Class The vehicle class is the parent class of a derived class: locomotive. Their inheritance will be public inheritance so reflect that appropriately in their .h files. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +setName(s:string):void +getName():string +getMap():char** +getSize():int +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator−−():void +determineRouteStatistics()=0:void The class variables are as follows: • map: A 2D array of chars, it will represent the...
C++ Code Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive....
C++ Code Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive. Their inheritance will be public inheritance so reect that appropriately in their .h les. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +getSize():int +setName(s:string):void +getName():string +getMap():char** +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of chars, it will represent the map...
Create 2 derived classes from Clothing class: Pants class Write only necessary constructors Override the wash()...
Create 2 derived classes from Clothing class: Pants class Write only necessary constructors Override the wash() method to indicate that pants are dry clean only. Include additional method hang() Add to your driver/tester file to make and print new pants objects and test it. Shirt class Include additional property of type string called sleeves. Write necessary constructors For sleeves only allow it to be set to {"short", "long", "none"} For size, only allow {"S","M","L"} Override the wash() method to indicate...
(JAVA) Create three classes, Vehicle, Truck, and Person. The Vehicle class has a make and model,...
(JAVA) Create three classes, Vehicle, Truck, and Person. The Vehicle class has a make and model, test emissions per mile, and a driver/owner (= Person object). (Each vehicle can only have one driver/owner.) The class Truck is a derived class from the Vehicle class and has additional properties load capacity in tons (type double since it can contain a fractional part) and a towing capacity in pounds (type int). Be sure that your classes have appropriate constructors, accessors, mutators, equals(),...
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class....
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class. The vehicle class should contain at least 2 variables that could pertain to ANY vehicle and two methods. The truck class should contain 2 variables that only apply to trucks and one method. Create a console program that will instantiate a truck with provided member information then call one method from the truck and one method contained from the inherited vehicle class. Have these...
JAVA A simple Class in a file called Account.java is given below. Create two Derived Classes...
JAVA A simple Class in a file called Account.java is given below. Create two Derived Classes Savings and Checking within their respective .java files. (modify display() as needed ) 1. Add New private String name (customer name) for both, add a New int taxID for Savings only. 2. Add equals() METHOD TO CHECK any 2 accounts Demonstrate with AccountDemo.java in which you do the following: 3. Create 1 Savings Account and 3 Checking Accounts, where 2 checkings are the same....
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
Base class: Polygon Derived classes: Rectangle, Triangle Make Square a derived class of Rectangle. There can...
Base class: Polygon Derived classes: Rectangle, Triangle Make Square a derived class of Rectangle. There can be several ways to represent the shapes. For example, a shape can be represented by an array of side lengths counted in the clock-wise order. For example, {2, 4, 2, 4} for a rectangle of width 2 and height 4, and {4, 4, 4, 4} for a square. You need to design your representation. Each polygon should have a function area() that returns its...
1. Implement the Vehicle class.  Add the following private instance variables to the Accoun class:...
1. Implement the Vehicle class.  Add the following private instance variables to the Accoun class: • An instance variable called wheelsCount of type int • An instance variable called vType of type String • An instance variable called isTruck of type boolean .  Add getters and setters for the three instance variables  Add the following methods to the Account class: • A void method called initialize that takes a parameter of type int, a String,and one double...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT