Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the declaration of the copy assignment operator for Dealership. Ex: If the input is 2 8 0 . 5 0 , then the output

Complete the declaration of the copy assignment operator for Dealership.
Ex: If the input is 280.50, then the output is:
Self-assignment not permitted
dealership: $259.50 daily profit
dealershipCopy: $280.50 daily profit
Destructor called
Destructor called#include =0.0
The Code is:
#include
#include
using namespace std;
class Dealership {
public:
Dealership();
~Dealership();
void setDailyProfit(double newDailyProfit);
void Print() const;
Dealership& operator=(const Dealership& dealershipToCopy);
private:
double* dailyProfit;
};
Dealership::Dealership(){
dailyProfit = new double;
*dailyProfit =0.0;
}
Dealership::~Dealership(){
cout "Destructor called" endl;
delete dailyProfit;
}
/* Your code goes here */{
if (this != &dealershipToCopy){
delete dailyProfit;
dailyProfit = new double;
*dailyProfit =*(dealershipToCopy.dailyProfit);
}
else {
cout "Self-assignment not permitted" endl;
}
return *this;
}
void Dealership::setDailyProfit(double newDailyProfit){
*dailyProfit = newDailyProfit;
}
void Dealership::Print() const {
cout fixed setprecision(2)"$"*dailyProfit " daily profit" endl;
}
int main(){
double dailyProfit;
Dealership dealership;
Dealership dealershipCopy;
cin >> dailyProfit;
dealership.setDailyProfit(dailyProfit);
dealership = dealership; // Test self-assignment
dealershipCopy = dealership;
dealership.setDailyProfit(259.50);
cout "dealership: ";
dealership.Print();
cout "dealershipCopy: ";
dealershipCopy.Print();
return 0;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago