Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program. Business is booming for Luigi and Gina LaMota and their automotive parts business. They would like you to help them keep track of

C++ Program.

Business is booming for Luigi and Gina LaMota and their automotive parts business. They would like you to help them keep track of the items that sell the best. To do this, you will need to write a program that will read data from a file and determine the item that produces the most revenue for a certain category. These best selling items and all the information pertaining to them will be written out to a file and delivered to Luigi and Gina.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

I need this program to open .txt file which contains:

"Category","Description","Price","Manufacturer","QtySold","CarBrand","CarModel","CarYear","Material","Watts","Weight","Type","Quarts","Size","Warranty" "Oil","Max Life Motor Oil","30.99","Valvoline","44","","","","","","5W-20","Synthetic Blend","5","","" "Oil","Mobil Super Motor Oil","7.49","Mobil","322","","","","","","0W-20","Synthetic","1","","" "Brakes","Thermoquiet Disc Brake Pads","26.44","Wagner","76","Honda","Accord","2012","Ceramic","","","","","","" "Brakes","Thermoquiet Disc Brake Pads","23.39","Wagner","101","Chrysler","LeBaron","2001","Ceramic","","","","","","" "Brakes","Quietcast Disc Brake Pads","29.00","Bosch","203","Nissan","Quest","2012","Organic","","","","","","" "Oil","Heavy Duty Motor Oil","5.29","Shell","354","","","","","","10W-30","Conventional","1","","" "Oil","Max Life Motor Oil","30.99","Valvoline","44","","","","","","5W-20","Synthetic Blend","5","","" "Oil","GTX Motor Oil","30.99","Castrol","52","","","","","","5W-20","Synthetic Blend","5","","" "Tires","Altimax","89.99","General","14","","","","","","","","","P225/70R16","60000" "Lights","SilverStar Headlight Bulb","26.99","Sylvania","342","Honda","Civic","1993","","60","","","","","" "Lights","XtraVision Headlight Bulb","14.99","Sylvania","533","Ford","Fiesta","2014","","55","","","","","" "Brakes","Professional Disc Brake Pads","44.56","AC Delco","123","Infiniti","J30","2007","Ceramic","","","","","","" "Brakes","ProACT Premium Disc Brake Pads","149.85","Akebono","99","Lexus","LS460","2012","Ceramic","","","","","","" "Oil","Advanced Durability Motor Oil","5.49","Quaker State","201","","","","","","10W-40","Conventional","1","","" "Oil","Long Life Motor Oil","4.99","Pennzoil","351","","","","","","10W-30","Conventional","1","","" "Oil","High Mileage Motor Oil","6.49","Valvoline","154","","","","","","10W-40","Conventional","1","","" "Brakes","Professional Grade Disc Brake Pads","39.15","Raybestos","45","Ford","Taurus","1998","Ceramic","","","","","","" "Brakes","HiPerform Disc Brake Pads","33.52","BrakeBest","144","Jeep","Wrangler","2013","Carbon Metallic","","","","","","" "Lights","SilverStar ULTRA Headlight Bulb","44.99","Sylvania","128","Toyota","Corolla","2015","","60","","","","","" "Lights","TruVision Headlight Bulb","32.99","Bosch","172","Chevrolet","Cavalier","2004","","60","","","","","" "Lights","Headlight Bulb","9.99","EiKO","621","Nissan","Altima","2014","","60","","","","","" "Oil","Mobil 1 Motor Oil","36.99","Mobil","39","","","","","","0W-20","Synthetic","5","",""

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Count how many categorys and print out the data as following to new file:

** Brakes ** Description: Price: Manufacturer: QtySold: Car: Brand: Model: Year: Material: ** Lights ** Description: Price: Manufacturer: QtySold: Car: Brand: Model: Year: Watts: ** Oil ** Description: Price: Manufacturer: QtySold: Weight: Type: Quarts: ** Tires ** Description: Price: Manufacturer: QtySold: Size: Warranty:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is what I've got so far:

#include #include #include #include #define PARTINFO_CNT 15

using namespace std;

class Car { public: Car(string b, string m, int y); int getYear(); string getBrand(); string getModel();

private: string brand; string model; int year; };

class Parts { public: Parts(string m, double p, string d, int q); string getManu(); double getPrice(); string getDesc(); int getQty();

private: string manufacture; double price; string description; int quantity;

};

class Brakes : public Parts { public: Brakes(string m, double p, string d, int q, , string mat); string getMaterial();

private: string material; };

class Lights : public Parts { public: Lights(string m, double p, string d, int q, int w); int getWatts();

private: int watts; };

class Oil : public Parts { public: Oil(string m, double p, string d, int q, int qty, string t, string w); int getQuarts(); string getType(); string getWeight();

private: int quarts; string type; string weight; };

class Tires : public Parts { public: Tires(string m, double p, string d, int q, , int w, string s); int getWarranty(); string getTires(); private: int warranty; string size;

};

void parseLineToTokens(string lineText, string tokens[]);

int main() { //open the file from which to read the data ifstream FileIn("Parts_List.txt"); if (!FileIn) { cerr << "Unable to open File!" << endl; exit(1); } else cout << "1. File Opend!" << endl << endl;

//call a global function to find out how many objects of each type to create cout << "2. Counting how many objects of each type to create" << endl; countObjects(ifstream &FileIn);

//create arrays to contain the necessary objects

//global function to read information from the file into the arrays of objects

//call functions to find the best selling item for each category, output best to a file

//close the file explicitly }

void countObjects(ifstream &InFile) { int totalLines; string line = ""; string NumLine[PARTINFO_CNT];

int BrakesCount = 0; int OilCount = 0; int LightsCount = 0; int TiresCount = 0;

for (int i = 0; i < totalLines; i++) { if (NumLine[0] == "Brakes") { BrakesCount++; } else if (NumLine[1] == "Oil") { OilCount++; } else if (Category.compare("\"Lights\"") == 0) { LightsCount++; } else if (Category.compare("\"Tires\"") == 0) { TiresCount++; } } }

Car::Car(string b, string m, int y) :brand(b), model(m), year(y) {}

string Car::getBrand() { return brand; }

string Car::getModel() { return model; }

int Car::getYear() { return year; }

Parts::Parts(string m, double p, string d, int q) :manufacture(m), price(p), description(d), quantity(q) {}

string Parts::getManu() { return manufacture; }

int Parts::getPrice() { return price; }

string Parts::getDesc() { return description; }

int Parts::getQty() { return quantity; }

Brakes::Brakes(string m, double p, string d, int q, string mat) :Parts(m, p, d, q), material(mat) {}

string Brakes::getMaterial() { return material; }

Lights::Lights(string m, double p, string d, int q, int w) :Parts(m, p, d, q), watts(w) {}

int Lights::getWatts() { return watts; }

Oil::Oil(string m, double p, string d, int q, int qty, string t, string w) :Parts(m, p, d, q), quarts(qty), type(t), weight(w) {}

int Oil::getQuarts() { return quarts; }

string Oil::getType() { return type; }

string Oil::getWeight() { return weight; }

Tires::Tires(string m, double p, string d, int q, int w, string s) :Parts(m, p, d, q), warranty(w), size(s) {}

int Tires::getWarranty() { return warranty; }

string Tires::getTires() { return tires; }

// Parse a line of text into tokens and store them in an array of strings void parseLineToTokens(string lineText, string tokens[]) { int end, start;

start = -2; for (int j = 0; j < PARTINFO_CNT; j++) { start = start + 3; end = lineText.find('"', start); tokens[j] = lineText.substr(start, end - start); start = end; } }

// Notes: // // Example: // To create an array of 'cnt' Books items, where 'cnt' can only be determined at the time the program is run: // Books *booksList; // booksList = new Books[cnt]; // // // To go back and read from the beginning of the file that was already opened and read till the EOF // bookFile.clear(); // reset the EOF state // bookFile.seekg(0, ios::beg); // set pointer at the beginning of the file

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions