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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
//*************************************************************************
int main()
{
//VARIABLES
int cnt = 0; // counter
string studentID; // validated user input for student ID
int targetID; // return numerical value from the called function idSearch
string title; // stored value for the string value of class level
int numTitle;
int cnt1;
// opening the text file CREDIT.txt
ifstream inCreditData;
inCreditData.open(IN_CREDIT_FILE.c_str());
// opening the text file SORTED.txt
ofstream outCreditData;
outCreditData.open(OUT_CREDIT_FILE.c_str());
// array's
string idNum[MAX_ARRAY];
int classLevel[MAX_ARRAY];
// display header
display_header();
// verification that file exists
if (!inCreditData)
{
cout << "The input data file does not exist!" << endl;
cout << "Please verify input file and run the program again!" << endl;
return 5;
}
// calling different functions to compute and display the results
else
{
cout << "File opened successfully! Reading file." << endl << endl;
// function to read data from the text file into the correct array
readCreditFile(inCreditData, idNum, classLevel, cnt);
// function to sort the data in the student ID array (idNum[])
selectSort(classLevel, idNum, cnt);
// function to store sorted data into another array
newSorted(outCreditData, idNum, classLevel, cnt);
// function to display the student ID's
displayID(idNum, cnt);
// function to prompt user for student ID and validate the format
studentID = userInput();
while (studentID != "X" && studentID != "x")
{
// function to search for the student ID
targetID = idSearch (studentID, idNum, cnt);
// convert numeric value to string
// ????????? ?????
// function to display the student information
displayStudentInfo(studentID, numTitle, targetID);
studentID = userInput();
}
}
cin.ignore();
// return EXIT_SUCCESS;
return 0;
}
//***************************************************************************
string studentTitle(int num)
{
string name;
switch (num)
{
case 0:
name = "Freshman";
break;
case 1:
name = "Sophomore";
break;
case 2:
name = "Junior";
break;
case 3:
name = "Senior";
}
return name;
}
//***************************************************************************
void displayStudentInfo(string id , int title, int num)
{
if (num == NOT_FOUND)
cout << "No student with ID " << id << " was found." << endl;
else
cout << "The student with ID " << id << " is a " << title << "." << endl;
return;
}
|