C++ -------------------------------------------------- vehicles.h - ------------
ID: 3725707 • Letter: C
Question
C++
--------------------------------------------------
vehicles.h -
-------------------------------------------------
Output Examples -
COSC 1430 - Group Assignment 2 Classes, Inheritance, Operator Overloading TO BE TURNED IN ON BLACKBOARD - 1 submission per group 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 - -eneine to "Minn Kota Max 70" - eight to 1860 -hull to "V- Hull" - seats 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 member function of the class for the "-” sign that will allow you to copy the information from one watercraft object to another - 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 sectionExplanation / Answer
//vehicle.h
#pragma once
//vehicles.h -
#ifndef GA2_VEHICLES_H
#define GA2_VEHICLES_H
#include <string>
using namespace std;
class vehicles {
protected:
string engine;
int seats;
int weight;
public:
vehicles();
static int count;
};
#endif //GA2_VEHICLES_H
---------------------------------------
//vehicle.cpp
#include"vehicles.h"
int vehicles::count = 0;
vehicles::vehicles()
{
engine = "";
seats = 0;
weight =0;
count++;
}
-----------------------------------------------------------
//watercraft.h
#pragma once
#include"vehicles.h"
class Watercraft:public vehicles
{
string hull;
string manufacturer;
public:
Watercraft();
Watercraft& operator=(Watercraft &obj);
//mutator functions
void setEngine(string e);
void setSeats(int s);
void setWeight(int w);
void setHull(string h);
void setManufacturer(string m);
//accessor functions
string getEngine();
int getSeats();
int getWeight();
string getHull();
string getManufacturer();
static int count;
};
------------------------------------------------------
//watercraft.cpp
#include"Watercraft.h"
int Watercraft::count=0;
Watercraft::Watercraft()
{
hull = "V -Hull";
manufacturer = "Sea Ark Boats";
engine = "Minn Kota Max 70";
weight = 1860;
seats = 12;
count++;
}
//mutator functions
void Watercraft::setEngine(string e)
{
engine = e;
}
Watercraft& Watercraft::operator=(Watercraft &obj)
{
hull = obj.hull;
manufacturer = obj.manufacturer;
engine = obj.engine;
weight = obj.weight;
seats = obj.seats;
return *this;
}
void Watercraft::setSeats(int s)
{
seats = s;
}
void Watercraft::setWeight(int w)
{
weight = w;
}
void Watercraft::setHull(string h)
{
hull = h;
}
void Watercraft::setManufacturer(string m)
{
manufacturer = m;
}
//accessor functions
string Watercraft::getEngine()
{
return engine;
}
int Watercraft::getSeats()
{
return seats;
}
int Watercraft::getWeight()
{
return weight;
}
string Watercraft::getHull()
{
return hull;
}
string Watercraft::getManufacturer()
{
return manufacturer;
}
---------------------------------------------
//main.cpp
#include<iostream>
#include"Watercraft.h"
#include"automobile.h"
using namespace std;
int main()
{
Watercraft w[3];
automobile a[4];
//add some attrinuets to array objects w
w[1].setHull ("Fiberglass");
w[1].setSeats(10);
w[1].setEngine("Yamaha 115 HP");
w[1].setWeight(5200);
/*w[2].setHull("Fiberglass");
w[2].setSeats(10);
w[2].setEngine("Yamaha 115 HP");
w[2].setWeight(5200);*/
w[2] = w[1];
//set automobile objects
a[1].setEngine("3A90 I3");
a[1].setWheels(4);
a[1].setWeight(2072);
a[1].setSeats(5);
a[1].setMake("Mirage");
a[1].setModel("Mitsubishi");
a[2].setEngine("V6");
a[2].setWheels(4);
a[2].setWeight(4079);
a[2].setSeats(2);
a[2].setMake("Honda");
a[2].setModel("Accord");
/*a[3].setEngine("3A90 I3");
a[3].setWheels(4);
a[3].setWeight(2072);
a[3].setSeats(5);
a[3].setMake("Mirage");
a[3].setModel("Mitsubishi");*/
a[3] = a[1];
//now print water crafts and automobile objects
for (int i = 0, k = 0, j = 0; i < 7; i = i + 2 , k++, j++)
{
if (k < 3)
{
cout << "WaterCraft: " << endl;
cout << "Engine: " << w[k].getEngine() << endl;
cout << "Weight: " << w[k].getWeight() << endl;
cout << "Seats: " << w[k].getSeats() << endl;
cout << "Hull: " << w[k].getHull() << endl;
cout << "Manufacturer: " << w[k].getManufacturer() << endl;
}
if (j < 4)
{
cout << "Automobile: " << endl;
cout << "Engine: " << a[j].getEngine() << endl;
cout << "Wheels: " << a[j].getWheels() << endl;
cout << "Weight: " << a[j].getWeight() << endl;
cout << "Seats: " << a[j].getSeats() << endl;
cout << "Make: " << a[j].getMake() << endl;
cout << "Model: " << a[j].getModel() << endl;
}
}
cout << "Number of vehicles created: " << ::vehicles::count << endl;
cout << "Number of watercrafts created: " << ::Watercraft::count << endl;
cout << "Number of automobiles created: " << ::automobile::count << endl;
}
/*output:
WaterCraft:
Engine: Minn Kota Max 70
Weight: 1860
Seats: 12
Hull: V -Hull
Manufacturer: Sea Ark Boats
Automobile:
Engine: V6
Wheels: 4
Weight: 4079
Seats: 4
Make: Toyota
Model: Solara
WaterCraft:
Engine: Yamaha 115 HP
Weight: 5200
Seats: 10
Hull: Fiberglass
Manufacturer: Sea Ark Boats
Automobile:
Engine: 3A90 I3
Wheels: 4
Weight: 2072
Seats: 5
Make: Mirage
Model: Mitsubishi
WaterCraft:
Engine: Yamaha 115 HP
Weight: 5200
Seats: 10
Hull: Fiberglass
Manufacturer: Sea Ark Boats
Automobile:
Engine: V6
Wheels: 4
Weight: 4079
Seats: 2
Make: Honda
Model: Accord
Automobile:
Engine: 3A90 I3
Wheels: 4
Weight: 2072
Seats: 5
Make: Mirage
Model: Mitsubishi
Number of vehicles created: 7
Number of watercrafts created: 3
Number of automobiles created: 4
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.