Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

URGENT!! I really need help figuring out how to make my code work. Below is the assignment, and following is the code I have now.

URGENT!! I really need help figuring out how to make my code work. Below is the assignment, and following is the code I have now. Help me Chegg hero, you're my only hope!

PROJECT 4

Objectives: The main objectives of this project is to test your ability to create and use C++ classes, with multiple constructors, static members/functions, and expand to operator overloading. A review of pointers, structs, arrays, iostream, file I/O and C-style strings is also included.

Description: This project will significantly expand upon Project 3 by adding additional functionality, and implementing more abstract data types (ADTs) and their operations through classes. Pointers must be used for array manipulation, including arrays with ADTs (structs, classes) e.g, rental cars, rental agencies. Pointers must be used in function prototypes and function parameter lists - not square brackets. Make sure all your C-string functions (e.g. string copy, string compare, etc.) work with pointers (parameters list and function implementation). Const should be used in parameter lists, functions, and function signaturesas appropriate. Square brackets should be used only when declaring an array, or if otherwise you specify your own overloaded operator[] . Pointers can only be moved by incrementing or decrementing (i.e., ++ or - -), or by setting the pointer back to the base address using the array name. You should use the arrow operator (->) with any pointers where appropriate.

The additional functionality is as follows: You are given an updated data file where there is 1 Agency location (Agency) which has 5 cars (Car) which can potentially be of a high-tech type. Each car can incorporate up to 3 (0-3) special driving sensors (Sensor). You will have similar menu options, but the functionality has been updated below. Note: using multiple helper functions to do smaller tasks will make this project significantly easier.

The Sensor Class will contain the following private data members:

m_type, a C-string char array of 256 max characters (name of sensor type), valid strings for Sensor m_type are "gps", "camera", "lidar", "radar", "none".

m_extracost, a float (additional rent cost per day for the car that carries the sensor, for "gps":=$5.0/day, for "camera":=$10.0/day, for "lidar":=$15.0/day, for "radar":=$20.0/day, for "none":=$0.0/day)

gps_cnt, a static int member (keeps track of existing gps-type sensors)

camera_cnt, a static int member (keeps track of existing camera-type sensors)

lidar_cnt, a static int member (keeps track of existing lidar-type sensors)

radar_cnt, a static int member (keeps track of existing radar-type sensors)

and will have the following methods:

Default Constructor will set the aforementioned data members to default initial values.

Parameterized Constructor will create a new object based on a C-string value passed into it (sensor type being instantiated). Hint: bear in mind what a sensor type implies about its other data members.

Copy Constructor will create a new object which duplicates an input Sensor Object.

Get/Set methods for appropriate data member(s).

A Get and a Reset static member function to return and to reset each of the static member variables.

A Method to check if 2 Sensor Objects are the same. You should make this an operator overload of (operator==). You may want to try for practice to make it a non-Class Member function which will have to access member data over Class methods.

The Car Class will contain the following private data members:

m_make, a C-string char array of 256 max characters (car make)

m_model, a C-string char array of 256 max characters (car model)

m_year, an int (year of production)

m_sensors, a Sensor class type array of size 3 (max allowable number of sensors per car). Hint: You are allowed to use an auxiliary member variable of your choice to keep track of how many actual sensors exist onboard, this will also help for instance in case adding a new sensor is required.

m_baseprice, a float (price per day for the sensorless vehicle)

m_finalprice, a float (price per day with the increased cost of the car sensors)

m_available, a bool (1 = true; 0 = false; try to display true/false using the "std::boolalpha" manipulator like: cout << boolalpha << boolVariable; )

m_owner, a C- string char array of 256 max characters (the current lessee; if no lessee, i.e. the Car object is available), set to a \0-starting (0-length) C-string).

and will have the following methods:

Default Constructor will set the aforementioned data members to default initial values.

Parameterized Constructor will create a new object based on the values passed into it for the make, model, year, baseprice, and sensors.

Copy Constructor will create a new object which duplicates an input Car object.

