Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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: .cpp or .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 __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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91673854
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As