//
// NAME
// asgn1.cpp
//
// DESCRIPTION
// This file contains the functions in the Main module.
// This module contains the top-level functions of the program.
// They display a menu, read the user input, and carry out the
// user's request.
//
//
// Include files.
//
#include <iostream.h>
#include "bool.h"
#include "person.h"
#include "plist.h"
//
// Function prototypes.
//
static void displayMenu();
static void doAdd();
static void doPrint();
static void doEmpty();
//
// NAME
// main
//
// DESCRIPTION
// This function is the top-level function of the program. It
// displays a menu, reads the user's input, then carries out the
// user's request.
//
// PARAMETERS
// (none)
//
// RETURNS
// 0
//
int main() {
char choice = '1'; // Menu choice enter by the user.
bool done = false; // true = we are finished.
while (!done) {
displayMenu();
cin >> choice;
switch (choice) {
case '1': doAdd(); break;
case '2': doPrint(); break;
case '3': doEmpty(); break;
case '4': done = true; break;
}
}
return 0;
}
//
// NAME
// displayMenu
//
// DESCRIPTION
// This function displays the menu to the standard output.
//
// PARAMETERS
// (none)
//
// RETURNS
// (none)
//
static void displayMenu() {
cout << endl;
cout << "1. Add person" << endl;
cout << "2. Print list" << endl;
cout << "3. Empty list" << endl;
cout << "4. Quit" << endl;
cout << endl;
cout << "> ";
return;
}
//
// NAME
// doAdd
//
// DESCRIPTION
// This function reads a person from the standard input stream
// then adds then person to the list of people.
//
// PARAMETERS
// (none)
//
// RETURNS
// (none)
//
static void doAdd() {
person p;
readPerson(p);
addToEnd(p);
return;
}
//
// NAME
// doPrint
//
// DESCRIPTION
// This function prints the list of people to the standard output
// stream. It loops through the list, retrieving and printing each
// person. After all people in the list have been printed, it
// prints the number of people in the list.
//
// PARAMETERS
// (none)
//
// RETURNS
// (none)
//
static void doPrint() {
person p;
int count = 0;
bool done = false;
done = !getFirst(p);
while (!done) {
printPerson(p);
count++;
done = !getNext(p);
}
cout << "There are " << count << " people in the list." << endl;
return;
}
//
// NAME
// doEmpty
//
// DESCRIPTION
// This function empties the list of people.
//
// PARAMETERS
// (none)
//
// RETURNS
// (none)
//
static void doEmpty() {
clearList();
return;
}
//
// End of file.
//