Get methods for data members.

Set methods for data members except the m_sensors, and m_finalprice.

UpdatePrice a method to update the m_finalprice after any potential changes (to the m_baseprice or the m_sensors)

Print will print out all the cars data.

EstimateCost will estimate the cars cost given (a parameter passed to it) a number of days to rent it for.

A Method to Add a Sensor to the Car object. You should make this an operator overload of (operator+). Hint: a Car Class member method will be the better choice, since it will have access to private members. You may want to try that for practice.

A Method to Add a lessee (the name of a lessee) to the Car object. You should make this an operator overload of (operator+). Hint: bear in mind what adding a renter to a Car object might imply about other data members.

The Agency Class will contain the following private data members:

m_name, a C-string char array of 256 max characters

m_zipcode, a preferably const int number of size 5

m_inventory, an array of Car objects with a size of 5

and will have the following methods:

Default Constructor will set the aforementioned data members to default initial values.

Get/Set (IF possible) methods for m_name and m_zipcode data members by-Value.

A Method to Index by-Reference an Object of the m_inventory data (i.e. you should use return by-Reference). Hint: This will allow you to access (read and write) to the agencys inventory like in Project_3.) You should make this an operator overload of (operator[]). Reminder: Any calls to this operator are excluded from the Projects restrictions about using brackets.

ReadAllData read all of the data for the agency from a user-provided file.

PrintAllData - prints out all of the data for an agency (including car info).

PrintAvailableCars prints out all of the data (including Car info) only for the available Car Objects of the agency.

The menu must have the following updated functionality:

1) Read ALL data from file. The provided sample file HighTechAgency.txt is structured : The first line is the car agency info, followed by 5 cars. For each car the order is: year make model baseprice {sensors} available [lessee]. The sensors are enclosed in {braces} and can be 0 up to 3 ws-separated names. The lessee name is [optional], it will only be there if the car is available.

2) Print to terminal ALL data for the Agency and all its corresponding Cars in a way that demonstrates this relationship (similarly to Project_3).

3) Print to terminal the TOTAL number of sensors built to equip the agencys car fleet (total number by sensor type).

4) Find the most expensive available car ask the user if they want to rent it update that cars lessee and availability status if the user says yes.

5) Exit program.

The following minimum functionality and structure is required:

Ask the user for the input file name.

The list of Sensors must be stored in an array of Objects.

The list of Cars must be stored in an array of Objects.

Use character arrays to hold your strings (i.e., C-style) exclusively (using the string data type is still not allowed).

Write multiple functions (Hint: You could have each menu option be a function).

At least one function must use Pass-by-Reference.

At least one function must Return-a-Reference.

Otherwise, as before, you are free to use pass by-Value, pass by-Reference, pass by-Address for your function parameters.

Variables, data members, functions, function signatures, should all be const in a perfect program, unless there is no other way for the program to work. (This might seem as an overstatement. However, try to remember the const keyword and design around it as much as you can). You are required to at least try.

Pointers must be used for all array manipulation (iterating over elements to read/modify cannot be performed with bracket operator accessing). The only exception on [] is if you are using your own overload of operator[].

Pointers must be used in function prototypes and function parameter lists (the bracket notation is not allowed in parameters lists).Pointers can only be moved by incrementing or decrementing: double d[3] = {1,2,3}; double * d_Pt = d; for (int i=0; i<3; ++i,++d_Pt){ cout << *d_Ptd; }

Or by setting the pointer back to the base address using the array name. d_Pt = d; cout << *d_Pt << endl;

Write your own C-string length, compare, copy, concatenate functions. Their prototypes will have the form (use the prototypes exactly as provided, with char * parameters):

// counts characters in str array until a NULL-character '\0' is found, then it returns that number excluding the '\0' one // the return type size_t represents an unsigned integral number large enough to contain the maximum possible number of a storage size that can appear on a target architecture size_t myStringLength(const char * str);

