Answer to Question #188878 in C++ for Asad

Question #188878

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 



1
Expert's answer
2021-05-11T12:22:18-0400
#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 ";
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS