i need to read from text file.
this is what inside the text file: (name, code, price)
EG:
Fish F0001 5
chicken C0001 7
beef B0001 6
etc
i need to print it out as a menu. and then add/delete it to/from Order list.
for example i input 1 and 2, it will add chicken C0001 7,and beef B0001 6 into Order list.
and calculate total price.
sorry i am new and here is my code i write to read the file and get the name (only), it look pretty logic to me but it is not doing anything.. where the problem is at?
OO based doesn't mean you have to blindly make a class. The way you can do this, is by storing the values in a class object. So make a class like this:
1 2 3 4 5 6 7
class Item
{
public:
std::string name;
long code;
double price;
}
And then create instances (objects)of this class to store the data you read from a file. That would be OO.
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
vector<Item> allItems;
while(//till the end of the file)
{
//read file here, then save the data in a class
Item tempItem;
tempItem.name = //name from the file;
tempItem.code = //code from the file;
tempItem.price = //price from the file;
allItems.push_back(tempItem); //add this item to the array of items
}