// returns 0 when the C-strings match, i.e. their characters are equal one-by-one until a NULL-character '\0' is found in both strings and at the same position as well // returns a value < -1 if the first character that does not match has a lower value in str1 than in str2 // returns a value > 1 if the first character that does not match has a higher value in str1 than in str2 int myStringCompare(const char * str1, const char * str2);

// copies characters from source to destination array until a NULL-character '\0' is found in source, then it NULL-terminates destination too // returns a pointer to the destination array char * myStringCopy(char * destination, const char * source);

// appends the content of source to the destination array // this means that the NULL-terminator of destination is overwritten by the first character of source and a NULL-character '\0' is appended at the end of the concatenated Cstring in destination

// returns a pointer to the destination array char * myStringCat(char * destination, const char * source);

The other functionality and structure of the program should remain the same as Project #3, including writing to screen and file, as well as restrictions on string libraries, global variables and constants, etc.

Implement the concepts of encapsulation and data hiding (necessary)! Use the const keyword where appropriate (almost everywhere you can make it)! Implement Class Constructors with Initializer-Lists as much as possible (advised)!

Implement operator overloads as much as you can !

This is a chance to experiment as much as possible with more advanced concepts and the intricacies of classes. It is not a strict requirement that const data members which can only be instantiated with a list initialization are there in your code right now, neither is it necessary to make your member functions in the operator overload approach. Try your best in order to acquaint yourself with these new concepts however, and figure out what might be giving you a hard time understanding and/or implementing at this early point.

The supplied txt file for the program HighTechAgency.txt is as follows:

Enterprise 89502 2014 Toyota Tacoma 115.12 {gps} 1 2012 Honda CRV 85.10 {camera lidar} 0 Mike 2011 Toyota Rav4 65.02 {} 0 Oscar 2009 Dodge Neon 45.25 {camera lidar radar} 1 2015 Ford Fusion 90.89 {lidar} 0 Juliet

Below is the code I have now:

//This program takes a file detailing 1 agency which contains 5 cars which are potentially of high-tech type. The user can interact with a menu in order to achieve certain outcomes.

#include

#include

#include

using namespace std;

void strcpy(char*, char*);

int strcmp(char*, char*);

class CarSensor{

private:

char m_type[256];

float m_extracost;

int gps_cnt;

int camera_cnt;

int lidar_cnt;

int radar_cnt;

public:

void SensCon();

void SensCon(char*);

void SensCpy(const CarSensor &initsensor);

//primary get methods

char* GetType();

float GetExtraCost();

int GetGps();

int GetCam();

int GetLid();

int GetRad();

//primary set methods

bool SetType(char* newtype);

bool SetExtraCost(float newextracost);

void GetReset(int&, int&, int&, int&);

};

bool operator==(const CarSensor& lhs, const CarSensor& rhs);

void CarSensor::SensCon(){

strcpy(m_type, '\0');

m_extracost = 0.0;

}

void CarSensor::SensCon(char* startType){

strcpy(m_type, startType);

if(startType == "gps"){

m_extracost = 5.0;

}

else if(startType == "camera"){

m_extracost = 10.0;

}

else if(startType == "lidar"){

m_extracost = 15.0;

}

else{

m_extracost = 20.0;

}

}

void CarSensor::SensCpy(const CarSensor &initsensor){

CarSensor newsensor = initsensor;

strcpy(m_type, newsensor.m_type);

m_extracost = newsensor.m_extracost;

gps_cnt = newsensor.gps_cnt;

camera_cnt = newsensor.camera_cnt;

lidar_cnt = newsensor.lidar_cnt;

radar_cnt = newsensor.radar_cnt;

}

char* CarSensor::GetType(){ //returns current value for an individual car's year

return m_type;

}

float CarSensor::GetExtraCost(){ //return current value for an individual car's make

return m_extracost;

}

int CarSensor::GetGps(){ //returns current value for an individual car's model

return gps_cnt;

}

int CarSensor::GetCam(){ //returns current value for an individual car's model

return camera_cnt;

}

int CarSensor::GetLid(){

return lidar_cnt;

}

