answer.
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
torisob
1 month 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:
Natasha_Volkova [946]1 month ago
3 0

Answer:

This is the implementation of the copy assignment operator for CarCounter:

CarCounter& CarCounter::operator=(const CarCounter& objToCopy) {

carCount = objToCopy.carCount;

return *this;  }

The syntax for a copy assignment operator is:

ClassName& ClassName:: operator= ( ClassName& object_name)

In this code snippet, the class name is CarCounter, and the object being copied is objToCopy.

The assignment operator = is invoked to transfer objToCopy.carCount to the carCount of the new instance.

This operator is utilized when an initialized object receives a new value from another active object.

Then return *this returns a reference to the invoking object.

Explanation:

The complete program looks like this:

#include <iostream>  // for input/output functions

using namespace std;   // enables access to objects like cin cout

class CarCounter {  // defining the class

public:  // public member functions of CarCounter

CarCounter();  // constructor for CarCounter

CarCounter& operator=(const CarCounter& objToCopy);  // copy assignment operator for CarCounter

void SetCarCount(const int setVal) {  // method to set the car count value

carCount = setVal;  } // assigns setVal to carCount

int GetCarCount() const {  // method to access carCount

return carCount;  }  

private:  // private members of the class

int carCount;  };    // private data member of CarCounter

CarCounter::CarCounter() {  // constructor

carCount = 0;  // initializes carCount to zero in the constructor

return; }  

// FIXME implement copy assignment operator  

CarCounter& CarCounter::operator=(const CarCounter& objToCopy){

/* this copy assignment operator sets objToCopy.carCount to the new object's carCount, then returns *this */

carCount = objToCopy.carCount;

return *this;}  

int main() {  // start of the main() function

CarCounter frontParkingLot;  // creates CarCounter instance

CarCounter backParkingLot;   // creates another CarCounter instance

frontParkingLot.SetCarCount(12);  // sets the value of carCount in frontParkingLot to 12

backParkingLot = frontParkingLot;  // assigns frontParkingLot's value to backParkingLot

cout << "Cars counted: " << backParkingLot.GetCarCount();  // retrieves and prints the value of carCount using GetCarCount

return 0;  }

The program outputs:

Cars counted = 12

You might be interested in
Write a class named Taxicab that has three **private** data members: one that holds the current x-coordinate, one that holds the
amid [867]

Response:

Refer to the explanation

Details:

class Taxicab():

def __init__(self, x, y):

self.x_coordinate = x

self.y_coordinate = y

self.odometer = 0

def get_x_coord(self):

return self.x_coordinate

def get_y_coord(self):

return self.y_coordinate

def get_odometer(self):

return self.odometer

def move_x(self, distance):

self.x_coordinate += distance

# increase the odometer with the absolute distance

self.odometer += abs(distance)

def move_y(self, distance):

self.y_coordinate += distance

# increase odometer with the absolute distance

self.odometer += abs(distance)

cab = Taxicab(5,-8)

cab.move_x(3)

cab.move_y(-4)

cab.move_x(-1)

print(cab.odometer) # will output 8 3+4+1 = 8

7 0
1 month ago
6. A small design agency you are consulting for will be creating client websites and wants to purchase a web server so they can
amid [867]

Answer:

Clarification:

The most effective recommendation for the agency would be to ensure they fully grasp the overall ownership costs of the server. This encompasses not only the server itself but also various factors including necessary software, an IT server manager, facility expenses, security investments, and backup options. Although these are key costs they will face, there may be additional unexpected expenses. Consequently, the best approach is to supply them with comprehensive information for making an informed decision.

3 0
21 day ago
A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
oksian1 [849]

Answer:

Below is the Python code with suitable comments.

Explanation:

#Input file name acquisition

filename=input('Enter the input file name: ')

#Opening the input file

inputFile = open(filename,"r+")

#Dictionary definition.

list={}

#Read and split file content using a loop

for word in inputFile.read().split():

#Check if the word exists in the file.

if word not in list:

list[word] = 1

#Increment count by 1

else:

list[word] += 1

#Closing the file.

inputFile.close();

#Output a blank line

print();

#Sorting words according to their ASCII values.

for i in sorted(list):

#Display unique words along with their

#frequencies in alphabetical order.

print("{0} {1} ".format(i, list[i]));

3 0
1 month ago
In mathematics, the factorial of a positive integer n, denoted as n! , is the product of all positive integers less than or equa
oksian1 [849]
public static int factorial(int n) { if (n >= 1 && n <=12) { if (n == 1) return 1; else return n * factorial(n - 1); } else return -1; } Explanation: The factorial method takes a single integer n as input. It checks if n is within the range of 1 to 12. If it is, it further checks if n equals 1. If it is indeed 1, it returns 1 as the factorial. Otherwise, it recursively calls itself with n decreased by 1, multiplying the result by n. If n is outside this range, the method returns -1 indicating the input is invalid.
6 0
13 days ago
Read 2 more answers
Which kind of file would be hurt most by lossy compression algorithm
oksian1 [849]

Response: a file containing audio

Clarification:

8 0
13 days ago
Read 2 more answers
Other questions:
  • Accenture is helping a large retailer transform their online sales and services. The Data Analyst audits the client’s customer j
    12·1 answer
  • A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output i
    15·1 answer
  • A video conferencing application isn't working due to a Domain Name System (DNS) port error. Which record requires modification
    15·1 answer
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • Write a statement that reads a floating point value from standard input into temperature. Assume that temperature. has already b
    6·1 answer
  • Imagine you were using some of our pixelation tools to create an image and you posted it online for your friends to see - but, a
    11·1 answer
  • An array subscript can be an expression, but only as long as the expression evaluates to what type?
    7·1 answer
  • Henry, a graphic artist, wants to create posters. Which software should Henry use for this purpose?
    13·1 answer
  • Which of the following is opened when the Find command is clicked?
    12·1 answer
  • A wireless network does not benefit like a wired network does, when it comes to collision reduction. Which device reduces collis
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!