Thanks to zuk and Daved and elad for giving me some pointers and insights. Like one of them said to get the idea before I start putting them into code, I did and they're in code. Except the codes are really I guess. I tried to run it and gave me a list of lots of errors. The program is suppose to be an inventoryItem class that calculates data. It reads from input.txt and the input file has
command Item Number Quantity Cost Total cost (cost*quantity)
The commands are:
add - adds a new product number, price and quantity of that item to a vector
sold - finds the product number, and decrease the quantity based on the the amount that the input file has
deliver - finds the product number, and increase the quantity based on the the amount that the input file has
priceChange - finds the product number and changes the price
remove - removes the itemNumber from the inventory
Here is what I have as of now
The header file:
The calculation file:Code:class inventoryItem { private: string itemNumber; //a variable that is set when the item is created int quantity; //the variable that represents number of items currently in stock int cost; //the per-unit price of the item int totalCost; //total inventory cost of the item public: void inputnewItem(string n) //adds a new item and set itemNumber only :itemNumber(n) /*adds a new item and set itemNumber along with quantity and cost*/ void inventoryItem( string n, int q, double c ) :itemNumber(n), quantity(q), cost(c) void string erase(); //it will delete the item number void int setQuantity(); //modifies the quantity of inventory void double setCost(); //modifies the cost of the inventory int getItemNumber(); //gets the item number of the inventory int getQuantity(); //gets the quantity of the inventory (sold) int getQuantity2(); //gets the quantity of the inventory (delievered) double getCost(); //gets the cost of the inventory double getTotalPrice(); //cost*quantity };
The main:Code:#include "Wong_inventoryItem.h" #include <iostream> #include <vector> #include <iomanip> #include <fstream> using namespace std; void inventoryItem::inventoryItem ( string n, int q, double c ) { vector < inventoryItem > inventoryList; //vector to store the inventory item inventoryList.push_back( n, q, c); //adds inventory number to vector cout << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; Output << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; } //this function will change the quantity number of the product int inventoryItem::getQuantity( string n, int q, double c ) { string getQuantity( const vector <inventoryItem> &inventoryList, string n); string i = 0; int q_q = 0; void swap (int q_q, int q); //swaps the read from input quantity into q_q int c = q_q; q_q = q; q = c; for ( i = 0; i < inventoryList.size(); i++) { if (inventoryList[i].getQuantity == n) //searchs for the item number //that the input file has just been read { inventoryList[i].setQuantity( inventoryList[i].getQuantity() - q_q); iventoryList.push_back( n, q, c ); //stores the new quantity along with //itemNumber and cost into vector cout << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; Output << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; } else { Error <<"Error: " << n << "not in inventory"<<endl; } } return -1; } //this function will change the quantity number of the product int inventoryItem::getQuantity2( string n, int q) { string getQuantity2(const vector <inventoryItem> &inventoryList, string n); string i = 0; int q_q = 0; void swap (int q_q, int q); //swaps the read from input quantity into q_q int c = q_q; q_q = q; q = c; for ( i = 0; i < inventoryList.size(); i++) { if (inventoryList[i].getQuantity2 == n) //searchs for the item number //that the input file has just been read { inventoryList[i].setQuantity( inventoryList[i].getQuantity2() + q_q); iventoryList.push_back( n, q, c ); //stores the new quantity along with //itemNumber and cost into vector cout << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; Output << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; } else { Error <<"Error: " << n << "not in inventory"<<endl; } } return -1; } //this function will change the price of the product double inventoryItem::getCost( string n, int q, double c ) { string getCost(const vector <inventoryItem> &inventoryList, string n); string i = 0; double c_c = 0; void swap (double c_c, double c); //swaps the read from input price into c_c int d = c_c; c_c = c; c = d; for ( i = 0; i < inventoryList.size(); i++) { if (inventoryList[i].getCost == n) //searchs for the item number //that the input file has just been read { inventoryList[i].setCost(c); iventoryList.push_back( n, q, c ); //stores the new quantity along with //itemNumber and cost into vector cout << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; Output << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl; } else { Error <<"Error: " << n << "not in inventory"<<endl; } } return -1; } //this function will remove the item number of the product void inventoryItem::erase( string n ) { string erase(const vector <inventoryItem> &inventoryList, string n); string i = 0; for ( i = 0; i < inventoryList.size(); i++) { if (inventoryList[i].erase == n) //searchs for the item number //that the input file has just been read { inventoryList[i].erase(c); } else { Error <<"Error: " << n << "not in inventory"<<endl; } } return -1; }
And the input file:Code:#include "Wong_inventoryItem.h" #include <iostream> #include <vector> #include <iomanip> #include <fstream> using namespace std; int main () { string command; //reads commands from the input file string holditemNumber; //variable to hold the item number int holdquantity; //variable that will hold the return of quantity double holdcost; //variable that will hold the return of the cost of product double holdtotalcost; //variable that will hold the return of the total cost string findvecbyitemnumber(vector <inventoryItem> &L, string n); //searches for a vector by inventory item number inventoryItem iItem; //creates inventoryItem object iItem ifstream Input ("input.txt"); //declares the input file "Input" if (!Input) { cerr <<"Cannot open the file input.txt"<<endl; //checks to see if input file is opened successfully return 0; } ofstream Output ("Wong_inventory.txt"); //declares the output file "Output" if (!Output) { cerr <<"Cannot open the file Wong_inventory.txt"<<endl; //checks to see if output file is opened successfully return 0; } ofstream Error ("Wong_log.txt"); //declares the error output file "Error" if (!Error) { cerr <<"Cannot open the file Wong_log.txt"<<endl; //checks to see if Error file is opened successfully return 0; } While (!Input()) //keeps reading the lines of the input file until the end { Input>>command; if (command == "add") //if it reads add, inventoryItem will run { Input >> holditemNumber >> holdquantity >> holdcost; iItem.inventoryItem(holditemNumber, holdquantity, holdcost); } else if (command == "sold") //if it reads sold, getQuantity will run { Input >> holditemNumber >> holdquantity; iItem.getQuantity(holditemNumber, holdquantity); } else if (command == "delievered") //if it reads delievered, getQuantity2 //will run { Input >> holditemNumber >> holdquantity; iItem.getQuantity2(holditemNumber, holdquantity); } else if (command == "priceChange") //if it reads priceChange, getCost //will run { Input >> holditemNumber >> holdcost; iItem.getCost(holditemNumber, holdcost); } else if (command == "remove") //if it reads remove, { Input >> holditemNumber; iItem.erase(holditemNumber); } } //ends while loop Input.close(); //we close the input file Output.close(); //we close the output file Error.close(); //we close the error file return 0; } //end of main
Code:add 123456789123 12.65 50 add 123456789123 12.65 50 add 123456789124 12.65 50 add 123456789125 12.65 50 add 123456789126 12.65 50 delivered 123456789123 50 delivered 123456789123 1 sold 123456789123 2 delivered 123456789123 1 sold 123456789123 100 sold 123456789123 99 sold 123456789123 5 remove 123456789124 sold 123456789124 5 delivered 123456789127 50 sold 123456789128 50 priceChange 123456789123 10.99 priceChange 123456789128 10.99 remove 123456789128



LinkBack URL
About LinkBacks