int CarSensor::GetRad(){ //return current value for an individual car's availability

return radar_cnt;

}

bool CarSensor::SetType(char* newtype){

strcpy(m_type, newtype);

return true;

}

bool CarSensor::SetExtraCost(float newextracost){

if(newextracost > 0.0){

m_extracost = newextracost;

return true;

}

}

void CarSensor::GetReset(int &gps_cnt, int &camera_cnt, int &lidar_cnt, int &radar_cnt){

gps_cnt = 0;

camera_cnt = 0;

lidar_cnt = 0;

radar_cnt = 0;

}

bool operator==(CarSensor& lhs, CarSensor& rhs){

if(strcmp(lhs.GetType(), rhs.GetType()) == 0){

if(lhs.GetExtraCost() == rhs.GetExtraCost()){

if(lhs.GetGps() == rhs.GetGps()){

if(lhs.GetCam() == rhs.GetCam()){

if(lhs.GetLid() == rhs.GetLid()){

if(lhs.GetRad() == rhs.GetRad()){

return true;

}

}

}

}

}

}

else{

return false;

}

}

class RentalCar{

private:

char m_make[256];

char m_model[256];

int m_year;

float m_tank;

CarSensor m_sensors[3];

int m_senscnt;

float m_baseprice;

float m_finalprice;

bool m_available;

char m_owner[256];

public:

void CarCon();

void CarCon(char*, char*, int, float, CarSensor*, float, float, bool, char*);

void CarCpy(RentalCar &initcar);

//primary get methods

char* GetMake();

char* GetModel();

int GetYear();

float GetTank();

CarSensor* GetSensors();

int GetSenscnt();

float GetBasePrice();

float GetFinalPrice();

bool GetAvailable();

char* GetOwner();

//primary set methods

bool SetMake(char* newMake);

bool SetModel(char* newModel);

bool SetYear(int newYear);

bool SetTank(float newTank);

bool SetSens(int newSenscnt);

bool SetBasePrice(float newBaseprice);

bool SetAvailable(bool newAvail);

bool SetOwner(char* newOwner);

bool UpdatePrice();

void PrintCar();

float EstimateCost(int);

RentalCar& operator+(CarSensor& nsens);

RentalCar& operator+(char* nowner);

};

void RentalCar::CarCon(){

int i;

strcpy(m_make, '\0');

strcpy(m_model, '\0');

m_year = 0;

m_tank = 0.0;

CarSensor* senPtr = m_sensors; //ptr to current sensor

for(int i = 0; i < 3; i++){

senPtr->SensCon();

senPtr++;

}

m_senscnt = 0;

m_baseprice = 0.0;

m_finalprice = 0.0;

m_available = false;

strcpy(m_owner, '\0');

}

void RentalCar::CarCon(char* stMake, char* stModel, int stYear, float stTank, CarSensor* stSensors, float stBprice, float stFprice, bool stAvail, char* stOwner){

int i;

strcpy(m_make, stMake);

strcpy(m_model, stModel);

m_year = stYear;

m_tank = stTank;

CarSensor* sen1Ptr = m_sensors;

CarSensor* sen2Ptr = stSensors; //ptr to current sensor of initial sensors

for(int i = 0; i < 3; i++){

sen1Ptr->SensCpy(*sen2Ptr);

sen1Ptr++;

sen2Ptr++;

}

m_baseprice = stBprice;

m_finalprice = stFprice;

m_available = stAvail;

strcpy(m_owner, stOwner);

}

void RentalCar::CarCpy(RentalCar &initcar){

int i;

strcpy(m_make, initcar.m_make);

strcpy(m_model, initcar.m_model);

m_year = initcar.m_year;

m_tank = initcar.m_tank;

CarSensor* sen1Ptr = m_sensors;

CarSensor* sen2Ptr = initcar.m_sensors; //ptr to current sensor of the input RentalCar

for(int i = 0; i < 3; i++){

sen1Ptr->SensCpy(*sen2Ptr);

sen1Ptr++;

sen2Ptr++;

}

m_senscnt = initcar.m_senscnt;

m_baseprice = initcar.m_baseprice;

m_finalprice = initcar.m_finalprice;

m_available = initcar.m_available;

strcpy(m_owner, initcar.m_owner);

}

