// UserInterface.cpp
#include <iostream>
#include "DataBase.h"
using namespace std;
using namespace MyRecord;
int menu ();
void addStudent (DataBase& db);
void addDegree (DataBase& db);
void subDegree (DataBase& db);
int main (int argc , char** argv)
{
DataBase studentDB;
bool state = true;
while ( state )
{
switch ( menu() )
{
case 1:
addStudent(studentDB);
break;
case 2:
addDegree(studentDB);
break;
case 3:
subDegree(studentDB);
break;
case 4:
studentDB.displayAll();
break;
case 5:
studentDB.displayPass();
break;
case 6:
studentDB.displayFail();
break;
case 7 :
state = false;
break;
default :
cerr << "Invalid Choice , try Again ...";
break;
}
}
return 0;
}
int menu ()
{
cout << endl << endl << endl;
cout << "Student DataBase " << endl
<< "-----------------" << endl
<< "1) Add Student " << endl
<< "2) Add Degree " << endl
<< "3) Sub Degree " << endl
<< "4) List All Student " << endl
<< "5) List All Pass Student " << endl
<< "6) List All Fail Student " << endl
<< "7) Close DataBase System " << endl
<< "t --> ";
int selection;
cin >> selection;
return selection;
}
void addStudent (DataBase& db)
{
string firstName;
string lastName;
cout << "Enter First Name : ";
cin >> firstName;
cout << "Enter Last Name : ";
cin >> lastName;
int degree;
cout << "Enter Degree : ";
cin >> degree;
try
{
db.addStudent(firstName,lastName,degree);
}
catch (exception ex)
{ cerr << "Unable To Add New Student !n"; }
}
void addDegree (DataBase& db)
{
string firstName;
string lastName;
cout << "Enter First Name : ";
cin >> firstName;
cout << "Enter Last Name : ";
cin >> lastName;
int degree;
cout << "Enter Addtion Degree : ";
cin >> degree;
try
{
Student& s = db.getStudent(firstName,lastName);
s = s + degree;
}
catch (exception ex)
{ cerr << "Unable to Add Degree to Student !n"; }
}
void subDegree (DataBase& db)
{
int number;
cout << "Enter Student Number : ";
cin >> number;
int degree;
cout << "Enter Subtraction Degree : ";
cin >> degree;
try
{
Student& s = db.getStudent(number);
s = s - degree;
}
catch (exception ex)
{ cerr << "Unable to Sub Degree From Student !n"; }
}