Machine Problem Limiting Function

Hi, I'm almost done with my machine problem. I wrote code to accept students to a university and I have all the criteria for acceptance in and the output looks how I want it to. I just need to add the last step which is that only 5 applicants are to be accepted to the first school and 3 accepted to the second. I'm not sure what to use to limit the acceptances.

To be accepted into Liberal Arts:
No more than 5 people can be accepted.
If a parent is an alumnus, the GPA must be at least 3.0, but if no parents are alumni the GPA must be at least 3.5.
If a parent is an alumnus, the combined SAT score must be at least 1000, but if no parents are alumni the SAT must be at least 1200.

To be accepted into Music:
No more than 3 people can be accepted.
Math and verbal SAT’s must be at least 500.

To my understanding it's first come first serve to those who meet the criteria. Any help would be appreciated!

Here's the content of the text file app.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

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
  #include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
	ifstream inFile("app.txt");

	char school, alumnus;
	double gpa;
	int mathSAT, verbalSAT;
	int combinedSAT = 0;
	int applicant = 1;

	cout << "Acceptance to College by Cailin Ferguson" << '\n' << '\n';

	if (inFile.is_open())
	{
		while (inFile >> school >> gpa >> mathSAT >> verbalSAT >> alumnus)
		{
			cout << "Applicant #" << applicant++ << endl;
			cout << "School:" << school << '\t' << "GPA:" << setprecision (1) << fixed << gpa  << '\t' << "Math:" << mathSAT << '\t' << "Verbal:" << verbalSAT << '\t' << "Alumnus:" << alumnus << '\n';

			combinedSAT = mathSAT + verbalSAT;

			if (school == 'L')
			{
				cout << "Applying to Liberal Arts." << endl;
				if (alumnus == 'Y')
				{
					if (gpa >= 3.0)
					{
						if (combinedSAT >= 1000)
						{
							cout << "Accepted to Liberal Arts." << '\n';
							cout << "*************************" << endl;
						}
						else if (combinedSAT < 1000)
						{
							cout << "Rejected: SAT is too low." << endl;
							cout << "*************************" << endl;
						}
					}
					else if (gpa < 3.0)
					{
						cout << "Rejected: GPA is too low." << endl;
						cout << "*************************" << endl;
					}
				}
				else if (alumnus == 'N')
				{
					if (gpa >= 3.5)
					{
						if (combinedSAT >= 1200)
						{
							cout << "Accepted to Liberal Arts." << endl;
							cout << "*************************" << endl;
						}
						else if (combinedSAT)
						{
							cout << "Rejected: SAT is too low." << endl;
							cout << "*************************" << endl;
						}
					}
					else if (gpa < 3.5)
					{
						cout << "Rejected: GPA is too low." << endl;
						cout << "*************************" << endl;
					}
				}
			}
			if (school == 'M')
			{
				cout << "Applying to Music" << endl;
				if (mathSAT >= 500 && verbalSAT >= 500)
				{
					cout << "Accepted to Music." << '\n';
					cout << "*************************" << endl;
				}
				else
				{
					cout << "Rejected: SAT is too low." << endl;
					cout << "*************************" << endl;
				}
			}
		}
	}
	cout << "There were " << applicant-1 << " applicants in the file." << endl;
	cout << "There were " << " acceptances to Liberal Arts." << endl;
	cout << "There were " << " acceptances to Music." << endl;
}
Last edited on
I'm not sure what to use to limit the acceptances.

You haven't specified what criteria is to be used to limit acceptances. First N applicants to a school (file order)? N applicants with the highest SATs? Highest GPA? Do alumni get preference?

Until you can clearly specify the criteria, it doesn't make sense to code anything.

> I just need to add the last step which is that only 5 applicants are to be accepted to the first school and 3 accepted to the second
So what are the requirements for an applicant to enter the first and the second school?
To be accepted into Liberal Arts:

No more than 5 people can be accepted.
If a parent is an alumnus, the GPA must be at least 3.0, but if no parents are alumni the GPA must be at least 3.5.
If a parent is an alumnus, the combined SAT score must be at least 1000, but if no parents are alumni the SAT must be at least 1200.

To be accepted into Music:
No more than 3 people can be accepted.
Math and verbal SAT’s must be at least 500.

To my understanding it's first come first serve to those who meet the criteria.
Last edited on
To my understanding it's first come first serve to those who meet the criteria.

Simply add a counter for each school. If the max count for a school has been reached, then simply output a message "Admissions for that school are full".

A few observations:
Line 13: Why does applicant start at 1?

Line 38: if (combinedSAT < 1000) is totally unnecessary. If combinedSAT is >= 1000, then the else clause can onlly be < 1000. No need for the additional if statement.

Line 44, 59, 65: ditto



Hi,
Your code looks pretty messy but it should be wise if you write your criteria checking parts in seperate functions instead.

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
void NotifyAcceptedApplicant
(char school, double gpa, int mathSAT, int verbalSAT, char alumnus, int &count)
{
     if(school == 'L')
     cout << "A liberal art applicant accepted!" << endl;
     else
     cout << "A music applicant accepted!" << endl;
     cout << "#" << ++count << ". School:" << school << '\t' << "GPA:" << setprecision (1) << fixed << gpa  << '\t' << "Math:" << mathSAT << '\t' << "Verbal:" << verbalSAT << '\t' << "Alumnus:" << alumnus << '\n\n'; return;
}

void NotifyRejectedApplicant
(char school, double gpa, int mathSAT, int verbalSAT, char alumnus, int &count)
{
     if(school == 'L')
     cout << "A liberal art applicant rejected." << endl;
     else
     cout << "A music applicant rejected." << endl;
     cout << "+ School: " << school << '\t' << "GPA:" << setprecision (1) << fixed << gpa  << '\t' << "Math:" << mathSAT << '\t' << "Verbal:" << verbalSAT << '\t' << "Alumnus:" << alumnus << '\n\n'; return;
}

void LiberalArtAccepting(char school, double gpa, int mathSAT, int verbalSAT, char alumnus, int &count)
{
     if(count > 5) return NotifyRejectedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);

     int combineSAT = mathSAT + verbalSAT;
     if(alumnus == 'Y')
     {
          if(gpa >= 3.0 && combinedSAT >= 1000) return NotifyAcceptedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);
     }    
     else
     {
          if(gpa >= 3.5 && combinedSAT >= 1200) return NotifyAcceptedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);
     }

     return NotifyRejectedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);
}

void MusicAcepting(char, school, double gpa, int mathSAT, int verbalSAT, char alumnus, int &count)
{
     if(count > 3) return NotifyRejectedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);
     
     if(mathSAT >= 500 && verbalSAT >= 500) return NotifyAcceptedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);

return NotifyRejectedApplicant(school, gpa, mathSAT, verbalSAT, alumnus);
}

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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string> 
using namespace std;

const int MAX_LIBERAL = 5;
const int MAX_MUSIC = 3;

bool Rejected (const string & reason)
{   cout << "Rejected: " << reason << endl;
    cout << "******************" << endl;
    return false;
}

bool Accepted (const string & school)
{   cout << "Accepted to " << school << '\n';
	cout << "*************************" << endl;    
	return true;
}

bool LiberalArtsCriteria (int & applicants, char alumnus, int combinedSAT, double gpa)
{   if (applicants >= MAX_LIBERAL) 
        return Rejected ("Liberal Arts admissions full");
	cout << "Applying to Liberal Arts." << endl;
	if (alumnus == 'Y')
	{   if (gpa < 3.0)
	        return Rejected ("GPA is too low."); 		
	    if (combinedSAT < 1000)
	        return Rejected ("SAT is too low.");					       		
	}
	else 
	{   if (gpa < 3.5)
	        return Rejected ("GPA is too low.");
		if (combinedSAT < 1200)
		    return Rejected ("SAT is too low."); 									 		     
	}
	Accepted ("Liberal Arts."); 	
	applicants++;
	return true;
}	

bool MusicCriteria (int & applicants, int mathSAT, int verbalSAT) 
{   if (applicants >= MAX_MUSIC)
	    return Rejected ("Music admissions are full"); 
	cout << "Applying to Music" << endl;
	if (mathSAT < 500 || verbalSAT < 500)
	    return Rejected ("SAT is too low.");
    Accepted ("Music."); 
	applicants++;	     				
	return true;
}
				
int main()
{   ifstream inFile("app.txt");
	char school, alumnus;
	double gpa;
	int mathSAT, verbalSAT;
	int combinedSAT = 0;
	int applicant = 0;
    int liberal_applicants = 0;
    int music_applicants = 0;
    
	cout << "Acceptance to College by Cailin Ferguson" << '\n' << '\n';
	if (! inFile.is_open())
	{   cout << "Could not open input file" << endl;
	    return 1;
	}
	while (inFile >> school >> gpa >> mathSAT >> verbalSAT >> alumnus)
	{   cout << "Applicant #" << ++applicant << endl;
		cout << "School:" << school << '\t' << "GPA:" << setprecision (1) << fixed << gpa  << '\t' << "Math:" << mathSAT << '\t' << "Verbal:" << verbalSAT << '\t' << "Alumnus:" << alumnus << '\n';
		combinedSAT = mathSAT + verbalSAT;

        if (school == 'L')
		{   LiberalArtsCriteria (liberal_applicants, alumnus, combinedSAT, gpa);
		}
		if (school == 'M')
		{   MusicCriteria (music_applicants, mathSAT, verbalSAT);
		}
	}
	cout << "There were " << applicant << " applicants in the file." << endl;
	cout << "There were " << liberal_applicants << " acceptances to Liberal Arts." << endl;
	cout << "There were " << music_applicants << " acceptances to Music." << endl;
}
Thank you so much!! This makes a lot more sense.
Topic archived. No new replies allowed.