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

  Program that asks user to enter two sides of a rectangle

The program will then display the perimeter and area of the rectangle. Both output values will be labeled and formatted with two decimal places.

  Grocery store program

This program draws upon several concepts that were covered in CptS 121 and should serve as a good refresher for CptS 122. Our store, Cougar Mart, maintains its inventory in a text file. Not being very tech savvy, the owner of Cougar Mart needs you to..

  C++ code to find the greatest common divisor

C++ Code to find the Greatest common divisor between two numbers.

  A program computes and displays the number of centimeter

The Earth's ocean levels have risen an average of 1.8 millimeters per year over the past century. Write a program computes and displays the number of centimeters and number of inches the oceans rose during this time.

  Design a java software system that simulates

Design a java software system that simulates a calculator that performs at least the basic arithmetic operation and trigonometric functions. Your program must contain selection (if), repetition (loop) and functions, arrays and classes

  A program in c that adds and subtracts two arrays of size 3

a program in c that adds and subtracts two arrays of size 3 rows of 4 columns using functions to add the arrays and

  Ansi-c program complete assignment as per written in the

complete assignment as per written in the

  Write a number guessing game in which the computer selects

Write a number guessing game in which the computer selects a random number in the range of 0 to 100, and users get a maximum of 20 attempts to guess it.

  Write equivalent compound statements

What action must be taken before a variable can be used in a program?

  Write program that stores the numbers in array

Write a c++ program that stores the following numbers in the array named miles: 15,22,16,18,27,23, and 20. have your program copy the data stored in miles to another array.

  Calculate and display the number of units of electricity

The manager of PG&E wants a program that calculates a customer's electric bill. He will enter the current and previous meter readings.

  Three dimensional array representing parking spaces

start with code in the file lab.cpp. This program works with a three dimensional array representing parking spaces in a parking garage on several floors. The code is incomplete. The functions "main", "display" and "showSpace" are complete. Your job i..

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