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;
}
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
<em> stringstream sstream(Score);</em>
<em> sstream>>testScore;</em>
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
<em> if (testScore >= 90){</em>
If classRank >=25
<em> if(classRank >=25){cout<<"Accept";}</em>
If otherwise
<em> else{cout<<"Reject";}</em>
<em> } ---</em>
If testScore >= 80
<em> else if(testScore >= 80){</em>
If classRank >=50
<em> if(classRank >=50){cout<<"Accept";}</em>
If otherwise
<em> else{cout<<"Reject";}</em>
<em> }</em>
If testScore >= 70
<em> else if(testScore >= 70){</em>
If classRank >=75
<em> if(classRank >=75){cout<<"Accept";}</em>
If otherwise
<em> else{cout<<"Reject";}</em>
<em> }</em>
For testScore less than 70
<em> else{cout<<"Reject";}</em>
<em />