Input data: http://pastebin.ca/3374639 C++ Program using Structs, and functions
ID: 3668389 • Letter: I
Question
Input data: http://pastebin.ca/3374639
C++ Program using Structs, and functions outside main.
You are to write a program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports.
Format: The information for each student in on separate lines of input. The first data will be the student’s ID number, next the students classification, next line is the students name and the last line are the 9 grades where the last grade is a final and is to be counted twice.
Read in the students, compute their averages and print out the following reports:
Print out each student ID and their average.
Print out all the Seniors in a list with their name and average.
Print out all the Juniors in a list with their name an average.
Sort the students on ID and print out ID and average.
Print out the class average, (average of the averages.)
Be sure to label each list and line up all output in straight columns. (No waves)
Input file: http://pastebin.ca/3374639
Example of inputs are given below.
Example input
12345
Junior
tom archer jones
89 90 95 90 95 100 85 90 95
51321
Senior
dewy luewey
90 95 100 100 95 95 95 100 95
Explanation / Answer
Answer:
#include<iostream>
#include <iomanip>
#include<string.h>
using namespace std;
const int MAX_NUM = 15;
int p[MAX_NUM];
int q[10];
float AVG[MAX_NUM];
int main()
{
float class_avg=0.0;
float avg,min=1001;
float total = 0;
char name[50];
string classification;
string st2="Senior";
string st1="Junior";
for (int i = 0; i < MAX_NUM; i++)
{
avg = 0;
total = 0;
cout << "Enter an ID number: " << endl;
cin >> p[i];
cout << "Enter classification of the student: ";
cin >>classification;
//cout<<classification;
cout << "Enter name of the student: ";
cin >>name;
//cout<<name;
cout << "Enter 9 grades: " << endl;
for (int j = 0; j < 9; j++)
{
cin >> q[j];
while (q[j]>100)
{
cout << "Please enter a valid grade that is less than a 100: " << endl;
cin >> q[j];
}
total += q[j];
}
avg = total / 9;
AVG[i] = avg;
if(avg < min)
//min = avg;
cout<<"Student Details"<<endl;
cout << "ID: " << p[i] << endl;
cout << "Average: "<< avg << endl;
cout<<"Student Is Senior So The List Is Displayed"<<endl;
if(classification=="Senior")
cout << "ID:" <<p[i]<< endl;
cout << "AVG:" <<AVG[i]<< endl;
cout<<"Student Is Junior So The List Is Displayed"<<endl;
if(classification=="Junior")
cout << "ID:" <<p[i]<< endl;
cout << "AVG:" <<AVG[i]<< endl;
}
for(int i = 0; i < MAX_NUM; i++)
{
class_avg=class_avg+AVG[i];
//cout<<sums<<endl;
}
cout<<"Class Average Is"<<class_avg/MAX_NUM<<endl;
};