63 193
Assignments Done
Successfully Done
In July 2018

Answer to Question #63814 in C++ for Alex Low

Question #63814
The answer 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 accepting the two dimensional array and the number of tests as parameters and returns a one dimensional array containing the grades for each test, where each question is worth 5 marks.

Test 1: T, F, T, T, T
Test 2: T, T, T, T, T
Test 3: T, T, F, F, T
Test 4: F, T, F, F, F
Test 5: F, F, F, F, F
Test 6: T, T, F, T, F
Expert's answer
#include <iostream>

int *getMarks(const char answers[][5], size_t ntests);

int main()
char tests[6][5] = {
{'T', 'F', 'T', 'T', 'T'},
{'T', 'T', 'T', 'T', 'T'},
{'T', 'T', 'F', 'F', 'T'},
{'F', 'T', 'F', 'F', 'F'},
{'F', 'F', 'F', 'F', 'F'},
{'T', 'T', 'F', 'T', 'F'},

int *marks = getMarks(tests, 6);
for (size_t j = 0; j < 6; j++)
std:: cout << marks[j] << " ";

return 0;

int *getMarks(const char answers[][5], size_t ntests)
const char answer[5] = {'T', 'T', 'F', 'F', 'T'};
int *marks = new int[ntests]();
const int mark = 5;

for (size_t j = 0; j < ntests; j++)
for (size_t i = 0; i < 5; i++)
if (answers[j][i] == answer[i])
marks[j] += mark;

return marks;

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions