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 you wish to sign out of your Microsoft account, tap or click ____ on the ribbon to open the Backstage view and then tap or cl
tatuchka [14]

According to you have to http://windows.microsoft.com/en-PH/windows-8/sign-in-out-of-windows you have to click on the account picture on the upper right hand corner to access the backstage view and you have to tap or click the account tab to view the account gallery and sign out from the account. You may also want to check this link as well: https://support.office.com/en-us/article/Sign-out-of-your-Microsoft-account-268b49c8-398f-4057-8a3f-e376789f273a

<span> </span>

3 0
4 years ago
Assume the user types in 7 for x and 2 for y. What is output by the
vladimir1956 [14]

Answer:

49

Explanation:

3 0
3 years ago
What folder holds 32-bit programs installed in a 64-bit installation of windows?
raketka [301]
<span>C:\Program Files (x86) folder</span>
8 0
3 years ago
Write a function that is named times_ten and accepts a number as an argument. When the function is called, it should return the
Stells [14]

It changes a little depending on what programming language you're using, but in C you could say

int times_ten (int num) {

    num = num*10;

    return num;

}

Or, in general terms:

Integer Function times_ten (Integer num)

    Set num = num * 10

    Return num

This is all done assuming the number used as an argument is an integer and that you are returning an integer value, not a decimal. The main thing to notice is that since you have to return a value, you must have two things: a return statement, and a type declaration for the function, otherwise you'll get an error.

4 0
3 years ago
Which wireless communication technology is most likely used when synchronizing device information to an automobile?
Over [174]

Answer:

Bluetooth

Explanation:

hope that helps bro

5 0
4 years ago
Other questions:
  • Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
    15·1 answer
  • Which of the following would allow for more data to be stored on a CD?
    11·2 answers
  • Type the correct answer in the box spell all words correctly
    8·1 answer
  • The acronym LAH stands for
    14·2 answers
  • What does CRM stand for?
    10·1 answer
  • What is not true of credit scores?
    11·1 answer
  • Task 1 (25 points): In database [your Pitt username], create the following entity tables: movies actors locations Each tables lo
    7·1 answer
  • A celebrity blogger you have followed for years advises readers to try a new beauty product. Before purchasing the product, a sa
    10·1 answer
  • A major retailer wants to enhance their customer experience and reduce losses
    9·1 answer
  • The Ingenuity and the MOXIE are two new pieces of technology on the Perseverance. What role will these instruments play? How wil
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!