repl.it
@sdemodica/

7.3 Practice

C++

No description

fork
loading
Files
  • main.cpp
  • chores.txt
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;


void addToList(vector<string>, vector<string>, vector<string>);

void listEditing(vector<string>, vector<string>, vector<string>);

void displayList1(vector<string>, vector<string>, vector<string>);

void mainMenu(vector<string>, vector<string>, vector<string>);


int main()
{
//the three vectors for list additions in the 'addToList' function
  vector<string> listAddition;
  vector<string> listAddition2;
  vector<string> listAddition3;

//the three vectors for editing the lists using the files in the 'listEdit' function
  vector<string> listEdit;
  vector<string> listEdit2;
  vector<string> listEdit3;

  mainMenu(listAddition, listAddition2, listAddition3);

  addToList(listAddition, listAddition2, listAddition3);

  listEditing(listEdit, listEdit2, listEdit3);

return 0;
}


//main menu function for displaying and decision making
void mainMenu(vector<string> listAddition, vector<string> listAddition2, vector<string> listAddition3)
{
  string listAction,
         addList = "ADD",
         removeFromList = "DEL",
         viewLists = "VLST";

  cout << "___________________________________________________\n";
  cout << "\n~~~~Welcome to the List Manager program!~~~~";
  cout << "\nYou can make your own lists and manage them.";
  cout << "\n__________________________________________________\n";


  cout << "\nTo add items to a list, enter 'ADD'\n";
  cout << "\nTo delete item from a list, enter 'DEL'\n";

  getline(cin, listAction);

//to call the functions
  if(listAction == addList)
  {
    void addToList();
  }

  if(listAction == removeFromList)
  {
    void deleteFromList();
  }

  if(listAction == viewLists)
  {
    void listView();
  }

}



//calling the three vectors
void addToList(vector<string> listAddition, vector<string> listAddition2, vector<string> listAddition3)
{
//counters
  int count = 0,
      count2 = 0,
      count3 = 0,
      index = 0,
      index2 = 0,
      index3 = 0,
      listChoice,
      listChoice2,
      displayIndex = 0,
      displayIndex2 = 0,
      displayIndex3 = 0;

  string sentinel = "END",
         sentinelQuit = "QUIT",
         returnMain = "RTN",
         viewLists = "VLIST",
         endDecision,
         item,
         item2,
         item3;

//the three files
  ofstream outFile;
  ofstream outFile2;
  ofstream outFile3;

  ifstream inFile;
  ifstream inFile2;
  ifstream inFile3;

//to choose list
  cout << "\nEnter a list '1', '2', or '3'\n";

  cin >> listChoice;

//each list gathers items into the cooresponding vector and the outputs the strings to the corresponding list, this is list1
  if(listChoice == 1)
  {
    cout << "\nYou have chosen the 'Chores' list.";
    cout << "\nEnter 'END' when finnished.\n";


    do 
    {
        cout << "Enter an item into the list : " << endl;
        getline(cin, item);
        listAddition.push_back(item);
    }
    while (item != sentinel);


//sends vector entries to the corresponding file
    outFile.open("chores.txt");

    for (string list : listAddition)
    {
      outFile << listAddition[index];

      index++;
    }

    outFile.close();
  }
  
//list2
   if(listChoice == 2)
  {
    cout << "\nYou have chosen the 'Grocery' list.";
    cout << "\nEnter 'end' when finnished.\n";


    do 
    {
        cout << "Enter an item into the list : " << endl;
        getline(cin, item2);
        listAddition2.push_back(item2);
    }
    while (item2 != sentinel);


    outFile2.open("grocery.txt");

    for (string list : listAddition2)
    {
      outFile2 << listAddition2[index2];

      index2++;
    }

    outFile2.close();
  }

//list3
   if(listChoice == 3)
  {
    cout << "\nYou have chosen the 'Hardware Store' list.";
    cout << "\nEnter 'end' when finnished.\n";


    do 
    {
        cout << "Enter an item into the list : " << endl;
        getline(cin, item3);
        listAddition3.push_back(item3);
    }
    while (item3 != sentinel);


    outFile3.open("hardwarestore.txt");

    for (string list : listAddition3)
    {
      outFile3 << listAddition3[index3];

      index3++;
    }

    outFile3.close();
  }

int displaySentinel = -1;

  while(listChoice2 != displaySentinel)
{
  cout << "\n\nEnter '1' to display the Chores list, '2' to display the Grocery\nlist, or '3' to display the Hardware Store list.\n";

  cout << "\nOr enter -1 to continue\n";

cin >> listChoice;

if(listChoice2 == 1)
{
  for(string display1 : listAddition)
  {
    cout << listAddition[displayIndex];

    displayIndex++;
  }
}

if(listChoice2 == 2)
{
  for(string display2 : listAddition2)
  {
    cout << listAddition2[displayIndex2];

    displayIndex2++;
  }
}

if(listChoice2 == 3)
{
  for(string display3 : listAddition3)
  {
    cout << listAddition3[displayIndex3];

    displayIndex3++;
  }
}
}


//this whole block is to make a decision of what to do next
  cout << "\nTo view lists and to return to the main menu, enter 'RTN'\n";
  cout << "To quit the program, enter 'QUIT'\n";

  cin.clear();

  getline(cin, endDecision);

  if(endDecision == returnMain)
  {
    main();
  }

  if(endDecision == sentinelQuit)
  {
    exit(0);
  }

}


void listEditing(vector<string> listEdit, vector<string> listEdit2, vector<string> listEdit3)
{
  int index = 0,
      index2 = 0,
      index3 = 0,
      displayIndex = 0,
      displayIndex2 = 0,
      displayIndex3 = 0;

  ofstream outFile;
  ofstream outFile2;
  ofstream outFile3;

  ifstream inFile;
  ifstream inFile2;
  ifstream inFile3;

  inFile.open("chores.txt");

  while (getline(inFile, listEdit[index]))
  {
    index++;
  }

  inFile.close();

  inFile2.open("grocery.txt");

  while (getline(inFile2, listEdit2[index2]))
  {
    index2++;
  }

  inFile2.close();

  while (getline(inFile3, listEdit3[index3]))
  {
    index3++;
  }

  inFile3.close();

  cout << "These are your lists with your current items.";

  cout << "Chores list:";
  for(string display1 : listEdit)
  {
    cout << listEdit[displayIndex];

    displayIndex++;
  }

  cout << "Grocery list:";
  for(string display2 : listEdit2)
  {
    cout << listEdit2[displayIndex2];

    displayIndex2++;
  }

  cout << "Hardware Store list:";
  for(string display3 : listEdit3)
  {
    cout << listEdit3[displayIndex3];

    displayIndex3++;
  }

}

Fetching token
?