//Vehicle.h
#pragma once
#include<iostream>
#include"Warranty.h"
#include<string>
using namespace std;
class Vehicle{
protected:
string make;
int year;
double mpg;
Warranty warranty;
static int numOfVehicles;
public:
Vehicle();
Vehicle(string s, int y, double m, Warranty warranty);
Vehicle(Vehicle& v);
~Vehicle();
string getMake();
int getYear();
double getGasMileage();
void setMake(string s);
void setYear(int y);
void setYear(string y);
void setGasMileage(double m);
void setGasMileage(string m);
void displayVehicle();
static int getNumVehicles();
Warranty getWarranty();
void setWarranty(Warranty& );
};
//Vehicle.cpp
#include "Vehicle.h"
#include <string>
Vehicle::Vehicle()
{
make = "unknown";
year = 0;
mpg = 0;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
Vehicle::Vehicle(string s, int y, double m, Warranty w)
{
make = s;
year = y;
mpg = m;
this->warranty.setNumMiles(w.getNumMiles());
this->warranty.setNumYears(w.getNumYears());
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
// copy constructor
Vehicle::Vehicle(Vehicle& v)
{
this->make = v.make;
this->year = v.year;
this->mpg = v.mpg;
this->warranty = v.warranty;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
//destructor decrementing numVehicles by one
Vehicle::~Vehicle()
{
Vehicle::numOfVehicles--;
}
string Vehicle::getMake()
{
return make;
}
int Vehicle::getYear()
{
return year;
}
double Vehicle::getGasMileage()
{
return mpg;
}
void Vehicle::setMake(string s)
{
make = s;
}
void Vehicle::setYear(int y)
{
year = y;
}
//an overloaded setYear method
void Vehicle::setYear(string y)
{
//string to integer
year = stoi(y);
}
void Vehicle::setGasMileage(double m)
{
mpg = m;
}
//an overloaded setMpg method
void Vehicle::setGasMileage(string m)
{
//string to double
mpg = stod(m);
}
void Vehicle::displayVehicle()
{
warranty.displayWarranty();
cout << "Make: "<< make << endl;
cout << "Year: "<< year << endl;
cout << "Mpg: "<< mpg << endl;
}
//Making the getNumVehicles a static method.
int Vehicle::getNumVehicles()
{
return Vehicle::numOfVehicles;
}
Warranty Vehicle::getWarranty()
{
return warranty;
}
void Vehicle::setWarranty(Warranty& warranty)
{
this->warranty.setNumMiles(warranty.getNumMiles());
this->warranty.setNumYears(warranty.getNumYears());
}
//Warranty.h
#pragma once
#include<iostream>
using namespace std;
class Warranty
{
private:
int numYears, numMiles;
public:
Warranty();
Warranty(int numYears, int numMiles);
~Warranty();
int getNumYears();
int getNumMiles();
void setNumYears(int);
void setNumMiles(int);
void displayWarranty();
};
//Warranty.cpp
#include"Warranty.h"
Warranty::Warranty()
{
numMiles = 0;
numYears = 0;
}
Warranty::Warranty(int numYears, int numMiles)
{
this->numMiles = numMiles;
this->numYears = numYears;
}
Warranty::~Warranty()
{
}
int Warranty::getNumYears()
{
return numYears;
}
int Warranty::getNumMiles()
{
return numMiles;
}
void Warranty::setNumYears(int years)
{
numYears = years;
}
void Warranty::setNumMiles(int miles)
{
numMiles = miles;
}
void Warranty::displayWarranty()
{
cout << "Warranty Info: " << endl;
cout << "Num of miles: " << numMiles<< " Num of Years: " << numYears << "\n";
}
//Hybrid.h
#pragma once
#include"Vehicle.h"
#include"Warranty.h"
class Hybrid :public Vehicle
{
private:
double range;
public:
Hybrid();
Hybrid(double range);
Hybrid(double range, string make, int year, double
mileage, Warranty warranty);
~Hybrid();
double getRange();
void setRange(double range);
void displayVehicle();
};
//Hybrid.cpp
#include"Hybrid.h"
Hybrid::Hybrid():Vehicle()
{
range = 0;
}
Hybrid::Hybrid(double range): Vehicle()
{
this->range = range;
}
Hybrid::Hybrid(double range, string make, int year, double mileage,
Warranty warranty)
: Vehicle(make,year,mileage,warranty)
{
this->range = range;
}
Hybrid::~Hybrid()
{
Vehicle::numOfVehicles--;
}
double Hybrid::getRange()
{
return range;
}
void Hybrid::setRange(double range)
{
this->range = range;
}
void Hybrid::displayVehicle()
{
Vehicle::displayVehicle();
cout << "Range of Hybrid Vehicle: " <<
range << endl;
}
Update and call the TerminateApplication function.
#pragma once
#include<iostream>
#include"Warranty.h"
#include<string>
using namespace std;
class Vehicle{
protected:
string make;
int year;
double mpg;
Warranty warranty;
static int numOfVehicles;
public:
Vehicle();
Vehicle(string s, int y, double m, Warranty warranty);
Vehicle(Vehicle& v);
~Vehicle();
string getMake();
int getYear();
double getGasMileage();
void setMake(string s);
void setYear(int y);
void setYear(string y);
void setGasMileage(double m);
void setGasMileage(string m);
void displayVehicle();
static int getNumVehicles();
Warranty getWarranty();
void setWarranty(Warranty& );
};
//Vehicle.cpp
#include "Vehicle.h"
#include <string>
Vehicle::Vehicle()
{
make = "unknown";
year = 0;
mpg = 0;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
Vehicle::Vehicle(string s, int y, double m, Warranty w)
{
make = s;
year = y;
mpg = m;
this->warranty.setNumMiles(w.getNumMiles());
this->warranty.setNumYears(w.getNumYears());
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
// copy constructor
Vehicle::Vehicle(Vehicle& v)
{
this->make = v.make;
this->year = v.year;
this->mpg = v.mpg;
this->warranty = v.warranty;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
//destructor decrementing numVehicles by one
Vehicle::~Vehicle()
{
Vehicle::numOfVehicles--;
}
string Vehicle::getMake()
{
return make;
}
int Vehicle::getYear()
{
return year;
}
double Vehicle::getGasMileage()
{
return mpg;
}
void Vehicle::setMake(string s)
{
make = s;
}
void Vehicle::setYear(int y)
{
year = y;
}
//an overloaded setYear method
void Vehicle::setYear(string y)
{
//string to integer
year = stoi(y);
}
void Vehicle::setGasMileage(double m)
{
mpg = m;
}
//an overloaded setMpg method
void Vehicle::setGasMileage(string m)
{
//string to double
mpg = stod(m);
}
void Vehicle::displayVehicle()
{
warranty.displayWarranty();
ANSWER:
==================================Veh.h========================================
#pragma once
#include<iostream>
#include<string>
using namespace std;
class Vehicle
{
string make;
int year;
double mpg;
static int numOfVehicles;
public:
Vehicle();
Vehicle(string s, int y, double m);
Vehicle(Vehicle& v);
~Vehicle();
string getMake();
int getYear();
double getGasMileage();
void setMake(string s);
void setYear(int y);
void setYear(string y);
void setGasMileage(double m);
void setGasMileage(string m);
void displayVehicle();
static int getNumVehicles();
};
=====================================Veh.cpp====================================
#include "stdafx.h"
#include "Veh.h"
#include <string>
Vehicle::Vehicle()
{
make = "unknown";
year = 0;
mpg = 0;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
Vehicle::Vehicle(string s, int y, double m)
{
make = s;
year = y;
mpg = m;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
// copy constructor
Vehicle::Vehicle(Vehicle& v)
{
this->make = v.make;
this->year = v.year;
this->mpg = v.mpg;
//constructor incrementing numVehicles by one
Vehicle::numOfVehicles++;
}
//destructor decrementing numVehicles by one
Vehicle::~Vehicle()
{
Vehicle::numOfVehicles--;
}
string Vehicle::getMake()
{
return make;
}
int Vehicle::getYear()
{
return year;
}
double Vehicle::getGasMileage()
{
return mpg;
}
void Vehicle::setMake(string s)
{
make = s;
}
void Vehicle::setYear(int y)
{
year = y;
}
//an overloaded setYear method
void Vehicle::setYear(string y)
{
//string to integer
year = stoi(y);
}
void Vehicle::setGasMileage(double m)
{
mpg = m;
}
//an overloaded setMpg method
void Vehicle::setGasMileage(string m)
{
//string to double
mpg = stod(m);
}
void Vehicle::displayVehicle()
{
cout << "Make: " << make <<
endl;
cout << "Year: " << year <<
endl;
cout << "Mpg: " << mpg <<
endl;
}
//Making the getNumVehicles a static method.
int Vehicle::getNumVehicles()
{
return Vehicle::numOfVehicles;
}
=======================================Main.cpp============================
// Vehicle.cpp : Defines the entry point for the console
application.
//
#pragma once
#include "stdafx.h"
#include <iostream>
#include "Veh.h"
void
displayApplicationInformation();
void terminateApplication();
//static numVehicles variable
initialized to zero.
int Vehicle::numOfVehicles =
0;
int main()
{
cout <<
"Start Program\n";
//Updating
and calling the DisplayApplicationInformation function.
displayApplicationInformation();
Vehicle
veh1;
string
make;
string
year;
string m;
cout <<
"Enter car Make: ";
cin >>
make;
veh1.setMake(make);
cout <<
"Enter year: ";
cin >>
year;
//Prompting for
and then setting year and mpg using the new overloaded
setters
veh1.setYear(year);
cout <<
"Set mileage: ";
cin >>
m;
veh1.setGasMileage(m);
//display
vehicle info
veh1.displayVehicle();
//calling the
DisplayApplicationInformation function.
displayApplicationInformation();
Vehicle
veh2("Toyota", 2019, 35.0);
veh2.displayVehicle();
//Creating a
third object by copying the second object.
Vehicle
veh3(veh2);
veh3.displayVehicle();
//Deleting
the third object by calling the destructor method.
veh3.~Vehicle();
//Displaying the
number of vehicles created using getNumVehicles
cout <<
"Number of vehicles created is " << Vehicle::getNumVehicles()
<< " \n";
//Calling the
TerminateApplication function.
terminateApplication();
}
void
displayApplicationInformation()
{
cout <<
"Welcome to CIS247C Project\n";
}
void
terminateApplication()
{
cout <<
"Exiting program\n";
}
Output:
//Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected: string make; int year; ...
CIS247C Week 3 Project Overview The objective of this week is to enhance last week's Vehicle class by making the following changes: • Create a static variable called numVehicles that holds an int and initialize it to zero. This will allow us to count all the Vehicle objects created in the main class. • Add the copy constructor • Increment numVehicles in all of the constructors • Decrement numVehicle in destructor • Add overloaded versions of setYear and setMpg that...
Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year : int ----------------------- + Car() + setMake(m: string) : void + getMake() : string + setYear(y: int) : void + getYear() : int ---------------------- */ #ifndef CAR_H #define CAR_H #include <iostream> using namespace std; class Car { private: string make; int year; public: Car(); Car(string); Car(int); Car(string, int); void setMake (string); string getMake() {return make;} void setYear (int); int getYear() {return year;} }; #endif #include...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
#include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured in feet and inches. */ class FeetInches { private: int feet; // The number of feet int inches; // The number of inches /** The simplify method adjusts the values in feet and inches to conform to a standard measurement. */ void simplify() { if (inches > 11) { feet = feet + (inches / 12); inches = inches % 12; } } /**...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
#include <iostream> #include <string> #include "hashT.h" #include "stateData.h" using namespace std; void stateData::setStateInfo(string sName, string sCapital, double stArea, int yAdm, int oAdm) { stateName = sName; stateCapital = sCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission; } void stateData::getStateInfo(string& sName, string& sCapital, double& stArea, int& yAdm, int& oAdm) { sName = stateName; sCapital = stateCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission; } string stateData::getStateName() { return stateName;...
Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
#include "stdafx.h" #include <iostream> using namespace std; class dateType { private: int dmonth; int dday; int dyear; public: void setdate (int month, int day, int year); int getday()const; int getmonth()const; int getyear()const; int printdate()const; bool isleapyear(int year); dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) { int numofdays; if (year<=2008) { dyear=year;...
#include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...