The objective of this lab is to create a inventory tracker program based on the
ID: 3713225 • Letter: T
Question
The objective of this lab is to create a inventory tracker program based on the vehicle class created. #ifndef VEHICLE_H #define VEHICLE_H/* @file vehicle.cpp @author @date 4/15/2018
@description Implements 5 classes for vehicle information */
#include <string> #include <sstream> using namespace std;
const int CURRENT_YEAR = 2018; // Use this variable whever you are doing // your price/year calculations. class Vehicle { protected: string color; int passengers; int wheels; int year; public: Vehicle(){ color = ""; passengers = 1; wheels = 2; year = CURRENT_YEAR; } void setColor(string color){ this->color = color; } string getColor(){ return color; } void setPassengers(int passengers){ this->passengers = passengers; } int getPassengers(){ return passengers; } void setWheels(int wheels){ this->wheels = wheels; } int getWheels(){ return wheels; } void setYear(int year){ if (year <= CURRENT_YEAR){ this->year = year; } else { this->year = CURRENT_YEAR; } } int getYear(){ return year; } virtual float getPrice() = 0;
virtual string print(){ stringstream ss; ss << "Color: " << color << endl; ss << "Year built: " << year << endl; ss << "# of Passengers: " << passengers << endl; return ss.str(); } };
class Bike : public Vehicle { public: Bike(){ passengers = 1; wheels = 2; } void setPassengers(int passengers){ if (passengers != 1) { cout << "Bike can only hold 1 passenger" << endl; } this->passengers = 1; } void setWheels(int wheels){ if (wheels != 2){ cout << "Bike can only have 2 wheels" << endl; } this->wheels = 2; } float getPrice(){ float price; price = 1000 - 100 * (CURRENT_YEAR - year); if (price < 0){ return 0; } else { return price; } } string print(){ stringstream ss; ss << "Bike: " << endl; ss << Vehicle::print(); ss << "# of Wheels: " << wheels << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
class Car : public Vehicle { private: bool air; bool DVD; public: Car(){ wheels = 4; air = false; DVD = false; } void setPassengers(int passengers){ if (passengers >= 1 && passengers <= 10){ this->passengers = passengers; } else { cout << "Car can only hold 1 to 4 passengers" << endl; } } void setWheels(int wheels){ if (wheels != 4){ cout << "Car can only have 4 wheels" << endl; } this->wheels = 4; } void setAir(bool air){ this->air = air; } bool getAir(){ return air; } void setDVD(bool DVD){ this->DVD = DVD; } bool getDVD(){ return DVD; } float getPrice(){ float price; price = 5000 * passengers - 500 * (CURRENT_YEAR - year); if (price < 100) { price = 100; } price += 200 * air + 100 * DVD; return price; } string print(){ stringstream ss; ss << "Car: " << endl; ss << Vehicle::print(); ss << "# of Wheels: " << wheels << endl; ss << "Has Air-conditioning: " << (air ? "True" : "False") << endl; ss << "Has DVD: " << (DVD ? "True" : "False") << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
class Truck : public Vehicle { private: int cap;
public: Truck(){ wheels = 4; cap = 0; } void setPassengers(int passengers){ if (passengers >= 1 && passengers <= 4){ this->passengers = passengers; } else { cout << "Truck can only hold 1 to 4 passengers" << endl; } } void setWheels(int wheels){ if (wheels >= 4 && wheels <= 16){ this->wheels = wheels; } else { cout << "Truck can only have 4 to 16 wheels" << endl; } } void setCap(int cap){ if (cap >=0 && cap <= 20000){ this->cap = cap; } else { cout << "Truck can only carry no more than 20000lb" << endl; } } int getCap(){ return cap; } float getPrice(){ float price = 10000; price += 1000 * passengers - 500 * (CURRENT_YEAR - year); if (price < 200) { price = 200; } price += 1.25 * cap + 200 * wheels; return price; } string print(){ stringstream ss; ss << "Truck: " << endl; ss << Vehicle::print(); ss << "# of Wheels: " << wheels << endl; ss << "Capacity: " << cap << "lb" << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
class Airplane : public Vehicle { private: int cap; int props; public: Airplane(){ wheels = 0; cap = 0; props = 1; } void setPassengers(int passengers){ if (passengers >= 1 && passengers <= 40){ this->passengers = passengers; } else { cout << "Airplane can only hold 1 to 40 passengers" << endl; } } void setWheels(int wheels){ cout << "Airplane does not have wheels" << endl; this->wheels = 0; } void setCap(int cap){ if (cap >=0 && cap <= 20000){ this->cap = cap; } else { cout << "Airplane can only carry no more than 20000lb" << endl; } } int getCap(){ return cap; } void setProps(int props){ if (props >= 1) { this->props = props; } else { cout << "Airplan must have at least 1 props" << endl; } } int getProps(){ return props; } float getPrice(){ float price = 15000; price += 1000 * passengers - 500 * (CURRENT_YEAR - year); if (price < 1000) { price = 1000; } price += 5.25 * cap + 100 * props; return price; } string print(){ stringstream ss; ss << "Airplane: " << endl; ss << Vehicle::print(); ss << "# of Props: " << props << endl; ss << "Capacity: " << cap << "lb" << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
#endif #ifndef VEHICLE_H #define VEHICLE_H
/* @file vehicle.cpp @author @date 4/15/2018
@description Implements 5 classes for vehicle information */
#include <string> #include <sstream> using namespace std;
const int CURRENT_YEAR = 2018; // Use this variable whever you are doing // your price/year calculations. class Vehicle { protected: string color; int passengers; int wheels; int year; public: Vehicle(){ color = ""; passengers = 1; wheels = 2; year = CURRENT_YEAR; } void setColor(string color){ this->color = color; } string getColor(){ return color; } void setPassengers(int passengers){ this->passengers = passengers; } int getPassengers(){ return passengers; } void setWheels(int wheels){ this->wheels = wheels; } int getWheels(){ return wheels; } void setYear(int year){ if (year <= CURRENT_YEAR){ this->year = year; } else { this->year = CURRENT_YEAR; } } int getYear(){ return year; } virtual float getPrice() = 0;
virtual string print(){ stringstream ss; ss << "Color: " << color << endl; ss << "Year built: " << year << endl; ss << "# of Passengers: " << passengers << endl; return ss.str(); } };
class Bike : public Vehicle { public: Bike(){ passengers = 1; wheels = 2; } void setPassengers(int passengers){ if (passengers != 1) { cout << "Bike can only hold 1 passenger" << endl; } this->passengers = 1; } void setWheels(int wheels){ if (wheels != 2){ cout << "Bike can only have 2 wheels" << endl; } this->wheels = 2; } float getPrice(){ float price; price = 1000 - 100 * (CURRENT_YEAR - year); if (price < 0){ return 0; } else { return price; } } string print(){ stringstream ss; ss << "Bike: " << endl; ss << Vehicle::print(); ss << "# of Wheels: " << wheels << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
class Car : public Vehicle { private: bool air; bool DVD; public: Car(){ wheels = 4; air = false; DVD = false; } void setPassengers(int passengers){ if (passengers >= 1 && passengers <= 10){ this->passengers = passengers; } else { cout << "Car can only hold 1 to 4 passengers" << endl; } } void setWheels(int wheels){ if (wheels != 4){ cout << "Car can only have 4 wheels" << endl; } this->wheels = 4; } void setAir(bool air){ this->air = air; } bool getAir(){ return air; } void setDVD(bool DVD){ this->DVD = DVD; } bool getDVD(){ return DVD; } float getPrice(){ float price; price = 5000 * passengers - 500 * (CURRENT_YEAR - year); if (price < 100) { price = 100; } price += 200 * air + 100 * DVD; return price; } string print(){ stringstream ss; ss << "Car: " << endl; ss << Vehicle::print(); ss << "# of Wheels: " << wheels << endl; ss << "Has Air-conditioning: " << (air ? "True" : "False") << endl; ss << "Has DVD: " << (DVD ? "True" : "False") << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
class Truck : public Vehicle { private: int cap;
public: Truck(){ wheels = 4; cap = 0; } void setPassengers(int passengers){ if (passengers >= 1 && passengers <= 4){ this->passengers = passengers; } else { cout << "Truck can only hold 1 to 4 passengers" << endl; } } void setWheels(int wheels){ if (wheels >= 4 && wheels <= 16){ this->wheels = wheels; } else { cout << "Truck can only have 4 to 16 wheels" << endl; } } void setCap(int cap){ if (cap >=0 && cap <= 20000){ this->cap = cap; } else { cout << "Truck can only carry no more than 20000lb" << endl; } } int getCap(){ return cap; } float getPrice(){ float price = 10000; price += 1000 * passengers - 500 * (CURRENT_YEAR - year); if (price < 200) { price = 200; } price += 1.25 * cap + 200 * wheels; return price; } string print(){ stringstream ss; ss << "Truck: " << endl; ss << Vehicle::print(); ss << "# of Wheels: " << wheels << endl; ss << "Capacity: " << cap << "lb" << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
class Airplane : public Vehicle { private: int cap; int props; public: Airplane(){ wheels = 0; cap = 0; props = 1; } void setPassengers(int passengers){ if (passengers >= 1 && passengers <= 40){ this->passengers = passengers; } else { cout << "Airplane can only hold 1 to 40 passengers" << endl; } } void setWheels(int wheels){ cout << "Airplane does not have wheels" << endl; this->wheels = 0; } void setCap(int cap){ if (cap >=0 && cap <= 20000){ this->cap = cap; } else { cout << "Airplane can only carry no more than 20000lb" << endl; } } int getCap(){ return cap; } void setProps(int props){ if (props >= 1) { this->props = props; } else { cout << "Airplan must have at least 1 props" << endl; } } int getProps(){ return props; } float getPrice(){ float price = 15000; price += 1000 * passengers - 500 * (CURRENT_YEAR - year); if (price < 1000) { price = 1000; } price += 5.25 * cap + 100 * props; return price; } string print(){ stringstream ss; ss << "Airplane: " << endl; ss << Vehicle::print(); ss << "# of Props: " << props << endl; ss << "Capacity: " << cap << "lb" << endl; ss << "Price: " << "$" << getPrice() << endl; return ss.str(); } };
#endif **************************************************** /* @file vehicle-sandbox.cpp @author @date 4/15/2018
@description Sandbox for the Bicycle, Car, Truck and Airplane classes */
#include <iostream> #include <vector>
#include "vehicle.h"
using namespace std;
int main(int argc, char* argv[]){ Bike a; a.setColor("Red"); a.setYear(2016); cout << a.print() << endl; a.setYear(2000); cout << a.print() << endl; Car b; b.setColor("Silver"); b.setPassengers(5); b.setYear(2014); b.setAir(true); b.setDVD(true); cout << b.print() << endl; Truck c; c.setColor("Blue"); c.setPassengers(2); c.setWheels(8); c.setYear(2016); c.setCap(10000); cout << c.print() << endl; Airplane d; d.setColor("White"); d.setPassengers(20); d.setProps(4); d.setYear(2010); d.setCap(20000); cout << d.print() << endl; }
Explanation / Answer
#ifndef VEHICLE_H
#define VEHICLE_H
#include <string>
#include <sstream>
using namespace std;
const int CURRENT_YEAR = 2018; // Use this variable wherever you are doing your price/year calculations.
// Class Vehicle definition
class Vehicle
{
protected:
// Data member to store data
string color;
int passengers;
int wheels;
int year;
public:
// Default constructor to initialize data members
Vehicle()
{
color = "";
passengers = 1;
wheels = 2;
year = CURRENT_YEAR;
}// End of default constructor
// Function to set color
void setColor(string color)
{
this->color = color;
}// End of function
// Function to return color
string getColor()
{
return color;
}// End of function
// Function to set number of passengers
void setPassengers(int passengers)
{
this->passengers = passengers;
}// End of function
// Function to return number of passengers
int getPassengers()
{
return passengers;
}// End of function
// Function to set number of wheels
void setWheels(int wheels)
{
this->wheels = wheels;
}// End of function
// Function to return number of wheels
int getWheels()
{
return wheels;
}// End of function
// Function to set year
void setYear(int year)
{
// Checks if parameter year is less than or equals to the current year
if (year <= CURRENT_YEAR)
{
// Set the year
this->year = year;
}
// Otherwise set the current year
else
{
this->year = CURRENT_YEAR;
}
}// End of function
// Function to return year
int getYear()
{
return year;
}// End of function
// Pure virtual function to return price
virtual float getPrice() = 0;
// Virtual unction to return concatenated vehicle information
virtual string print()
{
stringstream ss;
ss << "Color: " << color << endl;
ss << "Year built: " << year << endl;
ss << "# of Passengers: " << passengers << endl;
return ss.str();
}// End of function
};// End of class
// Class Bike derived from Vehicle
class Bike : public Vehicle
{
public:
// Default constructor to initialize data members
Bike()
{
passengers = 1;
wheels = 2;
}// End of default constructor
// Function to set number of passengers
void setPassengers(int passengers)
{
// Checks if parameter passengers is not equals to one
if (passengers != 1)
{
cout << "Bike can only hold 1 passenger" << endl;
}
// Set the number of passengers to one
this->passengers = 1;
}// End of function
// Function to set wheels
void setWheels(int wheels)
{
// Checks if number of wheels is not 2 then display error message
if (wheels != 2)
{
cout << "Bike can only have 2 wheels" << endl;
}
// Set the wheels to 2
this->wheels = 2;
}// End of function
// Checks if number of wheels is not 2 then display error message
float getPrice()
{
float price;
price = 1000 - 100 * (CURRENT_YEAR - year);
if (price < 0)
{
return 0;
}
else
{
return price;
}
}// End of function
// Function to return concatenated Bike information
string print()
{
stringstream ss;
ss << "Bike: " << endl;
ss << Vehicle::print();
ss << "# of Wheels: " << wheels << endl;
ss << "Price: " << "$" << getPrice() << endl;
return ss.str();
}// End of function
};// End of class
// Class Car derived from Vehicle
class Car : public Vehicle
{
private:
// your price/year calculations.
bool air;
bool DVD;
public:
// Default constructor to initialize data members
Car()
{
wheels = 4;
air = false;
DVD = false;
}// End of default constructor
// Function to set number of passengers
void setPassengers(int passengers)
{
// Checks if parameter passengers is between the rang 1 - 10 then set the passenger
if (passengers >= 1 && passengers <= 10)
{
this->passengers = passengers;
}
// Otherwise display message
else
{
cout << "Car can only hold 1 to 10 passengers" << endl;
}
}// End of function
// Function to set wheels
void setWheels(int wheels)
{
// Checks if number of wheels is not 4 then display error message
if (wheels != 4)
{
cout << "Car can only have 4 wheels" << endl;
}
this->wheels = 4;
}// End of function
// Function to set air condition status
void setAir(bool air)
{
this->air = air;
}// End of function
// Function to return air condition status
bool getAir()
{
return air;
}// End of function
// Function to set DVD status
void setDVD(bool DVD)
{
this->DVD = DVD;
}// End of function
// Function to return DVD status
bool getDVD()
{
return DVD;
}// End of function
// Checks if number of wheels is not 2 then display error message
float getPrice()
{
float price;
price = 5000 * passengers - 500 * (CURRENT_YEAR - year);
if (price < 100)
{
price = 100;
}
price += 200 * air + 100 * DVD;
return price;
}// End of function
// Function to return concatenated Car information
string print()
{
stringstream ss;
ss << "Car: " << endl;
ss << Vehicle::print();
ss << "# of Wheels: " << wheels << endl;
ss << "Has Air-conditioning: " << (air ? "True" : "False") << endl;
ss << "Has DVD: " << (DVD ? "True" : "False") << endl;
ss << "Price: " << "$" << getPrice() << endl;
return ss.str();
}// End of function
};// End of class
// Class Truck derived from Vehicle
class Truck : public Vehicle
{
private:
// your price/year calculations.
int cap;
public:
// Default constructor to initialize data members
Truck()
{
wheels = 4;
cap = 0;
}// End of default constructor
// Function to set number of passengers
void setPassengers(int passengers)
{
// Checks if parameter passengers is between the rang 1 - 4 then set the passenger
if (passengers >= 1 && passengers <= 4)
{
this->passengers = passengers;
}
// Otherwise display message
else
{
cout << "Truck can only hold 1 to 4 passengers" << endl;
}
}// End of function
// Function to set wheels
void setWheels(int wheels)
{
// Checks if number of wheels is not between the range 4 - 16 then display error message
if (wheels >= 4 && wheels <= 16)
{
this->wheels = wheels;
}
else
{
cout << "Truck can only have 4 to 16 wheels" << endl;
}
}// End of function
// Function to set carry load
void setCap(int cap)
{
// Checks if the capacity is within the range or 0 - 20000 then the set the capacity
if (cap >=0 && cap <= 20000)
{
this->cap = cap;
}
// Otherwise display error message
else
{
cout << "Truck can only carry no more than 20000lb" << endl;
}
}// End of function
// Function to return carry load
int getCap()
{
return cap;
}
// Function to calculate and return price
float getPrice()
{
float price = 10000;
price += 1000 * passengers - 500 * (CURRENT_YEAR - year);
if (price < 200)
{
price = 200;
}
price += 1.25 * cap + 200 * wheels;
return price;
}// End of function
// Function to return concatenated Truck information
string print()
{
stringstream ss;
ss << "Truck: " << endl;
ss << Vehicle::print();
ss << "# of Wheels: " << wheels << endl;
ss << "Capacity: " << cap << "lb" << endl;
ss << "Price: " << "$" << getPrice() << endl;
return ss.str();
}// End of function
};// End of class
// Class Airplane derived from Vehicle
class Airplane : public Vehicle
{
private:
// your price/year calculations.
int cap;
int props;
public:
// Default constructor to initialize data members
Airplane()
{
wheels = 0;
cap = 0;
props = 1;
}// End of default constructor
// Function to set number of passengers
void setPassengers(int passengers)
{
// Checks if parameter passengers is between the rang 1 - 40 then set the passenger
if (passengers >= 1 && passengers <= 40)
{
this->passengers = passengers;
}
// Otherwise display message
else
{
cout << "Airplane can only hold 1 to 40 passengers" << endl;
}
}// End of function
// Function to set wheels
void setWheels(int wheels)
{
cout << "Airplane does not have wheels" << endl;
this->wheels = 0;
}// End of function
// Function to set carry load
void setCap(int cap)
{
// Checks if the capacity is between the range of 0 - 20000 then the capacity
if (cap >=0 && cap <= 20000)
{
this->cap = cap;
}
// Otherwise display error message
else
{
cout << "Airplane can only carry no more than 20000lb" << endl;
}
}// End of function
// Function to return carry load
int getCap()
{
return cap;
}// End of function
// Function to set props
void setProps(int props)
{
if (props >= 1)
{
this->props = props;
}
else
{
cout << "Airplane must have at least 1 props" << endl;
}
}// End of function
// Function to return props
int getProps()
{
return props;
}// End of function
// Checks if number of wheels is not 2 then display error message
float getPrice()
{
float price = 15000;
price += 1000 * passengers - 500 * (CURRENT_YEAR - year);
if (price < 1000)
{
price = 1000;
}
price += 5.25 * cap + 100 * props;
return price;
}// End of function
// Function to return concatenated airplane information
string print()
{
stringstream ss;
ss << "Airplane: " << endl;
ss << Vehicle::print();
ss << "# of Props: " << props << endl;
ss << "Capacity: " << cap << "lb" << endl;
ss << "Price: " << "$" << getPrice() << endl;
return ss.str();
}// End of function
};// End of class
#endif
-------------------------------------------------------------------
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include "vehicle.h"
#define MAX 100
using namespace std;
// Function to display main menu
int mainMenu()
{
// To store user choice
int choice;
// Displays menu
cout<<" 1 - Add Vehicle.";
cout<<" 2 - Print Vehicle Type.";
cout<<" 3 - Print All Vehicles.";
cout<<" 4 - Search Vehicle.";
cout<<" 5 - Print Aggregate.";
cout<<" 6 - Quit.";
// Accepts user choice
cout<<" Enter your choice: ";
cin>>choice;
// Returns choice
return choice;
}// End of function
// Function to display vehicle type menu
int VehicleTypeMenu()
{
// To store user choice
int choice;
// Displays menu
cout<<" 1 - Bike.";
cout<<" 2 - Car.";
cout<<" 3 - Truck.";
cout<<" 4 - Airplane.";
// Accepts user choice
cout<<" Enter your choice: ";
cin>>choice;
// Returns choice
return choice;
}// End of function
// Function to display search menu
int SearchMenu()
{
// To store user choice
int choice;
// Displays menu
cout<<" 1 - Print vehicles for specific color.";
cout<<" 2 - Print vehicles within price range.";
// Accepts user choice
cout<<" Enter your choice: ";
cin>>choice;
// Returns choice
return choice;
}// End of function
// Function to display aggregate menu
int AggregateMenu()
{
// To store user choice
int choice;
// Displays menu
cout<<" 1 - Print total number of vehicles.";
cout<<" 2 - Print total price.";
// Accepts user choice
cout<<" Enter your choice: ";
cin>>choice;
// Returns choice
return choice;
}// End of function
// main function definition
int main(int argc, char* argv[])
{
// Declares array of objects for each vehicle type
Bike bike[MAX];
Car car[MAX];
Truck truck[MAX];
Airplane airplane[MAX];
// Counter for each vehicle type
int counterBike = 0, counterCar = 0, counterTruck = 0, counterAirplane = 0;
// Local variable to store user entered data
string stringData;
int integerData;
bool boolData;
float floatData1, floatData2;
// To store total price of all vehicles
float totalPrice = 0;
// To store search found status
int found = 0;
// Loops till user choice is not 6
do
{
// Call the function to display main menu and calls appropriate function based on user choice
switch(mainMenu())
{
case 1:
// Call the function to display vehicle type menu and calls appropriate function based on user choice
switch(VehicleTypeMenu())
{
case 1:
cout<<" Enter Bike information: "<<endl;
cout<<" Enter color: ";
cin>>stringData;
bike[counterBike].setColor(stringData);
cout<<" Enter year: ";
cin>>integerData;
bike[counterBike].setYear(integerData);
counterBike++;
break;
case 2:
cout<<" Enter Car information: "<<endl;
cout<<" Enter color: ";
cin>>stringData;
car[counterCar].setColor(stringData);
cout<<" Enter number of passengers: ";
cin>>integerData;
car[counterCar].setPassengers(integerData);
cout<<" Enter year: ";
cin>>integerData;
car[counterCar].setYear(integerData);
cout<<" Has Air-conditioning(true / false)? ";
cin>>boolData;
car[counterCar].setAir(boolData);
cout<<" Has DVD(true / false)? ";
cin>>boolData;
car[counterCar].setDVD(boolData);
counterCar++;
break;
case 3:
cout<<" Enter Truck information: "<<endl;
cout<<" Enter color: ";
cin>>stringData;
truck[counterTruck].setColor(stringData);
cout<<" Enter number of passengers: ";
cin>>integerData;
truck[counterTruck].setPassengers(integerData);
cout<<" Enter number of wheels: ";
cin>>integerData;
truck[counterTruck].setWheels(integerData);
cout<<" Enter year: ";
cin>>integerData;
truck[counterTruck].setYear(integerData);
cout<<" Enter capacity: ";
cin>>integerData;
truck[counterTruck].setCap(integerData);
counterTruck++;
break;
case 4:
cout<<" Enter Airplane information: "<<endl;
cout<<" Enter color: ";
cin>>stringData;
airplane[counterAirplane].setColor(stringData);
cout<<" Enter number of passengers: ";
cin>>integerData;
airplane[counterAirplane].setPassengers(integerData);
cout<<" Enter number of props: ";
cin>>integerData;
airplane[counterAirplane].setProps(integerData);
cout<<" Enter year: ";
cin>>integerData;
airplane[counterAirplane].setYear(integerData);
cout<<" Enter capacity: ";
cin>>integerData;
airplane[counterAirplane].setCap(integerData);
counterAirplane++;
break;
default:
cout<<" Invalid vehicle type!";
}// End of switch case
break;
case 2:
// Call the function to display vehicle type menu and calls appropriate function based on user choice
switch(VehicleTypeMenu())
{
case 1:
// Loops till number of bikes
for(int x = 0; x < counterBike; x++)
cout<<bike[x].print();
break;
case 2:
// Loops till number of car
for(int x = 0; x < counterCar; x++)
cout<<car[x].print();
break;
case 3:
// Loops till number of truck
for(int x = 0; x < counterTruck; x++)
cout<<truck[x].print();
break;
case 4:
// Loops till number of airplane
for(int x = 0; x < counterAirplane; x++)
cout<<airplane[x].print();
break;
default:
cout<<" Invalid vehicle type!";
}// End of switch case
break;
case 3:
// Loops till number of bikes
for(int x = 0; x < counterBike; x++)
cout<<bike[x].print();
// Loops till number of car
for(int x = 0; x < counterCar; x++)
cout<<car[x].print();
// Loops till number of truck
for(int x = 0; x < counterTruck; x++)
cout<<truck[x].print();
// Loops till number of airplane
for(int x = 0; x < counterAirplane; x++)
cout<<airplane[x].print();
break;
case 4:
// Call the function to display search menu and calls appropriate function based on user choice
switch(SearchMenu())
{
case 1:
cout<<" Enter the color to search vehicle: ";
cin>>stringData;
// Loops till number of bikes
for(int x = 0; x < counterBike; x++)
// Checks if the user entered color is equals to the current bike color
if(stringData.compare(bike[x].getColor()) == 0)
{
// Set the found status to one for found
found = 1;
cout<<bike[x].print();
}// End of if condition
// Loops till number of car
for(int x = 0; x < counterCar; x++)
// Checks if the user entered color is equals to the current car color
if(stringData.compare(car[x].getColor()) == 0)
{
// Set the found status to one for found
found = 1;
cout<<car[x].print();
}// End of if condition
// Loops till number of truck
for(int x = 0; x < counterTruck; x++)
// Checks if the user entered color is equals to the current truck color
if(stringData.compare(truck[x].getColor()) == 0)
{
// Set the found status to one for found
found = 1;
cout<<truck[x].print();
}// End of if condition
// Loops till number of airplane
for(int x = 0; x < counterAirplane; x++)
// Checks if the user entered color is equals to the current airplane color
if(stringData.compare(airplane[x].getColor()) == 0)
{
// Set the found status to one for found
found = 1;
cout<<airplane[x].print();
}// End of if condition
// Checks if found status is zero record not found
if(found == 0)
cout<<" No vehicle found with color "<<stringData;
break;
case 2:
cout<<" Enter the price range beginning: ";
cin>>floatData1;
cout<<" Enter the price range end: ";
cin>>floatData2;
// Loops till number of bikes
for(int x = 0; x < counterBike; x++)
// Checks if the current bike price is with in user entered rate
if(bike[x].getPrice() > floatData1 && bike[x].getPrice() < floatData2)
{
// Set the found status to one for found
found = 1;
cout<<bike[x].print();
}// End of if condition
// Loops till number of car
for(int x = 0; x < counterCar; x++)
// Checks if the current car price is with in user entered rate
if(car[x].getPrice() > floatData1 && car[x].getPrice() < floatData2)
{
// Set the found status to one for found
found = 1;
cout<<car[x].print();
}// End of if condition
// Loops till number of truck
for(int x = 0; x < counterTruck; x++)
// Checks if the current truck price is with in user entered rate
if(truck[x].getPrice() > floatData1 && truck[x].getPrice() < floatData2)
{
// Set the found status to one for found
found = 1;
cout<<truck[x].print();
}// End of if condition
// Loops till number of airplane
for(int x = 0; x < counterAirplane; x++)
// Checks if the current airplane price is with in user entered rate
if(airplane[x].getPrice() > floatData1 && airplane[x].getPrice() < floatData2)
{
// Set the found status to one for found
found = 1;
cout<<airplane[x].print();
}// End of if condition
// Checks if found status is zero record not found
if(found == 0)
cout<<" No vehicle found with range "<<floatData1<<" - "<<floatData2;
break;
default:
cout<<" Invalid search type!";
}// End of switch case
break;
case 5:
// Call the function to display aggregate menu and calls appropriate function based on user choice
switch(AggregateMenu())
{
case 1:
cout<<" Total number of vehicles: "<<(counterBike + counterCar + counterTruck + counterAirplane);
break;
case 2:
// Loops till number of bikes
for(int x = 0; x < counterBike; x++)
totalPrice += bike[x].getPrice();
// Loops till number of car
for(int x = 0; x < counterCar; x++)
totalPrice += car[x].getPrice();
// Loops till number of truck
for(int x = 0; x < counterTruck; x++)
totalPrice += truck[x].getPrice();
// Loops till number of airplane
for(int x = 0; x < counterAirplane; x++)
totalPrice += airplane[x].getPrice();
cout<<" Total price of all the vehicles: $"<<totalPrice;
break;
default:
cout<<" Invalid aggregate type choice!";
}// End of switch case
break;
case 6:
exit(1);
default:
cout<<" invalid choice!";
}// End of switch case
}while(1); // End of do while loop
}// End of main function
Sample Output:
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 1
Enter Bike information:
Enter color: red
Enter year: 2001
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 1
Enter Bike information:
Enter color: green
Enter year: 2012
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 2
Enter Car information:
Enter color: blue
Enter number of passengers: 6
Enter year: 2012
Has Air-conditioning(true / false)? 0
Has DVD(true / false)? 0
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 2
Enter Car information:
Enter color: red
Enter number of passengers: 9
Enter year: 2013
Has Air-conditioning(true / false)? 1
Has DVD(true / false)? 1
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 3
Enter Truck information:
Enter color: red
Enter number of passengers: 12
Truck can only hold 1 to 4 passengers
Enter number of wheels: 3
Truck can only have 4 to 16 wheels
Enter year: 2001
Enter capacity: 1000
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 3
Enter Truck information:
Enter color: blue
Enter number of passengers: 6
Truck can only hold 1 to 4 passengers
Enter number of wheels: 5
Enter year: 2012
Enter capacity: 1500
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 1
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 4
Enter Airplane information:
Enter color: red
Enter number of passengers: 6
Enter number of props: 2
Enter year: 2010
Enter capacity: 12
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 2
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 1
Bike:
Color: red
Year built: 2001
# of Passengers: 1
# of Wheels: 2
Price: $0
Bike:
Color: green
Year built: 2012
# of Passengers: 1
# of Wheels: 2
Price: $400
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 2
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 2
Car:
Color: blue
Year built: 2012
# of Passengers: 6
# of Wheels: 4
Has Air-conditioning: False
Has DVD: False
Price: $27000
Car:
Color: red
Year built: 2013
# of Passengers: 9
# of Wheels: 4
Has Air-conditioning: True
Has DVD: True
Price: $42800
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 2
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 3
Truck:
Color: red
Year built: 2001
# of Passengers: 1
# of Wheels: 4
Capacity: 1000lb
Price: $4550
Truck:
Color: blue
Year built: 2012
# of Passengers: 1
# of Wheels: 5
Capacity: 1500lb
Price: $10875
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 2
1 - Bike.
2 - Car.
3 - Truck.
4 - Airplane.
Enter your choice: 4
Airplane:
Color: red
Year built: 2010
# of Passengers: 6
# of Props: 2
Capacity: 12lb
Price: $17263
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 3
Bike:
Color: red
Year built: 2001
# of Passengers: 1
# of Wheels: 2
Price: $0
Bike:
Color: green
Year built: 2012
# of Passengers: 1
# of Wheels: 2
Price: $400
Car:
Color: blue
Year built: 2012
# of Passengers: 6
# of Wheels: 4
Has Air-conditioning: False
Has DVD: False
Price: $27000
Car:
Color: red
Year built: 2013
# of Passengers: 9
# of Wheels: 4
Has Air-conditioning: True
Has DVD: True
Price: $42800
Truck:
Color: red
Year built: 2001
# of Passengers: 1
# of Wheels: 4
Capacity: 1000lb
Price: $4550
Truck:
Color: blue
Year built: 2012
# of Passengers: 1
# of Wheels: 5
Capacity: 1500lb
Price: $10875
Airplane:
Color: red
Year built: 2010
# of Passengers: 6
# of Props: 2
Capacity: 12lb
Price: $17263
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 4
1 - Print vehicles for specific color.
2 - Print vehicles within price range.
Enter your choice: 1
Enter the color to search vehicle: red
Bike:
Color: red
Year built: 2001
# of Passengers: 1
# of Wheels: 2
Price: $0
Car:
Color: red
Year built: 2013
# of Passengers: 9
# of Wheels: 4
Has Air-conditioning: True
Has DVD: True
Price: $42800
Truck:
Color: red
Year built: 2001
# of Passengers: 1
# of Wheels: 4
Capacity: 1000lb
Price: $4550
Airplane:
Color: red
Year built: 2010
# of Passengers: 6
# of Props: 2
Capacity: 12lb
Price: $17263
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 4
1 - Print vehicles for specific color.
2 - Print vehicles within price range.
Enter your choice: 2
Enter the price range beginning: 10000
Enter the price range end: 20000
Truck:
Color: blue
Year built: 2012
# of Passengers: 1
# of Wheels: 5
Capacity: 1500lb
Price: $10875
Airplane:
Color: red
Year built: 2010
# of Passengers: 6
# of Props: 2
Capacity: 12lb
Price: $17263
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 5
1 - Print total number of vehicles.
2 - Print total price.
Enter your choice: 1
Total number of vehicles: 7
1 - Add Vehicle.
2 - Print Vehicle Type.
3 - Print All Vehicles.
4 - Search Vehicle.
5 - Print Aggregate.
6 - Quit.
Enter your choice: 5
1 - Print total number of vehicles.
2 - Print total price.
Enter your choice: 2
Total price of all the vehicles: $102888
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.