Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 11.5, Problem 11.9CP
Explanation of Solution
Memberwise assignment:
In the same class, one object of each member can be assigned to another object of same data type.
- Using assignment operator “equal to (=)”, one object is copied to another object
- The objects are passed by value to functions or returned by value from functions.
The memberwise assignment operator occurs during two instances, they are,
- When copying one object to another object.
- To initialize data of one object to another object.
Example:
Consider the example of memberwise assignment is as follows:
//main method
int main()
{
//create the objects for the class
Triangle a (10);
Triangle b (5);
//display the output
cout << "Area of triangle1 is: " << a...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Using the scenario of Object oriented programming
Q1 Write a program that defines a class with a data member to holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each about its serial number. They should respond I am object number 2, and so on.
A C++ assignment
Implement the GradedActivity class. Copying from the pdfs is fine.
Create a new class Assignment which is derived from GradedActivity. It should have three private member ints for 3 different parts of an assignment score: functionality (max 50 points), efficiency (max 25 points), and style (max 25 points).
Create member function set() in Assignment which takes three parameter ints and sets the member variables. It should also set its score member, which is inherited from GradedActivity, using the setScore() function, to functionality + efficiency + style. Signature:
void Assignment::set(int, int, int)
Create a main program which instantiates an Assignment, asks the user for its functionality, efficiency, and style scores, and prints out the score and letter grade for the assignment.
___________________________________________________
Examples from the pdfs:
d PassFailExam::set(int q, int m, int p) { double numericScore, pointsEach;
numQuestions =…
You have to implement program that compares graduate students based on their ranks.
The design of the program is given in the following UML diagram:
• Student class: Base class that GradStudent extends.
• GradStudent class: The objects from this class will be used for comparisons.
• Rankable interface: Defines the implementation needed for comparison. GradStudent implements this interface.
• Test class will be used to get student information from the user and demonstrate the comparison of students.
Chapter 11 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 11.3 - What is the difference between an instance member...Ch. 11.3 - Static member variables are declared inside the...Ch. 11.3 - Does a static member variable come into existence...Ch. 11.3 - What limitation does a static member function...Ch. 11.3 - What action is possible with a static member...Ch. 11.3 - If class X declares function f as a friend, does...Ch. 11.3 - Suppose that class Y is a friend of class X,...Ch. 11.5 - Briefly describe what is meant by memberwise...Ch. 11.5 - Prob. 11.9CPCh. 11.5 - Prob. 11.10CP
Ch. 11.5 - When is a copy constructor called?Ch. 11.5 - How does the compiler know that a member function...Ch. 11.5 - What action is performed by a classs default copy...Ch. 11.6 - Assume there is a class named Pet. Write the...Ch. 11.6 - Assume that dog and cat are instances of the Pet...Ch. 11.6 - What is the disadvantage of an overloaded ...Ch. 11.6 - Prob. 11.17CPCh. 11.6 - Prob. 11.18CPCh. 11.6 - Assume there is a class named Animal, which...Ch. 11.6 - Prob. 11.20CPCh. 11.6 - Describe the values that should he returned from...Ch. 11.6 - Prob. 11.22CPCh. 11.6 - What type of object should an overloaded operator...Ch. 11.6 - Prob. 11.24CPCh. 11.6 - If an overloaded or operator accesses a private...Ch. 11.6 - Prob. 11.26CPCh. 11.6 - When overloading a binary operator such as or as...Ch. 11.6 - Explain why overloaded prefix and postfix and ...Ch. 11.6 - Prob. 11.29CPCh. 11.6 - Overload the function call operator ( ) (int i,...Ch. 11.8 - Prob. 11.31CPCh. 11.8 - How is the type declaration of an r value...Ch. 11.8 - Prob. 11.33CPCh. 11.8 - Prob. 11.34CPCh. 11.8 - Which operator must be overloaded in a class...Ch. 11.8 - Prob. 11.36CPCh. 11.10 - What arc the benefits of having operator functions...Ch. 11.10 - Prob. 11.38CPCh. 11.10 - Assume that there is a class named BlackBox. Write...Ch. 11.10 - Assume there are two classes, Big and Smal1.Write...Ch. 11.13 - What type of relationship between classes is...Ch. 11.13 - Why does it make sense to think of a base class as...Ch. 11.13 - What is a base class access specification?Ch. 11.13 - Think of an example of two classes where one class...Ch. 11.13 - What is the difference between private members and...Ch. 11.13 - What is the difference between member access...Ch. 11.13 - Suppose a program has the following class...Ch. 11.14 - What is the reason that base class constructors...Ch. 11.14 - Why do you think the arguments to a base class...Ch. 11.14 - Passing arguments to base classes constructors...Ch. 11.14 - What will the following program display? #include...Ch. 11.14 - What will the following program display? #include...Ch. 11 - If a member variable is declared _____, all...Ch. 11 - Static member variables are defined _____ the...Ch. 11 - A(n) _____ member function cannot access any...Ch. 11 - A static member function may be called _____ any...Ch. 11 - A(n) _____ function is not a member of a class,...Ch. 11 - A(n) _____ tells the compiler that a specific...Ch. 11 - _____ is the default behavior when an object is...Ch. 11 - A(n) _____ is a special constructor, called...Ch. 11 - _____ is a special built-in pointer that is...Ch. 11 - An operator may be _____ to work with a specific...Ch. 11 - When the _____ operator is overloaded, its...Ch. 11 - Making an instance of one class a member of...Ch. 11 - Object composition is useful for creating a(n)...Ch. 11 - A constructor that takes a single parameter of a...Ch. 11 - The class Stuff has both a copy constructor and an...Ch. 11 - Explain the programming steps necessary to make a...Ch. 11 - Explain the programming steps necessary to make a...Ch. 11 - Consider the following class declaration: class...Ch. 11 - Describe the difference between making a class a...Ch. 11 - What is the purpose of a forward declaration of a...Ch. 11 - Explain why memberwise assignment can cause...Ch. 11 - Explain why a classs copy constructor is called...Ch. 11 - Explain why the parameter of a copy constructor...Ch. 11 - Assume a class named Bird exists. Write the header...Ch. 11 - Assume a class named Dollars exists. Write the...Ch. 11 - Assume a class named Yen exists. Write the header...Ch. 11 - Assume a class named Length exists. Write the...Ch. 11 - Assume a class named Collection exists. Write the...Ch. 11 - Explain why a programmer would want to overload...Ch. 11 - Each of the following class declarations has...Ch. 11 - A derived class inherits the _____ of its base...Ch. 11 - The base class named in the following line of code...Ch. 11 - The derived class named in the following line of...Ch. 11 - In the following line of code, the class access...Ch. 11 - In the following line of code, the class access...Ch. 11 - Protected members of a base class are like _____...Ch. 11 - Complete the following table by filling in...Ch. 11 - Complete the following table by filling in...Ch. 11 - Complete the following table by filling in...Ch. 11 - When both a base class and a derived class have...Ch. 11 - When both a base class and a derived class have...Ch. 11 - An overridden base class function may be called by...Ch. 11 - Each of the following class declarations and/or...Ch. 11 - Soft Skills 44. Your companys software is a market...Ch. 11 - Check Writing Design a class Numbers that can be...Ch. 11 - Day of the Year Assuming that a year has 365 days,...Ch. 11 - Day of the Year Modification Modify the DayOfYear...Ch. 11 - Number of Days Worked Design a class called...Ch. 11 - Palindrome Testing A palindrome is a string that...Ch. 11 - Prob. 6PCCh. 11 - Corporate Sales A corporation has six divisions,...Ch. 11 - Prob. 8PCCh. 11 - Rational Arithmetic II Modify the class Rational...Ch. 11 - HTML Table of Names and Scores Write a class whose...Ch. 11 - Prob. 11PC
Knowledge Booster
Similar questions
- Problem B Now we are going to use the design pattern for collecting objects. We are going to create two classes, a class AmazonOrder that models Amazon orders and a class Item that models items in Amazon orders. An item has a name and a price, and the name is unique. The Item class has a constructor that takes name and price, in that order. The class also has getters and setters for the instance variables. This is the design pattern for managing properties of objects. The setName() method should do nothing if the parameter is the empty string, and the setPrice() method should do nothing if the parameter is not positive. The class also has a toString() method that returns a string representation for the item in the format “Item[Name:iPad,Price:399.99]”. For simplicity, we assume an Amazon order can have at most 5 items, and class AmazonOrder has two instance variables, an array of Item with a length of 5 and an integer numOfItems to keep track of the number of items in the…arrow_forwardImplement the classes according to the given class diagram. It shows both the composition and aggregation relationships. Driver has a Vehicle and Engine is a part of that Vehicle. [Note: consider the necessary data members, constructors, destructors and member functions accordingly] Note: solve as soon as possible use C++ LANGUAGE Class diagram is givenarrow_forwardOOP project by java programming languagearrow_forward
- A User class has an association link to a Service class, and calls its compute() method to do mathematical calculations. Because the computation takes time, it is better to first prompt a waiting message, which was not yet provided, to inform the user. However, the Service class is also used by other internal classes that do not need the message. Therefore, your job is to come out a way to provide the message without modifying the association relationship and the code of the Service class. What design pattern is a useful choice? Also,Show the new design in UML class diagram. Extra interfaces or classes can be added.arrow_forwardProgram thisarrow_forwardWe wish to implement a system that allows the management of Employees and Students. As a first step. you need to implement the above UML diagrams Notes: . ZOOM . PERSON, EMPLOYEE and STUDENT should be public static constants The no-arg constructor will initialize ID, firstName and lastName to their respective null values. It will set personType to PERSON, and sortorder to LAST_NAME The overloaded constructor will assign each parameter to its respective field. sortorder will also be set to LAST_NAME toString() will output type, ID, firstName and lastName, all tab separated. This is an override method equals() will compare if the current object and the parameter contain the same values. This is an override method compareTo() compares the current object and the parameter. This is an override method. It will be used to sort objects Needs the Comparable interface O Will only compare fields depending on the sortorder. For example, if the sortorder is TYPE, it should then compare the…arrow_forward
- True or False? A composition association relationship connects a Student class with a Schedule class, which means that if you remove the student, the schedule is also removed.arrow_forwardIt is a Programming logic and design based questionarrow_forwardIn this piece, we'll talk about when it's appropriate to use buddy functions and how to create and use them.Learning, for instance, may be accomplished by active participation, as in an exercise, such that subsequentarrow_forward
- In this exercise, you have to perform composition between the Toyota class and its Engine! Problem Statement# You have to create a Toyota class which inherits from a Car class, and is composed of an Engine Note: You already know that in such a composition relation, the oyota class will be res ible for Engine's lifetime. Consider this diagram for reference Car - id: int model: String - color: String + carFeatures(): void +setModel(): void + setColor(): void Toyota ToyotaEngine **** start): void stop): void . ..... + setStart(): void Part of- Car, Toyota and ToyotaEngine: Class Representation You should implement the Toyota class as the child class of the Car. It should have an instance of ToyotaEngine and a setStart() function which in turn calls the start () function of the ToyotaEngine class. The start () and stop () functions of ToyotaEngine class simply print out on screen that the engine has been started/stopped.arrow_forwardA new class safe member that would allow us to export a reference to a member Suggest a simple scheme for creating a new class SafeMember that would allow us to export a reference to a Member. The classes outside the system should be unaware of this additional class, and access the reference like a reference to a Member object. However, the reference would not allow the integrity of the data to be compromised. Remember that when designing the “Return Book with fines” use case, Member object is returned to the UserInterface to be able to display the member information such as owed fine. But this also means that the UserInterface can access all the Member methods. Your implementation of SafeMember class should prevent this.arrow_forwardQuestion 5 Enhance the invoice-printing program by providing for two kinds of line items: One kind describes products that are purchased in certain numerical quantities (such as “3 toasters”), another describes a fixed charge (such as “shipping: $5.00”). Hint: Use inheritance. Produce a UML diagram of your modified implementation. I only need the UML diagram.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage