1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Blababa [14]
4 years ago
7

Write a copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *thi

s. Sample output for the given program:

Computers and Technology
1 answer:
ollegr [7]4 years ago
3 0

Answer:

Here is the copy assignment operator for CarCounter:

CarCounter& CarCounter::operator=(const CarCounter& objToCopy) {

carCount = objToCopy.carCount;

return *this;  }

The syntax for copy assignment operator is:

ClassName& ClassName :: operator= ( ClassName& object_name)

In the above chunk of code class name Is CarCounter and object name is objToCopy.

Assignment operator = is called which assigns objToCopy.carCount to the new objects's carCount.

This operator basically is called when an object which is already initialized is assigned a new value from another current object.

Then return *this returns the reference to the calling object

Explanation:

The complete program is:

#include <iostream>  //to use input output functions

using namespace std;   //to access objects like cin cout

class CarCounter {  //class name

public:  // public member functions of class CarCounter

CarCounter();  //constructor of CarCounter

CarCounter& operator=(const CarCounter& objToCopy);  //copy assignment operator for CarCounter

void SetCarCount(const int setVal) {  //mutator method to set the car count value

carCount = setVal;  } //set carCount so setVal

int GetCarCount() const {  //accessor method to get carCount

return carCount;  }  

private:  //private data member of class

int carCount;  };    // private data field of CarCounter

CarCounter::CarCounter() {  //constructor

carCount = 0;  //intializes the value of carCount in constructor

return; }  

// FIXME write copy assignment operator  

CarCounter& CarCounter::operator=(const CarCounter& objToCopy){

/* copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *this */

carCount = objToCopy.carCount;

return *this;}  

int main() {  //start of main() function

CarCounter frontParkingLot;  // creates CarCounter object

CarCounter backParkingLot;   // creates CarCounter object

frontParkingLot.SetCarCount(12);  // calls SetCarCount method using object frontParkingLot to set the value of carCount to 12

backParkingLot = frontParkingLot;  //assigns value of frontParkingLot to backParkingLot

cout << "Cars counted: " << backParkingLot.GetCarCount();  //calls accessor GetCarCount method to get the value of carCount and display it in output

return 0;  }

The output of this program is:

Cars counted = 12

You might be interested in
If I gain a rank and go under the points that the rank coust do I lose the rank
padilas [110]
This is a good question, and I've wondered about that myself. I'm going to 'report' the question, not because there's anything wrong with it, but to bring it to the attention of the Moderators, so they can tell both of us.
4 0
3 years ago
Read 2 more answers
Convert Dec 185 to Binary Byte
nata0808 [166]

Answer:

185 = 1011 1001

252 = 1111 1100

Explanation:

If you add the decimal values corresponding to the bit positions that are 1, you get your decimal number.

5 0
3 years ago
Kevin wants to add the numbers in his spreadsheet. What formula would he have to enter to get the correct total?
Stels [109]

Answer:

Explanation:

If the spread sheet is in Excel or equivalent, then you can use the function SUM( ) and select all the cells Kevin wants to add.

3 0
3 years ago
When a large project begins, a programmer can build a(n) ________, which is a small model of what the final program will look li
Furkat [3]

Answer:

A Prototype

Explanation:

<em>Prototype:</em> It is an early sample, model, or release of a product built by the programmer to test a concept or process and that will how the final product will look like.

5 0
4 years ago
Read 2 more answers
Stanford Rosenberg Computing wants to establish an assembly line for producing a new product, the Personal Digital Assistant (PD
Elina [12.6K]

Answer:

d what is the efficiency of this assembly line assignment?

8 0
4 years ago
Other questions:
  • Which term is used to describe a password-protected, encrypted data file that verifies the identity of the sender of a message?
    8·1 answer
  • What does it mean when a computer can't break the rules
    10·2 answers
  • Which of the following is NOT a rule you should follow when creating a presentation?
    5·1 answer
  • A Cisco Catalyst switch has been added to support the use of multiple VLANs as part of an enterprise network. The network techni
    5·1 answer
  • How do ice and water on the ground affect incoming solar radiation? They filter 22 percent of solar radiation that reaches the s
    9·2 answers
  • A customer has several small branches and wants to deploy a Wi-Fi solution with local management using CAPWAP. Which deployment
    6·1 answer
  • Write a program to accept radius and find area of circle
    10·2 answers
  • Which is the fastest memory in computer​
    9·2 answers
  • In which of the following situations would it be most appropriate to choose lossy compression over lossless compression?
    5·1 answer
  • Complete the following sentences using each of the words provided ONCE only. KEYBOARD DESKTOP STORE PRINTER COMPUTER MOUSE MONIT
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!