Purchase Solution

C++ - arrays

Not what you're looking for?

Ask Custom Question

Create a C++ class that implements a "safe" array, where the arrays bounds are checked before accessing its elements. The class constructor must accept an integer parameter and create a dynamic array of that size for storing integers, implemented as a vector. The constructor must initialize all array elements with 0. Add two methods get(int) that returns the i-th element of the array and set(int) that uses return by reference for setting the corresponding array element, whose index is passed as the parameter. The method must allow to be used in the left-hand-side of assignment operator like array.set(i) = 5;. Report an error if the array index is out of bounds.

In the main() method, create an array instance of size n provided by the user, assign its values to 1,2,...,n and print them out.

Purchase this Solution

Solution Summary

The expert examines C++ arrays in programming.

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.