Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

15 points Due in Lab The answers to a true-false test are as follows: T T FFT. G

ID: 3739688 • Letter: 1

Question

15 points Due in Lab The answers to a true-false test are as follows: T T FFT. 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 param and returns a one-dimensional array containing the grades for each test. (Each is worth 5 points so that the maximum possible grade is 25.) Test your function with the following data eters question Test1 Test2 Test3 Test4 Test5 Test6 Sample Output: Enter the answers of Test Enter the answers of Tes Enter the answer Tes Enter the answers of Test FTFFF Enter the answers of Test Enter the answers of Tes TTFTF The grades for all tests are est 1:20 est 2:25 Test 3:15 Test 45 Test S0 Test 6: 15 Press any key to continue

Explanation / Answer

// Code for calculating the test scores

#include <iostream>
#include <stdio.h>
#include <ctime>
const int number_of_questions = 5;   // since maximum is 25 points. Change this value to increase number of questions per test
int no_of_tests = 6;

using namespace std;

int* calculate_score(char arr[][number_of_questions], int no_of_tests)
{
    // Please Note that the right way to return an array is to have a dynamically allocated array or a static array, otherwise program might crash giving segmentation fault.
    // Moreover you can also pass the score array as a reference to this function.
  
    static int score_array[6]; // static initialization of the array
    //int *score_array = new int[6]; // Dynamically allocated array
    int i, j;
    for (i = 0; i < no_of_tests; i++){
    int current_score = 0;
      for (j = 0; j < number_of_questions; j++){
         if (arr[i][j] == 'T')
             current_score = current_score + 5;
      }
      //cout <<current_score<<" ";
      score_array[i] = current_score;
    }
     return score_array;
}

int main()
{
      // Change this to modify number of tests. You can also ask user to input it.
        //cout<<"I am here1";

// Given 2 dimensional array, calculating the score. Firslty declaring the 2d array(can also be taken as input) and then calling the calculate score function.
    char array[no_of_tests][number_of_questions] = {{'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', 'T'}};

    int *score;
    score = calculate_score(array, no_of_tests);
    // Printing the test results
   for ( int i = 0; i < no_of_tests; i++ ) {
           cout << "Test " << i << ": ";
        cout << *(score+i) << endl;
   }
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote