Q2: Continue of previous question 1. Copy the previous program to a new file. 2. Create a class named Car derived from Vehicle. a. Private data member: weight — dynamic member int b. Implement default and two argument constructors c. Redefine output function d. Mutator and accessor function for weight 3. Create a class named Boat derived from Vehicle. a. Private data member: hullLength — dynamic member int b. Implement default and two argument constructors c. Redefine output function d. Mutator and accessor function for hullLength

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter11: Introduction To Classes
Section11.2: Basic Class Functions
Problem 5E
icon
Related questions
Question
100%

Hello, I need help with this C++ homework question

 

Q2: Continue of previous question

1. Copy the previous program to a new file.

2. Create a class named Car derived from Vehicle.

a. Private data member: weight — dynamic member int

b. Implement default and two argument constructors

c. Redefine output function d. Mutator and accessor function for weight

3. Create a class named Boat derived from Vehicle.

a. Private data member: hullLength — dynamic member int

b. Implement default and two argument constructors

c. Redefine output function

d. Mutator and accessor function for hullLength

 

Use following main() to test your function (DO NOT CHANGE THE INT MAIN. Any alteration will not be accepted)

int main(){

Car a,b("Honda",2000);

a.output(); // Brand:TBD Weight: 0

b.output(); // Brand:Honda Weight: 2000 b.setBrand("Tesla");

b.setWeight(3000);

b.output(); // Brand:Tesla Weight: 3000

Boat c,d("Baja",100);

c.output(); // Brand:TBD hullLength: 0

d.output(); // Brand:Baja hullLength: 100 d.setBrand("Bertram");

d.sethullLength(60);

d.output(); // Brand:Bertram hullLength: 60

}

Output from main:

Brand:TBD Weight: 0

Brand:Honda Weight: 2000

Brand:Tesla Weight: 3000

Brand:TBD hullLength: 0

Brand:Baja hullLength: 100

Brand:Bertram hullLength: 60

This is the code have from what is being asked

 

#include<iostream>
#include<string>
using namespace std;
class Vehicle{
private:
string *brand; //declaring dynamic variable
public:
Vehicle(){brand=new string;*brand="TBD";}
Vehicle(string b){brand=new string;*brand=b;}
void output(){cout<<"Brand: "<<*brand << "\n";}
void setBrand(string b){*brand=b;}
string getBrand(){return *brand;}
};
int main(){
Car a,b("Honda",2000);
a.output(); // Brand:TBD Weight: 0
b.output(); // Brand:Honda Weight: 2000
b.setBrand("Tesla");
b.setWeight(3000);
b.output(); // Brand:Tesla Weight: 3000
Boat c,d("Baja",100);
c.output(); // Brand:TBD hullLength: 0
d.output(); // Brand:Baja hullLength: 100
d.setBrand("Bertram");
d.sethullLength(60);
d.output(); // Brand:Bertram hullLength: 60
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr