, COS1512 Assignment 3
Semester 2 2025
DUE 4 August 2025
Use this document as a guide and for references to answer your assignment
Question 1
Write a program that asks a user to enter the size of a dynamic array that stores exam marks obtained
by students. Create the dynamic array and a loop that allows the user to enter an exam mark into each
array element. Loop through the array, find the average mark for the exam and output it. Delete the
memory allocated to your dynamic array before exiting your program.
✅Program Objective
Ask the user to enter the size of a dynamic array for exam marks.
Use a loop to populate the array.
Calculate and output the average mark.
Free the dynamically allocated memory before exiting.
�C++ Program:
#include <iostream>
using namespace std;
int main() {
int size;
cout << "Enter the number of students: ";
cin >> size;
// Allocate memory dynamically
float* marks = new float[size];
// Input exam marks
for (int i = 0; i < size; ++i) {
cout << "Enter mark for student " << i + 1 << ": ";
cin >> marks[i];
}
// Calculate average
Semester 2 2025
DUE 4 August 2025
Use this document as a guide and for references to answer your assignment
Question 1
Write a program that asks a user to enter the size of a dynamic array that stores exam marks obtained
by students. Create the dynamic array and a loop that allows the user to enter an exam mark into each
array element. Loop through the array, find the average mark for the exam and output it. Delete the
memory allocated to your dynamic array before exiting your program.
✅Program Objective
Ask the user to enter the size of a dynamic array for exam marks.
Use a loop to populate the array.
Calculate and output the average mark.
Free the dynamically allocated memory before exiting.
�C++ Program:
#include <iostream>
using namespace std;
int main() {
int size;
cout << "Enter the number of students: ";
cin >> size;
// Allocate memory dynamically
float* marks = new float[size];
// Input exam marks
for (int i = 0; i < size; ++i) {
cout << "Enter mark for student " << i + 1 << ": ";
cin >> marks[i];
}
// Calculate average