Question: please help me.This is in C++. I got the simple problem and the more complex but I dont know how to modify yet to get
please help me.This is in C++. I got the simple problem and the more complex but I dont know how to modify yet to get to th even more complex one.
Create a program that makes a grocery list. You will need an array of strings. You dont know how many items will be on your list.
Simple problem: User tells you how many items, then tells you the items. You display the items for the user.
More complex problem: User tells you how many items, then tells you the items. You display the items for the user. At the end of the program, write the grocery list to a text file called grocery.txt.
Even more complex problem: If grocery.txt exists, read it into an array and display to the user. User then tells you how many more items, and then tells you the items. You display all the items for the user. At the end of the program, write the grocery list to a text file called grocery.txt.
========================================================================================================================================
#include
int main() { string items[MAX]; int n,more_items = 0;
cout << "Enter number of items: "; cin >> n; cin.ignore(); //ask the user about each item name for (int i = 0; i < n; i++) { cout << "item" << i + 1 << " :"; getline(cin, items[i]); } print(items, n); ofstream out; //open Grocery file for writing out.open("Grocery.txt"); //check if file is open if (!out) { cout << "file can't be open for writing" << endl; } //write items to file for (int i = 0; i < n; i++) { out << items[i] << endl; } //out << EOF; out.close(); }
//function definitin for displaying item list void print(string s[],int n) { cout << " Display items: " << endl; for (int i = 0; i < n; i++) { cout << i+1<<". " << s[i] << endl; }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
