I think I did what everyone said in my other thread and once again, reduced a bunch of errors. I started with 200+ errors but I'm down to around 40. Most of it has to do with the output part in my first function in my cpp file. Another part that is giving me problems now is the last function. I have the errors of that function in the code. My compiler tells me that most of my errors are in the cpp file. Here is what I have now:
header file:
Code:
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
#include <fstream>
using namespace std;
class inventoryItem
{
private:
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
string itemNumber; //a variable that is set when the item is created
public:
/*adds a new item and set itemNumber along with quantity and cost*/
inventoryItem( string n, int q, double c );
inventoryItem::inventoryItem ( string n, int q, double c )
:itemNumber(n), quantity(q), cost(c)
void string erase(string n) {itemNumber = n;} //it will delete the item number
void setQuantity(int q) {quantity = q;} //modifies the quantity of inventory
void setCost(double c) {cost = c;} //modifies the cost of the inventory
int getItemNumber() {return itemNumber;} //gets the item number of the inventory
int getQuantity() {return quantity;} //gets the quantity of the inventory (sold)
int getQuantity2() {return quantity2;} //gets the quantity of the inventory (delievered)
double getCost() {return cost;} //gets the cost of the inventory
double getTotalPrice(); //cost*quantity
};
main file:
Code:
#include <iostream>
#include "Wong_inventoryItem.h"
#include <fstream>
#include <string>
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
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;
}
inventoryItem iItem; //creates inventoryItem object iItem
While (!Input.eof()) //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
cpp file:
Code:
#include "Wong_inventoryItem.h"
#include <fstream>
inventoryItem::inventoryItem ( string n, int q, double c )
{
vector < inventoryItem > inventoryList; //vector to store the inventory item
inventoryItem myItem(n,q,c);
inventoryList.push_back(myItem); //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
inventoryItem::getQuantity( inventoryItem(string n, int q)
{
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 == << c <<"\t" << c * q <<endl;
}
else
{
Error <<"Error: " << n << "not in inventory"<<endl;n) //searchs for the item number
//that the input file has just been read
{
inventoryList[i].setQuantity( inventoryList[i].getQuantity() - q_q);
inventoryItem myItem(n,q,c);
inventoryList.push_back(myItem); //adds inventory number to vector
//itemNumber and cost into vector
cout << n << "\t" << q << "\t" << c <<"\t" << c * q <<endl;
Output << n << "\t" << q << "\t"
}
}
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);
inventoryItem myItem(n,q,c);
inventoryList.push_back(myItem); //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, 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);
inventoryItem myItem(n,q,c);
inventoryList.push_back(myItem); //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;
}
/*
The errors of the following function are:
error C2039: 'erase' : is not a member of 'inventoryItem'
error C2065: 'inventoryList' : undeclared identifier
error C2228: left of '.size' must have class/struct/union type
error C2593: 'operator =' is ambiguous
error C2676: binary '++' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
error C2228: left of '.erase' must have class/struct/union type
errorC3861: 'inventoryList': identifier not found, even with argument-dependent look up
*/
//this function will remove the item number of the product
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(n);
}
else
{
Error <<"Error: " << n << "not in inventory"<<endl;
}
}
return -1;
}
input:
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
I don't understand why it said erase is not part of inventoryItem. I have it in my header file.