Tuesday, 15 January 2019

Problem No#13 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis | Asad Ali


Problem No#13 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis




/*
Name: Grade Book
Copyright: JanGoO
Author: Asad Ali
Date: 15/01/19 15:37
Description: This program will take input from the user for
the name of each 5 students and then marks obtained by each
of them in each of the four subjects and then program will
operate on these few informations and show the sum, average
percentage and grade of the each student in the exams.
*/

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string student_name[5];
char grades[5] = {'A', 'B', 'C', 'D', 'F'};
int student_marks[5][4];
double sum[5] = {0, 0, 0, 0, 0};
double ave[5] = {0, 0, 0, 0, 0};
double per[5] = {0, 0, 0, 0, 0};

for ( int i = 0; i < 5; i++ )
{
cout << "Name of " << i+1 << " student : ";
cin >> student_name[i];
for ( int j = 0; j < 4; j++ )
{
cout << "Marks of " << student_name[i] << " in subject " << j+1 << " : ";
cin >> student_marks[i][j];
if ( student_marks[i][j] >= 1 && student_marks[i][j] <= 100 )
{
sum[i] = sum[i] + student_marks[i][j];
}
else
{
cout << "Error! Please Enter marks out 100.";
return 0;
}
}
ave[i] = sum[i] / 4;
per[i] = ( sum[i] / 400 ) * 100;
system("cls");
}
cout << endl;
cout << "Name";
for ( int i = 0; i < 4; i++ )
{
cout << "\t Sub1" << i;
}
cout << "\t S  u  m ";
cout << "\t\t averg";
cout << "\t per %";
cout << "\t Grade";
cout << endl;
for ( int i = 0; i < 5; i++ )
{
for ( int j = 0; j < 1; j++ )
{
cout << student_name[i];
}
for ( int j = 0; j < 4; j++ )
{
cout << "\t " << "  " << student_marks[i][j];
}
for ( int j = 0; j < 1; j++ )
{
cout << "\t " << "  " << setprecision(1) << fixed << setw(4) << sum[i];
}
for ( int j = 0; j < 1; j++ )
{
cout << "\t " << "  " << setprecision(1) << fixed << setw(4) << ave[i];
}
for ( int j = 0; j < 1; j++ )
{
cout << "\t " << "  " << setprecision(1) << fixed << setw(4) << per[i];
}
for ( int j = 0; j < 1; j++ )
{
//// cout << "\t " << "  " << grades[i];
if ( per[i] >= 90 && per[i] <= 100 )
{
cout << "\t " << "  " << grades[0];
}
else if ( per[i] >= 80 && per[i] <= 89 )
{
cout << "\t " << "  " << grades[1];
}
else if ( per[i] >= 70 && per[i] <= 79 )
{
cout << "\t " << "  " << grades[2];
}
else if ( per[i] >= 60 && per[i] <= 69 )
{
cout << "\t " << "  " << grades[3];
}
else if ( per[i] >= 0 && per[i] <= 59 )
{
cout << "\t " << "  " << grades[4];
}
else
{
/// Error! Statement
cout << "ERROR!";
}
}
cout << endl;
}
}

/// Code by Asad Ali and officially posted on padacode.blogspot.com

Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
Share:

0 comments:

Post a Comment

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email: asadalipkp9@gmail.com

Have a nice day!

padacode.blogspot.com

Powered by Blogger.