Question

In: Computer Science

//draft to work from for Assignment 7 where you compute a student's quiz average, dropping two...

//draft to work from for Assignment 7 where you compute a student's quiz average, dropping two lowest scores, assuming
//they have 2 or more quizzes
// a max of 12 quizzes can be taken
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>

using namespace std;

const int NUM_QUIZZES = 12;  //assume 12 quizzes max can be taken

int buildQuizArray( int [] );   //you need to write these 5 functions below
void printQuizArray( string, int [], int );

double calcQuizAverage( int [], int );

void sortQuizArray( int [], int );
void copyArray( int [], int [], int );


int main()
{ //this is the driver code in main routine , calling your functions
int quizArray[NUM_QUIZZES];  //declare array to hold 12 quizzes
int numQuizzes;              //will be filled in with number of quizzes from buildQuizArray

numQuizzes = buildQuizArray( quizArray );  //call buildQuiz array, numQuizzes is returned from function

printQuizArray( "Quiz Scores From QuizArray After My Build Function", quizArray, numQuizzes );  //print it out to make sure it is built correctly
                                                                                    //take out when finished
cout << fixed << setprecision(2);

cout << endl << "Your quiz average is " << calcQuizAverage(quizArray, numQuizzes)
     << "%" << endl;  //call function and get a double returned to print to user

printQuizArray( "Quiz Scores From QuizArray after calling calcQuizAverage", quizArray, numQuizzes );  
                                                   //print array again to make sure you did not change the original array

return 0;
}

 //********************************************************************************

int buildQuizArray( int array[] )
{
//build the array of quizzes  and return the count of entries of the array back to main routine
}


//*************************************************************************
void printQuizArray( string reportTitle, int array[], int numValues )
{
//print out the quiz array with appropriate title passed to you in reportTitle....add  "/10" to end of each quiz score
}


//***************************************************************************

double calcQuizAverage( int array[], int numValues )
{

//if 2 or less values in array use formula in assignment sheet for 2 or less values to compute average

//if more than 2, define another "work" array in this function, call copyArray function below  to copy elements to a "work array" from array passed to you,
//and then call sortQuizArray function to sort your "work array". After work array has been sorted ascending order, use formula in sheet
// to compute the quiz average  (which will not factor in the two lowest quiz scores in positions 0 and 1 in array)

//return the average computed to the main return
}



//***********************************************************

void copyArray( int destinationArr[], int sourceArr[], int numValues )
{
//copy the data from source array into destination array with a loop
// numValues has number of entries in the array

//at the bottom of this function print out  destinationArr to make sure it is correctly copied, simply call printQuizArray
printQuizArray("Here's my copy/work array that is to be sorted: ", destinationArr ,numValues);
}
//***************************************************************
void sortQuizArray( int array[], int numValues )
{
//code selection sort logic here to sort array passed in ,  BEGIN=0, END=numValues-1
//suggestion: document each line of code here to simulate the selection sort algorithm


//at bottom of sort, to make sure table is sorted call print function and verify it is sorted
printQuizArray( "Here is my sorted array", array, numValues );  //print it out to make sure it is built correctly,take out when finished

}

Solutions

Expert Solution

This was the output screen.

here's the code:

/*draft to work from for Assignment 7 where you compute a student's quiz average, dropping two lowest scores, assuming
//they have 2 or more quizzes
// a max of 12 quizzes can be taken*/
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>

using namespace std;

const int NUM_QUIZZES = 12; //assume 12 quizzes max can be taken

int buildQuizArray( int [] ); //you need to write these 5 functions below
void printQuizArray( string, int [], int );

double calcQuizAverage( int [], int );

void sortQuizArray( int [], int );
void copyArray( int [], int [], int );


int main()
{ //this is the driver code in main routine , calling your functions
int quizArray[NUM_QUIZZES]; //declare array to hold 12 quizzes
int numQuizzes; //will be filled in with number of quizzes from buildQuizArray

numQuizzes = buildQuizArray( quizArray ); //call buildQuiz array, numQuizzes is returned from function

printQuizArray( "Quiz Scores From QuizArray After My Build Function", quizArray, numQuizzes ); //print it out to make sure it is built correctly
//take out when finished
cout << fixed << setprecision(2);

cout << endl << "Your quiz average is " << calcQuizAverage(quizArray, numQuizzes)
<< "%" << endl; //call function and get a double returned to print to user

printQuizArray( "Quiz Scores From QuizArray after calling calcQuizAverage", quizArray, numQuizzes );
//print array again to make sure you did not change the original array

return 0;
}

//********************************************************************************

