Instantiating objects 1. Select the constructor you want to use for instantiating the object. 2. When using the default constructor use the syntax {}; 3. When using a non-default constructor use the syntax {}; Using objects 1. Identify the name of the object and its data type (Class used to instantiate it). 2. Identify the member function that performs your intended action. 3. Call the member function by using the syntax .(); 4. If the member function returns a value, assign it to a variable with the same data type as the member function's return type.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write code to instantiate a DonationTracker object using its default constructor. Use the object to donate three amounts: $100.00, $224.25, and $5.75. Get the object's donation count and store it in a variable called num_donations. Get the average donations from the object and store it in a variable called avg_donations.

int main() {











  std::cout << "Number of donations: " << num_donations << "\n";

  std::cout << "Average donation: $" << avg_donations << "\n";

  return 0;

}

Instantiating objects
1. Select the constructor you want to use for instantiating the object.
2. When using the default constructor use the syntax <Class name> <identifier>{};
3. When using a non-default constructor use the syntax <Class name>
<identifier>{<arguments>};
Using objects
1.
Identify the name of the object and its data type (Class used to instantiate it).
Identify the member function that performs your intended action.
2.
3. Call the member function by using the syntax <object name>.<member function
name>(<arguments>);
4. If the member function returns a value, assign it to a variable with the same data type
as the member function's return type.
Transcribed Image Text:Instantiating objects 1. Select the constructor you want to use for instantiating the object. 2. When using the default constructor use the syntax <Class name> <identifier>{}; 3. When using a non-default constructor use the syntax <Class name> <identifier>{<arguments>}; Using objects 1. Identify the name of the object and its data type (Class used to instantiate it). Identify the member function that performs your intended action. 2. 3. Call the member function by using the syntax <object name>.<member function name>(<arguments>); 4. If the member function returns a value, assign it to a variable with the same data type as the member function's return type.
The Donation Tracker class is designed to track the number and total amount of donations
received.
Donation Tracker
int donation_count;
double total_donations;
Donation Tracker();
Donation Tracker(int donations_count, double total_donations);
void Donate(double amount);
int DonationCount();
double TotalDonations();
double AverageDonation();
Transcribed Image Text:The Donation Tracker class is designed to track the number and total amount of donations received. Donation Tracker int donation_count; double total_donations; Donation Tracker(); Donation Tracker(int donations_count, double total_donations); void Donate(double amount); int DonationCount(); double TotalDonations(); double AverageDonation();
Expert Solution
Step 1

The C++ code is given in the below step with output screenshots ?

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education