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]
3 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]3 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
Blank Are input instructions you give to a computer
kotegsom [21]

Explanation:

A computer is a machine that can be programmed to accept data (input), process it into useful information (output), and store it away (in a secondary storage device) for safekeeping or later reuse. The processing of input to output is directed by the software but performed by the hardware.

4 0
2 years ago
what's the best mouse for fast clicking ? I play a lot of fps and a lot of pvp games I need a mouse that I can click fast with a
kondaur [170]
Alenware hp dell logtech, and i know others
7 0
3 years ago
Write a little man program that accepts three values as input and produces the largest of the three as output.
ki77a [65]
Required: program to return the largest of three numbers.

pseudocode

input parameters, int A,B,C;
int T; // temporary storage
if (A>B) T=A;
else T=B;
if (T>C) print(T);
else print(C);


5 0
2 years ago
Is It Safe to Use LinkedIn Automation?
Stolb23 [73]

Answer:

A lot of people have claimed that they lost their full-established accounts after using LinkedIn automation tools. LinkedIn detected the activity and blocked their accounts.  

But it’s not the tool that causes spam, it’s the approach you adopt while using these tools.  

Many people think that LinkedIn automation tools(LinkedCamp) can generate leads magically over the night. They send thousands of connection requests and messages using automation and as a result, LinkedIn detects their activity.  This is not how it works. You need a proper strategy to leverage the potential of these tools. Even the best LinkedIn automation tools cannot guarantee success if you try to overdo the activities.

6 0
3 years ago
Read 2 more answers
Which of the items below are nodes? fax, IC, NOC, printer, twisted pair cables and workstation.
RSB [31]

The answer is Printer, workstation, NOC, and fax.

Any devices or systems connected to a network are called nodes. When defining a node, always have in mind that it is anything that has an IP address. For instance, if a network connects 5 computers, 1 file server, and 2 printers, there are 8 nodes on this network.

3 0
3 years ago
Other questions:
  • How do media and networks interact
    11·1 answer
  • Which group on the Home Tab allows you to add shapes to a PowerPoint slide?
    9·2 answers
  • The type of database that is connected by a company's local area networks is a(n:
    11·1 answer
  • Select the correct answer.
    10·1 answer
  • What task do the referential integrity settings prevent?
    12·2 answers
  • Ema Company for business .
    14·1 answer
  • Define a function isPrime that consumes an integer argument and returns 1 if it'a prime number; 0 if it's not a prime number.
    9·1 answer
  • Jason is the motion picture projectionist at the local IMAX theater. This means that he runs the huge movie projector so that cu
    12·1 answer
  • When creating a report,you can mske groups and subgroups by?​
    5·1 answer
  • quizlet ann is a security professional for a midsize business and typically handles log analysis and security monitoring tasks f
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!