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
Define the following:-<br><br>1) cryptography<br><br>2) Quantum Cryptography​
Readme [11.4K]
1.) the art of writing or solving codes.
2.) the science of exploiting quantum mechanical properties to perform cryptographic tasks.

hope this helps :)
8 0
3 years ago
Read 2 more answers
What are the similarities and differences between the sample résumés, in terms of content and formatting?
poizon [28]

Answer:

in general terms a sample resume would have less on it with more of a general overview,while a full resume has the whole 9 yards  

6 0
4 years ago
What came first, the internet or WIFI?
horsena [70]

Answer: wifi

Explanation:

because you can't have the internet if you don't have wifi to power it up

4 0
3 years ago
Write two scnr.nextInt statements to get input values into birthMonth and birthYear. Then write a statement to output the month,
Firlakuza [10]

Answer:

Here is code in Java.

// import package

import java.util.*;

class Main

{   // main method of class

public static void main (String[] args) throws java.lang.Exception

{

   try{

       // variables to store the input

       int birthMonth,birthYear;

       // Scanner class object to read the input

       Scanner scnr=new Scanner(System.in);

       System.out.print("Please enter the birth month:");

       // read the birth month

       birthMonth=scnr.nextInt();

       System.out.print("Please enter the birth year:");

       // read the birth year

       birthYear=scnr.nextInt();

       // print the output

       System.out.println(birthMonth+"/"+birthYear+"\n");

   }catch(Exception ex){

       return;}

}

}

Explanation:

Create two variables "birthMonth" & "birthYear" to store the birth month and birth year.Read the  values of both from user. Print the birth month and birth year separated by a slash("/").

Output:

Please enter the birth month:1                                                                                                

Please enter the birth year:2000                                                                                              

1/2000  

Please enter the birth month:5                                                                                                

Please enter the birth year:1950                                                                                              

5/1950  

7 0
3 years ago
Stateful packet inspection firewalls ________. always do application content filtering have the slow speed of relay operation Bo
Evgesh-ka [11]

Answer:

Neither always do application content filtering nor have the slow speed of relay operation.

Explanation:Stateful packet inspection is a dynamic firewall filtering which filters the inflow and outflow of packets of Information from time to time. It is also known to act as monitor for the state of a connection in a Network system. The filtering decisions of a stateful inspection firewall is based on two facts

(1) The rules defined by the administrator

(2) The previous context developed based on the filtering that taken place before.

6 0
3 years ago
Other questions:
  • Pls help me. ask yourself what would jesus do...
    14·1 answer
  • Please I need all the help I can get Thank You So Much
    14·1 answer
  • Can embedded computers automate security so you can lock and unlock doors remotely
    15·1 answer
  • Which program, available on all operating systems, provides all types of information from a dns server and allows you to query a
    8·1 answer
  • PLEASE HELP BRAINLIEST TO CORRECT ANSWER!!!
    14·1 answer
  • True or False
    13·1 answer
  • مسألة لبرنامج الماتلاب لمصفوفة وعمود
    10·1 answer
  • Write a structured algorithm that prompts the user to input the name and price of an item and the quantity purchased. It should
    10·1 answer
  • describe the impact of technology in your life . how does it affects your human relations with other people .​
    12·1 answer
  • What is the difference of using Selection Tool and Direct Selection Tool?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!