char* RentalCar::GetMake(){ //returns current value for indv car's make

return m_make;

}

char* RentalCar::GetModel(){ //return current value for indv car's model

return m_model;

}

int RentalCar::GetYear(){

return m_year;

}

float RentalCar::GetTank(){

return m_tank;

}

CarSensor* RentalCar::GetSensors(){ //returns curent calues for indv car's sensors

return m_sensors;

}

int RentalCar::GetSenscnt(){

return m_senscnt;

}

float RentalCar::GetBasePrice(){

return m_baseprice;

}

float RentalCar::GetFinalPrice(){

return m_finalprice;

}

bool RentalCar::GetAvailable(){

return m_available;

}

char* RentalCar::GetOwner(){

return m_owner;

}

bool RentalCar::SetMake(char* newMake){

strcpy(m_make, newMake);

return true;

}

bool RentalCar::SetModel(char* newModel){

return true;

}

bool RentalCar::SetYear(int newYear){

if(newYear > 0){

m_year = newYear;

return true;

}

}

bool RentalCar::SetTank(float newTank){

if(newTank > 0.0){

m_tank = newTank;

return true;

}

}

bool RentalCar::SetBasePrice(float newBaseprice){

if(newBaseprice > 0.0){

m_baseprice = newBaseprice;

return true;

}

}

bool RentalCar::SetAvailable(bool newAvail){ //given new value for car's avail, will set to new value

m_available = newAvail;

return true;

}

bool RentalCar::SetOwner(char* newOwner){

strcpy(m_owner, newOwner);

return true;

}

bool RentalCar::UpdatePrice(){

int i;

float sensCosts = 0.0; //additional costs from sensors to base rental price

CarSensor* senPtr = m_sensors; //ptr to current sensor

for(int i = 0; i < m_senscnt; i++){

sensCosts += senPtr->GetExtraCost();

senPtr++;

}

m_finalprice = m_baseprice + sensCosts;

return true;

}

void RentalCar::PrintCar(){ //where I deleted the outfile stuff

CarSensor* senPtr = m_sensors; //ptr to current sensor

cout << m_year << " " << m_make << " " << m_model << "Max Tank Capacity: ";

cout << m_tank << " gallons " << "Sensors: {";

while(senPtr->GetType() != "\0"){

cout << senPtr->GetType() << " ";

senPtr++;

}

cout << "} Base Price: $" << m_baseprice << " per day " << "Actual Price: &";

cout << m_finalprice << " per day " << "Available: " << boolalpha << m_available;

if(m_owner != "\0"){

cout << m_owner << endl;

}

}

float RentalCar::EstimateCost(int totalDays){

float value = 0.0; //total value for rental

value = m_finalprice* totalDays;

return value;

}

RentalCar& RentalCar::operator+(CarSensor& nsens){

int i;

CarSensor* senPtr = m_sensors; //ptr to current sensor

if(m_senscnt == 3){

cout << "This car already has the maximum number of sensors." << endl;

}

else{

for(int i = 0; i < m_senscnt; i++){

senPtr++;

}

*senPtr = nsens;

}

return *this;

}

RentalCar& RentalCar::operator+(char* nowner){

strcpy(m_owner, nowner);

m_available -= m_available;

return *this;

}

class RentalAgency{

private:

char m_name[256];

int m_zipcode[5];

RentalCar m_inventory[5];

public:

void AgenCon();

//primary get methods

char*GetName();

int* GetZipcode();

//primary set methods

bool SetName(char* newname);

bool SetZipcode(int* newzipcode);

RentalCar& operator[](const int index);

void ReadInData(ifstream &inFile);

void PrintAllData();

void PrintAvailableCars();

friend void callMenu(RentalAgency& currAgency);

friend void readIn(RentalAgency&);

friend void printAgency(RentalAgency&);

friend void sensorNum(RentalAgency&);

friend void carSearch(RentalAgency&);

};

