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
Using C++, design a class named sortedArray. In this class include three data members: capacity, size, and arr (a pointer that points to the first element of the array in the heap). In addition, design a member function named insert that adds elements to the end of the array and a function print that prints the elements of the array, which is equal to size. The elements of the array should be sorted. Create a member function called moveTowardEnd to be able to insert a new element and move the rest towards the end of the array. Likewise, create a member function called moveTowardFront to move the elements of the array towards the front after an element of the array is deleted. Create a member function named remove to delete an element of the array using “pass by value” and consequently moves the left-over elements to the front of the array to take place of the deleted element of the array. Output a message if an element not present in the array is attempted to be removed. Test your…
Object Oriented Programing:
Create a class template for a class named GeneralStackthat holds
• A single data member as an array named stack of size 50 to store certain elements
• Three member functions i.e. push(type) to add elements in the Stack, pop() to remove elements from the stack, and currentStatus() to check whether the array is filled or not. (A filled array is an array that has non-zero value at all of its indexes). In the main() function, create three objects with different data types of class General Stack and test the functionality of member functions for various values of data members for these objects.
write a c++ program
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
- In-class 5: Making an extensible array Language c Write a function to would allow you to extend the size of an array-based pointer. Feels free to come up with your own function signature, what it should return, and your own test cases.arrow_forwardin 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)…arrow_forwardIn C programming: Write a main() function using the following requirements:• Define a SIZE constant (the value is irrelevant, but for testing, you may want to keep it small enough – no bigger than 5)• Create an array of course pointers using SIZE• Dynamically allocate each element of the array• Call inputAllCourses()• Call printAllCourses().arrow_forward
- 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
- Pointer and classImplement a class called Team as specified:data members:name - the name of the Team (defined as a dynamic variable)members - a dynamic array of stringsize - number of members in the team.functions:Course(): default constructor set name to “TBD”, and size to 0, members toempty listCourse(string): one argument constructor set name, and size to 0, members toempty listaccessor - an accessor for the name and size variablemutator - an mutator for the name variableUse following main() to test your class.int main() {Team a,b("Mets");cout<<a.getName()<<endl; // print TBDa.setName("Yankee");cout<<a.getName()<<endl; // print Yankeecout<<b.getName()<<endl; // print Metscout<<a.getSize()<<endl; // print 0return 0;}arrow_forwardJAVA LANGUAGEarrow_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_forward
- T 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_forwardC++ Programming D.S.Malik12-10: Add the function max as an abstract function to the class arrayListType to return the largest element of the list. Also, write the definition of the function max in the class unorderedArrayListType and write a program to test this function.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