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
Optimizing a PC’s performance often involves utilities that can defragment disks, clean a system’s Registry, scan for malware, r
KATRIN_1 [288]

Answer:

a. True

Explanation:

PC's sometimes runs slowly and on the long run cost money. Optimizing performance involves running software utilities that could restore speed and efficiency.

Scanning for malware/ virus , cleaning system registry, uninstalling unused program,  deleting unnecessary files, disk defragment , updating of windows software and setting up the browser are ways to optimize your pc's performance.

3 0
3 years ago
Question #2: How would you demonstrate professionalism in a video call with a teacher? Edmentum Digital world Please Help!!
Stella [2.4K]

Answer:

good luck getting an answer then

Explanation:

5 0
3 years ago
How do I answer a question that was answered incorrectly on Brainly
Mashcka [7]

Answer:

Explanation:

Go and ask a teacher or search

6 0
3 years ago
Read 2 more answers
g Create a program that reads a list of states from an input file, puts them in order, and displays the sorted list to the user.
mixas84 [53]

Answer:

Check the explanation

Explanation:

# Step 1

the first thing to execute will be......

f = open("states.txt")

# Step 2

the second step is......

states = []

for line in f:

   states.append(line.strip())

# Step 3:

the third step is to......

for state in sorted(states):

   print(state)

f.close()

3 0
3 years ago
Angelina has added page numbers to her report, but all of the pages are labeled "Page 1" at the bottom. What caused
notka56 [123]

Answer:(A)

<em><u>Why?</u></em>

A footer is an area at the bottom of a document page that contains data common to other pages.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Assume you have a sorting algorithm that you can use as a black box. Use the sorting algorithm to sort the input list. Now write
    10·1 answer
  • The init() command initializes the task queue and scheduler data structures. run Next Task() MUST run to completion whatever tas
    9·1 answer
  • IBF Consultants, LLC provides consulting services in privacy and theft deterrence solutions. Another client has very sensitive d
    7·1 answer
  • 2. Suppose you want to write a method that prints a heading on a new output page, along with a page number that is 1 in the firs
    15·1 answer
  • What is the first step to creating a PivotTable?
    11·1 answer
  • The house belives that works should be compensated for the loss of jobs due to automation? Describe it in against motion of the
    15·1 answer
  • The first step to accurate coding is to identify the ___________ in the diagnostic statement.
    7·1 answer
  • What direction would a sprite go if you constantly increased its x property? Your answer What direction would a sprite go if you
    7·1 answer
  • How do you change your grade level
    10·1 answer
  • We can find out how robots work by looking in detail at the smaller parts. What do we call this?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!