void RentalAgency::AgenCon(){

int i;

strcpy(m_name, '\0');

int* zipPtr = m_zipcode; //ptr for current zip digit

RentalCar* carPtr = m_inventory; //ptr for current car of agency

for(int i = 0; i < 5; i++){

*zipPtr = 0;

carPtr->CarCon();

carPtr++;

zipPtr++;

}

}

char*RentalAgency::GetName(){

return m_name;

}

int* RentalAgency::GetZipcode(){

return m_zipcode;

}

bool RentalAgency::SetName(char* newname){ //given new value for name, will set to new value

strcpy(m_name, newname);

return true;

}

bool RentalAgency::SetZipcode(int* newzipcode){

int i;

int* zipPtr = m_zipcode;

for(int i = 0; i < 5; i++){

*zipPtr = *newzipcode;

zipPtr++;

newzipcode++;

}

return true;

}

RentalCar& RentalAgency::operator[](const int index){

int i;

RentalCar* carPtr = this->m_inventory; //ptr to current car

if(index < 0 || index > 4){ //checks to make sure index is between 0 and 4

cout << "Invalid index." << endl;

}

else{

for(int i = 0; i < index; i++){

carPtr++;

}

}

return *carPtr;

}

void RentalAgency::ReadInData(ifstream &inFile){ //given instream var, will read in data from user-provided file

int i;

RentalCar* carPtr = m_inventory; //ptr to current car

int* iptr = m_zipcode; //ptr to current digit in zip

//temp storage for info

char tempMake[256];

char tempModel[256];

int tempYear;

float tempTank;

float tempBaseprice;

float tempFinalprice;

bool tempAvail;

char tempOwner[256];

CarSensor newSensor[3];

char newType[256];

inFile >> m_name;

inFile.get();

for(int i = 0; i < 5; i++){

*iptr = inFile.get() - '0';

iptr++;

}

for(int i = 0; i < 5; i++){

CarSensor* newPtr = newSensor; //ptr to current sensor being read

inFile >> tempYear >> tempMake >> tempModel >> tempTank >> tempBaseprice;

carPtr->SetYear(tempYear);

carPtr->SetMake(tempMake);

carPtr->SetModel(tempModel);

carPtr->SetBasePrice(tempBaseprice);

inFile.get();

inFile.get();

char gps[20] = "gps";

char camera[20] = "camera";

char lidar[20] = "lidar";

char radar[20] = "radar";

while(inFile.get() != '}'){

inFile >> newType;

newPtr->SetType(newType);

if(strcmp(newType, gps) == 0){

newPtr->SetExtraCost(5.0);

newPtr->GetGps()+1;

}

else if(strcmp(newType, camera) == 0){

newPtr->SetExtraCost(10.0);

newPtr->GetCam()+1;

}

else if(strcmp(newType, lidar) == 0){

newPtr->SetExtraCost(15.0);

newPtr->GetLid()+1;

}

else if(strcmp(newType, radar) == 0){

newPtr->SetExtraCost(20.0);

newPtr->GetRad()+1;

}

else{

newPtr->SetExtraCost(0.0);

}

newPtr++;

}

inFile.get();

carPtr->UpdatePrice();

inFile >> tempAvail >> tempOwner;

carPtr->SetAvailable(tempAvail);

carPtr->SetOwner(tempOwner);

carPtr++;

}

}

void RentalAgency::PrintAllData(){ //prints data to terminal

int i;

RentalCar* carPtr = m_inventory; //ptr to RentalCar data

int* iptr = m_zipcode; //ptr to current zip digit

cout << m_name << " ";

for(int i = 0; i < 5; i++){

cout << *iptr;

iptr++;

}

cout << endl;

cout << "test1" << endl;

//for(int i = 0; i < 5; i++){

carPtr->PrintCar();

cout << "test2" << endl;

carPtr++;

cout << "test3" << endl;// }

cout << endl;

}

void RentalAgency::PrintAvailableCars(){ //outfile

int i;

RentalCar* carPtr = m_inventory; //ptr for car data

for(int i = 0; i < 5; i++){

if(carPtr->GetAvailable() == 1){

carPtr->PrintCar();

}

carPtr++;

}

}

RentalAgency currAgency;

bool exitProg();

int main(){

int count = 0; //count for total number of cars read as input

callMenu(currAgency);

return 0;

}

void callMenu(RentalAgency &currAgency){

int menuOption;

bool doneStatus = false;

do{

cout << "Menu Options" << endl;

cout << "1) Read all data from file" << endl;

cout << "2) Print all agency and car data" << endl;

cout << "3) Print total number of sensors" << endl;

cout << "4) Find most expensive available car" << endl;

cout << "5) Exit program" << endl;

cout << "Select menu option: " << endl;

cin >> menuOption;

switch(menuOption){

case 1:

readIn(currAgency);

break;

case 2:

printAgency(currAgency);

break;

case 3:

sensorNum(currAgency);

break;

case 4:

carSearch(currAgency);

break;

case 5:

doneStatus = exitProg();

break;

default:

cout << "Invalid input." << endl;

}

}

while(doneStatus != true);

}

void readIn(RentalAgency &currAgency){

ifstream inFile; //istream var

string inpfile; //name of ifile

//ifile input and open

cout << "Please enter the name of your input file: " << endl;

cin >> inpfile;

inFile.open(inpfile.c_str());

currAgency.ReadInData(inFile);

inFile.close();

}

void printAgency(RentalAgency &currAgency){

currAgency.PrintAllData();

}

void sensorNum(RentalAgency &currAgency){

int i;

int totSensors = 0; //total number of sensors for all cars

for(int i = 0; i < 5; i++){

totSensors += currAgency[i].GetSenscnt();

}

cout << "Total number of sensors in all cars: " << totSensors << endl;

}

void carSearch(RentalAgency &currAgency){

int i;

RentalCar* maxCarPtr = currAgency.m_inventory;

for(int i = 0; i < 5; i++){

if(currAgency.m_inventory[i].GetFinalPrice() > maxCarPtr->GetFinalPrice() && currAgency.m_inventory[i].GetAvailable() == true){

maxCarPtr = &currAgency.m_inventory[i];

}

}

if(maxCarPtr->GetAvailable() == false){

cout << "There are no cars available" << endl;

}

else{

CarSensor* senPtr = maxCarPtr->GetSensors(); //ptr to current sensor

char answer; //answer of user whether car should be rented

cout << "Most expensive available car: " << maxCarPtr->GetYear() << " " << maxCarPtr->GetMake() << " " << maxCarPtr->GetModel() << " Max Tank Capacity: " << maxCarPtr->GetTank() << " gallons " << "Sensors: {";

while(senPtr->GetType() != "\0"){

cout << senPtr->GetType() << " ";

senPtr++;

}

cout << "} Actual Price: $" << maxCarPtr->GetFinalPrice() << " per day " << endl;

cout << "Would you like to rent this car (Y or N): " << endl;

cin >> answer;

if(answer == 'Y' || answer == 'y'){

char ownName[20]; //name of user

cout << "Please enter your name: " << endl;

cin >> ownName;

maxCarPtr->SetAvailable(false);

maxCarPtr->SetOwner(ownName);

cout << "Thank you for your reservation." << endl;

}

}

}

bool exitProg(){

return true;

}

void strcpy(char* dest, char* src){

while(*src != '\0'){

*dest = *src;

dest++;

src++;

}

*dest = '\0';

}

int strcmp(char* first, char* sec){

int value = 0; //represents difference between strings

while(*first != '\0' || *sec != '\0'){

if(*first - *sec != 0){

value = *first - *sec;

return value;

}

first++;

sec++;

}

return value;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions