COS1512 Assignment 3
(COMPLETE ANSWERS)
2025 - DUE 4 August
2025
NO PLAGIARISM
[Pick the date]
[Type the abstract of the document here. The abstract is typically a short summary of the contents of
the document. Type the abstract of the document here. The abstract is typically a short summary of
the contents of the document.]
, Exam (elaborations)
COS1512 Assignment 3 (COMPLETE
ANSWERS) 2025 - DUE 4 August 2025
Course
Introduction to Programming II (COS1512)
Institution
University Of South Africa (Unisa)
Book
Introduction to Programming
COS1512 Assignment 3 (COMPLETE ANSWERS) 2025 - DUE 4 August 2025;
100% TRUSTED Complete, trusted solutions and explanations Ensure your
success with us..
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.
#include <iostream>
// This program demonstrates the use of a dynamic array in C++.
// It asks the user for the size of the array, populates it with exam
marks,
// calculates the average, and then properly deallocates the memory.
int main() {
// Variable to store the size of the dynamic array
int size;
// Prompt the user to enter the size of the array
std::cout << "Enter the number of students (size of the array): ";
std::cin >> size;
// Basic input validation to ensure a positive size
if (size <= 0) {
std::cout << "Invalid size. Please enter a positive number." <<
std::endl;
return 1; // Exit with an error code
}