Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 16, Problem 13PC
Program Plan Intro
Employee and ProductionWorker class
Program plan:
source.cpp:
- Include the required header files to the program.
- Declare the required function prototype.
- Define the “main()” function.
- Create the pointer and call the “create_Production_Worker” function with employee data.
- If the pointer is not null, then Call the function “display()” to display the employee details.
- Function definition for function “create_Production_Worker”.
- Create an object for “ProductionWorker” class and pass the employee data.
- Construct catch blocks for handling “InvalidEmployeeNumber”, “InvalidShift” and “InvalidPayRate”.
- Function definition for function “display()”.
- Display the name, number, hire date, shift name, shift number and pay rate using the respective function.
Employee.h:
- Define the “Employee.h”.
- Define an empty “InvalidEmployeeNumber” exception class.
- In private, declare the required variable.
- In public, create the constructor and return the name, number and hire date.
- Create a mutator function for name, number and hire date.
- Create an accessor function for name, number and hire date.
ProductionWorker.h:
- Define the “ProductionWorkder.h”.
- Define an empty “InvalidShift” exception class.
- Define an empty “InvalidPayRate” exception class.
- Create a “ProductionWorker” which is derived from “Employee” class.
- In private, declare the required variable.
- In public, create a default constructor which initializes the “shift” and “rate” as “0” and “0.0” respectively.
- Invoke the constructor “productionWorker” which also calls the “Employee” constructor.
- Assign the “shift” and “rate” as “empShift” and “empPayRate” respectively.
- Create a mutator function for shift name, rate and shift number.
- Create an accessor function for shift name, rate and shift number.
- Create a bool() function to check the employee shift number and pay rate. If it is not valid, then call its relevant exception.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
C++ Visual Studio 2019
Complete #13. Dependent #1 Employee and ProductionWorker classes showing below. Modify the Employee and ProductionWorker classes so they throw exceptions when the following errors occur:
The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999.
The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift.
The ProductionWorker class should throw an exception named InvalidPayRate when it receives a negative number for the hourly pay rate.
Write a driver program that demonstrates how each of these exception conditions works.
#1 Employee and ProductionWorker classes
#include <string>#include <iostream>#include <iomanip>using namespace std;
class Employee{private: string name; // Employee name string number; // Employee number string hireDate; // Hire date
public: // Default…
WAP to demonstrateuser defne exception create InsufficientBalanceException class create cust class if(withdrawlamt > avabal)---->throw InsufficentBalException else------------>collect the amt
Question 3
}
public class WeekDay {
static void daysFromSunday(int day) {
String dayName = "";
try {
}
}
if (day > 7) {
throw new Exception("Invalid Day! Too high!");
}
else if(day < 1){
throw new Exception("Invalid Day! Too low!");
}
switch(day){
case 1: dayName="Sun";
break;
case 2: dayName="Mon";
break;
case 3: dayName="Tue";
break;
case 4: dayName="Wed";
break;
}
▬▬
}
case 5: dayName="Thu";
Dreak;
case 5: dayName="Thu";
break;
case 6: dayName="Fri";
break;
default: dayName="Sat";
System.out.println(dayName);
}
catch (Exception excpt) {
System.out.println("Oops");
System.out.println(excpt.getMessage());
}finally{
System.out.println("Done!");
public static void main(String[] args) {
daysFromSunday(10);
daysFromSunday(3);
daysFromSunday(0);
OOops
Invalid Day! Too high!
Tue
Oops
Invalid Day! Too low!
OOops
Invalid Day! Too high!
Done!
Tue
Done!
Oops
Invalid Day! Too low!
Done!
O Oops
Invalid Day! Too high!
Done!
Oops
Invalid Day! Too high!
Done!
Oops
Invalid Day! Too low!
Done!
O Oops…
Chapter 16 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 16.1 - Prob. 16.1CPCh. 16.1 - Prob. 16.2CPCh. 16.1 - Prob. 16.3CPCh. 16.1 - Prob. 16.4CPCh. 16.1 - Prob. 16.5CPCh. 16.3 - Prob. 16.6CPCh. 16.3 - The following function accepts an i nt argument...Ch. 16.3 - Prob. 16.8CPCh. 16.3 - Prob. 16.9CPCh. 16.4 - Prob. 16.10CP
Ch. 16.4 - Prob. 16.11CPCh. 16 - Prob. 1RQECh. 16 - Prob. 2RQECh. 16 - Prob. 3RQECh. 16 - Prob. 4RQECh. 16 - What is unwinding the stack?Ch. 16 - What happens if an exception is thrown by a classs...Ch. 16 - How do you prevent a program from halting when the...Ch. 16 - Why is it more convenient to write a function...Ch. 16 - Why must you be careful when writing a function...Ch. 16 - The line containing a throw statement is known as...Ch. 16 - Prob. 11RQECh. 16 - Prob. 12RQECh. 16 - Prob. 13RQECh. 16 - The beginning of a template is marked by a(n)...Ch. 16 - Prob. 15RQECh. 16 - Prob. 16RQECh. 16 - Write a function that searches a numeric array for...Ch. 16 - Write a function that dynamically allocates a...Ch. 16 - Make the function you wrote in Question 17 a...Ch. 16 - Write a template for a function that displays the...Ch. 16 - Prob. 21RQECh. 16 - Prob. 22RQECh. 16 - Prob. 23RQECh. 16 - Prob. 24RQECh. 16 - T F All type parameters defined in a function...Ch. 16 - Prob. 26RQECh. 16 - T F A class object passed to a function template...Ch. 16 - Prob. 28RQECh. 16 - Prob. 29RQECh. 16 - Prob. 30RQECh. 16 - Prob. 31RQECh. 16 - T F A class template may not be derived from...Ch. 16 - T F A class template may not be used as a base...Ch. 16 - Prob. 34RQECh. 16 - Prob. 35RQECh. 16 - try { quotient = divide(num1, num2); } cout The...Ch. 16 - template class T T square(T number) { return T T;...Ch. 16 - template class T int square(int number) { return...Ch. 16 - Prob. 39RQECh. 16 - Assume the following definition appears in a...Ch. 16 - Assume the following statement appears in a...Ch. 16 - Prob. 1PCCh. 16 - Prob. 2PCCh. 16 - Prob. 3PCCh. 16 - Prob. 4PCCh. 16 - Prob. 5PCCh. 16 - IntArray Class Exception Chapter 14 presented an...Ch. 16 - TestScores Class Write a class named TestScores....Ch. 16 - Prob. 8PCCh. 16 - Prob. 9PCCh. 16 - SortableVector Class Template Write a class...Ch. 16 - Inheritance Modification Assuming you have...Ch. 16 - Prob. 12PCCh. 16 - Prob. 13PC
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 Month class that holds information about the month. Write exception classes for the following error conditions:• A number less than 1 or greater than 12 is given for the month number.• An invalid string is given for the name of the month.Modify the Month class so that it throws the appropriate exception when either of these errors occurs. Demonstrate the classes in a program.arrow_forwarduse C++ programing language Write a program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle a leap year.)arrow_forwardThe following class maintains an account balance and returns aspecial error code.public class Account{private double balance;// returns new balance or -1 if errorpublic double deposit(double amount){if (amount > 0)balance += amount;elsereturn -1; // Code indicating errorreturn balance;}}Rewrite the class so that it throws appropriate exception instead ofreturning -1 as an error code. Write test code that attempts to depositinvalid amounts and catches the exceptions that are thrownarrow_forward
- In preparation for a class Fraction, create a classNullDenominatorExceptionthat must be a checked exception whoseinstances are thrown if the denominator of an object of class Fraction is 0.arrow_forwardDefine an exception class called CoreBreachException. The class should have a default constructor. If an exception is thrown using this zero- argument constructor, getMessage should return "Core Breach! Evacuate Ship!" The class should also define a constructor having a single parameter of type String. If an exception is thrown using this constructor, getMessage should return the value that was used as an argument to the constructor.arrow_forwardDefine an exception class called CoreBreachException. The class should have a default constructor. If an exception is thrown using zero-argument constructor, getMessage should return "Cor Breach Evacuation Ship!" The class should also define a constructor having a single parameter of type String. If an exception is thrown using constructor, getMessage should return the value that was used as an argument to constructor.arrow_forward
- C++ Each Fraction contains a numerator, denominator, a whole number portion, and has access to several functions you have developed, including overloaded operators. Complete these tasks: a. Create a FractionException class. The class contains a Fraction object and a string message explaining the reason for the exception. Include a constructor that requires values for the Fraction and the message. Also include a function that displays the message. b. Modify each Fraction class constructor and data entry function so that it throws a FractionException whenever a client attempts to instantiate a Fraction with a zero denominator. c. Write a main()function that asks the user to enter values for four Fractions. If the user attempts to create a Fraction with a zero denominator, catch the exception, display a message, and force the Fraction to 0 / 1. Display the four Fraction objects. Save the file as FractionException1.cpp.arrow_forwardChallenge 1: Division.java You have to implement a Division class that divides two numbers given by the user. The program should handle exceptions that could be thrown during operation: If the second number is 0 If any of the numbers is not a valid number, such as a letter.arrow_forwardJava Problem:Create a Class named Bishop. Make sure the class cannot be inherited. If there have already been 5 objects initiated for this class, trying to initiate the 6th object, the constructor will throw a user-defined exception BishopCreationLimitExceeded. This class has an instance method named printObjectNumber which will print the object creation sequence number for the object for which you are calling the method as follows: This Bishop Object number is 3. Here, 3 is the object creation sequence number that is the third call to new Bishop() in your code that initiated the object. The BishopCreationLimitExceeded class sets the exception message (using super call in the constructor) as follows: The maximum number of bishop objects can be 5. You can define instance variables in the Bishop class if you need them.arrow_forward
- C# Program Create program that computes student average Requirements:1. Use inheritance2. Use exception handling if applicable3. Create a class student4. Use the constructor method to collect the student information: name, math, science and english grade (User should be able to input student info)5. Create a method that computes the average6. Create another method that outputs (similarly to) the ff. when calledName: AnnaMath: 92Science: 92English: 92Average: 927. Instantiate a Student object and utilize the defined methods.arrow_forwardTrue or False: IOException serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript.arrow_forward1. Create an exception class called SocSecException. The UML diagram for this class is below. SocSecException + SocSecException(error: String) : The constructor will call the superclass constructor. It will set the message associated with the exception to "Invalid social security number" concatenated with the error string. 2. Create a driver program called SocSecProcessor. This program will have a main method and a static method called isValid that will check if the social security number is valid. SocSecProcessor + main(args : String[]): void + is Valid(ssn: String): boolean Copyright © 2019 Pearson Education, Inc., Hoboken NJ Task #2 Writing Code to Handle an Exception 1. In the main method: a. The main method should read a name and social security number from the user as String objects. b. The main method should contain a try-catch statement. This statement tries to check if the social security number is valid by using the method isValid. If the social security number is valid, it…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage