I'm pretty new to programming in C++, and I need help with this lab for school. If someone could point me in the right direction that would be great!
Here is the assignment...
Write a program to 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 as follows :
Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;
and define two namespace globalTypes (tys and fys) for the function :
class_level deriveClassLevel(int num_of_credits) ;
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.
Four Year School Policy:
Freshman 0-29 credits Sophomore 30-59 credits
Junior 60-89 credits Senior 90 or more credits
Two Year School Policy:
Freshman 0-29 credits Sophomore 30 or more credits
and this is the code I have so far...
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
|
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
enum class_level {FRESHMAN, SOPHOMORE,JUNIOR,SENIOR};
class_level classLevel;
namespace tys
{
class_level deriveClassLevel(int num_of_credits)
{
if (num_of_credits >= 0 && num_of_credits <= 29)
{
classLevel = FRESHMAN;
} else if (num_of_credits >= 30)
{
classLevel = SOPHOMORE;
}
}
}
namespace fys
{
class_level deriveClassLevel(int num_of_credits)
{
if (num_of_credits >= 0 && num_of_credits <= 29)
{
classLevel = FRESHMAN;
} else if (num_of_credits >= 30 && num_of_credits <= 59)
{
classLevel = SOPHOMORE;
} else if (num_of_credits >= 60 && num_of_credits <= 89)
{
classLevel = JUNIOR;
} else if (num_of_credits >= 90)
{
classLevel = SENIOR;
}
}
}
using namespace fys;
int main()
{
string level = "";
deriveClassLevel(30);
switch (classLevel)
{
case FRESHMAN:
level = "Freshman";
break;
case SOPHOMORE:
level = "Sophomore";
break;
case JUNIOR:
level = "Junior";
break;
case SENIOR:
level = "Senior";
break;
}
system("pause");
return 0;
}
|
My main question is did I use the namespaces and enum correctly? And my second question is whats the best way to input the data from the text file? This is really where I get stuck.