0% found this document useful (0 votes)
29 views7 pages

Student Grade Calculator Using C++ Only

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

Student Grade Calculator Using C++ Only

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

Department of Information & Technology

University of Haripur

Student Grade Calculator


Assignment

Submitted to

Muhammad Bilal

Submitted by

Aitezaz Ur Rehman Rajpoot

F23-0517-IT-BS(SE)/UOH

Assignment #02

Software Engineering (C)

Fall, 2024

University of Haripur, Haripur-Pakistan


Objective
This lab assignment is designed to help you practice and understand the following C++
concepts:

• Input and Output Operations: cin, cout


• Variables: Declaration, initialization, and different data types (int, float, double, char,
string)
• Operators: Arithmetic, relational, and logical operators
• Conditional Statements: if, if-else, else if, and switch
Libraries:
- Math Library Functions: cmath library
- String Library Functions: string library and related functions

Description
I created a GPA calculator that calculates GPA based on specific conditions using if-else-if and
switch statements. The user is prompted to enter their name and the marks they receive in each
subject. The program includes the subjects from my second semester. It computes the average
of the marks, and using that average, it determines the GPA through if-else-if statements.
Finally, the program provides feedback based on the GPA obtained by the user using a switch
statement. Additionally, I used a transform function to convert the username to uppercase. The
program turned out to be well and its accuracy and precision are greater than 90%.

Source Code
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>

using namespace std;


int main()
{
cout << "----------Welcome to Grade Calculator----------\n\n";

string student_Name;
float natural_science, arts_humanities, functional_english, social_science,
quantitative_reasoning, islamic_studies;

2
//student name

cout << "Enter your name = ";


getline(cin, student_Name);

//Entering Marks

cout << "\nEnter the score of following subjects\n";

cout << "Natural Science = ";


cin >> natural_science;

cout << "Arts & Humanities = ";


cin >> arts_humanities;

cout << "Functional English = ";


cin >> functional_english;

cout << "Social Science = ";


cin >> social_science;

cout << "Quantitative Reasoning = ";


cin >> quantitative_reasoning;

cout << "Islamic Studies = ";


cin >> islamic_studies;

//Changing name to uppercase

transform(student_Name.begin(), student_Name.end(),
student_Name.begin(),::toupper);

//ouputs of user's input

cout << "\n\nYour Name =" << student_Name;

cout << "\n\nMarks :";


cout << "\nNatural Science = " << natural_science;
cout << "\nArts & Humanities = " << arts_humanities;
cout << "\nFunctional English = " << functional_english;
cout << "\nSocial Science = " << social_science;

3
cout << "\nQuantitative Reasoning = " << quantitative_reasoning;
cout << "\nIslamic Studies = " << islamic_studies;

//Calculating Average

float sum = natural_science + arts_humanities + functional_english +


social_science + quantitative_reasoning + islamic_studies;
float average = sum/6;
cout << "\nAverage = " << round(average);

//Calculatiing GPA using if-else-if

float gpa;

if (average >= 90 && average <= 100)


{
gpa = 4.0;
}

else if(average >= 85 && average <= 89)


{
gpa = 3.8;
}

else if(average >= 80 && average <= 84)


{
gpa = 3.6;
}

else if(average >= 75 && average <= 79)


{
gpa = 3.4;
}

else if(average >= 70 && average <= 74)


{
gpa = 3.2;
}

else if(average >= 65 && average <= 69)


{
gpa = 3.0;
}

4
else if(average >= 60 && average <= 64)
{
gpa = 2.8;
}

else if(average >= 55 && average <= 59)


{
gpa = 2.6;
}

else if(average >= 50 && average <= 54)


{
gpa = 2.4;
}

else if(average >= 45 && average <= 49)


{
gpa = 2.2;
}

else if(average >= 40 && average <= 44)


{
gpa = 2.0;
}

else if(average < 40)


{
cout << "\nFailed.";
}

else
{
cout << "\nInvalid Input.";
}

//gpa output

cout << "\nGPA = " << gpa;

//feedback using switch

5
int gpa_int = gpa *10;

string feedback;

switch (gpa_int)
{
case 40:
feedback = "Excellent Work (A+)";
break;

case 39:
case 38:
case 37:
case 36:
case 35:
feedback = "Very Good (A-)";
break;

case 34:
case 33:
case 32:
case 31:
case 30:
feedback = "Good (B)";
break;

case 29:
case 28:
case 27:
case 26:
case 25:
feedback = "Fair (C)";
break;

case 24:
case 23:
case 22:
case 21:
case 20:
feedback = "Pass (D)";
break;

default:

6
feedback = "Fail (F)";
break;
}

//feedback output

cout << "\nFeedback = " << feedback;

return 0;
}

Output
----------Welcome to Grade Calculator----------

Enter your name = Aitezaz ur Rehman Rajpoot

Enter the score of following subjects


Natural Science = 78
Arts & Humanities = 91
Functional English = 85
Social Science = 89
Quantitative Reasoning = 92
Islamic Studies = 91

Your Name = AITEZAZ UR REHMAN RAJPOOT

Marks :
Natural Science = 78
Arts & Humanities = 91
Functional English = 85
Social Science = 89
Quantitative Reasoning = 92
Islamic Studies = 91
Average = 88
GPA = 3.8
Feedback = Very Good (A-)

The End

You might also like