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
2 months 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 [1K]2 months 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
Assume that the reference variable r refers to a serializable object. Write code that serializes the object to the file ObjectDa
oksian1 [950]
To serialize an object, the following code can be used: FileOutputStream out = new FileOutputStream("ObjectData.dat"); ObjectOutputStream ostream = new ObjectOutputStream(out); ostream.writeObject(r); Explanation: For serializing an object, the writeObject method from the java.io.ObjectOutputStream class is utilized. The complete code snippet is as follows: import java.io.*; class Demo{ public static void main(String args[]){ try{ r = <reference to="" object="" be="" serialized="">; FileOutputStream out = new FileOutputStream("ObjectData.dat"); ObjectOutputStream ostream = new ObjectOutputStream(out); ostream.writeObject(r); ostream.close(); } catch(Exception e){ e.printStackTrace(); }} }. </reference>
5 0
2 months ago
The following is a string of ASCII characters whose bit patterns have been converted into hexadecimal for compactness: 73 F4 E5
Rzqust [1037]

Answer:

a) Transforming each character into its binary equivalent:

73:

The digits are 7 and 3

7 in binary is: 111

3 in binary is: 11

Thus

73: 0_111_0011

Likewise

F4:

F stands for 15 and its binary is: 1111

4 in binary: 100

Consequently

F4:  1_111_0100

E5:

E corresponds to 14 and its binary form is: 1110

5 in binary: 101

Therefore

E5:  1_110_0101

76:

7 in binary: 111

6 in binary: 110

Hence

76:  0_111_0110

E5:

E has a binary representation of: 1110

5 in binary: 101

Consequently

E5:  1_110_0101

4A:

4 in binary: 100

A represents 10

A in binary form: 1010

Therefore

4A:  0_100_1010

EF:

E in binary is: 1110

F in binary is: 1111

Thus

EF: 1_110_1111

62:

6 in binary form: 110

2 in binary form: 10

Therefore

62:  0_110_0010

73:

The digits are 7 and 3

7 in binary is: 111

3 in binary is: 11

Thus

73: 0_111_0011

for 0_1110011: the decimal equivalent is: 115 which translates to s

for 1_1110100:  the decimal equivalent is: 116 which translates to t

for 1_1100101:  the decimal equivalent is: 101 which translates to e

for 0_1110110: the decimal equivalent is:  118 which translates to v

for 1_1100101:  the decimal equivalent is: 101 which translates to e

for 0_1001010: the decimal equivalent is:  74 which translates to j

for 1_1101111: the decimal equivalent is: 111 which translates to o

for 0_1100010:  the decimal equivalent is: 98 which translates to b

for 0_1110011: the decimal equivalent is:  115 which translates to s

Thus the decoded sequence is:  stevejobs

b) The parity being utilized is odd.

for 0_1110011:  There are 5 instances of 1s and the parity is 0 indicating it is odd.

for 1_1110100: There are 4 instances of 1s and the parity is 1 indicating it is odd.

Thus, we count the number of 1s and then verify if the parity is odd or even.

Likewise

for 1_1100101:  the parity is odd

for 0_1110110: the parity is odd

for 1_1100101:  the parity is odd

for 0_1001010: the parity is odd

for 1_1101111: the parity is odd

for 0_1100010: the parity is odd

for 0_1110011: the parity is odd

Therefore, the parity being used is odd.

5 0
2 months ago
Other questions:
  • Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
    5·1 answer
  • Assume a program requires the execution of 50 x 106 FP instructions, 110 x 106 INT instructions, 80 x 106 L/S instructions, and
    9·1 answer
  • Write an if-else statement to describe an integer. Print "Positive even number" if isEven and is Positive are both true. Print "
    14·1 answer
  • In cell e5, create a formula using the vlookup function to determine the dog type for teen anna morante based on the program cod
    13·2 answers
  • This question refers to a standard deck of playing cards. If you are unfamiliar with playing cards, there is an explanation in P
    10·2 answers
  • Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
    13·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • ___________is used for drawing 3D objects in the field of Science and Engineering.
    12·2 answers
  • Which of the following image file formats uses lossy file compression?
    7·1 answer
  • In today’s fast-paced, often "agile" software development, how can the secure design be implemented?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!