88: Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: // Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F

 

// Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer.
//     Calculate percentage and grade according to following:
//     Percentage >= 90% : Grade A
//     Percentage >= 80% : Grade B
//     Percentage >= 70% : Grade C
//     Percentage >= 60% : Grade D
//     Percentage >= 40% : Grade E
//     Percentage < 40% : Grade F

#include <iostream>
using namespace std;
int main()
{
    float phy_g, phy_t, chem_g, chem_t, bio_g, bio_t, math_g, math_t, comp_g, comp_t, per;

    cout << "Enter your Physics marks: ";
    cin >> phy_g;
    cout << "Out of: ";
    cin >> phy_t;

    cout << "Enter your Chemistry marks: ";
    cin >> chem_g;
    cout << "Out of: ";
    cin >> chem_t;

    cout << "Enter your Biology marks: ";
    cin >> bio_g;
    cout << "Out of: ";
    cin >> bio_t;

    cout << "Enter your Math marks: ";
    cin >> math_g;
    cout << "Out of: ";
    cin >> math_t;

    cout << "Enter your Computer marks: ";
    cin >> comp_g;
    cout << "Out of: ";
    cin >> comp_t;

    per = (phy_g + chem_g + bio_g + math_g + comp_g) / (phy_t + chem_t + bio_t + math_t + comp_t) * 100;

    switch (per >= 90)
    {
    case 1:
        cout << "You got Grade A";
        break;
    case 0:
        switch (per >= 80)
        {
        case 1:
            cout << "You got Grade B";
            break;

        case 0:
            switch (per >= 70)
            {
            case 1:
                cout << "You got Grade C";
                break;

            case 0:
                switch (per >= 60)
                {
                case 1:
                    cout << "You got Grade D";
                    break;

                case 0:
                    switch (per >= 40)
                    {
                    case 1:
                        cout << "You got Grade E";
                        break;

                    case 0:
                        cout << "You got Grade F";
                        break;
                    }
                    break;
                }
                break;
            }
            break;
        }
        break;

    default:
        cout << "Invalid Input";
        break;
    }

    return 0;
}


Comments

Popular posts from this blog

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345

206: Write a program to create a class named "Circle" which has the property "radius". Define functions to calculate the area and circumference of the circle.

212: Build a class representing a university student with private data members for name, ID, and a static data member for the total number of students. Implement getter and setter functions for name and ID, and a static getter function to retrieve the total number of students. Use default constructors