Answer to Question #113021 in C++ for joya

Question #113021
Create a class called Float. We’ll use it to model numbers of type float that are stored
in fmemory instead of real memory. The only instance data in Float is its own “address”;
that is, the index where its float value is stored in fmemory. Call this instance variable
addr. Class Float also needs two member functions. The first is a one-argument constructor
to initialize the Float with a float value. This constructor stores the float
value in the element of fmemory pointed to by fmem_top, and stores the value of
fmem_top in addr. This is similar to how the compiler and linker arrange to store an ordinary
variable in real memory. The second member function is the overloaded & operator.
It simply returns the pointer (really the index, type int) value in addr.
Create a second class called ptrFloat. The instance data in this class holds the address
(index) in pmemory where some other address (index) is stored. A member function initializes
this “pointer” with an int index value.
1
Expert's answer
2020-05-01T14:44:33-0400
class Float {
    int addr;
public:
    /*Float(float *fmem_top) {
        fmemory[addr] = *fmem_top;
    }*/
    Float(float value) {
        fmemory[addr = fmem_top++] = value;
    }
    int operator&() {
        return addr;
    }
};

class ptrFloat {
    int addr;
public:
    /*ptrFloat(int value) {
        addr = value;
    }*/
    ptrFloat(int value) {
        pmemory[addr = pmem_top++] = value;
    }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS