Lab0

Reading:

The World of C++, part 1

The World of C++, part 2

Using Emacs editor:

Quick Emacs Reference

Debugging in Emacs

Files:

Copy all files from the lab0 folder. In your home directory, make a labs/lab0 folder and issue the following command:

cp /comp/15/public_html/labs/lab0/problem/* $HOME/labs/lab0/

Problem:

Given an Array class (declared in Array.h), having the following definitions in Array.cpp:

1. Constructors

2. Destructor

3. Copy Constructor

4. Assignment operator

5. operator== (for supporting a==b)

6. operator>> (for supporting cin)

The entry point is in main.cpp, which instantiates the Array class with different usages.

You are responsible for providing the following functionalities (in Array.cpp):

1. operator+ for supporting the following operations:

Array a, b, c, d, e;
c = a + b; // Element-wise addition of a and b; Error out if sizes don't match
d = c + 1; // Adding 1 to every element of c
e = 5 + d; // Adding 5 to every element of d

2. operator<< (for supporting cout)

Compilation:

Run “make” in the lab1 folder.

Execution:

Run “./Array” in the folder where you ran the compilation command.

Expected Output:

Negative index.

a2: { }

a4: { 1 2 3 4 5 6 7 8 9 10 }; a3: { 1 2 3 4 5 6 7 8 9 10 }

a5: { 1 2 3 4 5 6 7 8 9 10 }

a4 is equal to a5

Length of array: 10

A[0] = 10

A[1] = 9

A[2] = 8

A[3] = 7

A[4] = 6

A[5] = 5

A[6] = 4

A[7] = 3

A[8] = 2

A[9] = 1

a5: { 10 9 8 7 6 5 4 3 2 1 }

a6: { 13 12 11 10 9 8 7 6 5 4 }

a7: { 14 14 14 14 14 14 14 14 14 14 }

Solution:

Posted here.