In: Computer Science
Many prestigious universities have a system called a “Legacy Preference System” which is used to decide which applicants should be accepted to the university. If an applicant’s parent is an alumnus of the university, the applicant will be admitted with lower GPA and SAT scores than if the parent is not an alumnus. (There is currently a lot of discussion about the fairness of this system, but universities get a lot of money from their alumni so they are unwilling to change it!!)
Your assignment for MP2 is to implement a computerized system like this for a very small prestigious university. The university has two schools, Liberal Arts and Music, each with their own criteria for accepting students. Your program must read in certain information about an applicant and print a message saying whether the applicant should be accepted or not.
The criteria for acceptance are:
Liberal Arts
Music – no preferences for alumni here.
Your program must accept as input the school the student is applying to (L or M), their high school grade point average, their math SAT score, their verbal SAT score and whether or not either parent is an alumnus (Y or N). The program must process several applicants, echoing the data for each applicant and printing a message indicating if the student was accepted to the school they were applying to. If they were not accepted, the message should indicate why. This message only has to indicate one reason for failure in cases of multiple disqualifications. Acceptances are to be made in the order received so that if a school is full, a later applicant cannot be accepted even if they happen to have better qualifications than an earlier one. You do NOT have to check for bad data coming from the file – assume that it is in the required format and has appropriate values.
The data file is arranged with the information for each applicant on a separate line. Your program must process the data until the end of file is reached, at which time the program must print out the total number of applicants and the number of acceptances to each school. The data file should be created by you. Create the file and store it in the same project folder as your program. Please turn in a hard copy of this file along with your program and output.
SUGGESTION You should design, compile, run and debug your program in stages. You might start by testing if your program can just read and echo the data file. After this is working accurately move on to identifying the school the person is applying to, then continue to add more of the details. Remember to use good style with consistent indentation, plenty of comments, good variable names etc. and don't forget to echo the data as it is read. The output must be clear and readable with appropriate string constants and spacing. Here is an example of the input data file:
L 4.0 600 650 N
M 3.9 610 520 N
L 3.8 590 600 N
…
Sample output from the first few lines of the example data file
follows:
Acceptance to College by (your name)
Applicant #: 1
School = L GPA = 4.0 math = 600 verbal = 650 alumnus = N
Applying to Liberal Arts
Accepted to Liberal Arts!!!
*******************************
Applicant #: 2
School = M GPA = 3.9 math = 610 verbal = 520 alumnus = N
Applying to Music
Accepted to Music!!
*******************************
Applicant #: 3
School = L GPA = 3.8 math = 590 verbal = 600 alumnus = N
Applying to Liberal Arts
Rejected - SAT is too low
*******************************
…
There were xx applicants in the file
There were xx acceptances to Liberal Arts
There were xx acceptances to Music
Press any key to continue
Use the following input file for your program, notice there is exactly 14 applicants, make sure you display the counts at the end of your output as in the sample above.
mp2accept.txt
L 4.0 600 650 N
M 3.9 610 520 N
L 3.8 590 600 N
L 3.0 600 600 Y
L 3.4 600 600 N
L 3.0 500 490 Y
L 2.9 500 500 Y
M 3.5 500 490 Y
M 3.9 490 600 Y
L 3.5 700 500 N
L 3.1 600 400 Y
L 3.0 490 510 Y
L 4.0 800 800 Y
M 3.2 500 500 N
here is my solution;(i don't know where I am wrong, I couldn't open up the mp2accept file)
#include <iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
//prompt the user for input
int x;
ifstream inputFileX;
inputFileX.open("Cis161:\\assignment2\\mp2accept.txt");// this
fstream is to read the data from the file
getline(inputFileX, line);
string mp2accept,line;
if (inputFileX.good() == false) {
cout << "Unable to open the
file named " << mp2accept;
exit(1);
}
while (true) {
getline(inputFileX, line);
if (inputFileX.eof()) break;
FILE OUTPUT
cout <<
line << endl;
//prompt the user for input
char school; // character variable for school and
alumunus
bool LiberalArts = false, Music = true;
int Math, Verbal; // Integer variable for SAT
score
int SAT;
float GPA; // float variable for GPA
char Alumunus;// character variable for alumunus
// is the student accepted either LiberalArts or
Music school
const int LiberalArtslimit = 5; // limits for counting
accepted and total applicants
const int Musiclimit = 3;
int LiberalArtsNum, MusicNum;
filename = "mp2accept.txt"; //opening file
// conitinuing extracting data
until end of the file
if (LiberalArtsNum ==
LiberalArtslimit)// checking for availability of seats
{
cout <<
"Sorry there is no avaialble seats\n";
return 1;
}
// Checking for other requirements
includes GPA
if ((GPA < 3.0 &&
Alumunus == 'Y') || (GPA < 3.5 && Alumunus ==
'N'))
{
cout << "Rejected" <<
endl;// print a messsage 'GPA is too low for art school'
}
if ((Math + Verbal < 1000 && Alumunus ==
'Y') || (Math + Verbal < 1200 && Alumunus == 'N'))
{
cout <<
"Rejected" << endl; //print a message'SAT is too low for art
school'
}
else
{
cout <<
"Applicant is accepted to LiberalArts" << endl;
LiberalArtsNum++; //counter for accepted applicant in LiberalArt
school
}
}
// iF appliacnt applied to Music school, checking
requirements
if (MusicNum == Musiclimit)// checking for
availability of seats
{
cout << "Sorry there is no
avaialble seats\n";
return 1;
}
else if (Math < 500) {
cout << "Rejected" <<
endl;// print a message'Math score is too low for admsission'
}
else if (Verbal < 500) {
cout << "Rejected" <<
endl;// print a message'Verbal score is too low for
admsission'
}
else
{
cout << "Accepted to Music"
<< endl;
MusicNum++; // count applicants
accepted in Music school
}
cout <<
"*******************************\n";
//Print overall output
cout << "There were" <<applicant
count<< "Applicants in the file" << endl;
cout << "There were" << LiberalArtsNum
<< "Applicants accepted in LiberaLArts" << endl;
cout << "There were" << MusicNum <<
"Applicants accepted in Music School" << endl;
return 0;
//Modified the code to have correct functioning.
//Be careful to place enter at the end of text file otherwise the code will not access the last element.
//START_PROGRAM
#include <iostream>
#include<fstream>
#include <sstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
char school; // character variable for school and alumunus
int Math, Verbal; // Integer variable for SAT score
int SAT;
int applicant_count=1;
float GPA; // float variable for GPA
char Alumunus;// character variable for alumunus
// is the student accepted either LiberalArts or Music
school
const int LiberalArtslimit = 5; // limits for counting accepted and
total applicants
const int Musiclimit = 3;
int LiberalArtsNum=0, MusicNum=0;
std::stringstream stream(std::stringstream::in |
std::stringstream::out); //to parse the string line
into saperate variables.
int x;
string mp2accept,line;
ifstream inputFileX;
inputFileX.open("mp2accept.txt"); // this fstream is to read the
data from the file
getline(inputFileX, line);
if (inputFileX.good() == false) {
cout << "Unable to open the file named " <<
mp2accept;
exit(1);
}
while (true) {
getline(inputFileX, line);
if (inputFileX.eof())
break;
cout << line << endl;
stream <<line;
//sending line string to
stream.
stream>>school>>GPA>>Math>>Verbal>>Alumunus;
//getting saperate variables from stream.
cout<<"Applicant #: "<<
applicant_count;
applicant_count++;
cout<<"School=
"<<school<<" GPA= "<<GPA<<"
Math="<<Math<<" Verbal="<<Verbal<<"
Alumnus="<<Alumunus<<endl; //showing each
value saperately.
if(school=='L')
//If applied to Liberal Arts
school
{
cout<<"Applying to Liberal Arts"<<endl;
if (LiberalArtsNum == LiberalArtslimit)//
checking for availability of seats
{
cout << "Sorry there is no avaialble
seats\n"<<endl;
return 1;
}
int accepted2arts=1;
//0 means rejected to Arts. 1 means accepted. this flag is used to
check the status of acceptance.
// Checking for other requirements includes GPA
if ((GPA < 3.0 &&
Alumunus == 'Y') || (GPA < 3.5 && Alumunus ==
'N'))
{
cout << "Rejected: GPA is too
low for Liberal Arts school"<<endl;
accepted2arts=0;
//means that application is
rejected.
}
if ((Math + Verbal
< 1000 && Alumunus == 'Y') || (Math + Verbal < 1200
&& Alumunus == 'N'))
{
cout << "Rejected: SAT is too low for Liberal
Arts school"<<endl;
accepted2arts=0;
//means that application is rejected.
}
if(accepted2arts==1)
//accepted2arts is still 1. this means that
application is accepted.
{
cout << "Applicant is accepted to LiberalArts"
<< endl;
LiberalArtsNum++; //counter for accepted applicant in
LiberalArt school
}
cout <<
"*******************************\n";
}
if(school=='M')
// if applicant applied to Music school, checking
requirements
{
cout<<"Applying to
Music"<<endl;
int accepted2mus=1;
//0 means rejected to take
Liberal Arts. 1 means application accepted.
if (MusicNum == Musiclimit)// checking for
availability of seats
{
cout << "Sorry there is no avaialble
seats\n";
return 1;
}
else if (Math < 500) {
cout << "Rejected: Math score is too low for
admsission"<<endl;
accepted2mus=0;
//means that application is
rejected.
}
else if (Verbal < 500) {
cout << "Rejected: Verbal score is too low for
admsission"<<endl;
accepted2mus=0;
//means that application is
rejected.
}
if(accepted2mus==1)
//accepted2mus is still 1.
this means that application is accepted.
{
cout << "Accepted to Music" << endl;
MusicNum++; // count applicants accepted in Music
school
}
cout <<
"*******************************\n";
}
}
//Print overall output
cout << "There were " <<applicant_count<< "
Applicants in the file" << endl;
cout << "There were " << LiberalArtsNum << "
Applicants accepted in LiberaLArts" << endl;
cout << "There were " << MusicNum << " Applicants
accepted in Music School" << endl;
return 0;
}
//END_PROGRAM
INPUT FILE:
should be placed in the same folder.
L 4.0 600 650 N
M 3.9 610 520 N
L 3.8 590 600 N
L 3.0 600 600 Y
L 3.4 600 600 N
L 3.0 500 490 Y
L 2.9 500 500 Y
M 3.5 500 490 Y
M 3.9 490 600 Y
L 3.5 700 500 N
L 3.1 600 400 Y
L 3.0 490 510 Y
L 4.0 800 800 Y
M 3.2 500 500 N
OUTPUT: