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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
enum level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR};
const string STUD_REC = "CREDITS.TXT";
const int MAX_NUM = 999;
void ifUnder(int hrs, string idNum, string idArray1[MAX_NUM], int classLevel1[MAX_NUM]); //if undergraduate, this will fill the arrays with the data
// and apply the enumerated value to it.
void sortArrays(string array1[MAX_NUM], int array2[MAX_NUM], int count1);
int sortData(string idArray[MAX_NUM], int classLevel[MAX_NUM]);//goes through data and calls the ifUnder function if necessary
int main()
{
string id[MAX_NUM];
int claLevel[MAX_NUM];
int counter;
cout << "This program will convert hours taken to class level for all"
"Undergraduate students. You will be able to search for each student by"
"the student ID number." << endl << endl;
counter = sortData(id, claLevel);
cout << counter;
cout << endl;
return 0;
}
int sortData(string idArray[MAX_NUM], int classLevel[MAX_NUM])
{
string id;
char stuType;
double hours;
ifstream studData;
int count = 0;
studData.open (STUD_REC.c_str()); // open the file for reading
if(studData) //If the file opens successfully
{
studData >> id >> stuType >> hours; //priming read
while(studData) // while an id was successfully read
{
if((stuType == 'U') || (stuType == 'u'))
{
ifUnder(hours, id, idArray, classLevel);
count++;
}
studData >> id >> stuType >> hours; //attempt to read next line
}
}
return count;
}
void ifUnder(int hrs, string idNum, string idArray1[MAX_NUM], int classLevel1[MAX_NUM])
{
int array1Count = 0;
int array2Count = 0;
level idLevel;
if(0 <= hrs < 32)
{
idLevel = FRESHMAN;
}
else if(32 <= hrs <= 63)
{
idLevel = SOPHOMORE;
}
else if(64 <= hrs <= 95)
{
idLevel = JUNIOR;
}
else if(96 <= hrs)
{
idLevel = SENIOR;
}
idArray1[array1Count] = idNum;
array1Count++;
classLevel1[array2Count] = idLevel;
array2Count++;
}
void sortArrays(string array1[MAX_NUM], int array2[MAX_NUM], int count1)
{
int i, j, first;
string temp;
for (i = count1 - 1; i > 0; i--)
{
first = 0; // initialize to subscript of first element
for (j=1; j<=i; j++) // locate smallest between positions 1 and i.
{
if (array1[j] < array1[first])
first = j;
}
temp = array1[first]; // Swap smallest found with element in position i.
array1[first] = array1[i];
array1[i] = temp;
}
}
|