Quiz Statistics or this assignment, you will write a program that requests the q
ID: 3914945 • Letter: Q
Question
Quiz Statistics or this assignment, you will write a program that requests the quiz scores for 6 students identi number of the student with the highest score. The ID numbers for the students in this class are: ified by ID numbers. The program computes the average score and determines the ID 1234 2333 4432 3323 2143 3421 Your program must use this This program requests exam scores for each main procedure which calls student and computes the arverag ad highest grade the four procedures you are to implement. setStudentlds takes an out parameter, Studentlds, which is an array of integers. It sets each array element to a student ID according to the table above. Start setStudentids(studentids) inputScores (studantids scores) getAverage scores, average) inputScores takes an in parameter, studentlds and an out parameter, scores. which is an array of 6 doubles. It asks for the score for each student and fills the scores array. This procedure must use a loop. PUT The average score i + average highindex) PUT Thehigh score was studect"+ studenti ds [highlndel+"na. +scores [highinde:] getAverage takes scores as an in parameter and returns the average in an out parameter. End getHighindex also takes scores as an in parameter and returns the index (1-6) of the student with the highest score. This procedure will require an if statement inside a loop. Hints 1. This program requires the use of parallel arrays as described in chapter 7.Explanation / Answer
The program( with extra credit score) is given below:
#include <iostream>
using namespace std;
int studid[6],score[6];
void setStudId(int ar[6]);
void inputScores(int stdId,int scr);
double getAvg(int scr[6]);
int getHighIndex(int score[6]);
int getSecondHighIndex(int score[6]);
int main()
{
int arval[6]={1234,2333,4432,3323,2143,4321};
int highInd,scndhighInd;
double average;
int sId,scr;
setStudId(arval);
for(int i=0;i<6;i++)
{
cout<<" Please enter score for student"<<studid[i]<<" ";
cin>>scr;
inputScores(studid[i],scr);
}
average=getAvg(score);
cout<<" The average score is "<<(double)average;
highInd=getHighIndex(score);
cout<<" The high score was student "<<studid[highInd]<<"with a "<<score[highInd];
scndhighInd=getSecondHighIndex(score);
cout<<" The next high score was student "<<studid[scndhighInd]<<"with a "<<score[scndhighInd];
return 0;
}
void setStudId(int ar[6]) // function to set student Id
{
for(int i=0;i<6;i++)
studid[i]=ar[i];
}
void inputScores(int stdId,int scr) //function to get input score and set score to corresponding student
{
for(int i=0;i<6;i++)
{
if(studid[i]==stdId)
score[i]=scr;
}
}
double getAvg(int scr[6]) // function to find average of score and return average
{
int sum=0;
double avg;
for(int i=0;i<6;i++)
sum=sum+score[i];
avg=(double)sum/6;
return (double)avg;
}
int getHighIndex(int score[6]) // function to get index of highest student with highest score
{
int maxInd;
maxInd=0;
for(int i=1;i<6;i++)
{
if(score[maxInd]<score[i])
maxInd=i;
}
return maxInd;
}
int getSecondHighIndex(int score[6]) // function to get index of second highest student with second highest score
{
int maxInd,secondmaxInd;
maxInd=0;
for(int i=1;i<6;i++)
{
if(score[maxInd]<score[i])
{
secondmaxInd=maxInd;
maxInd=i;
}
}
return secondmaxInd;
}
Output:
Please enter score for student1234 73
Please enter score for student2333 81
Please enter score for student4432 68
Please enter score for student3323 95
Please enter score for student2143 77
Please enter score for student4321 46
The average score is 73.3333
The high score was student 3323with a 95
The next high score was student 2333with a 81
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.