
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.6, Problem 11.17CP
Explanation of Solution
Purpose of “this” pointer:
In C++, every object should access its own address over a pointer called as “this” pointer.
- It is a special built-in pointer present in the class member function.
- The “this” pointer always points to the instance of the class which is making the function call.
- Friend function does not contain “this” pointer, because the friend function is not a member of a class.
Example:
Consider the below program as the example of “this” pointer:
//Header file
#include<iostream>
using namespace std;
// Declaration of class
class sample
{
//access specifier
private:
//declare the variable
int a;
//access specifier
public:
//return the value
void set_X (int a)
{
// return the value using "this" pointer
this->a = a;
}
//definition of "show" function
void show()
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
Write a complete Java program named FindSumAndAverage that performs the following tasks in 2-D array:
Main Method:
a. The main() method asks the user to provide the dimension n for a square matrix. A square matrix has an equal number of rows and columns.
b. The main() method receives the value of n and calls the matrixSetUp() method that creates a square matrix of size n and populates it randomly with integers between 1 and 9.
c. The main method then calls another method named printMatrix() to display the matrix in a matrix format.
d. The main method also calls a method named findSumAndAverage() which:
• Receives the generated matrix as input.
• Calculates the sum of all elements in the matrix.
• Calculates the average value of the elements in the matrix.
• Stores these values (sum and average) in a single-dimensional array and returns this array
• e. The main method prints the sum and average based on the result returned from findSumAndAverage()).
Enter the dimension n for the square…
The partial sums remain the same no matter what indexing we done to s
artial sum of each series
onverges,
*
+
s of each series to
the series or show
12. (1)+(0)+(0)+(+1)+
17,
" (F) + (F) + (F)(F)(-
18.
19. 1
#20.
(三)+(三)-(三)+(3)
20 (9)-(0)-(0)--
10
+1
2.1+(男)+(男)+(罰)+(鄂
9
T29
x222-끝+1-23 + -....
Repeating Decimals
64
Express each of the numbers in Exercises 23-30 as the m
integers.
23. 0.23 = 0.23 23 23...
24. 0.234 = 0.234 234 234.
25. 0.7 = 0.7777...
26. 0.d = 0.dddd...
where d is a digit
natio of own
s converges or
* 27. 0.06 = 0.06666..
28. 1.4141.414 414 414...
29. 1.24123 = 1.24 123 123 123...
30. 3.142857 = 3.142857 142857.
Using the ath-Term Test
In Exercises 31-38, use the ath-Term Test for divergence to show that
the series is divergent, or state that the test is inconclusive
8
CPS 2231 Computer Programming
Homework #3
Due Date: Posted on Canvas
1. Provide answers to the following Check Point Questions from our textbook (5 points):
a. How do you define a class? How do you define a class in Eclipse?
b. How do you declare an object's reference variable (Hint: object's reference variable
is the name of that object)?
c. How do you create an object?
d. What are the differences between constructors and regular methods?
e. Explain why we need classes and objects in Java programming.
2. Write the Account class. The UML diagram of the class is represented below (10 points):
Account
id: int = 0
- balance: double = 0
- annualInterestRate: double = 0.02
- dateCreated: java.util.Date
+ Account()
+
Account(id: int, balance: double)
+ getId(): int
+ setId(newId: int): void
+ getBalance(): double
+ setBalance(newBalance: double): void
+
getAnnualInterestRate(): double
+ setAnnualInterest Rate (newRate: double): void
+ toString(): String
+ getDataCreated(): java.util.Date
+…
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
- THIS IS NOT A GRADING ASSIGNMENT: Please only do lab 2.2 (bottom part of the first picture) For that Lab 2.2 do: *Part 1 (do the CODE, that's super important I need it) *Part 2 *Part 3 I also attached Section 2.5.2 which is part of the step 1 so you can read what is it about. Thank you!arrow_forwardTHIS IS NOT A GRADING ASSIGNMENT: Please only do lab 2.2 (bottom part of the first picture) For that Lab 2.2 do: *Part 1 *Part 2 *Part 3 I also attached Section 2.5.2 which is part of the step 1 so you can read what is it about. Thank you!arrow_forwardcan you please give me: * the code (step 3) *the list file (step 5) *and answer step 6 Thank youarrow_forward
- # Find the error# Why will the following code not print out a list of contact namesphoneBook = {'Doe, Jane' : '843-000-0000' ,'Doe, John' : '843-111-1111' ,'Smith, Adam' : '843-222-2222' ,'Jobs, Steve' : '999-333-3333' ,}for contact in phoneBook.values():print(contact)arrow_forward# Find the error:# The following code creates an empty dictionary and attempts to add a record# Why will the following code not create a new dictionary entry as intended?phoneBook = {}phoneBook{'Jobs, Steve'} = '999-111-1111'arrow_forwardSelect all the possible polar representations of the vector that is obtained from rotating where by Zrot Ź x = 3e² T= 3п 8 Hint: Consider the negative angle that is equivalent to the positive angle of the rotated vector. 0arrow_forward
- Character Analysis If you have downloaded the source code you will find a file named text.txt on the Chapter 08 folder. Write a program that reads the file's contents and determines the following: The number of uppercase letters in the file The number of lowercase letter in the file The number of digits in the file The number of whitespace characters in the filearrow_forwardWrite a program that reads the text file's contents and calculates and outputs the following in this order: • The number of words in the file • The number of lines in the file • The number of uppercase letters in the file • The number of lowercase letters in the file • The number of digits in the file • The number of letter H's in the file • The number of whitespace characters in the file NOTE: Your program should include at least one try-except error handling statement block. Your program should also validate any input that could cause your program to crash. I'm Henery The Eighth, I Am! Henery The Eighth, I Am, I am!I got married to the widow next door,She's been married seven times before.And ev'ryone was a Henery,She wouldn't have Willie or a Sam.I'm her eighth old man named Henery,Henery the Eighth, I Am!Second verse same as the first!I'm Henery The Eighth, I Am! Henery The Eighth, I Am, I am!I got married to the widow next door,She's been married seven times before.And…arrow_forwardFigure 4-40 Modern Database Management, 13th edition, question 4-53arrow_forward
- Which of the following needs improvement in the dashboard shown? A. Instructional clarity missing for the views B. Filter placed at the top of the dashboard C. Inconsistent use of colors to represent missed goals D. Dashboard title too largearrow_forwardIf we click Show dashboard title in this dashboard, what will the title be?arrow_forwardPlease draw the diagram where it is asked to be drawn. Don't just describe how to do it.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