You are on page 1of 1

Midterm online test: Fundamental Computer Programming- C++ Lab(II), Rung-Bin Lin

April 16, 2022, International Bachelor Program in Informatics, Yuan Ze University

Problem D: Array Class


(35%, related to Lab 5, 6, 7)

Problem Description
Include the code of overloading the following operators into Array class contained in Fig. 11.6, 11.7, 11.8.
 Overload operator + to concatenate two arrays, said array A and array B, into an array. Place the
elements of second array right after the elements of first array. For example, given A=(1,2,3) and
B=(4,5,6,7), executing A+B will return (1,2,3,4,5,6,7).
 Overload the operator + to perform A+anInt and anInt+A, where A is an array and anInt is an integer.
The added integer anInt should be stored right after the last element of array A. For example, if
A=(1,2,3), then A+4 or 4+A should return (1,2,3,4).
 Overload operator + to add together all the elements in an array. For example, if A=(1,2,3,4,5), then +A
will return 15.
 Overload operator – to negate each element in an array. For example, if A=(1,2,3,4,5), -A will return
(-1,-2,-3,-4,-5).
 Overload operator += to perform A = A + B where A is an object of Array class and B is either an object
of int type or an object of Array class. This operator stores the elements of B after the last element of A.
The modified A should be returned.
 Overload operator << to shift the elements in an array of n elements down by k places. If k > n, the
element at i-th place will be moved down by (k mod n) places. For example, A << 1 means that an array
element A[i] will be moved to the (i-1)th place if i-1>=0 and A[0] will be placed at the (n-1)-th place.
Yet another example, A=(1,2,3,4,5), after performing A << 7, A will become A=(3, 4,5,1,2).

The main() function is given in a file called help.rtf and cannot be changed. The code in Fig. 11.6 and Fig.
11.7 will also be provided there.

Input format & output format:


As shown in the example below.

Example:
Input Output
1 2 3 4 5 6 7 8 9 10 11

You might also like