Purchase Solution

A Vector Class in C++

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.

Purchase this Solution

Solution Summary

This solution provides an implementation of a vector class in C++ in the attached files. The vector class is written to hold doubles.

Solution Preview

This solution provides a simple implementation of a vector that holds ...

Purchase this Solution

Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C# variables and classes

This quiz contains questions about C# classes and variables.

C++ Operators

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

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 Networking Questions

This quiz consists of some basic networking questions.