Implement a single-arg constructor

Assignment Help C/C++ Programming
Reference no: EM13979086

Write a C++ program that defines, implements, and tests all member functions of a class called DynamicArray which mimics the capabilities of a C++ vector of ints. You may not use the standard C++ vector class or any code from the (decompiled) implementation of the standard vector class in your implementation. Use a primitive array of ints as the internal data structure in your class.

You will need to implement the member functions and overloaded operators listed below under Detailed Requirements. As per the standing requirements, each member function and any nonmember (related) functions such as the << operator overload, must be used in at least one test case in main.

Standing Requirements for all Projects

SR1. Provide a standard comment block at the top of each file documenting the file name and other details listed below. Failure to provide the information will result in a 5-point deduction per file.

/*
File Name: <filename>.cpp or <filename>.h Author: your first and last name
Course: CSC 402 (502 for MSCS students) Date: date completed
*/

SR2. All code you submit should compile without errors, and should be free of runtime errors for typical or expected input values. For instance, if a function is written to expect an integer from 1 to 1000, any number in that range should be handled gracefully. Each syntax or runtime error will result in a 5-point deduction with a maximum of 25 points total.

SR3. Observe C++ stylistic conventions demonstrated in class or in the textbook and use standard C++ constructs, as opposed to C language features that may be supported in C++ due to its origin. For example, prefer cout to printf. Also, be consistent in your approach to indentation, block structure, etc. Gross violations may result in a 5-point deduction.

SR4. In general, each function in a program will require at least one test case that proves that it works. In other words, code that is never executed in the typical program run is considered untested and may result in point deductions based on the extent of the problem.

Project-specific Requirements

R1. Separate the class declaration, class implementation, and test driver (main) into 3 files: DynamicArray.h, DynamicArray.cpp, and TestDynamicArray.cpp. [Use the Rational.h, Rational.cpp, and TestRational.cpp files in the Chapter 5 code examples as a model of what to place in the class declaration, class implementation, and test driver.]

R2. Use standard "header guards" in the .h files or the #pragma once directive (if your compiler supports it).

R3. Implement a single-arg constructor that sets the initial capacity of the array, with a default of 10, which also serves as the default (no-arg) constructor. The size of the array, unless it is created from an existing array, is initialized to 0. Test two ways of constructing DynamicArray objects using this constructor syntax:

DynamicArray d1 ; DynamicArray d2(20) ;

R4. Implement a second constructor that takes a primitive array of ints and its length as the arguments and initializes the DynamicArray as a deep copy of the passed-in array. The size of the dynamic array is determined by the length of the passed-in array. Test this constructor call with a small array initialized with non-zero values.

int iArr[10] = {10,9,8,7,6,5,4,3,2,1} ;
DynamicArray d3(iArr, 10) ;

R5. Implement the Big Three: Destructor, Copy Constructor, and operator = with appropriate test cases for all three.

R6. Implement the following accessor member functions that will mirror the functions of the vector class with the same name: Note that front() and back() for an empty vector are undefined in the specification. For our class, return negative INT_MAX if the vector is empty

• int size()
• int capacity()
• bool empty()
• int front(), int back()

R7. Implement the following additional accessor member function:

• int find ( int val )

searches the dynamic array for the value specified and returns the index if found, -1 if not found

R8. Implement the following mutator functions:

• void clear( )

sets the array's size to 0, but does not necessarily need to deallocate the memory occupied.

• void push_back( int val )

adds val to the end of the array. Capacity is extended if necessary.

• int insert ( int pos, int val )

inserts int value val at position pos and returns the position if successful, -1 if unsuccessful. Existing content is shifted to the right and the capacity is extended if necessary.

• void pop_back ()

ostensibly removes the last element in the array. Size is adjusted, but you do not have to reclaim the memory. Behavior for an empty vector is undefined in the standard, but it generally silently does nothing.

R9. Implement an overloaded << operator such that the following code will function correctly:

DynamicArray d1(10) ;

cout << d1 << endl ;

R10. Implement an overloaded == operator such that d1 == d2 will return true if and only if the variables d1 and d2 are DynamicArrays with the same size and the same elements. Capacity is not a factor.

R11. Provide inline comments in the class declaration, implementation, and main to describe the purpose of blocks of code, to set apart sections of the class declaration, etc., following the code examples for Chapter 5. There is no set minimum or maximum. Use your best judgment.

