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
What is computer???<br>A. Electornic device<br>B. Storage<br>C. Accuarcy.<br>D. Communciation​
Gemiola [76]

Answer:

A

Explanation:

It's explanable the other ones dont make sense

8 0
3 years ago
The contents of an array of type ______ can be displayed with the cout operator (without specifying an element). - 1 point(s)
xxMikexx [17]
The contents of an array of type char can be displayed with the cout operator.  <span>Array declarations </span>must<span> contain the information about the size of the array. It is possible to leave the size out of the [ ] in the declaration </span>as long as<span> you initialize the array inline, in which case the array is made just large enough to capture the initialized data. </span>  
5 0
3 years ago
Most nosql data stores were created to address problems associated with storing large amounts of distributed data in __________.
finlep [7]
NoSQL is primarily designed for supporting the decision making systems. Most NoSQL data stores were created to address problems associated with storing large amounts of distributed data in relational database management systems(RDBMS).
RDBMS is system used for the management of the database.D<span>ata is stored in the form of related tables.</span>
3 0
4 years ago
In this question, you will experimentally verify the sensitivity of using a precise Pi to the accuracy of computing area. You ne
zhannawk [14.2K]

Answer:

Follows are the code to this question:

import math as x #import math package

#option a

radius = 10#defining radius variable  

print("radius = ", radius)#print radius value

realA = x.pi * radius * radius#calculate the area in realA variable

print("\nrealA = ", realA)#print realA value

#option b

a1 = 3.1  * radius * radius#calculate first area in a1 variable  

print("Area 1= ", a1)#print Area

print("Percentage difference= ", ((realA - a1)/realA) * 100) #print difference  

a2 = 3.14  * radius * radius#calculate first area in a2 variable                            

print("Area 2= ", a2)#print Area

print("Percentage difference= ", ((realA - a2)/realA) * 100)#print difference  

a3 = 3.141  * radius * radius#calculate first area in a2 variable                       print("Area 3= ", a3)#print Area

print("Percentage difference= ", ((realA - a3)/realA) * 100) #print difference  

Output:

please find the attached file.

Explanation:

In the given Python code, firstly we import the math package after importing the package a "radius" variable is defined, that holds a value 10, in the next step, a "realA" variable is defined that calculate the area value.

In the next step, the "a1, a2, and a3" variable is used, which holds three values, that is "3.1, 3.14, and 3.141", and use the print method to print its percentage difference value.  

4 0
3 years ago
Workers in a child care facility or preschool are part of what career path?
dedylja [7]

Answer:

A

Explanation:

Preschool teachers show education

8 0
3 years ago
Read 2 more answers
Other questions:
  • Your health insurance company gives you a discount if you wear a fitness-tracking bracelet. After wearing it for a few months, y
    5·1 answer
  • Consider sending a 2400-byte datagram into a link that has an mtu of 700 bytes. suppose the original datagram is stamped with th
    10·1 answer
  • Agile methods typically use a ______ model, which represents a series of iterations, or revisions, which are based on user feedb
    7·1 answer
  • What is the purpose of the 5 Whys Strategy? How could you use the 5 Whys strategy in your day-to-day life? (Site 2)
    5·1 answer
  • Mk chưa hiểu nên các bạn giúp mk vs
    14·1 answer
  • How can a user restore a message that was removed from the Deleted Items folder?
    10·1 answer
  • ¡Hola! He visto en muchos comentarios de Twitter "svd" cuando alguien dice "dale fav a este Tweet y siganse entre ustedes" y en
    8·1 answer
  • Schuyler is making a list of the parts of a computer that are software. Which of the following will be on the list?
    13·2 answers
  • What are building blocks? Select three options.
    14·1 answer
  • The following image shows the number of orders Company A received in 2015-2020. A financial analyst wants to calculate the year-
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!