Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 - Objective Enhance the understanding of classes, inheritance, and operator ov

ID: 3726529 • Letter: 1

Question

1 - Objective Enhance the understanding of classes, inheritance, and operator overloading. 2 Problem Using the given class header file (vehicles.h), you will need to implement vehicles.cpp. Do not make any changes to vehicles.h. From the vehicles class you will need to make two child classes, watercraft and automobile. These should also be implemented using separate header and cpp files (e.g., watercraft.h watercraft.cpp, automobile.h, automobile.cpp) Your watercraft class must have the following: Two additional attributes, hull and manufacture, in the private section. They should be of type string -A default constructor that takes no arguments and sets the attributes to: engine to "Minn Kota Max 70" · weight to 1860 -hull to "V- Hull" -scats to 12 manufacture to "Sea Ark Boats" -Member functions to access and modify these attributes (i.e., seats, engine, hull, etc. must all be able to be changed by calling a member function) -Print to file should take a string as an argument and be a member function. This should be the name of the file to be printed to, your default output file should be out.txt A static int counter that will be used to count how many watercraft objects were created. An operator overloaded function that is a that will allow you to copy the information from one watercraft object to another. member function of the class for the "#" sign - Your automobile class must have the following: Two additional attributes of type string, make and model, and one additional attribute of type int: wheels. All of them should be defined in the private section. -

Explanation / Answer

here is your files : ---------->>>>>>>.

main.cpp : ------------->>>>>>>>>>>

#include "watercraft.cpp"
#include "automobile.cpp"

int main(){
watercraft boat1,boat2,boat3;
automobile car1,car2,car4;
string make = "Mahindra";
string model = "SUV";
automobile car3(make,model,4);
string engine = "Yamaha 115 HP";
string hull = "FiberGlass";
boat2.setEngine(engine);
boat2.setWeight(5200);
boat2.setHull(hull);
boat2.setSeats(10);
boat3 = boat2;
car4 = car3;
boat1.print_to_file();
boat2.print_to_file();
boat3.print_to_file();
car1.print_to_file();
car2.print_to_file();
car3.print_to_file();
car4.print_to_file();
}

vehicles.cpp : --------->>>>>>>

#include "vehicles.h"

vehicles::vehicles(){
engine = "";
seats = 0;
weight = 0;
vehicles::count++;
}

watercraft.h : -------------->>>>>>>

#ifndef GA2_WATERCRAFT_H
#define GA2_WATERCRAFT_H
#ifndef S2_VEH
#define S2_VEH
#include "vehicles.cpp"
#endif

class watercraft:public vehicles{
private:
  string hull;
  string manufacture;
public:
  static int counter;
  watercraft();
  void setEngine(string);
  void setWeight(int);
  void setSeats(int);
  void setHull(string);
  void setManufacture(string);
  void print_to_file(string file = "out.txt");
  string getEngine()const;
  int getWeight()const;
  int getSeats()const;
  string getHull()const;
  string getManufacture()const;
  watercraft& operator=(const watercraft&);
};

int watercraft::counter = 0;

#endif

automobile.h : ----------->>>>>>>

#ifndef GA2_AUTOMOBILE_H
#define GA2_AUTOMOBILE_H
#ifndef S2_VEH
#define S2_VEH
#include "vehicles.cpp"
#endif

class automobile:public vehicles{
private:
  string make;
  string model;
  int wheels;
public:
  static int counter;
  automobile();
  automobile(string,string,int);
  void print_to_file(string file = "out.txt");
  automobile& operator=(const automobile&);
  void setMake(string);
  void setModel(string);
  void setWheels(int);
  void setEngine(string);
  void setWeight(int);
  void setSeats(int);
  string getEngine()const;
  int getWeight()const;
  int getSeats()const;
  int getWheels()const;
  string getMake()const;
  string getModel()const;
};

int automobile::counter = 0;

#endif

watercraft.cpp : ----------->>>>>>>

#include "watercraft.h"
#include<fstream>
#include<iostream>