R12. The internal data members are to be named _size, _capacity, and _arr to disambiguate them from member functions size() and capacity() or possible parameters named arr.

R13. Upload the 3 files to the BlackBoard drop box associated with Project 2 as one zip file named <LastName>_<FirstName>_Project2.zip.

You may want to write a utility member function called diag() that simply prints the internal state of a DynamicArray instance, showing capacity, size, front and back elements, and so on, in an easy to read format.

Reference no: EM13979086

Questions Cloud

Did your results support your expectation : Difficulties making a true random sample? What population is your sample describing? Is it representative of most check or credit purchases in the US/>/>?Did your results support your expectation? Provide anexplanation
Flying fish specializes in shipping fresh seafood : Flying Fish specializes in shipping fresh seafood up and down the coast. To improve service, the company wants to develop an in-house application called 53 (Super Shipping System). When 53 is operational, ship· pers and consignees will be able to tra..
What will be impact of fiscal expansion in a large economy : What will be the impact of a fiscal expansion in a large economy like the U.S. on aggregate income, the exchange rate, investment, trade balance and interest rate? Assume that the large economy in question has aborting exchange rate.
What is its transition matrix : The pattern is, count heads, toss heads, count tails, toss tails, count heads, toss heads, etc., and X0 = 3. Then (Xn) is a Markov chain. What is its transition matrix?
Implement a single-arg constructor : Implement a single-arg constructor that sets the initial capacity of the array, with a default of 10, which also serves as the default (no-arg) constructor. The size of the array, unless it is created from an existing array, is initialized to 0.
What is the magnitude of the force exerted on the block : The acceleration of gravity is 9.8 m/s2. If Fl = 16 N and Fr = 6N, what is the magnitude of the force exerted on the block with mass 8 kg by the block with mass 5 kg?
The molarity of pcl5 but asks for atm : A lot of trouble with this question, I think because it gives you the molarity of PCl5 but asks for atm at the end and I'm not really sure how to solve the question that way. I first found deltaG standard to be 2.75 kJ, then plugged that in to find t..
Show that both systems have the same moment about point b : Replace the 250-lb force in Figure P3.64 by an equipollent system consisting of a force at Q and a couple. Then show that both systems have the same moment about point B.
What is the cash conversion cycle for your company : What has created the largest inflow and outflow of cash for investing activities? Did investing activities provide or use cash for each of the years presented?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program that analyzes a months worth of temperatures

Write a program that analyzes a month's worth of temperatures. Provide a menu for the user to choose which statistics they want.

  Textual table describing the catalogues of retail stores

Write a function to read a series of catalogue records from a file into a vector of catalogue objects. You will need to use the class ifstream, which is derived from istream, like so:

  What are reasons for using generics

Explain generics in C#. What are reasons for using generics? How do generics apply to collections? Write the code for a small example using C# code

  A c++ program using the concept of function overloading

write a c++ program using the concept of function overloading for the following options : select the options from [1-3], 1- Area of rectangle 2- Area of square 3- Exit ,

  Declare and use single dimension arrays

How do you declare and use single dimension arrays? How do you perform basic sort and search routines on arrays?

  Generate a random integer in the range

Write a parallel program with MPI functions, Define an array of size 1000. Generate a random integer in the range of: 0 t0 999 for: n. Generate n random integers in the range of: 0 to 1000 and save them in array.

  Can you have an array of arrays

What are the purposes of the following three functions? How would you use them in your programs? Hint: In relation to buffers.

  Write a loan calculator program

Write a loan calculator program in C++ that displays monthly balances for user-specified loan terms. To be flexible, you decide to specify the loan terms in a file and provide that filename  entered from the keyboard. To keep things simple

  Write recursive and iterative versions of functions

Write recursive and iterative versions of functions that compute the sum of components of an array.

  Write a pseudocode function in terms of adt appointment

Write speci?cations for a method within Date that advances any given date by one day. Include a statement of purpose, the preconditions and postconditions, a description of the arguments, and a description of any return value.

  What does the term polymorphism mean

What does the term polymorphism mean and Use case models use two patterns - "Common Sub Behavior" and "Interrupts as Extensions." Explain these two patterns in your own terms and give an example for each pattern.

  Question 1 use the attached database to provide the

question 1 use the attached database to provide the relational algebra which would list the requested information

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd