Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 15, Problem 1PC
Program Plan Intro
Analysis of Sorting
Program Plan:
- Include the required header files to the program.
- Define “AbstractSort” class.
- In public, declare the pure virtual function.
- In the “get_comparison” function return the total number of comparison.
- In the “reset_comparison” function reset the comparison value to “0”.
- In protected, declare the “compare” function.
- In private, declare the required variable.
- In public, declare the pure virtual function.
- Define the “compare” function outside the class definition.
- Inside the function, increment the comparison count and return the number of comparison.
- Define the derived class “Max_sort”.
- In public, declare the “sort” function.
- Define the “sort” function.
- Get the array of numbers from the main method and swap operation is performed.
- Define the “main()” function.
- Declare and initialize the required variables.
- Get the array value from the user.
- Check the array value with array index.
- If the array value is greater than index value exits the program.
- Initialize the random number generator and generate the random numbers.
- Create the object for the class “Max_sort”.
- Call the “sort” function.
- Display the result.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
object oriented programing
Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically allocate the array to hold that many numbers. The destructor should free the memory held by the array. In addition, there should be member functions to perform the following operations: • Store a number at any index of the array • Retrieve a number from any index of the array • Return the highest value stored in the array • Return the lowest value stored in the array • Return the average of all the numbers stored in the array
Object Oriented Programming C++
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 theyre 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. Heres what a fragment of a main() program that operates on such a class might look like:If the Number is 738 then: // in case of zero consider next digitmatrix m1(5, 4); // define a matrix objectint temp = 12345; // define an int value m1.putel(7, 4, temp); // insert value of temp into matrix at 7,4 temp = m1.getel(7, 4); // obtain value from matrix at 7,4
Bookstore class uses a dynamic array to hold names book titles.
class BookStore {
public:
BookStore ();
BookStore (const Bookstore & b); // POST: object made from b
-BookStore ();
void insert(string title); // POST: add title to the end of the titles list
private:
string store;
int capacity;
int size;
};
Describe two different situations in which the copy constructor function is called.
Write a short code snippet illustrating each situation. Explain the problem if this class
did not provide a deep copy constructor function.
// POST: empty object with room for 10 titles
// POST: object is destructed
// pointer to dynamic array of book titles
// capacity of array
// number of books used in the bookstore
Chapter 15 Solutions
Starting Out with C++: Early Objects
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 - 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. 18RQECh. 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 - 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
- please fastarrow_forwardData Structuresarrow_forwardThis is an object oriented programming question The code should be in c++ language Create a class Employee having a private data members E_ID, E_Name, E_Age and E_Salary. Now create a public member function void getData() and void ShowData() to take and display an employee data. In the main(), function create an array of Employee class, size of the array should be taken from user at run time and call all the functions defined in the class. Sample Output: Enter details of Employee 1 Enter Employee Id: 101 Enter Employee Name: Usman Enter Employee Age: 29 Enter Employee Salary: 45000 Enter details of Employee 2 Enter Employee Id: 102 Enter Employee Name: Sana Enter Employee Age: 31 Enter Employee Salary: 51000 Enter details of Employee 3…arrow_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_forwardThis is an object oriented programming question The code should be in C++ language Create a class Student having a private data members S_ID, S_Name and S_CGPA. Now create a public member functions void getID(), void getName() and getCGPA() and finally to display all the data members, create a function void display(). In the main(), create an array of student class, size of the array should be taken from user at run time and call all the functions defined in the class. Sample Output: Student 1 Enter ID: 1 Enter Name: Ali Enter CGPA: 2.5 Student 2 Enter ID: 2 Enter Name: Ahmed Enter CGPA: 2.9 Student 3 Enter ID: 3 Enter Name: Zain Enter CGPA: 3.4 Student 1 informationID: 1 Name: Ali CGPA: 2.5 Student 2 information ID: 2 Name: Ahmed CGPA: 2.9 Student 3 information ID: 3 Name: Zain CGPA: 3.4arrow_forwardPLEASE CODE IN PYTHON PLEASE USE NESTED CLASS FUNCTION Design a Point Class with attributes X and Y coordinates. The Class should have following functions: a) change the coordinates, b) return a 2 element list [x,y] c) print a Point object. d) return distance from this instance to a given [x,y] Also design a Line Class which has 2 Point attributes. The Line class should have functions for following behaviours: a) Return the length of the line. b) Print the equation of the line c) Find if this instance is equal in length to another line.arrow_forward
- Design a struct with following members: p_num_lots, int* type pa_lots, int [] type (dynamically allocated) Implement following methods: parameterized constructor which takes an int for num of lots copy constructor copy assignment operator destructorarrow_forwardarray of Payroll ObjectsDesign a PayRoll class that has data members for an employee’shourly pay rate and number of hours worked. Write a program withan array of seven PayRoll objects. The program should read thenumber of hours each employee worked and their hourly pay ratefrom a file and call class functions to store this information in theappropriate objects. It should then call a class function, once foreach object, to return the employee’s gross pay, so this informationcan be displayed.arrow_forwardInstructions: Turn all instances of classes into pointers. You will also need to combine the player and vector into one vector objects and fix all issues this causes. #ifndef ITEM_H #define ITEM_H class Item { public: Item() {}; enum class Type { sword, armor, shield, numTypes }; Item(Type classification, int bonusValue); Type getClassification() const; int getBonusValue() const; private: Type classification{ Type::numTypes }; int bonusValue{ 0 }; }; std::ostream& operator<< (std::ostream& o, const Item& src); bool operator< (const Item& srcL, const Item& srcR); int& operator+=(int& srcL, const Item& srcR); #endif // !ITEM_H #ifndef MONSTER_H #define MONSTER_H #include "Object.h" class Player; class Monster : public Object { public: Monster() {}; Monster(const Player& player); void update(Player& player, std::vector& monsters) override; int attack() const override; void defend(int damage) override; void print(std::ostream& o)…arrow_forward
- Smart Pointer: Write a smart pointer class. A smart pointer is a data type, usually implemented with templates, that simulates a pointer while also providing automatic garbage collection. It automatically counts the number of references to a SmartPointer<?> object and frees the object of type T when the reference count hits zero.arrow_forwardINHERITANCE AND ERROR HANDLING OOP SUBJECTarrow_forward7. Dynamic MathStack The MathStack class shown in this chapter has only two member functions: add and sub. Write the following additional member functions: Function Description mult Pops the top two values off the stack, multiplies them, and pushes their product onto the stack. div Pops the top two values off the stack, divides the second value by the first, and pushes the quotient onto the stack. addAll Pops all values off the stack, adds them, and pushes their sum onto the stack. multA11 Pops all values off the stack, multiplies them, and pushes their prod- uct onto the stack. Demonstrate the class with a driver program. here is the extention file please use it. // Specification file for the IntStack class #ifndef INTSTACK_H #define INTSTACK_H class IntStack { private: int *stackArray; // Pointer to the stack array int stackSize; // The stack size int top; // Indicates the top of the stack public: // Constructor IntStack(int); // Copy constructor…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