The answers to a true-false test are as follows: T T F F T. Given a two-dimensio
ID: 3529731 • Letter: T
Question
The answers to a true-false test are as follows: T T F F T. Given a two-dimensional answer array, in which each row corresponds to the answers provided on one test, write a function that accepts the two-dimensional array and number of tests as parameters and returns a onc-dimensional array containing the grades for each test. (Each question is worth 5 points so that the maximum possible grade is 25.) Test your function with the following data: Write a program that has a declaration in main( ) to store the following numbers in an array named rates: 6.5, 7.2, 7.5, 8.3, 8.6, 9.4, 9.6, 9.8, and 10.0. Include a function call to show( ) that accepts rates in a parameter named rates and then displays the numbers by using the pointer notation *(rates + i).Explanation / Answer
Answer-1
int * calGrades(char answer[6][5],int numOfTest)
{
char result[5]={'T','T','F','F','T'};
int grades[6];
int tempGrade,i,j;
for(i=0;i<numOfTest;i++)
{
tempGrade=0;
for(j=0;j<5;j++)
{
if(result[i]==answer[i][j])
{
tempGrade=tempGrade+5;
}
}
grades[i]=tempGrade;
}
return grades;
}
Answer-2
#include <iostream>
using namespace std;
void show(double rates[])
{
int i;
for(i=0;i<9;i++)
{
cout<<*(rates+i)<<" ";
}
}
int main()
{
double rates[]={6.5,7.2,7.5,8.3,8.6,9.4,9.6,9.8,10.0};
show(rates);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.