repl.it
@sdemodica/

7.3: Vector Lists

C++

No description

fork
loading
Files
  • main.cpp
  • chores.txt
  • grocery.txt
  • hardwarestore.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;


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

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

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

void displayList();


int main()
{
//the three vectors for list additions in the 'addToList' function
  vector<string> choresAddition;
  vector<string> groceryAddition;
  vector<string> hardwareAddition;

  string listAction,
         addList = "ADD",
         removeFromList = "DEL",
         viewLists = "VLIST";

  
  mainMenu(choresAddition, groceryAddition, hardwareAddition);

  getline(cin, listAction);

//to call the functions
  if(listAction == addList)
  {
    addToList(choresAddition, groceryAddition, hardwareAddition);
  }

  else if(listAction == removeFromList)
  {
    editList(choresAddition, groceryAddition, hardwareAddition);
  }

  else if(listAction == viewLists)
  {
    displayList();
  }

return 0;
}









//main menu function for displaying and decision making
void mainMenu(vector<string> choresAdd, vector<string> groceryAdd, vector<string> hardwareAdd)
{
  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";
  cout << "\nTo view lists, enter 'VLIST'\n";

}








//calling the three vectors
void addToList(vector<string> choresAdd, vector<string> groceryAdd, vector<string> hardwareAdd)
{
//counters
  int count = 0,
      count2 = 0,
      count3 = 0,
      index = 0,
      index2 = 0,
      index3 = 0,
      listChoice;

  string sentinel = "END",
         sentinelQuit = "QUIT",
         returnMain = "RTN",
         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 to add to: '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);
        choresAdd.push_back(item);
    }
    while (item != sentinel);


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

    for (string list : choresAdd)
    {
      outFile << choresAdd[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);
        groceryAdd.push_back(item2);
    }
    while (item2 != sentinel);


    outFile2.open("grocery.txt");

    for (string list : groceryAdd)
    {
      outFile2 << groceryAdd[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);
        hardwareAdd.push_back(item3);
    }
    while (item3 != sentinel);


    outFile3.open("hardwarestore.txt");

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

      index3++;
    }

    outFile3.close();
  }



//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);
  }

}






//to edit lists
void editList(vector<string> choresAdd, vector<string> groceryAdd, vector<string> hardwareAdd)
{
  //Three vectors to use for editing the lists
  vector<string> choresEdit;
  vector<string> groceryEdit;
  vector<string> hardwareEdit;

  int listSelect,
      choresDisplay1,
      choresDisplay2,
      groceryDisplay1,
      groceryDisplay2,
      hardwareDisplay1,
      hardwareDisplay2,
      choresFileIndex,
      groceryFileIndex,
      hardwareFileIndex,
      choresErase,
      groceryErase,
      hardwareErase;

  ofstream outfile;
  ofstream outfile2;
  ofstream outfile3;

//to copy vectors
for (int i=0; i<choresAdd.size(); i++) 
        choresEdit.push_back(choresAdd[i]);

for (int i=0; i<groceryAdd.size(); i++) 
        groceryEdit.push_back(groceryAdd[i]);

for (int i=0; i<hardwareAdd.size(); i++) 
        hardwareEdit.push_back(hardwareAdd[i]);

cout << "\n______________________________________________________\n";
cout << "\nThis is the editing part of the program.\n";
cout << "\nSelect a list to edit\n";

cin >> listSelect;

//edit list1~~~~~~~~~~~~~~~~~~~~~~
if(listSelect == 1)
{
  cout << "\nThese are your current items in your list\n";
  for(string disp : choresEdit)
  {
    cout << choresEdit[choresDisplay1] << endl;

    choresDisplay1++;
  }

  cout << "\nSelect items to delete by entering corresponding column numbers\n";

  cin >> choresErase;

  choresEdit.erase (choresEdit.begin()+choresErase);

//to send contents to chores file
  outfile.open("chores.txt");
  for(string filesend : choresEdit)
  {
    outfile << choresEdit[choresFileIndex];

    choresFileIndex++;
  }
  outfile.close();


  // for(string disp1 : choresEdit)
  // {
  //   cout << choresEdit[choresDisplay2] << endl;

  //   choresDisplay2++;
  // }
}

//edit list2~~~~~~~~~~~~~~~~~~~~~~~
if(listSelect == 2)
{
  cout << "\nThese are your current items in your list\n";
  for(string disp : groceryEdit)
  {
    cout << groceryEdit[groceryDisplay1] << endl;

    groceryDisplay1++;
  }

  cout << "\nSelect items to delete by entering corresponding column numbers\n";

  cin >> groceryErase;

  groceryEdit.erase (groceryEdit.begin()+groceryErase);

//to send content to grocery file
  outfile2.open("grocery.txt");
  for(string filesend2 : groceryEdit)
  {
    outfile << groceryEdit[groceryFileIndex];

    groceryFileIndex++;
  }
  outfile2.close();


  // for(string disp1 : groceryEdit)
  // {
  //   cout << groceryEdit[groceryDisplay2] << endl;

  //   groceryDisplay2++;
  // }
}

//edit list3~~~~~~~~~~~~~~~~~~~~~~~~~
if(listSelect == 3)
{
  cout << "\nThese are your current items in your list\n";
  for(string disp : hardwareEdit)
  {
    cout << hardwareEdit[hardwareDisplay1] << endl;

    hardwareDisplay1++;
  }

  cout << "\nSelect items to delete by entering corresponding column numbers\n";

  cin >> hardwareErase;

  hardwareEdit.erase (hardwareEdit.begin()+hardwareErase);

//to send content to hardwarestore file
  outfile3.open("hardwarestore.txt");
  for(string filesend3 : hardwareEdit)
  {
    outfile << hardwareEdit[hardwareFileIndex];

    hardwareFileIndex++;
  }
  outfile3.close();


  // for(string disp1 : hardwareEdit)
  // {
  //   cout << hardwareEdit[hardwareDisplay2] << endl;

  //   hardwareDisplay2++;
  // }
}
cout << "\n______________________________________________________\n";

}






void displayList()
{
  ifstream infile;
  ifstream infile2;
  ifstream infile3;

  string namesFromChoresFile;

  infile.open("chores.txt");
  while (getline(infile, namesFromChoresFile));
  cout << namesFromChoresFile << endl;
  
}
Fetching token
?