STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 15, Problem 20RQE
Program Plan Intro
- Start a program.
- Declare a class named “Sorter”.
- Declare a required member variables and pure virtual function.
- In public, define the member function “set_Array()”.
- Inside the function set the array and size of an array.
- Define the “sort” function.
- Inside the function, call the “sort()” function with an argument size.
- Define the “sort” function.
- If the size is less than 1, the condition will ended.
- Find the position of largest value in array and put it at the end of the array.
- Use the “compare ()” function for sorting the given array.
- Swap a pair of array elements.
- Decrement the size by 1.
- Define the derived class “Incr_Sorter” from the class “Sorter”.
- In private, define the pure virtual function “compare()”.
- If the “x” value is greater than “y” value return true.
- In private, define the pure virtual function “compare()”.
- Define the derived class “Decr_Sorter” from the class “Sorter”.
- In private, define the pure virtual function “compare()”.
- If the “x” value is less than “y” value return true.
- In private, define the pure virtual function “compare()”.
- Inside the “main” function,
- Create the objects for the classes.
- Declare and initialize an array of 5 values.
- Call the “Incr_Sorter” function.
- Call the “print_Array()” function for displaying the output.
- Call the “Decr_Sorter” function.
- Call the “print_Array()” function for displaying the output.
- Define the “print_Array()” function.
- Display the array.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
write a c++ program
in c++: Implement the Array class that is defined below and test it in the main program. The main program must test all the member functions including the overloaded operators that are defined in the class:
#ifndef array_h
#define array_h
#include <iostream>
using namespace std;
class Array { // Class declaration
friend const Array operator+(const Array & a1, const Array &a2);
friend bool operator==(const Array & a, const Array &b);//Equality test
public:
Array(int = 10); //Initialize the array with 0 values, default size =10
Array(const Array & a); // copy constructor
~Array();//Destructor
int getSize();// return the size of the array.
const Array & operator=(const Array & a);//assignement operator
Array operator+(int x);//+ operator
bool operator!=(const Array & a) const;//Not equal test
void read();
void print();
Array operator-();//Negate (unary operation)…
Computer Science
Write in Javascript please and use high order functions liek map or filter or reduce
let obj = [ { mode: "hot" }, { temp: "low" }, { mode: "cold } ]
I want to create a function that get object by key such as:
myFunc("mode"); returns { mode: "hot" }
next call of myFunc("mode") returns { mode: "cold
Chapter 15 Solutions
STARTING OUT WITH C++ MPL
Ch. 15.3 - Prob. 15.1CPCh. 15.3 - Prob. 15.2CPCh. 15.3 - What will the following program display? #include...Ch. 15.3 - What will the following program display? #include...Ch. 15.3 - What will the following program display? #include...Ch. 15.3 - What will the following program display? #include...Ch. 15.3 - How can you tell from looking at a class...Ch. 15.3 - What makes an abstract class different from other...Ch. 15.3 - Examine the following classes. The table lists the...Ch. 15 - A class that cannot be instantiated is a(n) _____...
Ch. 15 - A member function of a class that is not...Ch. 15 - A class with at least one pure virtual member...Ch. 15 - In order to use dynamic binding, a member function...Ch. 15 - Static binding takes place at _____ time.Ch. 15 - Prob. 6RQECh. 15 - Prob. 7RQECh. 15 - Prob. 8RQECh. 15 - The is-a relation between classes is best...Ch. 15 - The has-a relation between classes is best...Ch. 15 - If every C1 class object can be used as a C2 class...Ch. 15 - A collection of abstract classes defining an...Ch. 15 - The keyword _____ prevents a virtual member...Ch. 15 - To have the compiler check that a virtual member...Ch. 15 - C++ Language Elements Suppose that the classes Dog...Ch. 15 - Will the statement pAnimal = new Cat; compile?Ch. 15 - Will the statement pCreature = new Dog ; compile?Ch. 15 - Will the statement pCat = new Animal; compile?Ch. 15 - Rewrite the following two statements to get them...Ch. 15 - Prob. 20RQECh. 15 - Find all errors in the following fragment of code,...Ch. 15 - Soft Skills 22. Suppose that you need to have a...Ch. 15 - Prob. 1PCCh. 15 - Prob. 2PCCh. 15 - Sequence Sum A sequence of integers such as 1, 3,...Ch. 15 - Prob. 4PCCh. 15 - File Filter A file filter reads an input file,...Ch. 15 - Prob. 6PCCh. 15 - Bumper Shapes Write a program that creates two...Ch. 15 - Bow Tie In Tying It All Together, we defined a...
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
- 03 Inheritance / Polymorphism Task 1 Currently, you are using composition by creating an instance of a vector / ArrayList inside your AddressBook. This works fine but if we really think about it, and AddressBook is a collection like a stack or a queue or a vector for that matter. Your task is to: C++ derive AddressBook from vector. In other words, use the vector as a base class and derive AddressBook from it. This means that you will need to remove the Vector from the private section of your class. You are going to have to make some fundamental changes to your AddressBook so that you are using the vector / ArrayList functionality to store and retrieve people. In other words, you should be accessing the ArrayList / vector using this. C++ people, don’t forget you are returning pointers in the accessors of the AddressBook class Test your AddressBook the same way you did for assignment 2. If you have coded everything properly it should work the same. Task 2 Create class called Player that…arrow_forwardmember and non-member functions c++arrow_forwardC++ codearrow_forward
- : A designer in 3D graphics company wants to design a matrix as a two-dimensional array. The size of 2D array could be the last two digit of arid number. Initially he creates a class matrix that provides the member function to check that no array index is out of bounds. Make the member data in the matrix class a 10-by-10 array. A constructor should allow the programmer to specify the actual dimensions of the matrix (provided they’re less than 10 by 10). The member functions that access data in the matrix will now need two index numbers: one for each dimension of the array. Here’s what a fragment of a main() program that operates on such a class might look like: If my Arid Number is 20-Arid-254 then: // in case of zero consider next digit matrix m1(5, 4); // define a matrix object int temp = 12345; // define an int value m1.put(3, 4, temp); // insert value of temp into matrix at 3,4 temp = m1.get(3, 4); // obtain value from matrix at 3,4arrow_forwardT or F -Functions are considered to be objects in JavaScript because they contain three critical attributes: data, methods that act on the data, parameters for passing the data also known as awareness. -A recursive function is a function that calls itself and eventually returns default value to break out of the recursion. -A function that is used to create a new object is called an anonymous function. -Attributes define additional characteristics or properties of the element which is the same as for the start tag. -Javascript is similar to the Java programming languagearrow_forwardDon't use vector array .using c++ languagearrow_forward
- Data Structures and Algorithms in C/C++ In this assignment, you will be using quicksort to sort an array of car objects by various criteria Define a struct Car as follow: #define MAX_STRING_LENGTH typedef struct Car_ { char make[MAX_STRING_LENGTH]; char model[MAX_STRING_LENGTH]; int mpg; /* Miles per gallon */ } Car; Implement a function called compareCarsByMakeThenModel that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByMakeThenModel should return a value that will cause qksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model. Implement a function called compareCarsByDescendingMPG that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByDescendingMPG should return a value that will cause qksort to sort an array of cars in descending order (from largest to smallest)…arrow_forwardSubject Object oriented programming DO task in C++ Start with the safearay class from the ARROVER3 program in Chapter 8 of Object Orient programming by Rober Lafore. Make this class into a template, so the safe array can store any kind of data. Include following member functions in Safe array class. The minimum function finds the minimum value in array. The maximum function find the maximum value in array. The average function find average of all the elements of an array. The total function finds the running total of all elements of an array. In main(), create safe arrays of at least two different types int and double and store some data in them. Then display minimum, maximum, average and total of array elements. Note: use subscript ([]) operator in sasfearay class.arrow_forwardIn C++ Syntax for arrays of objects classGrades allCS[15]; //the default constructor is applied to //all elements of this array //to set the number of students in each class to 25 for (i = 0; i < 15; i++) { allCS[i].setNumStudents(25); } //Assume values in all classes. Write the code to print all class averages?arrow_forward
- Attach code and screenshotarrow_forwardOCAML Programming language Sliding tiles The mechanics described in this exercise can be used to implement a game sliding tiles. 1. Create a type slidingTile, consisting of a char matrix and two integers x and y. The integers x and y are the coordinates of an empty tile. 2. Create a function val slide : slidingTile -> int -> int -> slidingTile = <fun> that given a slidingTile and two integers, that represent a location in the matrix, it slides the tile from the specified location to the empty tile, then returns the altered sliding Tile. If provided location is not adjacent to the empty tile, or out of bounds, then return the slidingTile unaltered. 3.Create a function val print_tile : slidingTile -> unit = <fun> that prints a sliding Tile on screen with the corresponding characters from the matrix. However, print an empty space where the empty tile is instead.arrow_forwardin c++ language pleasssearrow_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