subject
Computers and Technology, 27.05.2020 18:01 khambay

Answer in C++

Please answer very urgently. I will leave a good rating

In this question, you will be working with a somewhat artificial variation of the Pair class. The main modification is that the first and second data members are not the actual values of the pair, but pointers to those values. Thus β€” at constructor time β€” the arguments (integers) sent to the constructor are not placed into data members; rather two integers are dynamically allocated and their pointers are assigned to the first and second data members. As an example, here is object resulting from Pair(17, 23):

Pair

| | ---
first | --|>|17|
| | ---

| | ---
second | --|>|23|
| | ---

Again, you will be coding the .h file and the .cpp file in two separate questions.

Since we have data members that are pointers, and we are allocating dynamic memory, the canonical form ('rule of three') must be used (that is the whole reason for using pointers to the values). The name of the class is Pair. Since this requires the canonical form, the set of usual functions become:

A constructor that accepts a pair of integers and uses it to initialize the object
A copy constructor that preserves equivalence (i. e. equality) and ensures independence
An assignment operator that does the same
A destructor
A << operator that prints out the pair (the values, not the pointers) as (first, second)
An == operator β€” two Pair object are equal if their first and second components are respectively equal
A swap member function that swaps the first and second components of the pair (in place, i. e, no new Pair is created). swap returns void
getFirst and getSecond functions
The usual rules:

<< and == shold be declared non-member friends
getFirst and getSecond functions should be declared constant member functions
Again, the user of the class interacts with obejects of the class using integers; the fact that there are pointers internally is internal to the class and completely hidden to the outside. Thus, the constructor accepts integers, not pointers to integers; similarly getFirst and getSecond return the integer values, not the pointers.

Some coding help:

to allocate a single integer, one writes new int
to allocate AND initialize the integer (say to 17), one writes new int(17) (note the ()'s, not []'s as you would use to allocate an array)
Alternatively, you could allocate (as in the previous bullet) and then assign the value
given a Pair object named p, and a pointer data member first, to derefeence the pointer, one writes *p. first

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:00
Which of the following has not been attributed at least in part to social media a. drug addiction b. depression c. kidnapping d. murder
Answers: 2
question
Computers and Technology, 22.06.2019 17:40
Write a modular program (no classes yet, just from what you learned last year), that allows two players to play a game of tic-tac-toe. use a two-dimensional char array with 3 rows and 3 columns as the game board. each element of the array should be initialized with an asterisk (*). the program should display the initial board configuration and then start a loop that does the following: allow player 1 to select a location on the board for an x by entering a row and column number. then redisplay the board with an x replacing the * in the chosen location. if there is no winner yet and the board is not yet full, allow player 2 to select a location on the board for an o by entering a row and column number. then redisplay the board with an o replacing the * in the chosen location. the loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or reporting that a tie occurred. player 1 wins when there are three xs in a row, a column, or a diagonal on the game board. player 2 wins when there are three ox in a row, a column, or a diagonal on the game board. a tie occurs when all of the locations on the board are full, but there is no winner. input validation: only allow legal moves to be entered. the row must be 1, 2, or 3. the column must be 1, 2 3. the (row, column) position entered must currently be empty (i.e., still have an asterisk in it).
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Which of the following factors would your hypothetical supervisor look at when deciding whether to test a biological material sample for dna? the amount of other evidence you have implicating a suspect in a crime the annual budget for the crime lab both of the above none of the above; you would almost always order a test
Answers: 3
question
Computers and Technology, 23.06.2019 06:30
When early motion pictures played in movie theaters, they were often accompanied by live organ or piano music. which of the following are the most likely reasons that this happened? (select all that apply). the music was provided to distract audience members from the loud sounds made when filmstrips were changed. the music accompanied the movies because the movies were silent and audiences were used to hearing music during plays in theaters. the music usually was played before, and sometimes after the movie, as an alternative form of entertainment. the music viewers to interpret the dramatic action in the films.
Answers: 2
You know the right answer?
Answer in C++

Please answer very urgently. I will leave a good rating

In t...
Questions
question
Mathematics, 20.01.2021 06:00
question
Mathematics, 20.01.2021 06:00
question
History, 20.01.2021 06:00
question
Mathematics, 20.01.2021 06:00
question
Mathematics, 20.01.2021 06:00
question
Computers and Technology, 20.01.2021 06:00