Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 11.1, Problem 4STE
Explanation of Solution
Function declaration:
// Declaration of subtract() function
friend Money subtract(Money amount1, Money amount2);
The above function declaration is the “subtract()” friend function.
- In the class “Money”, add the declaration part in the “public” section below the “equal()” function declaration.
Function definition:
// Definition of substract() function
Money subtract(Money amount1, Money amount2)
{
// Create an object for Money class
Money temp;
// Compute amount and assign to temp...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
quick answer please
Write a C++ class to represent an Employee. Each employee is given a name, an age, a NIC number, anaddress, and a salary. Furthermore: The Employee class should keep track of how many employees (objects) have been created inthe system. Your Employee class should initialize all of its fields via a constructor.
Create function prototypes to set and get an employee's zip code. Declare a print_employee() function that prints all of an employee object's details.(Whenever possible, use constant functions.)
C++ OOP use classes only...
Chapter 11 Solutions
Problem Solving with C++ (10th Edition)
Ch. 11.1 - Write a function definition for a function called...Ch. 11.1 - What is the difference between a friend function...Ch. 11.1 - Suppose you wish to add a friend function to the...Ch. 11.1 - Prob. 4STECh. 11.1 - Notice the member function output in the class...Ch. 11.1 - Notice the definition of the member function input...Ch. 11.1 - The Pitfall section entitled Leading Zeros in...Ch. 11.1 - Give the complete definition of the member...Ch. 11.1 - Why would it be incorrect to add the modifier...Ch. 11.1 - What are the differences and the similarities...
Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...Ch. 11 - Do Programming Project 19 from Chapter 8 except...
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 in python. Write a class named Employee that has **private** data members for an employee's name, ID_number, salary, and email_address. It should have an init method that takes four values and uses them to initialize the data members. It should have get methods named get_name, get_ID_number, get_salary, and get_email_address.Write a separate function (not part of the Employee class) named **make_employee_dict** that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the whole Employee object. The function should return the resulting dictionary.For example, it could be used like…arrow_forwardIN C++ In your previous class, move the member variables (student name and grades) as private. Create the proper functions to fill data in them. In main, create an instance of that array and fill that instance with data. Call the DisplayInfo() function from main so it prints the content of the object. A screenshot showing the code in Visual Studio and the output (on the console screen). previous activity class code:- #include <iostream>using namespace std;class student{ public: string Name; string grade[3]; void DisplayInfo() { cout<<"Student Name:"<<Name; cout<<"\nGrade:"<<grade[1]; }};int main(){ cout << "Welcome to my world..." << endl; system("pause"); student obj; obj.Name="Rahul"; obj.grade[1]="A++"; obj.DisplayInfo(); return 0;}arrow_forwardIn C++ Create a class called Pencil. Pencil has a type. Create another class called Customer. The customer class should have a ID number, array (using pointers) called purchases, and a Pencil variable. Make sure to create the purchases array in the constructor. Create a function to fill in purchase amount. Create a way to output all the information about a customer, including all the details about their type of pencil.arrow_forward
- In GO language. Create a struct that has student name, id, and GPA. Write functions to create a student, modify the student’s id, and modify the student's GPA, and print the student’s information. (This is like creating a class and methods). Now create an array of three students and test your functions. You may hardcode your values if using a web conpiler. (Please hardcode the values!)arrow_forward82. Write a class definition for a class named Fraction that contains two integer fields named numerator and denominator. Include in the class a prototype for a method (function) named add that takes two Fraction objects as input arguments and returns a Fraction object as output. You do not need to provide an implementation of the add method.arrow_forwardIn c++1. Create a room structure with member-data room dimensions. Write a show () function that displays the room data and an area () function that calculates its face (squaring).In main () create a static array of rooms (Room variables) - the rooms in one apartment. For each of the rooms, display its dimensions and square footage. Determine the total square footage of the apartment.2. Create a Room class with the same member data and member functions:- constructors - by default and with parameters- member-functions set () - to set the corresponding size of the room- member-functions get () - return the corresponding size-show () - outputting a Room object-аrea () - returns the face of the roomIn main (), create:(a) single room objects located in the stack and in dynamic memory, respectively, using all defined constructors(b) 2 arrays of rooms located in the stack and in the dynamic memory (rooms in two apartments), using all defined constructorsFor each of the rooms: set the…arrow_forward
- Pythonarrow_forwardPlease pay attention to the required data types in the description. Thetuple, list and vector classes and their objects are not allowed to be used. 1. Define a new C++ class named “PayStub” that manages pay information: number of hours (integer), hourly pay rate (double). The total payout amount will be calculated based on overtime. Any hour that ismore than 40 hours will be paid at 1.5 pay rate. For example, with the hourly pay rate of $10.0 and if the number of hours is 40, the payout amount will be 400 and if the number of hours is 50 it will be (40 * 10)+ (10 * 15) = 550Please note that because the payout is a calculated value, it should not be part of the data members to make the object as small as possible. The class must provide at least the following two methods:• toString method that returns the string containing all the information about the paystub including the total payout amount. For example, here is the output for different paystubs:40 hours at $10.0 an hourHOURS(40)…arrow_forwardIN C++, create a class called Employee that includes three pieces of information as data members—a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.arrow_forward
- Code C++ In this project, you will create a class called Camel. Below, we willdescribe what will define a Camel. You will also create a main function inwhich you will create objects of type Camel to test the functionality ofyour new user-defined type. In the main, you will create enough objectsof your new type(s) in order to adequately test their functions. It is up toyou to do this properly.Your Camel class is to contain the following:Member variables:• a float for weight• a short for age (months)• a string for name• a char for gender• a bool to indicate whether alive (or not)Member functions: • a default constructor that creates a dead camel• a constructor that you can pass values to so as to establish itsgender, weight, age, and name; it will default to alive.• a print function that will output to the screen the attributes of thatcamel in a nice, easy to read format.• an age_me function that returns nothing but increments the object'sage.• an eat function that increases the…arrow_forwardPlease add a destructor to the code. Solve this in C++arrow_forwardUse C++ Create a class called Fruit. Add one member variables name. Add only one getter function for the name. The get function returns name. Implement a constructor that expects name value and assigns it to the member variable. This class doesn't have an empty constructor. Create a subclass of Fruit named CitrusFruit. The CitrusFruit class has two member variables weight and color. Add a constructor which expects weight and name and color.Pass name to the base constructor and set weight and color to it's member variable. Write a program that has an array of 3 Fruits, and an array of 3 CitrusFruits. Feel free to give the name , weight and color to the object as your choice. Use loops to print out the array properties to the terminal screen.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