-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (69 loc) · 1.74 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
73
74
/********************************************************
* CSCI251/851 - Assignment 2
* main.cpp - contains main program + menu function.
* Put you name, login and the date last modified here.
*
*********************************************************/
#include <iostream>
#include <cctype>
#include "ass2.h"
using namespace std;
char Menu();
int main()
{
// Option for redirecting input from input.txt
// Use this when you demo your program to your
// tutor as explained oin the specs.
char RedirectInput[20];
cout << "Redirect input? (y/n): ";
cin.getline(RedirectInput,20);
if(RedirectInput[0]=='y'){ // then get input from input.txt...
FILE *fp = freopen ("input.txt","r",stdin);
if(fp==NULL){cerr<<"\"input.txt\" not found!\n"; exit(1);}
}
bool Quit = false;
do
{
char Cmd = Menu();
switch(Cmd)
{
case 'r':
ReadFile();
break;
case 'd':
DisplayRecords();
break;
case 'a':
AddRecord();
break;
case 's':
SearchRecords();
break;
case 'q':
Quit = true;
break;
default:
cerr << "Invalid command!\n";
}
} while(!Quit);
CleanUp();
if(RedirectInput[0]=='y') fclose (stdin); // close redirected input from input.txt
return 0;
}
char Menu()
{
char Cmd;
cout << "*********************************"<< endl;
cout << "* Phone Records Database *"<< endl;
cout << "* (r)ead data file *"<< endl;
cout << "* (d)isplay records *"<< endl;
cout << "* (a)dd record to DB *"<< endl;
cout << "* (s)earch records *"<< endl;
cout << "* (q)uit *"<< endl;
cout << "*********************************"<< endl;
cout << "Command: ";
cin >> Cmd;
cin.ignore(); // eat up '\n'
Cmd = tolower(Cmd);
return Cmd;
}