EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 11, Problem 1PP
Program Plan Intro
Creation of program to construct class for a
Program Plan:
- Define a file “vectorDouble.h” to define properties of vector.
- Define a function prototype for constructor “VectorDouble()”.
- Define a function prototype for destructor “~VectorDouble()”.
- Define a function prototype for method “push_back()”.
- Define a function prototype for method “value_at()”.
- Define a function prototype for method “change_value_at()”.
- Define a function prototype for method “size()”.
- Define a function prototype for method “capacity()”.
- Define a function prototype for method “reserve()”.
- Define a function prototype for method “resize()”.
- Define a function prototype for method “operator<<()”.
- Define a function prototype for method “operator==()”.
- Define a function prototype for method “operator=()”.
- Define a function prototype for method “expandCapacity()”.
- Define a file “vectorDouble.cpp” to define properties of vector.
- Define a method for constructor “VectorDouble()” to create instance of vector.
- Define a method for destructor “~VectorDouble()” to destroy existing vector instances.
- Define a method “push_back()” to push value into array.
- Define a method “value_at()” to return value of element.
- Define a method “change_value_at()” to change value of element.
- Define a method “size()” to compute size of array.
- Define a method “capacity()” to return maximum count possible.
- Define a method “reserve()” to create new array and reserve space.
- Define a method “resize()” to resize the existing array.
- Define a method “operator<<()” to create an overloaded operator.
- Define a method “operator==()” to create an overloaded operator.
- Define a method “operator=()” to create an overloaded operator.
- Define a method “expandCapacity()” to expand capacity of array.
- Define a file “Source.cpp” to call member functions and methods.
- Create instance for vector class.
- Insert values into array.
- Call method “push_back()” to push value into array.
- Call method “value_at()” to return value of element.
- Call method “change_value_at()” to change value of element.
- Call method “size()” to compute size of array.
- Call method “capacity()” to return maximum count possible.
- Call method “reserve()” to create new array and reserve space.
- Call method “resize()” to resize the existing array.
- Call method “operator<<()” to create an overloaded operator.
- Call method “operator==()” to create an overloaded operator.
- Call method “operator=()” to create an overloaded operator.
- Call method “expandCapacity()” to expand capacity of array.
- Display resultant values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
in c++
Declare and implement 5 classes: FloatArray, SortedArray, FrontArray, PositiveArray & NegativeArray. 1- The FloatArray class stores a dynamic array of floats and its size. It has: - A parameterized constructor that takes the array size. - An add method that adds a float at the end of the array. - Overloading for the insertion operator << to write the array to a file (ofstream) - Overloading for the extraction operator >> to read the array elements from the file (ifstream) and add them to the array. - A destructor to deallocate the array 2- The SortedArray inherits from FloatArray. It has: - A parameterized constructor that takes the array size. - An add method that adds a float at the right place in the array such that the array remains sorted with every add. Don’t add to the array then sort but rather add in the right place. 3- The FrontArray inherits from FloatArray. It has: - A parameterized constructor that takes the array size. - An add method that adds a…
The native int type in C++ cannot store large integers of more than 10 decimal digits. In this project, you will implement a bigint class that behaves like the int type but can handle unsigned integers of up to 45 digits.
1. You are to build a class named bigint that can deal with up to 45 decimal digits of unsigned integers. Thebigint class is specified as follows.
2. The bigint class should have a five-element array (int v[5];) as its private date member. Each elementshould store 9 decimal digits.For example to store integer 1,300,000,000,000,900,000,000,100,000,000. You should have v[0] = 100000000,v[1] = 900000000, v[2] =0, v[3]= 1300, and v[4] = 0.
3. The bigint class should have the following constructors:bigint(); // default constructor, set the value to be 0bigint(int x0); // set the value to be x0bigint(int x0, int x1); // set the value to be x1 ∗ 109 + x0bigint(int x0, int x1, int x2); // set the value to be x2 ∗ 1018 + x1 ∗ 109 + x0bigint(int x0, int x1, int x2, int…
Write a program that will sort a prmiitive array of data using the following guidelines - DO NOT USE VECTORS, COLLECTIONS, SETS or any other data structures from your programming language. The codes for both the money and currency should stay the same, the main focus should be on the main file code (Programming language Java)
Create a helper function called 'RecurInsSort' such that:
It is a standalone function not part of any class from the prior lab or any new class you feel like creating here,
Takes in the same type of parameters as any standard Insertion Sort with recursion behavior, i.e.
void RecurInsSort(Currency arr[], int size)
Prints out how the array looks every time a recursive step returns back to its caller
The objects in the array should be Money objects added or manipulated using Currency references/pointers.
It is OK to print out the array partially when returning from a particular step as long as the process of sorting is clearly demonstrated in the output.
In…
Chapter 11 Solutions
EBK PROBLEM SOLVING WITH C++
Ch. 11.1 - Write a function definition for a function called...Ch. 11.1 - What is the difference between a friend function...Ch. 11.1 - Suppose you wish to add a friend function to the...Ch. 11.1 - Prob. 4STECh. 11.1 - Notice the member function output in the class...Ch. 11.1 - Notice the definition of the member function input...Ch. 11.1 - The Pitfall section entitled Leading Zeros in...Ch. 11.1 - Give the complete definition of the member...Ch. 11.1 - Why would it be incorrect to add the modifier...Ch. 11.1 - What are the differences and the similarities...
Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a program that uses two classes. The first class is called “dAta” and holds x and y coordinates of a point in 2-d space called p1. The second class is called “cOmpute” and holds an array of two pointers to the “dAta” class. The “cOmpute” class has a function, lOad(float x, float y, int n), which loads x and y coordinate data into the array at index n. It also has a function, sLope(), which computes the slope of the line connecting the two array data coordiantes. It also has a function, pRint(), which prints the slope result to the screen. Implement a divide by zero exception using throw in the sLope() nd/or pRint() function as appropriate. The exception should, when caught, print “Slope calculation error…” to the screen and exit the function. The program should load the array with some example points and print the slope to the screen using the class functions.arrow_forwardWrite a checkbook balancing program in C++. The program will read in the following information for all checks that were not cashed as of the last time the user balanced their checkbook: the number of each check the amount of the check whether or not the check has yet been cashed Use a dynamic array with a class base type for the checks. The check class should have three member variables: check number check amount whether or not the check's been cashed And don't forget to provide accessors, mutators, and constructors as well as input and output methods. BTW, the amount member variable will be of type Money. Just save this link to the Money class definition — you do not have to design it yourself! (A closer look, however, reveals that it is just a class definition... The definitions for the methods seem to be missing. Bummer...) In addition to all of the checks since the last checkbook update, your program should also read all of the user's deposits, the last balance we…arrow_forwardSuppose that the bag class is efficiently implemented with a fixed array with a capacity of 4000, as in Chapter 3 of the class text. We execute these statements: bag b; b.insert(5); b.insert(4); b.insert(6); b.erase_one(5); Group of answer choices b.used is 2, b.data[0] is 4, b.data[1] is 6 b.used is 2, b.data[0] is 6, b.data[1] is 4 b.used is 3, b.data[0] is 4, b.data[1] is 6 b.used is 3, b.data[0] is 6, b.data[1] is 4arrow_forward
- Implement a main program that defines a dynamically created array, consisting of objects of class Candidate, and calls three functions: to. getVotesCandidate: Function that asks the user for the name and votes of the candidate. b. displayStatistics: function that prints the three columns the name of the candidate, the number of votes obtained and calculates the percentage it represents with respect to the total sum of the votes of the possible candidates. c.getHighestIndex: Function that returns the index where the highest number of votes obtained among the candidates is storedarrow_forwardWrite a program that will sort a prmiitive array of data using the following guidelines - DO NOT USE VECTORS, COLLECTIONS, SETS or any other data structures from your programming language. This will also use your 'Currency' and 'Money' classes from the previous lab, so everything for this lab will be in a new file for 'main'. (Programming language Java) Create a helper function called 'RecurInsSort' such that: It is a standalone function not part of any class from the prior lab or any new class you feel like creating here, Takes in the same type of parameters as any standard Insertion Sort with recursion behavior, i.e. void RecurInsSort(Currency arr[], int size) Prints out how the array looks every time a recursive step returns back to its caller The objects in the array should be Money objects added or manipulated using Currency references/pointers. It is OK to print out the array partially when returning from a particular step as long as the process of sorting is clearly…arrow_forwardSolve the problem in C++ (Extend MyPoint) In Programming Exercise 9.4, the MyPoint class was created to model a point in a two-dimensional plane. The MyPoint class has the properties x and y that represent x- and y-coordinates, two getter functions for x and y, and the function for returning the distance between two points. Create a class named ThreeDPoint to model a point in a three-dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features: - A data field named z that represents the z-coordinate.- A no-arg constructor that constructs a point with coordinates (0, 0, 0).- A constructor that constructs a point with three specified coordinates.- A constant getter function that returns the z value.- A constant distance(const MyPoint&) function to return the distance between this point and the other point in the three-dimensional space. Draw the UML diagram for the classes involved. Implement the classes. Write a test program that creates two…arrow_forward
- I am learning C for a class I am taking and a homework assignment asks us to makes a list of integers, divides the list into a number of segments, and displays each segment in reverse order. We need to use the function malloc to dynamically allocate locations for variables a and b. The full assignment is below. I am not too familiar with C and I don't know how to split the list into two arrays.arrow_forwardTest the Baby class below by writing a client program which uses an array to storeinformation about 4 babies. That is, each of the four elements of the arraymust store a Baby object.If you have an array for baby names and another array for baby ages,then you have missed the point of the exercise and therefore not metthe requirement of this exercise.A Baby class object stores the required information about a Baby. Soeach Baby object will have its own relevant information, and thus eachobject must be stored in one element of the array.The client program should:a. Enter details for each baby (name and age) and thus populate theBaby arrayb. Output the details of each baby from the array (name and age)c. Calculate and display the average age of all babies in the arrayd. Determine whether any two babies in the array are the sameAs the required information for these tasks is stored in the Baby array, youwill need to use a loop to access each array element (and use the dot notationto access…arrow_forwardThe goal of this second exercise is to develop a better understanding of the Linuxinterprocess communication mechanisms. This would require you to write twoprograms P1 and P2. The first program P1 needs to generate an array of 50random strings (of characters) of fixed length each. P1 then sends a group offive consecutive elements of the array of strings to P2 along with the ID’s ofthe strings, where the ID is the index of the array corresponding to the string.The second program P2 needs to accept the received strings, and send backthe highest ID received back to P1 to acknowledge the strings received. Theprogram P2 simply prints the ID’s and the strings on the console. On receivingthe acknowledged packet, P1 sends the next five strings, with the string elementsstarting from the successor of the acknowledged ID. The above mechanism needs to be implemented FIFO and UNIX DOMAIN SOCKETS. Please note that you may NOT make assumptions about the reliability of the interprocess communication…arrow_forward
- Q3: Write a program in C++ using OOP to create a class (A), that have a two dimensional array X[5][5], and function (input) to read it from keyboard Then create a class(B), with public visibility mode inherit from class (A), contain the function (sample_T) to print the element that form the letter (T)in array (X). Then create a class(C), with public visibility mode inherit from class (A), contain the function (sample L.) to print the element that form the letter (L) in array (X). Then create a class(D), with public visibility mode inherit from class (B) and (C), contain the function (RUN) to call the to function above.arrow_forwardAn array is a container object that holds a fixed number of values of a single type. To create an array in C, we can do int arr[n];. Here, arr, is a variable array which holds up to integers. The above array is a static array that has memory allocated at compile time. A dynamic array can be created in C, using the malloc function and the memory is allocated on the heap at runtime. To create an integer array, of size , int *arr = (int*)malloc(n * sizeof(int)), where points to the base address of the array. When you have finished with the array, use free(arr) to deallocate the memory. In this challenge, create an array of size dynamically, and read the values from stdin. Iterate the array calculating the sum of all elements. Print the sum and free the memory where the array is stored. While it is true that you can sum the elements as they are read, without first storing them to an array, but you will not get the experience working with an array. Efficiency will be required later.…arrow_forwardComputer Science Create an inheritance hierarchy of Rodent: Mouse, Gerbil, Hamster, etc. In the base class, provide methods that are common to all Rodents, and redefine these in the derived classes to perform different behaviors depending on the specific type of Rodent. Create an array of pointers to Rodent, fill it with different specific types of Rodents, and call your base-class methods to see what happens. Write a small program to show the difference between calling a virtual function inside a normal member function and calling a virtual function inside a constructor. The program should prove that the two calls produce different results.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning