206k views
10 votes
In this lab, you use the flowchart and pseudocode found in the figures below to add code to a partially created C++ program. When completed, college admissions officers should be able to use the C++ program to determine whether to accept or reject a student, based on his or her test score and class rank.

start input testScore,
classRank if testScore >= 90 then if classRank >= 25 then output "Accept"
else output "Reject" endif else if testScore >= 80
then if classRank >= 50 then output "Accept" else output "Reject" endif
else if testScore >= 70
then if classRank >= 75 then output "Accept"
else output "Reject"
endif else output "Reject"
endif
endif
endif
stop
Study the pseudocode in picture above. Write the interactive input statements to retrieve: A student’s test score (testScore) A student's class rank (classRank) The rest of the program is written for you. Execute the program by clicking "Run Code." Enter 87 for the test score and 60 for the class rank. Execute the program by entering 60 for the test score and 87 for the class rank.
[comment]: <> (3. Write the statements to convert the string representation of a student’s test score and class rank to the integer data type (testScore and classRank, respectively).)
Function: This program determines if a student will be admitted or rejected. Input: Interactive Output: Accept or Reject
*/ #include using namespace std; int main()
{ // Declare variables
// Prompt for and get user input
// Test using admission requirements and print Accept or Reject
if(testScore >= 90)
{ if(classRank >= 25)
{ cout << "Accept" << endl; }
else
cout << "Reject" << endl; }
else { if(testScore >= 80)
{ if(classRank >= 50)
cout << "Accept" << endl;
else cout << "Reject" << endl; }
else { if(testScore >= 70)
{ if(classRank >=75) cout << "Accept" << endl;
else cout << "Reject" << endl; }
else cout << "Reject" << endl; } } } //End of main() function

User Kimberly
by
3.4k points

1 Answer

8 votes

Answer:

The equivalent program in C++:

#include<iostream>

#include <sstream>

using namespace std;

int main(){

string Score, Rank;

cout<<"Enter student score and class rank: ";

cin>>Score>>Rank;

int testScore = 0, classRank = 0;

stringstream sstream(Score);

sstream>>testScore;

stringstream tream(Rank);

tream>>classRank;

if (testScore >= 90){

if(classRank >=25){cout<<"Accept";}

else{cout<<"Reject";}

}

else if(testScore >= 80){

if(classRank >=50){cout<<"Accept";}

else{cout<<"Reject";}

}

else if(testScore >= 70){

if(classRank >=75){cout<<"Accept";}

else{cout<<"Reject";}

}

else{cout<<"Reject";}

return 0;

}

Step-by-step explanation:

This declares Score and Rank as string variables

string Score, Rank;

This prompts the user for score and class rank

cout<<"Enter student score and class rank: ";

This gets the user input

cin>>Score>>Rank;

This declarees testScore and classRank as integer; and also initializes them to 0

int testScore = 0, classRank = 0;

The following converts string Score to integer testScore

stringstream sstream(Score);

sstream>>testScore;

The following converts string Rank to integer classRank

stringstream tream(Rank);

tream>>classRank;

The following conditions implement the conditions as given in the question.

If testScore >= 90

if (testScore >= 90){

If classRank >=25

if(classRank >=25){cout<<"Accept";}

If otherwise

else{cout<<"Reject";}

} ---

If testScore >= 80

else if(testScore >= 80){

If classRank >=50

if(classRank >=50){cout<<"Accept";}

If otherwise

else{cout<<"Reject";}

}

If testScore >= 70

else if(testScore >= 70){

If classRank >=75

if(classRank >=75){cout<<"Accept";}

If otherwise

else{cout<<"Reject";}

}

For testScore less than 70

else{cout<<"Reject";}

User ZimZim
by
3.7k points