Answer to Question #295952 in C++ for Baba

Question #295952

WAP to find sum of number 1 to 10 using constructor , where n is parameter passed to constructor.

1
Expert's answer
2022-02-10T07:12:33-0500
#include <iostream>




using namespace std;
class ClassSum{
    private:
        int x;
    public:
        ClassSum(int n){
            x=n;
        }
        void calcuateSum(){
            int n, sum = 0;
            for(n=1;n<=10;n++)
            { 
                sum = sum + n;
            }
            cout<<"The sum of 1 to 10 is "<<sum;
        }
};
int main()
{
    ClassSum c(10);
    c.calcuateSum();

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