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

  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..

  Grade book program for his class

Your English instructor, realizing you are a programmer, asks you to write a Grade Book program for his class to help him compute final grades. Design a program that asks for the student's name and four test grades.

  Programing in c data validity

write a main function to input 20 integers in the range of 1 to 6. write a function count the number of times the numbers 2 and 5 occur. the function should declare static variables count2 and count5. check the data validity in the main functi..

  Create and prepare a disk file for records containing struct

Store the account records in the file using the same hashing/rehashing technique used for storing them in an array of structures.

  Create a friend class bestfriend to the class frac

Create a friend class BestFriend to the class frac. Inside the class BestFriend, and implement a function outputfrac() to print the content of the frac instance

  Demonstrate overriding of their getter and setter methods

Organize following animals using classes and virtual function. tigers,crocodile, elephants,pythons,zebras,hawks, chickens,rabbits using at least 3 properties some of the animals share. demonstrate overriding of their getter and setter methods.

  Write a program that request a students name

Write a program that request a student's name in the subsequent form: lastName,firstName.

  Which of the following correctly invokes the function f

which of the following correctly invokes the function F, assuming N is an integer variable?

  Writer a program that allows the user to enter an unknown

writer a program that allows the user to enter an unknown number of characters stores those characters in a data

  Client function that merges two instances of the sorted list

Write a client function that merges two instances of the Sorted List ADT using the following specification.

  Question 1 what basic differences exist between the

question 1 what fundamental differences exist between object-oriented and relational database systems?question 2

  Write a c function for reversing circular single linked list

Let A and B be two structures of type linked list. Write a function for creating new linked list C that contains elements alternately from A and B beginning with first element of A. If you run out of the elements in one of the lists then append the r..

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