76 964
Assignments Done
98,5%
Successfully Done
In June 2019

Answer to Question #50451 in C++ for Ehab

Question #50451
Write a program that can enter marks for number of students and calculate their Total and class
average with the following format

((((((((((((((((((((((((((((WITHOUT using functions))))))))))))))))))))))))))))))))))

The inputs:

ID (As 1 dimension array of Integers), First (As1 dimension array of Doubles), Second (As 1 dimension
array of Doubles), Final (As 1 dimension array of Doubles), Total (As 1 dimension array of Doubles), Grad
(As 1 dimension array of Chars)
The Grades are: A for 90’s, B for 80’s, C for 70’s, D for 60’s and F for less than 60.


Example of the output:
St_Nm ID First Second Final Total Grade
1 20071156 15.5 16.5 30.1 62.1 D
2 20071154 15.0 16.5 30.1 62.6 D

Class average for 10 students is: 72.5
Expert's answer
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int numOfStudents;
cout << "Enter number of students: ";
cin>>numOfStudents; // read number of students
int arrID[numOfStudents]; // create array of integers for ID
double arrFirst[numOfStudents]; // create array of double for first marks
double arrSecond[numOfStudents]; // create array of double for second marks
double arrFinal[numOfStudents]; // create array of double for final marks
double arrTotal[numOfStudents]; // create array of double for total marks
char arrGrade[numOfStudents]; // create array of chars grades
double sum = 0; // sum of total marks
cout << "Input data for each student." << endl << endl;
for (int i = 0; i < numOfStudents; i++) {// for each student
cout << "Students " << i + 1 << ": " << endl;
cout << " ID: ";
cin >> arrID[i]; // read id
cout << " First mark: ";
cin >> arrFirst[i]; // read first mark
cout << "Second mark: ";
cin >> arrSecond[i]; // read second mark
cout << " Final mark: ";
cin >> arrFinal[i]; // read final mark
arrTotal[i] = arrFirst[i] + arrSecond[i] + arrFinal[i]; // calculate total mark
sum += arrTotal[i]; // add total mark to the sum
// compute grade
if (arrTotal[i] >= 90)
arrGrade[i] = 'A';
else if (arrTotal[i] >= 80)
arrGrade[i] = 'B';
else if (arrTotal[i] >= 70)
arrGrade[i] = 'C';
else if (arrTotal[i] >= 60)
arrGrade[i] = 'D';
else arrGrade[i] = 'F';
cout << endl;
}
cout << endl;
double average = sum / numOfStudents; // calculate average class mark
cout.setf(ios::fixed);
cout.precision(1); // set output precision
// print header of the table
cout << "-------------------------------------------------------------" << endl;
cout << setw(2) << "#" << setw(10) << "ID" << setw(8) << "First"
<< setw(8) << "Second" << setw(8) << "Final" << setw(8)
<< "Total" << setw(6) << "Grade" << endl;
cout << "-------------------------------------------------------------" << endl;
// print table of stdents with marks and grades
for (int i = 0; i < numOfStudents; i++) {
cout << setw(2) << i + 1 << setw(10) << arrID[i] << setw(8) << arrFirst[i]
<< setw(8) << arrSecond[i] << setw(8) << arrFinal[i] << setw(8)
<< arrTotal[i] << setw(6) << arrGrade[i] << endl;
}
cout << "-------------------------------------------------------------" << endl;
// print average class mark
cout << "Class average for " << numOfStudents << " students is: " << average << endl;
return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions