Monday, June 21, 2021

Overall Average Grade Solver in C++

 A simple overall average grade solver that I wrote using C++ programming language. I am using codeblocks to run my program.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360








Program Listing

#include <iostream>

#include <iomanip>

#include <cmath>

#include <string>


#define EXIT_IF(cnd, msg) if(cnd){std::cerr << msg; exit(1);}


std::string get_performance(double grade)

{

if (grade < 70)

return "Poor";

else if(grade <= 74)

return "For Improvement";

else if (grade <= 80)

return "Good";

else if (grade <= 90)

return "Very good";

else

return "Excellent";

}


int main()

{

constexpr int num_grades = 5;

int num_students = 0, student, grade;

double sum , total_sum = 0.0;


std::cout << "Number of students in the class? ";

std::cin >> num_students;

std::cin.ignore(255, '\n');

EXIT_IF(num_students < 0, "Invalid Input: Please enter a nonnegative integer.");

for (student = 0; student < num_students; ++student)

{

sum = 0.0;

for (grade = 0; grade < num_grades; ++grade)

{

std::cout << "Grade of Student #" << student + 1 << " in Subject " << grade + 1 << ": ";

int tmp;

std::cin >> tmp;

EXIT_IF(tmp < 0, "Invalid Input: Please enter a nonnegative integer.");

sum += tmp;

}

double avg = std::round(sum / num_grades);

std::cout << "Average of Student " << student + 1 << " is : " << avg << "\n";

total_sum += avg;

}

double class_average = total_sum / num_students;

std::cout << std::fixed << std::setprecision(2) <<

"Class Average Grade is : " << class_average << "\n";

std::cout << "Class Performance is " << get_performance(class_average) << "\n";

}


No comments:

Post a Comment