0% found this document useful (0 votes)
44 views4 pages

CS 101 Assignment 2

The document contains the code solution for CS 101 Assignment #2. The code prompts the user to enter their VU-ID and marks for 4 subjects. It then calculates the total, average, and grade based on the average. Conditional statements are used to determine the grade based on the average marks ranging from A+ to Fail.

Uploaded by

Muzamil Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

CS 101 Assignment 2

The document contains the code solution for CS 101 Assignment #2. The code prompts the user to enter their VU-ID and marks for 4 subjects. It then calculates the total, average, and grade based on the average. Conditional statements are used to determine the grade based on the average marks ranging from A+ to Fail.

Uploaded by

Muzamil Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CS 101

Assignment # 2
Sloution:
Code :

#include <iostream>

using namespace std;

int main ()
{
string vuID;
int csMarks, mathMarks, pakstudyMarks, mgtMarks;

cout << "Enter your VU-ID: ";


cin >> vuID;

cout << "Enter marks for CS: ";


cin >> csMarks;

cout << "Enter marks for Math: ";


cin >> mathMarks;

cout << "Enter marks for Pak Study: ";


cin >> pakstudyMarks;
cout << "Enter marks for MGT: ";
cin >> mgtMarks;

int totalMarks = csMarks + mathMarks + pakstudyMarks + mgtMarks;


double averageMarks = static_cast<double>(totalMarks) / 4.0;

cout << " VU-ID: " << vuID << endl;


cout << " Total Marks: " << totalMarks << endl;
cout << " Average Marks: " << averageMarks << endl;

if (averageMarks >= 91 && averageMarks <= 100)


{
cout << "Grade: A+" << endl;
}
else if (averageMarks >= 81 && averageMarks <= 91)
{
cout << "Grade: A-" << endl;
}
else if (averageMarks >= 71 && averageMarks <= 81)
{
cout << "Grade: B+" << endl;
}
else if (averageMarks >= 61 && averageMarks <= 71)
{
cout << "Grade: B-" << endl;
}
else if (averageMarks >= 51 && averageMarks <= 61)
{
cout << "Grade: C" << endl;
}
else if (averageMarks >= 41 && averageMarks <= 51)
{
cout << "Grade: D" << endl;
}
else if (averageMarks >= 35 && averageMarks <= 41)
{
cout << "Grade: E" << endl;
}
else if (averageMarks >= 0 && averageMarks <= 34)
{
cout << "Fail" << endl;
}
else
{
cout << "Invalid average marks. Please check the input." << endl;
}

return 0;
}

You might also like