int buildQuizArray( int array[] )
{
array[NUM_QUIZZES]={-1};
int count=0;
cout<<"Either enter scores. Enter -1 when done."<<endl;//build the array of quizzes and return the count of entries of the array back to main routine
for(int i=0;i<NUM_QUIZZES;i++){
int n;
cin>>n;
array[i]=n;
if(n<0) break;
}
for(int i=0;i<NUM_QUIZZES;i++){
if(array[i]>=0) count++;
else break;
}
return count;
}


//*************************************************************************
void printQuizArray( string reportTitle, int array[], int numValues )
{
cout<<reportTitle<<endl;
for(int i=0;i<numValues;i++){
cout<<"Score of quiz "<<i+1<<": "<<array[i]<<"/10"<<endl;
}//print out the quiz array with appropriate title passed to you in reportTitle....add "/10" to end of each quiz score
}


//***************************************************************************

double calcQuizAverage( int array[], int numValues )
{
double averageScore;
int sum=0;
if(numValues<=2){
for(int i=0;i<numValues;i++){
sum+=array[i];
}
averageScore=(sum/numValues)*10;
}//if 2 or less values in array use formula in assignment sheet for 2 or less values to compute average

else{
int work[numValues];
copyArray(work,array,numValues);
sortQuizArray(work,numValues);
for(int i=2;i<numValues;i++){
sum+=work[i];
}
averageScore=(sum/(numValues-2))*10;
}
  
//if more than 2, define another "work" array in this function, call copyArray function below to copy elements to a "work array" from array passed to you,
//and then call sortQuizArray function to sort your "work array". After work array has been sorted ascending order, use formula in sheet
// to compute the quiz average (which will not factor in the two lowest quiz scores in positions 0 and 1 in array)

return averageScore;//return the average computed to the main return
}

//***********************************************************

void copyArray( int destinationArr[], int sourceArr[], int numValues )
{
for(int i=0;i<numValues;i++){
destinationArr[i]=sourceArr[i];
}//copy the data from source array into destination array with a loop
// numValues has number of entries in the array

//at the bottom of this function print out destinationArr to make sure it is correctly copied, simply call printQuizArray
printQuizArray("Here's my copy/work array that is to be sorted: ", destinationArr ,numValues);
}
//***************************************************************
void sortQuizArray( int array[], int numValues )
{
int i, j, min_idx;
for (i = 0; i < numValues-1; i++)
{
min_idx = i;
for (j = i+1; j < numValues; j++) {
if (array[j] < array[min_idx])
min_idx = j;
}   
int temp = array[min_idx];
array[min_idx] = array[i];
array[i] = temp;
} //code selection sort logic here to sort array passed in , BEGIN=0, END=numValues-1
//suggestion: document each line of code here to simulate the selection sort algorithm


//at bottom of sort, to make sure table is sorted call print function and verify it is sorted
printQuizArray( "Here is my sorted array", array, numValues ); //print it out to make sure it is built correctly,take out when finished

}


Related Solutions

A. To compute a student's Grade Point Average (GPA) for a term, the student's grades for...
A. To compute a student's Grade Point Average (GPA) for a term, the student's grades for each course are weighted by the number of credits for the course. Suppose a student had these grades: 3.6 in a 5 credit Math course 2.2 in a 2 credit Music course 2.6 in a 5 credit Chemistry course 3.1 in a 4 credit Journalism course What is the student's GPA for that term? Round to two decimal places. B) For a 4-unit class...
To compute a student's Grade Point Average (GPA) for a term, the student's grades for each...
To compute a student's Grade Point Average (GPA) for a term, the student's grades for each course are weighted by the number of credits for the course. Suppose a student had these grades: 3.8 in a 5 credit Math course 1.9 in a 3 credit Music course 2.8 in a 5 credit Chemistry course 3.4 in a 5 credit Journalism course What is the student's GPA for that term? Round to two decimal places. Student's GPA =
1. To compute a student's Grade Point Average (GPA) for a term, the student's grades for...
1. To compute a student's Grade Point Average (GPA) for a term, the student's grades for each course are weighted by the number of credits for the course. Suppose a student had these grades: 4.0 in a 5 credit Math course 2.1 in a 2 credit Music course 2.8 in a 5 credit Chemistry course 3.0 in a 4 credit Journalism course What is the student's GPA for that term? Round to two decimal places. Student's GPA = 2.A set...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
OverviewFor this assignment, write a program that will calculate the quiz average for a student in...
OverviewFor this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array.For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores).It is recommended that this program be written in two versions. The first version of the program will read a set of quiz scores from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT