One-dimensional arrays in a function
Ten students do a multiple choice assignment consisting of twenty questions. The lecturer wants to display their
names and the mark obtained by each on the screen. Write a program to help him.
Declare two global constants, namely NR_STUDENTS (set equal to 10) and NR_QUESTIONS (set equal to 20). The
program should consist of three functions. No global variables may be used.
The main function:
Declare the following four one-dimensional arrays:
names of type string where the 10 names are to be stored,
answers of type int where the 20 answers of one student are to be stored,
marks of type int where the mark of each of the 10 students will be stored.

The array correctAnswers has to be initialised in the declaration statement.
The main function should contain a forloop going from 1 to 10. Inside the loop two functions have to be
called: the void function inputNameAndAnswers to input the name and answers of one student, and the
int function markOfStudentto calculate the mark of one student.
After the loop is exited, the names of all the students and the mark of each should be displayed on the screen.
The name and 20 answers of one student should be input in this function and made available to the main
function. You need not validate the input.
The int function markOfStudent:
The mark out of 20 of one student has to be calculated here and returned to the main function.
Run your program on the data below and submit printouts of the program and output.
Abe 12345123451234512345
Basil 54321543215432154321
Cecelia 11122233344455511122
Doris 54321543215432154321
Elizabeth 11111111111111111111
Freddy 22222222222222222222
Gerty 33333333333333333333
Hercules 44444444444444444444
Irma 55555555555555555555
John 55544433322211155544

``````//Calculates the mark of a student
#include <iostream>
#include <string>
using namespace std;

const int NR_STUDENTS = 10;
const int NR_QUESTIONS = 20;

{
int mark;
string names;
cout << " Enter name: ";
cin >> names[j];

for(int k = 0; k <= NR_QUESTIONS; k++)
{
cout << " Enter marks for student: " << names[j] <<endl;
cin >> mark[k];
}
}
{
int counter;

for(int a = 0; a <=NR_QUESTIONS; a++)
{
counter ++;
}
return counter;
}

int main()
{
string names[NR_QUESTIONS];
int marks[NR_STUDENTS];

for( int q = 0; q <= NR_STUDENTS; q++)
{
marks[q] == markofStudent(r);
}

for(int p = 0; p <= NR_STUDENTS; p++)
{
cout << name[p] << " has got" << marks[p] << " out of 20 "<< endl;
cout << endl ;

}
return 0;
}``````

2
Contributors
1
``marks[q] == markofStudent(r);``