Computers and Technology
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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:00, banna01man
You need a reliable network for about twenty-five computers that will be distributed across a large building. it is important that the network be relatively cheap. which topology should you use?
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, la200564
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
image
Computers and Technology, 23.06.2019 19:30, alangonsales6232
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
image
Computers and Technology, 24.06.2019 15:00, firdausmohammed80
Universal windows platform is designed for which windows 10 version?
Answers: 1
Do you know the correct answer?
Answer in C++

Please answer very urgently. I will leave a good rating

In t...

Questions in other subjects:

Konu
Mathematics, 19.08.2019 22:30
Konu
Mathematics, 19.08.2019 22:30
Konu
World Languages, 19.08.2019 22:30