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
Create a class called Name that contains data members of type string called first name, middle
name, last name, and salutation. Add a constructor that takes four parameters which are used to
initialize the four data members and a member function called to-string that returns the person's full
name in the form of “Salutation First name Middle name Last name”. Finally add set and get functions
for all the data members. Add a destructor to the program displaying a suitable msg.
quick answer please
Create a class Employee with following data members, name, id, and salary as private datamember. Create array of objects for four employees, compare their salary using operatoroverloading, and display the records of the student who is getting less salary. by c++
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 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.)arrow_forwardC++ OOP use classes only...arrow_forwardWrite 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_forward
- So form code should be established in a functional way and outcome also.arrow_forwardI am trying to create a class called Car in Python with yearModel, make, and speed as attributes. I want to create a two-element constructor that accepts values to set yearModel and make. I need getter/setter functions for each attribute. An accelerate function to increment speed by 5 and a brake function to decrement by 5. I also want a main driver function to accept user input for a year and make of the car. I want to repeatedly call the accelerate and brake functions. I need to output the incrementing speed and decrementing braking speeds. As well as the cars year and make and starting 0 speed. This is the code I have so far, I mainly need help figuring out how to ask for user input at the end. class Car: def __init__(self, yearModel, make, speed): self.yearModel = yearModel self.make = make self.speed = 0 def getyearModel(self): return(self.yearModel) def getmake(self): return(self.make) def getspeed(self):…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_forward
- In 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_forwardusing c++ Develop a class called Point with two data members: x and y. Here you are dealing with a point in planar (2D) Cartesian coordinates with two integer values (x and y). Here are what you need to do: • Define a print function that returns the coordinates of a Point object. • Define a function to find the distance between two points. • Define a function to move a point to the specified location (x’, y’). • Define a function to translate a point by (dx, dy): the new location will be (x+dx, y+dy). • Define functions to tell the user if a point is on the left side, right side, above, or below another point (it can be the combination of some of these or exactly on the same spot). You also need to implement proper constructors (default and parameter constructors), a copy constructor, a destructor, getters, and setters for the data members. Implement the program with separate files: an interface file, an implementation file, and an application file (driver program). Your driver program…arrow_forward1. Short questions: a. What is the difference between having a function return type being "const dataType &" and it being "dataType&"? b. When is it necessary to make a function or a class a friend of another class? c. List all who can access: the private member of a class protected member of a class public member of a class d. What is difference between static data and a regular data of a class?arrow_forward
- What statements about the destructor of an object are accurate? a. The destructor of a class is a member function that is automatically activated when an object becomes inaccessible. b. The destructor has no arguments and its name must be the character ~ followed by the class name (e.g., ~bag for the bag class). c. Because the destructor is automatically called, programs rarely make explicit calls to the destructor, and we generally omit the destructor from the documentation that tells how to use the class. d. The primary responsibility of the destructor is simply releasing dynamic memory. c & d a, b, & c b & c a & b a, b, c, & darrow_forwardIn 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_forwardSuppose in Islamabad International Airport the plans arrivals and departures are frequent and they are moving with a kinetic energy. Your task is to write a class to find the kinetic energy of an airplane coming from UK having the mass and the velocity known to pilots only. You are a pilot so your captain of the plane has given you the task to write a class to perform the calculation, the function must be defined outside the class. Your task is to provide the mass and velocity as arguments to the function and then display the kinetic energy without returning a value.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