string watercraft::getEngine()const{
return engine;
}
string watercraft::getHull()const{
return hull;
}
string watercraft::getManufacture()const{
return manufacture;
}
int watercraft::getSeats()const{
return seats;
}
int watercraft::getWeight()const{
return weight;
}
void watercraft::setEngine(string en){
engine = en;
}
void watercraft::setHull(string h){
hull = h;
}
void watercraft::setManufacture(string mn){
manufacture = mn;
}
void watercraft::setSeats(int s){
seats = s;
}
void watercraft::setWeight(int w){
weight = w;
}
watercraft::watercraft(){
engine = "Minn Kota Max 70";
weight = 1860;
hull = "V-Hull";
seats = 12;
manufacture = "Sea Ark Boats";
}

watercraft& watercraft::operator=(const watercraft &other){
engine = other.engine;
weight = other.weight;
hull = other.hull;
manufacture = other.manufacture;
seats = other.seats;

return *this;
}

void watercraft::print_to_file(string file){
ofstream ofs;
ofs.open(file.c_str(),ios::app);
if(ofs.is_open()){
  ofs<<" Watercraft:";
  ofs<<" Engine : "<<engine;
  ofs<<" Weight : "<<weight;
  ofs<<" Seats : "<<seats;
  ofs<<" Hull : "<<hull;
  ofs<<" Manufacture : "<<manufacture;
  ofs.close();
}else{
  cout<<" File opening error";
}
}

automobile.cpp : ------------->>>>>>>>.

#include "automobile.h"
#include<fstream>
#include<iostream>


automobile::automobile(string ma,string mo,int wh):vehicles(){
make = ma;
model = mo;
wheels = wh;
}
string automobile::getEngine()const{
return engine;
}
int automobile::getWheels()const{
return wheels;
}
string automobile::getMake()const{
return make;
}
string automobile::getModel()const{
return model;
}
int automobile::getSeats()const{
return seats;
}
int automobile::getWeight()const{
return weight;
}
void automobile::setWheels(int w){
wheels = w;
}
void automobile::setEngine(string en){
engine = en;
}
void automobile::setMake(string m){
make = m;
}
void automobile::setModel(string mn){
model = mn;
}
void automobile::setSeats(int s){
seats = s;
}
void automobile::setWeight(int w){
weight = w;
}
automobile::automobile(){
engine = "V6";
weight = 4079;
make = "Toytoa";
seats = 12;
wheels = 4;
model = "Salara";
}

automobile& automobile::operator=(const automobile &other){
engine = other.engine;
weight = other.weight;
make = other.make;
model = other.model;
wheels = other.wheels;
seats = other.seats;

return *this;
}

void automobile::print_to_file(string file){
ofstream ofs;
ofs.open(file.c_str(),ios::app);
if(ofs.is_open()){
  ofs<<" Automobile:";
  ofs<<" Engine : "<<engine;
  ofs<<" Wheels : "<<wheels;
  ofs<<" Weight : "<<weight;
  ofs<<" Seats : "<<seats;
  ofs<<" Make : "<<make;
  ofs<<" Model : "<<model;
  ofs.close();
}else{
  cout<<" File opening error";
}
}

out.txt : ----------->>>>>>>>>


Watercraft:
Engine : Minn Kota Max 70
Weight : 1860
Seats : 12
Hull : V-Hull
Manufacture : Sea Ark Boats
Watercraft:
Engine : Yamaha 115 HP
Weight : 5200
Seats : 10
Hull : FiberGlass
Manufacture : Sea Ark Boats
Watercraft:
Engine : Yamaha 115 HP
Weight : 5200
Seats : 10
Hull : FiberGlass
Manufacture : Sea Ark Boats
Automobile:
Engine : V6
Wheels : 4
Weight : 4079
Seats : 12
Make : Toytoa
Model : Salara
Automobile:
Engine : V6
Wheels : 4
Weight : 4079
Seats : 12
Make : Toytoa
Model : Salara
Automobile:
Engine :
Wheels : 4
Weight : 0
Seats : 0
Make : Mahindra
Model : SUV
Automobile:
Engine :
Wheels : 4
Weight : 0
Seats : 0
Make : Mahindra
Model : SUV