Using constructors and destructors with array of data For th

Using constructors and destructors with array of data.

For this project, you are to modify and extend Project 3 to use classes with constructors and destructors. The header file for rental Car and Agency classes are attached. No changes to the class specifications are allowed. All the data members are the same as Project 3\'s struct data members. All class function implementations should be based on the description below. You must also use pointers without bracket notation or pointer arithmetic as specified in the previous projects. It is NOT required to size your arrays exactly. Note: the provided header file has both class definitions inside of it. You can create a single file that implements both classes\' member functions. Const should be used as appropriate in parameter lists and functions.
The revised functionality is as follow: An updated data file with one Agency with 15 cars. The main driver will be significantly less complex than Project 3.  A menu (9 menu options including exit) is required that will test all of the Agency\'s member functions.
The Car class will have the following member functions:
default constructor - allocates the memory for arrays and sets data members to initial

values.
parameterized constructor - creates a new object based on the values passed into it

(allocates memory and assigns data).
copy constructor - creates a duplicate of the class object (allocates memory and assigns

data).
destructor - deallocates data members and/or resets to initial values.

copy - takes in a Car and copies the data into the calling object.

print - prints all data members to screen.

get/set functions - for all data members.

The Agency class will have the following member functions:
default constructor - allocates the memory for arrays and sets data members to initial

values.
copy constructor - creates a duplicate of the class object (allocates memory and assigns

data).
destructor - deallocates data members and/or resets to initial values.

readInData- takes in a file name and fills the class with the data from the file.

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

printAvailableCars – prints available cars to screen.

findMostExpensive - finds the most expensive car and prints the car information to screen.

estimateCost - takes in the car number (1-15), number of days and returns the cost.

sortByMake - sorts the car inventory by the car\'s make alphabetically.

sortByPrice - sorts the car inventory by the car\'s price per day from highest to lowest.

searchByMake - takes in a char pointer and prints to screen ALL cars with the matching make.

The car File that is read is as follows ( The number at the end determines if available or not , ex 1 = available, 0 = unavailable:
National 93619

2014 Toyota Tacoma 115.12 1

2012 Honda CRV 85.10 0

2015 Ford Fusion 90.89 0

2013 GMC Yukon 110.43 0

2009 Dodge Neon 45.25 1

2011 Toyota Rav4 65.02 1

2012 Mazda CX5 86.75 1

2016 Subaru Outback 71.27 0

2015 Ford F150 112.83 1

2010 Toyota Corolla 50.36 1

2008 Ford Fiesta 42.48 0

2009 Dodge Charger 55.36 1

2012 Chevy Volt 89.03 0

2007 Subaru Legacy 59.19 0

2010 Nissan Maxima 51.68 1

Agency.h

class Car{
public:Car();

Car(char *, char *, int, float, bool);

Car(const Car&);

~Car();
void copy(Car);

void print() const;
char * getMake() const;

char * getModel() const;

int getYear() const;

float getPrice() const;

bool getAvailable() const;
void setMake(char *);

void setModel(char *);

void setYear(int);

void setPrice(float);

void setAvailable(bool);

private:

char * make;

char * model;

int year;

float price;

bool available;

};
class Agency{

public:Agency();

Agency(const Agency&);

~Agency();

void readInData(char *);
void print() const;

void printAvailableCars() const;
void findMostExpensive() const;

float estimateCost(int, int) const;
void sortByMake(); // alphabetical

void sortByPrice();   // highest to lowest
void searchByMake(char *) const;

private:

char * name;

int * zipcode;

Car * inventory;

};

Solution

#include<iostream>
#include<cstdio>
using namespace std;
class Car
{
private:
char * make;
char * model;
int year;
float price;
bool available;


public :
Car()
{
year=0;
price=0;
available=false;
make=new char[20];
model=new char[20];
}
Car(char *ma, char *mo, int y, float p, bool a)
{
year=y;
price=p;
available=a;
make=ma;
model=mo;
}
Car(const Car& c)
{
year=c.year;
price=c.price;
available=c.available;
make=c.make;
model=c.model;
}
~Car()
{
year=0;
price=0;
available=false;
make=null;
model=null;
}
void copy(Car c)
{
year=c.year;
price=c.price;
available=c.available;
make=c.make;
model=c.model;
}
void print() const
{
cout<<year<<\" \"<<price<<\" \"<<available<<\" \"<<make<<\" \"<<model;
}
char * getMake() const
{
return make;
}
char * getModel() const\\
{
return model;
}
int getYear() const
{
return year;
}
float getPrice() const
{
return price;
}
bool getAvailable() const
{
return available;
}
void setMake(char * ma)
{
make=ma;
}
void setModel(char *mo)
{
model=mo;
}
void setYear(int y)
{
year=y;
}
void setPrice(float p)
{
price=p;
}
void setAvailable(bool a)
{
available=a;
}
};
class Agency{
private:
char * name;
int * zipcode;
Car * inventory;

public:
Agency()
{
name=new char[20];
zipcode=new char[10];
inventory=new Car[100];
}
Agency(const Agency& a)
{
name=a.name;
zipcode=a.zipcode;
inventory=a.inventory;
}
~Agency()
{
name=null;
zipcoe=null;
inventory=null;
}
void readInData(char * fname)
{
name=fname;
}
void print() const;
{
cout<<name<<\" \"<<zipcode<<\" \"<<inventory;
}
void printAvailableCars() const
{
for(int i=0;i<100;i++)
if(inventory[i].available)
inventory[i].print();
}
void findMostExpensive() const
{
int p=0,idx=0;
for(int i=0;i<15;i++){
if(p<inventory[i].price)
{
p=inventory[i].price;
idx=i;
}
}
inventory[i].print();
}

float estimateCost(int, int) const;
void sortByMake()
{
sort(inventory,inventory+15,high);
}
void sortByPrice(){
sort(inventory[0].price,inventory[15].price);

}
void searchByMake(char * c) const
{
char* p;
for(int i=0;i<15;i++)
{
if(c.inventory[i].make==c.inventory[])
}
}

};
int main()
{
return 0;
}

Using constructors and destructors with array of data. For this project, you are to modify and extend Project 3 to use classes with constructors and destructors
Using constructors and destructors with array of data. For this project, you are to modify and extend Project 3 to use classes with constructors and destructors
Using constructors and destructors with array of data. For this project, you are to modify and extend Project 3 to use classes with constructors and destructors
Using constructors and destructors with array of data. For this project, you are to modify and extend Project 3 to use classes with constructors and destructors
Using constructors and destructors with array of data. For this project, you are to modify and extend Project 3 to use classes with constructors and destructors
Using constructors and destructors with array of data. For this project, you are to modify and extend Project 3 to use classes with constructors and destructors

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site