please help me, this is a C++ project: i have been given an inventory file of us
ID: 3758930 • Letter: P
Question
please help me, this is a C++ project:
i have been given an inventory file of used cars at a dealership. The first line of the inventory file tells you how many cars are in the inventory file below. That is followed by the car details for each car - one on each line. The following car attributes are detailed in the file:
Car Make as string
Car Model as string
Car Color as string
Car ModelYear as int
Car's MilesDriven as int
Whether the car has had major repairs as a boolean
IT HAS TO READ FROM A FILE WHICH WILL SERVE AS YOUR DEALER INVENTORY FILE, NAMED MY FILE, AND HAS SOME JUNKS IN IT. IT SHOULDN'T READ THE JUNK
For this program
Create a structure called Car with its attributes as above.
Then in your main program, first read the number of cars in the dealer's inventory and dynamically create a Cars Array with that many Car elements.
Then set the attributes of your car objects by reading them from the file.
Print out the car details of the inventory to screen and to a plain text file - it should be properly formatted in the form of a table with columns.
Explanation / Answer
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
// base class definition
class Inventory
{
private:
int quant; // number on hand
int reorder; // reorder quantity
double price; // price per unit
char *descrip; // description of item
public:
Inventory(int, int, double, char *);
~Inventory();
void print();
int get_quant();
int get_reorder();
double get_price();
};
Inventory::Inventory(int q, int r, double p, char * d) : quant(q), reorder(r), price(p)
{
descrip = new char[strlen(d)+1];
strcpy(descrip,d);
}
Inventory::~Inventory()
{
delete descrip;
}
{
delete [] descrip;
}
inline void Inventory::print()
{
cout <<"Description: " << descrip << endl;
}
inline int Inventory::get_quant()
{
return quant;
}
inline int Inventory::get_reorder()
{
return reorder;
}
inline double Inventory::get_price()
{
return price;
}
// first derived class //
class Auto : public Inventory
{
char * manufacturer;
public:
Auto(int, int, double, char *, char *);
~Auto();
void print();
char * get_manufacturer();
};
Auto::Auto(int q, int r, double p, char * d, char * man) :
Inventory(q, r, p, d) // calls base constructor
{
manufacturer = new char[strlen(man)+1];
strcpy(manufacturer, man);
}
Auto::~Auto()
{
delete manufacturer;
}
{
delete [] manufacturer;
}
char* Auto::get_manufacturer()
{
return manufacturer;
}
void Auto::print( ) // redefines Base class print function
{
cout << setiosflags(ios::fixed);
cout << "Manufacturer: " << manufacturer << endl;
}
// second derived class ///
class Machine : public Inventory
{
char * vendor;
public:
Machine(int, int, double, char *, char *);
~Machine();
void print();
char * get_vendor();
};
Machine::Machine(int q, int r, double p, char * d, char * ven) : Inventory(q, r, p, d)
{
vendor = new char[strlen(ven)+1];
strcpy(vendor,ven);
}
Machine::~Machine()
{
delete vendor;
}
// some implementations may require
{
delete [] vendor;
}
void Machine::print()
{
cout << setiosflags(ios::fixed);
cout << "Vendor: " << vendor << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.