Input a string from user in the following format: Name_RollNo_GPA.
Now perform string tokenization operation on this string to separate the Roll no and GPA. Now based on those values perform the following operations:
If the Roll no is greater than 120 or less than 1 then print: Record does not exist.
Otherwise:
If the GPA is greater than or equal to 3.75 then print Faculty Honors
If GPA is less than 3.75 and greater than 3.5 then print: Excellent.
If GPA is less than 3.5 and greater than 3 then print: Good.
If GPA is greater than 2.7 and less than 3 then print: Satisfactory.
If GPA is less than 2.7 then print: You should work hard.
Note: You can call built in function
#include<bits/stdc++.h>
using namespace std;
int main()
{
int f=1;
string input;
string Name,rollstring,gpastring;
int roll_no;
float gpa;
cout<<"Enter data in the following format: Name_RollNo_GPA : ";
getline(cin,input);
vector <string> tokens;
stringstream check1(input);
string intermediate;
while(getline(check1, intermediate, '_'))
{
tokens.push_back(intermediate);
}
Name=tokens[0];
rollstring=tokens[1];
gpastring=tokens[2];
roll_no=stoi(rollstring);
gpa=stof(gpastring);
if(roll_no>120 || roll_no<1)
{
cout<<"\nRecord does not exist ";
}
else
{
cout<<"\nName : "<<Name<<"\nRoll Number : "<<roll_no<<"\nCGPA : "<<gpa;
cout<<"\nRemarks : ";
if(gpa>=3.75)
{
cout<<"Faculty Honors ";
}
if(gpa<3.75 && gpa>3.50)
{
cout<<"Excellent ";
}
if(gpa<=3.5 && gpa>3)
{
cout<<"Good ";
}
if(gpa<=3 && gpa>2.7)
{
cout<<"Satisfactory ";
}
if(gpa<=2.7)
{
cout<<"You should work hard ";
}
}
}
Comments
Leave a comment