Answer to Question #185047 in C++ for RAHUL SINGH

Question #185047

Create a class called ADDITION has one integer and one float data member. Use pointer to 

data member to find their sum and print it from main method and also use the concept of 

dynamic constructor.


1
Expert's answer
2021-04-24T10:16:56-0400
#include <iostream>
using namespace std;
class Addition{
    int *x;
    float *y;
    public:
    Addition(int x, float y){
        this->x = &x;
        this->y = &y;
    }
    float sum(){
        return *x + *y;
    }
};
int main(){
    int x = 3;
    float y = 4.5;
    Addition* add = new Addition(x, y);
    cout<<add->sum();
    return 0;
}

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