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 01:00
How can a broadcast station be received through cable and satellite systems?
Answers: 1
question
Computers and Technology, 23.06.2019 06:20
Which text function capitalizes the first letter in a string of text? question 10 options: upper capital first proper
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
What is the name of the sound effect that danny hears
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Idon’t understand the double8 coding problem. it is java
Answers: 1
You know the right answer?
Answer in C++

Please answer very urgently. I will leave a good rating

In t...
Questions
question
Spanish, 14.10.2020 16:01
question
Mathematics, 14.10.2020 16:01
question
Mathematics, 14.10.2020 16:01
question
Social Studies, 14.10.2020 16:01
Questions on the website: 13722360