0% found this document useful (0 votes)
6 views

CS101 Assignment#02

The document describes a C++ program that calculates the total and average marks of a student from their marks in four subjects. The program prompts the user to enter their VU ID and marks in CS, Math, Pak Studies and MGT. It then calculates the total and average marks, and assigns a letter grade based on the average. The program outputs the total marks, average marks and final grade.

Uploaded by

Aisha Kanwal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

CS101 Assignment#02

The document describes a C++ program that calculates the total and average marks of a student from their marks in four subjects. The program prompts the user to enter their VU ID and marks in CS, Math, Pak Studies and MGT. It then calculates the total and average marks, and assigns a letter grade based on the average. The program outputs the total marks, average marks and final grade.

Uploaded by

Aisha Kanwal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

VU Id: bc230201788

Name: Aisha Kanwal


Question:
Deciding the Final Grads of various students manually is a tedious and
challenging task. Your job is to develop a C++ program that should be capable
of calculating the Total and Average Marks of a student.
Answer:
#include <iostream>
#include <string>
using namespace std;

int main() {
string vuId;
int cs, math, pakStudy, mgt;

// Input section
cout << "Enter your VU-ID: ";
cin >> vuId;

cout << "Enter Marks for CS: ";


cin >> cs;

cout << "Enter Marks for Math: ";


cin >> math;

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


cin >> pakStudy;

cout << "Enter Marks for MGT: ";


cin >> mgt;
// Calculation section
int totalMarks = cs + math + pakStudy + mgt;
float averageMarks = totalMarks / 4.0;

// Output section
cout << "\nTotal Marks: " << totalMarks << endl;
cout << "Average Marks: " << averageMarks << endl;

// Grading section
string finalGrade;
if (averageMarks >= 91 && averageMarks <= 100)
finalGrade = "A+";
else if (averageMarks >= 81 && averageMarks < 91)
finalGrade = "A-";
else if (averageMarks >= 71 && averageMarks < 81)
finalGrade = "B+";
else if (averageMarks >= 61 && averageMarks < 71)
finalGrade = "B-";
else if (averageMarks >= 51 && averageMarks < 61)
finalGrade = "C";
else if (averageMarks >= 41 && averageMarks < 51)
finalGrade = "D";
else if (averageMarks >= 35 && averageMarks < 41)
finalGrade = "E";
else if (averageMarks >= 0 && averageMarks < 35)
finalGrade = "Fail";
else
finalGrade = "Invalid";

cout << "Final Grade: " << finalGrade << endl;


return 0;
}

You might also like