Question: Dynamically allocate an integer array with numClasses elements and assign studentsRegistered with the array's address. The program will read numClasses integers into the array and

Dynamically allocate an integer array with numClasses elements and assign studentsRegistered with the array's address. The
program will read numClasses integers into the array and then print each value.
Please answer in C++! Thank you.
code I have is
#include "checkSolution.h"
#include
using namespace std;
void PrintStudents(int* arrayPtr, int arraySize){
int i;
if (arrayPtr != nullptr){
for (i =0; i arraySize; ++i){
cout "Class " i +1": " arrayPtr[i]" students" endl;
}
}
}
int main(){
int* studentsRegistered = nullptr;
int numClasses;
int i;
cin >> numClasses;
int* dynamic_array;
dynamic_array = new int[numClasses];
studentsRegistered =
dynamic_array;
for (i =0; i numClasses; ++i){
cin >> studentsRegistered[i];
}
PrintStudents(studentsRegistered, numClasses);
delete[] studentsRegistered;
checkSolution(); // Check solution for testing purposes only
return 0;
}
Dynamically allocate an integer array with

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!