Purchase Solution

A C++ vector class implementation

Not what you're looking for?

Ask Custom Question

Your class VectorDouble will have a private member variable for a dynamic array of doubles. It will also have two member variables of type int; one called maxCount for the size of the dynamic array of doubles, and one called count for the number of array positions currently holding values. (maxCount is the same as the capacity of a vector; count is the same as the size of a vector.)

If you attempt to add an element (a value of type double) to the vector object of the class VectorDouble and there is no more room, then a new dynamic array with twice the capacity of the old dynamic array is created and the values of the old dynamic array are copied to the new dynamic array.

Your class should have all of the following:
? Two constructors: a default constructor that creates a dynamic array for 50 elements and a constructor with one int argument for the number of elements in the initial dynamic array.
? A destructor.
? Member functions push_back, capacity, size, reserve, and resize that behave the same as the member functions of the same names for vectors.
? Two member functions to give your class the same utility as the square brackets: value_at(i), which returns the value of the ith element in the dynamic array; and change_value_at(d,i), which changes the double value at the ith element of the dynamic array to d. Enforce suitable restrictions on the arguments to value_at and change_value_at.

Attachments
Purchase this Solution

Solution Summary

This solution provides a C++ implementation of a vector class.

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

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.

Excel Introductory Quiz

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

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Networking Questions

This quiz consists of some basic networking questions.