-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
72 lines (67 loc) · 1.84 KB
/
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
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <cstdlib>
#include <algorithm>
#include "record.h"
#define clearScreen system ( "CLS" )
using namespace std;
int menu ()
{
string title = "Menu" ;
string choices[] = {"Enter new record", "Edit a record", "Display all records" ,"Delete" ,"Exit"};
cout << '\t' << title << '\n' ;
cout << '\t' << setfill('-') << setw(title.length()) ;
for (int i=0; i<5; i++)
cout << "\n" << i+1 << "\t" << choices[i] << "\n";
cout << "\nEnter your choice : ";
return getInt();
}
int main()
{
char fname[] = "Record.txt";
// load record from file to vector
vector<Record> phoneBook = getDataFromFile(fname);
Record rec;
int choice = menu();
while (true){
clearScreen;
if (not phoneBook.empty()){
sort(phoneBook.begin(),phoneBook.end(),cmp);
}
switch(choice){
case 1:
rec.getData();
phoneBook.push_back(rec);
cout << "\nRecord added.\n" ;
break;
case 2:
phoneBook = editRecord(phoneBook);
cout << "\nRecord updated.\n" ;
break;
case 3:
displayAll(phoneBook);
break;
case 4:
phoneBook = deleteRecord(phoneBook);
cout << "\nRecord deleted.\n" ;
break;
case 5:
writeToFile(phoneBook,fname);
phoneBook.clear();
return 0;
break;
default :
cout << "\nInvalid Choice ! \nRetry :\n" ;
break;
}
// wait for user
getchar();
clearScreen;
choice = menu();
}
}