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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
// declare enumerated type globally
enum studentLevel {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR};
// Global constants
const int MAX_ARRAY = 3;
const string IN_CREDIT_FILE = "CREDITS.txt";
const string OUT_CREDIT_FILE = "OUT_CREDITS.txt";
// prototypes
void display_header();
void readCreditFile (ifstream&, string [], string [], int&);
studentLevel studentNum (int);
string studentTitle (studentLevel);
double highestExpense ();
double aboveAverageExpense ();
void displayExpenses ();
//*************************************************************************
// FUNCTION: main
// DESCRIPTION: Asks user for a base number, then calls functions to read
// an exponent and compute the base raised to the exponent, and
// then displays the results. Loops, requesting numbers until
// user enters zero for base.
// OUTPUT: Return Value: 0 on success
// CALLS TO: GetPositiveNum, CalcAnswer
//*************************************************************************
int main()
{
//VARIABLES
int cnt = 0; // counter used for employee coverage
int cnt1;
double empAverage; // return value from the called function averageExpense for employee average
double famAverage; // return value from the called function averageExpense for family average
double empHighest; // return value from the called function highestExpense for employee average
double famHighest; // return value from the called function highestExpense for family average
double empAbove; // return value from the called function aboveAverageExpense for employee average
double famAbove; // return value from the called function aboveAverageExpense for family average
// opening the text file medical.txt
ifstream inCreditData;
inCreditData.open(IN_CREDIT_FILE.c_str());
// array's
string idNum [MAX_ARRAY];
string classLevel [MAX_ARRAY];
// 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;
readCreditFile (inCreditData, idNum, classLevel, cnt);
}
return 0;
}
//*************************************************************************
// FUNCTION: readCreditFile
// DESCRIPTION: reads data from a text file into two arrays called fam[]
// and emp[]. Data is transfered into
//*************************************************************************
void readCreditFile (ifstream& inCreditData, string idNum [], string classLevel [], int& cnt)
{
string studentId; // stored value for the students ID number
char ch; // stored value for the students status
int classesTaken; // number of credits completed by student
studentLevel num; // the numerical value of the function studentClass;
string title; // stored value from the function studentClass
bool arrayFull = false; // check to see if there is still space in the array idNum[]
while(inCreditData && cnt <= MAX_ARRAY)
{
inCreditData >> studentId >> ch >> classesTaken;
if (ch == 'U' && !arrayFull)
{
idNum[cnt] = studentId;
num = studentNum (classesTaken); // beginning of the enum
title = studentTitle (num);
classLevel[cnt] = title;
cnt++;
if (cnt >= MAX_ARRAY)
{
arrayFull = true;
cout << "Error: only the first " << MAX_ARRAY
<< " students will be read." << endl << endl;
}
}
}
inCreditData.close();
return;
}
//*************************************************************************
// FUNCTION: studentClass
// DESCRIPTION: reads data from a text file into two arrays called fam[]
//*************************************************************************
studentLevel studentNum (int numCredits)
{
studentLevel title;
if(numCredits < 32)
studentLevel title = FRESHMAN;
else if (numCredits >= 32 && numCredits <= 63)
studentLevel title = SOPHOMORE;
else if (numCredits >= 64 && numCredits <= 95)
studentLevel title = JUNIOR;
else
studentLevel title = SENIOR;
return title;
}
//***************************************************************************
string studentTitle (studentLevel level)
{
string name;
switch (level)
{
case 0:
name = "Freshman";
break;
case 1:
name = "Sophomore";
break;
case 2:
name = "Junior";
break;
case 3:
name = "Senior";
}
return name;
}
|