16.5k views
0 votes
Assume there are 15 students registered for a history class. You will need to declare an array of the StudentType structure to contain data for all students and another character array with 20 elements to hold the answer key to a test. The history teacher at your school needs help in grading a True/False test. Define a StudentType structure for that.

User Zigomir
by
6.1k points

1 Answer

6 votes

Answer:

#include <iostream>

using namespace std;

struct StudentType{

string studentName;

int studentId;

}

int n;

char answer[20];

int main(){

cout<< "Enter the size of the array: ";

cin >> n;

StudentType *student = new StudentType(n);

for (int i = 0; i < n; i++){

int name;

int number;

cin>> name;

cin >> number;

student[i].studentName = name;

student[i].studentId = number;

}

for (int i = 0; i < 20; i++){

cout<< "Enter answers: ";

cin >> ans;

answer[i] = ans;

}

}

Step-by-step explanation:

The C++ source code has three global variables namely, answer which is an array of character data type, StudentType which is a structure data type and the integer variable n. The main function declares and initializes the dynamic-spaced student array of the structure datatype with the n variable.

User Ajey
by
6.6k points