• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 233 pages
Exam (elaborations)

Cos1512 Exam Pack 2026

Document preview thumbnail
Preview 1 out of 233 pages

Introduction to Programming II - COS1512 Latest exam pack questions and answers and summarized notes for exam preparation. For assistance call or W.h.a.t.s.a.p.p us on +/ 2/ 5/ 4 /7 /7 /9 /5 /4 /0 /1 /3 /2 .

Content preview

COS1512

EXAM PACK

,COS1512 Assessment 2 2026

Introduction to Programming II

EXAM ANSWERS

QUESTION 1 [12]

1.1

The number used to refer to a particular element of an array is called its index
(subscript).

1.2

a) False.
An array stores elements of the same data type.

b) False.
An array index must be an integral type, such as int; it cannot be double.

c) True.
It is an error to provide more initializers than the declared number of array elements.

d) False.
Arrays are passed to functions by reference/address, not by value in the ordinary
array-parameter syntax.

e) False.
A function cannot directly return an array type. It can return a pointer/reference to an
array or use another mechanism such as a class/container.

1.3

The code has several errors:

,  prod_name is an array, so cin >> prod_name is incorrect; an individual element
such as prod_name[i] must be used.
 The loop condition i < 4 accesses four elements even though the arrays contain
only three elements (0–2).
 The for loop has no braces, so only the cout statement belongs to the loop.
 The program checks only price[0] rather than the price corresponding to each
product.
 The comment says products costing more than R200, but the condition uses
500.0.
 Input should be performed for each product.

Corrected code:

#include <iostream>
#include <string>
using namespace std;


int main()
{
string prod_name[3];
double price[3];


for (int i = 0; i < 3; i++)
{
cout << "Enter product name: ";
cin >> prod_name[i];


cout << "Enter product price: ";
cin >> price[i];


if (price[i] > 200.0)
cout << prod_name[i] << " is expensive!\n";

, }


return 0;
}



QUESTION 2 [20]

A suitable OOP solution using a 1D array, class and function overloading is:

#include <iostream>
using namespace std;


class StudentScores
{
private:
double scores[100];
int numberOfStudents;


public:
StudentScores(int n)
{
numberOfStudents = n;
}


void inputScores()
{
for (int i = 0; i < numberOfStudents; i++)
{
cout << "Enter score for student " << i + 1 << ": ";
cin >> scores[i];
}

Connected book
 image
James Roberge, George Smith An Introduction to Programming in C
Publisher: 1996 ISBN: 9780763703127 Edition: Unknown

Document information

Uploaded on
October 1, 2026
Number of pages
233
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$4.62

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
LIBvault
4.1
(20)
Sold
164
Followers
1
Items
317
Last sold
18 hours ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions