Coding C++ Simple Member Function

by - August 01, 2013



try out the lab quastion
The suggested output is as shown below.

class Marks {
private:
    string name;
    float gpa;
    char grade;
public:
    string set_name()
    {
        cout << "===================================\n";
        cout << "ENTER INFORMATION \n";
        cout << "===================================\n";
        cout << "Enter name : ";
        getline(cin, name);
        return name;
    }
    float set_gpa()
    {
        cout << "Enter CGPA : ";
        cin >> gpa;
        return gpa;
    }
    char set_grade()
    {
        if (gpa >= 3.00 && gpa <= 4.00) {
            grade = 'A';
        }
        else if (gpa >= 2.00 && gpa <= 2.99) {
            grade = 'B';
        }
        else if (gpa >= 0.00 && gpa <= 1.99) {
            grade = 'F';
        }
        return grade;
    }
};
void main()
{
    Marks M;
    string n;
    float gp;
    char gr;
    n = M.set_name();
    gp = M.set_gpa();
    gr = M.set_grade();
    cout << "\n===================================\n";
    cout << " RESULT SLIP \n";
    cout << "=================================== \n";
    cout << "Name : " << n << endl;
    cout << "GPA : " << gp << endl;
    cout << "Grade : " << gr << endl;
    system("PAUSE");
}

You May Also Like

0 comments