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,
correctAnswers of type intstoring the correct answers to the 20 questions,
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 voidfunction inputNameAndAnswers:
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.
Correct answers: 11223344551122334455
Abe 12345123451234512345
Basil 54321543215432154321
Cecelia 11122233344455511122
Doris 54321543215432154321
Elizabeth 11111111111111111111
Freddy 22222222222222222222
Gerty 33333333333333333333
Hercules 44444444444444444444
Irma 55555555555555555555
John 55544433322211155544

Below is my code but it gives errors - please help:

//Calculates the mark of a student 
#include <iostream> 
#include <string>
using namespace std; 
 
const int NR_STUDENTS = 10;
const int NR_QUESTIONS = 20; 
 
void inputNameandAnswers( int j)
{ 
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];
answers[k] = mark;
}
}
void markofStudent(int correctAnswers[],int answers[])
{
int counter;
 
for(int a = 0; a <=NR_QUESTIONS; a++)
{
if (correctAnswers[a] = answers[a]);
counter ++;
}
return counter;
} 
 
int main()
{
string names[NR_QUESTIONS];
int correctAnswers[NR_QUESTIONS];
int answers[NR_QUESTIONS];
int marks[NR_STUDENTS];
int correctAnswers[]{1,1,2,2,3,3,4,4,5,5,1,1,2,2,3,3,4,4,5,5};
 
for( int q = 0; q <= NR_STUDENTS; q++)
{
inputNameandAnswers(q);
marks[q] == markofStudent(r);
}
 
for(int p = 0; p <= NR_STUDENTS; p++)
{
cout << correctAnswers[p];
cout << name[p] << " has got" << marks[p] << " out of 20 "<< endl;
cout << endl ;
 
}
return 0;
}

Please help

marks[q] == markofStudent(r);

This should be the assignment operator =
the mark of student() function should be int, not void

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.