Question
I need to build a class (hfile) of this appleList.txt file that will run with this main.cpp file: The list needs to be in UML
I need to build a class (hfile) of this appleList.txt file that will run with this main.cpp file:
The list needs to be in UML format so this:
The main.cpp:
#include
// user made classes #include "apple.h" #include "potato.h"
// using statements using std::cout; using std::cin; using std::endl; using std::vector; using std::ifstream; using std::exit;
// user defined functions int processPotatoFile(vector
int main() { // initial vectors vector
// function to process file processPotatoFile(potatoes); processAppleFile(apples); cout
// display stock list before... cout
// testing functions... // potatoes potatoes[0].setStock(456); potatoes[1].setPrice(1.99); potatoes[2].setType("Purple"); potatoes[2].setOrganic(1);
// apples apples[0].setOrchardLocation("New York, NY"); apples[0].setType("Granny Smith"); apples[2].setPrice(0.45);
// display stock list after... cout
// testing other functions... cout
cout
return 0; }
// processing potato file int processPotatoFile(vector
// initial variables string type, itemID; int quantity, flag; float price;
// static potatoList file infile.open("potatoList.txt");
// checking for file success if(infile.is_open()) { cout
// exits program otherwise else { cout
// loop to read file while(getline(infile, line)) { if(line == "potato") { // initial object // constructor: no parameters Potato temp;
// get potato data... getline(infile, type); getline(infile, itemID); infile >> quantity; infile >> price; infile >> flag;
// ignore newline for next getline... infile.ignore();
// set potato data temp.setType(type); temp.setItemID(itemID); temp.setStock(quantity); temp.setPrice(price); temp.setOrganic(flag);
// add to appropriate vector potatoes.push_back(temp); }
}
return 0; }
int processAppleFile(vector
// initial variables string type, itemID, location; int quantity, flag; float price;
// static appleList file infile.open("appleList.txt");
// checking for file success if(infile.is_open()) { cout
// exits program otherwise else { cout
while(getline(infile, line)) { if(line == "apple") { // get apple data... getline(infile, type); getline(infile, itemID); infile >> quantity; infile >> price; infile >> flag;
// ignore newline... infile.ignore();
// final line... getline(infile, location);
// create object // constructor: with parameters Apple temp(type, location, itemID, quantity, price, flag);
// add to appropriate vector apples.push_back(temp); }
} }
// function to actually display the stock void displayStock(vector displayPotatoStock(potatoes); displayAppleStock(apples); } void displayPotatoStock(vector if(potatoes[i].isOrganic()) { cout else { cout void displayAppleStock(vector if(apples[i].isOrganic()) { cout else { cout Help appleList - Notepad File Edit Format View apple Fuji 0004 345 0.66 1 Salt Lake City, UT apple Pink Lady 0005 53 0.92 Boise, ID apple Red Delicious 0006 345 0.40 Detroit, MI yelers/sellers - all as usual Apple Apple() - standard empty constructor -- takes all items and sets them to their empty counterparts ("" for strings, O for numbers -- false for booleans); statically sets itemName to "Apples" Apple(with parameters) - takes in user parameters to set apple and inventory data equal to; statically sets itemName to "Apples" For organic: see setOrganic standards above getters/setters - act as usual o Hints (UML Cheat Sheet): Each portion of a detailed UML Class diagram contains a different part of the class. There's a section for the name, variables, and functions belonging to the class. A break down of these is found below. Contains the class name Inventory #itemID: string #itemName: string #stock: int #price: float #organic: bool Contains all of the class data attributes Contains the class functions + getitemIDO: string + getitemName(): string + getStock(): int + getPrice(): float + isOrganic(): bool + setitemID(string itemID): void + setStock(int stock): void + setPrice(float price): void + setOrganic(int flag): void + getitem Total(int quantity): float Additionally, each variable and function will be preceded by a symbol: +, -, or #. These refer to where your data will be accessible. Each of those mean the following: - Private + Public #Protected For your variables, each will be followed by the data type they should be initialized as. So, "# itemID: string" should be a protected string variable named itemID. Finally, your functions contain any/all parameters (and their data types!) following the function name. They then are following by a colon and the data type they should return. So," + getStock(): int" should be a public function that has no parameters and retums an integer. Help appleList - Notepad File Edit Format View apple Fuji 0004 345 0.66 1 Salt Lake City, UT apple Pink Lady 0005 53 0.92 Boise, ID apple Red Delicious 0006 345 0.40 Detroit, MI yelers/sellers - all as usual Apple Apple() - standard empty constructor -- takes all items and sets them to their empty counterparts ("" for strings, O for numbers -- false for booleans); statically sets itemName to "Apples" Apple(with parameters) - takes in user parameters to set apple and inventory data equal to; statically sets itemName to "Apples" For organic: see setOrganic standards above getters/setters - act as usual o Hints (UML Cheat Sheet): Each portion of a detailed UML Class diagram contains a different part of the class. There's a section for the name, variables, and functions belonging to the class. A break down of these is found below. Contains the class name Inventory #itemID: string #itemName: string #stock: int #price: float #organic: bool Contains all of the class data attributes Contains the class functions + getitemIDO: string + getitemName(): string + getStock(): int + getPrice(): float + isOrganic(): bool + setitemID(string itemID): void + setStock(int stock): void + setPrice(float price): void + setOrganic(int flag): void + getitem Total(int quantity): float Additionally, each variable and function will be preceded by a symbol: +, -, or #. These refer to where your data will be accessible. Each of those mean the following: - Private + Public #Protected For your variables, each will be followed by the data type they should be initialized as. So, "# itemID: string" should be a protected string variable named itemID. Finally, your functions contain any/all parameters (and their data types!) following the function name. They then are following by a colon and the data type they should return. So," + getStock(): int" should be a public function that has no parameters and retums an integer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started