Question: Hello I need help with this project //Please note I cant use any global variables or std:: libraries //I've posted my code from my previous

Hello I need help with this project

//Please note I cant use any global variables or std:: libraries

//I've posted my code from my previous project under the this project description if that helps for any reference

Hello I need help with this project //Please note I cant use

any global variables or std:: libraries //I've posted my code from my

previous project under the this project description if that helps for any

reference #ifndef SCHOOL_RENTALAGENCY_H #define SCHOOL_RENTALAGENCY_H #include "RentalCar.h" #define MAX_CSTRING_SIZE 255 #define AGENCIES_IN_FILE

3 #define ZIPCODE_SIZE 5 #define INVENTORY_SIZE 5 struct RentalAgency { char name[MAX_CSTRING_SIZE];

int zipcode[ZIPCODE_SIZE]; RentalCar inventory[INVENTORY_SIZE]; }; #endif //SCHOOL_RENTALAGENCY_H RentalCar.cpp #include #include "RentalCar.h" using

namespace std; char *myStringCopy(char * destination, const char * source); // Constructors

RentalCar::RentalCar() { m_year = -1; myStringCopy(m_make, "NOMAKE"); myStringCopy(m_model, "NOMODEL"); m_price = 0;

#ifndef SCHOOL_RENTALAGENCY_H #define SCHOOL_RENTALAGENCY_H

#include "RentalCar.h"

#define MAX_CSTRING_SIZE 255 #define AGENCIES_IN_FILE 3 #define ZIPCODE_SIZE 5 #define INVENTORY_SIZE 5

struct RentalAgency { char name[MAX_CSTRING_SIZE]; int zipcode[ZIPCODE_SIZE]; RentalCar inventory[INVENTORY_SIZE]; };

#endif //SCHOOL_RENTALAGENCY_H

RentalCar.cpp

#include

#include "RentalCar.h"

using namespace std; char *myStringCopy(char * destination, const char * source);

// Constructors RentalCar::RentalCar() { m_year = -1; myStringCopy(m_make, "NOMAKE"); myStringCopy(m_model, "NOMODEL"); m_price = 0; m_available = false; }

RentalCar::RentalCar(int year, const char *make, const char *model, float price, bool available) { m_year = year; myStringCopy(m_make, make); myStringCopy(m_model, model); m_price = price; m_available = available; }

// Getters int RentalCar::getYear() const { return m_year; }

char *RentalCar::getMake() { return m_make; }

char *RentalCar::getModel() { return m_model; }

float RentalCar::getPrice() const { return m_price; }

bool RentalCar::getAvailable() const { return m_available; }

// Setters void RentalCar::setYear(int year) { m_year = year; }

void RentalCar::setMake(char *make) { myStringCopy(m_make, make); }

void RentalCar::setModel(char *model) { myStringCopy(m_model, model); }

void RentalCar::setPrice(float price) { m_price = price; }

void RentalCar::setAvailable(bool available) { m_available = available; }

// Other methods void RentalCar::print() const { cout

void RentalCar::estimateCost(int days) const { cout

RentalCar.h

#ifndef SCHOOL_RENTALCAR_H #define SCHOOL_RENTALCAR_H

#define MAX_CSTRING_SIZE 255

class RentalCar { public: // Constructors RentalCar(); RentalCar(int year, const char* make, const char* model, float price, bool available);

// Getters int getYear() const; char* getMake(); char* getModel(); float getPrice() const; bool getAvailable() const;

// Setters void setYear(int year); void setMake(char* make); void setModel(char* model); void setPrice(float price); void setAvailable(bool available);

// Other methods void print() const; void estimateCost(int days) const;

private: int m_year; char m_make[MAX_CSTRING_SIZE]; char m_model[MAX_CSTRING_SIZE]; float m_price; bool m_available;

};

#endif //SCHOOL_RENTALCAR_H

proj3.cpp

#include #include

#include "RentalCar.h" #include "RentalAgency.h"

using namespace std;

int menu(); int getIntBetween(int min, int max); void fiveDigitIntToArray(int fiveDigitInt, int *arr); void fiveDigitArrayFromFile(int *arr, ifstream &inf); RentalAgency readRentalAgencyAndInventoryFromFile(ifstream &inf); void readAllDataFromFile(RentalAgency * agencies); void printRentalAgency(RentalAgency agency); void printRentalAgencies(RentalAgency * agencies); RentalCar readRentalCarFromFile(ifstream &inf); RentalAgency selectAgency(RentalAgency * agencies); RentalCar selectCar(RentalCar * cars); void estimateRentalCost(RentalAgency * agencies); void findMostExpensiveCar(RentalAgency * agencies); void writeAvailableCarsToFile(RentalAgency * agencies);

// Custom string functions required by project spec size_t myStringLength(const char * str); int myStringCompare(const char * str1, const char * str2); char *myStringCopy(char * destination, const char * source); char * myStringCat(char * destination, const char * source);

int main() { RentalAgency agencies[AGENCIES_IN_FILE]; ifstream inf; bool exit = false; int selection;

do { selection = menu(); switch (selection) { case 1: readAllDataFromFile(agencies); break; case 2: printRentalAgencies(agencies); break; case 3: estimateRentalCost(agencies); break; case 4: findMostExpensiveCar(agencies); break; case 5: writeAvailableCarsToFile(agencies); break; case 6: exit = true; break; } } while (!exit);

return 0; }

/* * Display a menu to the user and prompt user for selection */ int menu() { cout

return getIntBetween(1, 6); }

/* * Prompt user for an integer between min and max, inclusive. * NOTE: This function completely blows up user enters non-integer */ int getIntBetween(int min, int max) { int selection;

// Prompt until valid selection entered do { cout > selection; // TODO: Prevent non-integer input infinite loop

} while (selection max);

return selection; }

/* * Convert a five digit integer to an int array. * This function uses modulous to extract the trailing digit from a base-10 integer, then stores those digits * in a target int array working from end to beginning. */ void fiveDigitIntToArray(int fiveDigitInt, int *arr) { int digit; int *arrEnd = arr + ZIPCODE_SIZE - 1;

while (fiveDigitInt >= 10) { digit = fiveDigitInt % 10; // Get last digit of base-10 int *arrEnd-- = digit; // Fill array in reverse, because we're pulling digits from the end of fiveDigitInt fiveDigitInt /= 10; // Chop last digit off base-10 int } *arrEnd = fiveDigitInt; // At loop end, fiveDigitInt only contains final (first) digit }

/* * Read a five digit integer from an ifstream and pass to fiveDigitIntToArray(). Mainly a helper function. */ void fiveDigitArrayFromFile(int *arr, ifstream &inf) { int fiveDigitInt; inf >> fiveDigitInt; fiveDigitIntToArray(fiveDigitInt, arr); }

/* * Read in a single rental agency and all of it's associated inventory data from an ifstream. */ RentalAgency readRentalAgencyAndInventoryFromFile(ifstream &inf) { RentalAgency agency; RentalCar car; RentalCar *inventory = agency.inventory;

inf >> agency.name; fiveDigitArrayFromFile(agency.zipcode, inf); for (int i = 0; i

return agency; }

/* * Prompt user for input filename, then read in all rental agency and rental car data until file is exhausted. */ void readAllDataFromFile(RentalAgency * agencies) { ifstream inf; char filename[MAX_CSTRING_SIZE];

cout > filename;

inf.open(filename); if (inf) {

for (int i = 0; i

} else { cerr

inf.close(); }

/* * Print rental agency data, including inventory details */ void printRentalAgency(RentalAgency agency) { int *arrPtr = agency.zipcode; RentalCar *inventory = agency.inventory;

// Print name and zipcode cout

// Print inventory for (int i = 0; i print(); inventory++; } cout

/* * Helper function to print all rental agencies data. Mainly calls printRentalAgency() */ void printRentalAgencies(RentalAgency * agencies) { for (int i = 0; i

/* * Read in one rental car's data from an ifstream */ RentalCar readRentalCarFromFile(ifstream &inf) { int year; char make[MAX_CSTRING_SIZE], model[MAX_CSTRING_SIZE]; float price; bool available;

inf >> year >> make >> model >> price >> available; RentalCar car(year, make, model, price, available);

return car; }

/* * Prompt user to select a rental agency by entering an integer 1-3 */ RentalAgency selectAgency(RentalAgency * agencies) { int selection; RentalAgency agency; RentalAgency * agenciesStart = agencies;

cout name

return agency; }

/* * Prompt user to select a rental car by entering an integer 1-5 */ RentalCar selectCar(RentalCar * cars) { int selection; RentalCar * carsIterator = cars;

cout print(); carsIterator++; } selection = getIntBetween(1, INVENTORY_SIZE) - 1;

return *(cars + selection); }

/* * Calculate the estimated cost to rent a car for a user-input number of days, then print to screen */ void estimateRentalCost(RentalAgency * agencies) { RentalAgency agency; RentalCar car; int days;

agency = selectAgency(agencies); car = selectCar(agency.inventory);

cout

/* * Locate the rental car with the greatest m_price member and print to screen */ void findMostExpensiveCar(RentalAgency * agencies) { RentalCar car, mostExpensiveCar = *(agencies->inventory); RentalCar * inventory;

for (int i = 0; i inventory; for (int j = 0; j mostExpensiveCar.getPrice()) { mostExpensiveCar = car; } inventory++; } agencies++; }

cout

/* * Prompt user to enter output file and write all available rental cars to that file */ void writeAvailableCarsToFile(RentalAgency * agencies) { char filename[MAX_CSTRING_SIZE]; ofstream of; RentalCar car; RentalCar * inventory; int * zipcode;

cout > filename;

of.open(filename); if (of) {

for (int i = 0; i inventory; zipcode = agencies->zipcode;

of name

for (int j = 0; j

} else { cerr

of.close(); }

/* * Find the length of a string, not including the null-terminator */ size_t myStringLength(const char * str) { size_t i = 0;

while (*str++) { i++; };

return i; }

/* * Compare two strings. Return -1 of str1 is less than str2, 1 if the opposite, 0 if they're identical */ int myStringCompare(const char * str1, const char * str2) { while (*str1 && *str2 && *str1 == *str2) { str1++; str2++; }

return *str1 - *str2; }

/* * Copy a source string to a destination string */ char *myStringCopy(char * destination, const char * source) { while ((*destination++ = *source++)) ;

return destination; }

/* * Concatenate a source string onto the end of a destination string */ char *myStringCat(char * destination, const char * source) { // Find end of destination while (*destination) { destination++; // Leaves destination pointing to null character }

// Copy source onto end of destination while ((*destination++ = *source++)) ;

return destination; }

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 all 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 signatures as appropriate. Sauare brackets should be used only when d Pointer arithmetic (e.g., ++ , +-, --,--) and setting the pointer back to the base address using the array name can be used to move through arrays. work with pointers paraneters lil hur p s and function parameter lists an array.or if otherwise you specify your own overloaded operator [1 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. 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 all 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 signatures as appropriate. Sauare brackets should be used only when d Pointer arithmetic (e.g., ++ , +-, --,--) and setting the pointer back to the base address using the array name can be used to move through arrays. work with pointers paraneters lil hur p s and function parameter lists an array.or if otherwise you specify your own overloaded operator [1 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!