I am a new member, and have been taking c++ classes since January of this year. I am trying to create the program that generates a student status report from the text file. I can get the program to execute, but it won't display the data from the text files, nor the results thereafter.
The following is a .txt file:
John K. Doe
3460 25
Susan S. Andrews
3987 72
Marylin Monroe
2298 87
Arthur C. Gaston
2894 110
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
|
/*
This program should generate a report based on input received from a text
file. Suppose the input text file student_status.txt contains the student’s
name (lastName, firstName middleName), id, number of credits earned.
*/
#include <iostream>
#include <string>
#include <cstdio>
#include <fstream>
using namespace std;
enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR }; //must be written using this
string returnClasslev(class_level);
namespace tys{ //include members of tys
int num_of_credit=0;
string answer="";
class_level deriveClassLevel(int);
void printResult();
}
namespace fys { //including members of fys
int num_of_credits=0;
class_level answer;
class_level deriveClassLevel(int); //should derive the class_level of the student based on the number of credits earned.
void printResult();
}
using namespace fys;
using namespace tys;
int main()
{
string name;
int credits;
int id;
ifstream transferSchoolFile;
transferSchoolFile.open("student_status.txt", ios::in);
while( !transferSchoolFile.eof())
{
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;
//transferSchoolFile.ignore(); //Used here (with ifstream objects) to ignore the newline character.
}
cout<<name<<" "<<id<<" "<<" "<<credits<<" "<<returnClasslev(tys::deriveClassLevel (credits));
return 0;
}
string returnClasslev(class_level status) //should return student status
{
switch(status)
{
case FRESHMAN:
return "Freshman";
break;
case SOPHOMORE:
return "Sopomore";
break;
case JUNIOR:
return "Junior";
break;
case SENIOR:
return "Senior";
break;
default:
;
}
}
class_level tys::deriveClassLevel (int num_of_credits) //derive the class level based on a two year school policy.
{
if( num_of_credits>=0 && num_of_credits<30) //Freshman 0-29 credits
return FRESHMAN;
else //Sophomore 30 or more credits
return SOPHOMORE;
}
class_level fys::deriveClassLevel (int num_of_credits) //derive the class level based on a four year school policy.
{
if(num_of_credits>=0 && num_of_credits<30) //Freshman 0-29 credits
return FRESHMAN;
else if(num_of_credits>=30 && num_of_credits < 60) //Sophomore 30-59 credits
return SOPHOMORE;
else if(num_of_credits>=60 && num_of_credits < 90) //Junior 60-89 credits
return JUNIOR;
else //Senior 90 or more credits
return SENIOR;
}
|
I am trying to output the following while running namespace fys:
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior
...and while running namespace tys:
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Sophomore
Arthur C. Gaston 2894 110 Sophomore
Any suggestions will be appreciated :)