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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education