Answer to Question #197764 in C++ for Asif

Question #197764

Write a program to initialize the data members through passing two parameters using a

constructor. Calculate their sum and print the output on the screen using a separate member

function of a class.


1
Expert's answer
2021-05-25T14:10:22-0400


#include <iostream>


using namespace std;
class ClassSum{
    private:
        int x;
        int y;
    public:
        ClassSum(int a,int b){
            x=a;
            y=b;
        }
        void calcuateSum(){
            int sum=x+y;
            cout<<"The sum of "<<x<<" and "<<y<<" is "<<sum;
        }
};
int main()
{
    ClassSum c(50,71);
    c.calcuateSum();


    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