/*
***************************************************************
*
* MainProg.cpp
*
***************************************************************
*/
// standard library includes
#include <deque>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cctype>
// private includes
#include "project.h"
using std::cout;
using std::cin;
using std::endl;
using std::string;
// Function Prototypes
void display_record_menu();
void display_all(bool do_teachers, bool do_students);
void add_record();
void add_person(bool is_student);
void delete_record();
void delete_all_records();
void delete_surname(const string &surname);
void search_record();
void search_surname(const string &surname);
void save_records();
void load_records();
void record_report();
// Global variables
std::deque<Person*> persons; // Person Base Class Container
Person *pPerson; // Base class pointer
// Program code
/*
******************************************************
* Function: main
* return: int
* parameters: none
*
* Description:
* Start of the program. This function will display
* the Main Menu.
*
******************************************************
*/
int main() {
char option; // User input
do{
// Display the Main Menu
cout << endl << endl;
cout << endl << "MAIN MENU";
cout << endl << "---------";
cout << endl << "(A)dd a record";
cout << endl << "(D)elete a record";
cout << endl << "(C)lear all records";
cout << endl << "(S)earch a record";
cout << endl << "Displa(Y) records";
cout << endl << "Sa(V)e records to disk";
cout << endl << "(L)oad records from disk";
cout << endl << "(R)eport list contents" << endl;
cout << endl << "(Q)uit the Program" << endl << endl;
cout << endl << "Enter Selection" << endl;
cin >> option;
option = static_cast<char>(std::toupper(option));
switch (option) {
case 'A':
// The user wants to add records
add_record();
break;
case 'D':
// The user wants to delete record
delete_record();
break;
case 'C':
// The user wants to delete all the records.
delete_all_records();
break;
case 'S':
// The user wants to search a record
search_record();
break;
case 'Y':
// The user wants to display records on the screen
display_record_menu();
break;
case 'V':
// The user wants to save the records to disk
save_records();
break;
case 'L':
// The user wants to load a record file
load_records();
break;
case 'R':
// Report on what we have saved
record_report();
break;
case 'Q':
// Delete all records in Container 'persons' before exiting.
persons.clear();
break;
default:
cout << endl << "Invalid choice.";
break;
}
}while (option != 'Q'); // loop until user enters 'q' or 'Q'
return 0;
}
/*
******************************************************
* Function: display_record_menu
* return: void
* parameters: none
*
* Description:
* This function will display the menu which is used
* to control record display
*
******************************************************
*/
void display_record_menu() {
char option;
do{
// Display the display Record System menu
cout << endl << endl;
cout << endl << "display RECORD SYSTEM MENU";
cout << endl << "------------------------";
cout << endl << "display all (T)eachers";
cout << endl << "display all (S)tudents";
cout << endl << "display (A)ll Students and Teachers" << endl;
cout << endl << "Press (Q)uit to return to the Main Menu" << endl;
cout << endl << "Enter Selection" << endl;
cin >> option;
option = static_cast<char>(std::toupper(option));
switch (option) {
case 'T':
// display all teacher records
display_all(true, false);
break;
case 'S':
// display all student records
display_all(false, true);
break;
case 'A':
// display all teacher and student records
display_all(true, true);
break;
default:
cout << endl << "Invalid choice.";
break;
}
}while (option != 'Q'); // loop until user enters 'q' or 'Q'
cout << endl << "Returning to the Main Menu." << endl;
}
/*
******************************************************
* Function: delete_Record
* return: void
* parameters: none
*
* Description:
* This function will prompt the user to enter the surname
* of the record to delete.
*
******************************************************
*/
void delete_record() {
string search_surname;
char option;
do {
cout << endl << "DELETE SURNAME. " << endl;
cout << endl << "---------------" << endl;
cout << endl <<"Enter the Surname of the record you want to delete, or '.' to exit" << endl;
cin >> search_surname;
// cin.get(); // retrieve the final "ENTER" and discard
if (search_surname == ".")
return;
// Call the function vDelete_Surname to delete the record
delete_surname(search_surname);
// flush the standard input buffer
//std::fflush(stdin);
cout << endl << "Do you want to delete another record [Y/N]? " << endl;
cin >> option;
option = static_cast<char>(std::toupper(option));
}while (option != 'N'); // Continue deleting until user enters 'N' or 'n'
}
/*
******************************************************
* Function: delete_all_records
* return: void
* parameters: none
*
* Description:
* This function will clear the entire list of records, after
* first confirming the user's choice
*
******************************************************
*/
void delete_all_records() {
char option;
cout << endl << "Are you sure you want to delete all the records [Y/N]? " << endl;
cin >> option;
option = static_cast<char>(std::toupper(option));
if (option == 'Y') {
persons.clear();
cout << "All records deleted" << endl;
}
else
cout << "Deletion aborted" << endl;
}
/*
******************************************************
* Function: delete_surname
* return: void
* parameters: const string &surname
*
* Description:
* This function will search the existing records
* to find which record matches the user-entered
* surname, then delete the record.
*
******************************************************
*/
void delete_surname(const string &surname) {
unsigned int i = 0;
// Loop around all student and teacher records
// for a match on the surname.
for (i = 0; i < persons.size(); i++) {
pPerson = persons[i];
// Compare the surname field of the record at
// index i with the user input record.
if ((surname.compare(pPerson->get_surname()) == 0)) {
cout << endl << "Deleting the following Record." << endl;
pPerson->display_info();
pPerson->display_other_info();
// Set the pointer to 0, then delete the record.
pPerson = 0;
persons.erase(persons.begin() + i);
return;
}
}
// If we get here then the record was not found.
// Let the user know.
cout << endl << "The Surname " << surname << " was not found." << endl;
}
/*
******************************************************
* Function: add_record
* return: void
* parameters: none
*
* Description:
* This function will add a single record. The
* function will prompt the user to add either a
* Student record or a Teacher record.
*
******************************************************
*/
void add_record() {
char option = 0;
cout << endl << "ADD RECORD MENU";
cout << endl << "---------------";
cout << endl << "Enter (T) to add a Teacher record.";
cout << endl << "Enter (S) to add a Student record." << endl;
cin >> option;
option = static_cast<char>(std::toupper(option));
try {
switch(option) {
case 'T':
// Add a single teacher record
cout <<
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论











收起资源包目录





































































































共 553 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论

ChadSong
- 粉丝: 0
- 资源: 2

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制
