C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 22, Problem 22.25E
Program Plan Intro
- To define two classes: classItem and classItemGroup.
- Create objects of classItem in classItemGroup which could call the constructors desired.
- Using an exception handler in test program, check result for a specific value (in this program value is 2).
- When this value is validated, the program throws an exception and destructors are called only for those constructors which were called before the exception.
Summary Introduction- The program to demonstrate that destructors are called only for the object constructed before the exception.
Program Description- The program contains 5 files: classItem.h, classItem.cpp, classItemGroup.h, classItemGroup.cpp and testItem.cpp.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Constructors Throwing Exceptions) Write a program that shows a constructor passing information about constructor failure to an exception handler after a try block
(Local Variable Destructors) Write a program illustrating that all destructors for objectsconstructed in a block are called before an exception is thrown from that block.
(Catching Derived-Class Exceptions) Use inheritance to create various derived classes ofruntime_error. Then show that a catch handler specifying the base class can catch derived-classexceptions.
Chapter 22 Solutions
C How to Program (8th Edition)
Ch. 22 - Prob. 22.15ECh. 22 - (Catch Parameter) Under what circumstances would...Ch. 22 - (throw Statement) A program contains the statement...Ch. 22 - (Exception Handling vs. Other Schemes) Compare and...Ch. 22 - Prob. 22.19ECh. 22 - Prob. 22.20ECh. 22 - Prob. 22.21ECh. 22 - (Catching Derived-Class Exceptions) Use...Ch. 22 - Prob. 22.23ECh. 22 - Prob. 22.24E
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
- (Default Constructor) What’s a default constructor? How are an object’s data members initialized if a class has only an implicitly defined default constructor?arrow_forward(Package Inheritance Hierarchy) Use the Package inheritance hierarchy created inExercise 19.9 to create a program that displays the address information and calculates the shippingcosts for several Packages. The program should contain a vector of Package pointers to objects ofclasses TwoDayPackage and OvernightPackage. Loop through the vector to process the Packagespolymorphically. For each Package, invoke get functions to obtain the address information of thesender and the recipient, then print the two addresses as they would appear on mailing labels. Also,call each Package’s calculateCost member function and print the result. Keep track of the totalshipping cost for all Packages in the vector, and display this total when the loop terminates.arrow_forward(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. THIS IS C#arrow_forward
- (Dynamic Binding vs. Static Binding) Distinguish between static binding and dynamicbinding. Explain the use of virtual functions and the vtable in dynamic bindingarrow_forwardWrite in C++ Language. (Employee Record): Create a class named 'Staff' having the following members: Data members - Id – Name - Phone number – Address - AgeIt also has a function named 'printSalary' which prints the salary of the staff.Two classes 'Employee' and 'Officer' inherits the 'Staff' class. The 'Employee' and 'Officer' classes have data members 'Top Skill' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a officer by making an object of both of these classes and print the same.arrow_forward(Protected vs. Private Base Classes) Some programmers prefer not to use protected accessbecause they believe it breaks the encapsulation of the base class. Discuss the relative merits of usingprotected access vs. using private access in base classes.arrow_forward
- (Rectangle Class) Create a class Rectangle with attributes length and width, each of whichdefaults to 1. Provide member functions that calculate the perimeter and the area of the rectangle.Also, provide set and get functions for the length and width attributes. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.arrow_forward10) In C++, try-catch blocks can be nested. Also, an exception can be thrown again using “throw; ” true or false 8) Exceptions are run-time anomalies or abnormal conditions that a program encounters during its execution true or falsearrow_forwardusing c++arrow_forward
- (JAVA) The use case description for the View Exam Grades use case is described below. Determineclasses that are needed to implement the use case. Also, define each class's attributes andmethods. Represent class and its attributes and methods using the UML class notation.Use case name: View Exam Grades.Summary: The student looks at his/her exam grade of CS2365 OOP or CS3365 SoftwareEngineering.Actor: StudentPrecondition: None.Main sequence:1. The student enters the student ID and password into the system.2. The system checks if the student ID and password are valid.3. The system displays the course numbers (e.g., CS2365 and CS3365) if the ID andpassword are valid.4. The customer chooses only a course to view the grade.5. The system displays the course grade to the student.Alternative sequence:Step 3: If the student's ID and password are invalid, the system displays an error messageand asks to enter another ID and password into the system. If the ID and password arevalid, the system…arrow_forward(Account class)Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type int to represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display an error message indicating that the initial balance was invalid. Provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged, and the function should print a message indicating "Debit amount exceeded account balance." Member function get_Balance should return the current balance. Create a program that creates two Account objects and tests the member functions of class…arrow_forward(Stack Unwinding) Write a program that throws an exception from a deeply nested function and still has the catch handler following the try block enclosing the initial call in main catchthe exception.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education