Develop
2003.04.23 09:50
[c++] p.118 확인학습 5번
Views 10775 Comment 0
#include<iostream.h>
class summation{
int num;
long sum;
public:
void set_sum(int n);
void show_sum(){
cout << num << " summed is " << sum << "n";
}
};
void summation::set_sum(int n){
int i;
num=n;
sum=0;
for(i=1;i<=n;i++) sum+=i;
}
summation make_sum(int num){
summation ob;
ob.set_sum(num);
return ob;
}
int main(){
int num;
summation ob;
cout << "Enter a number : ";
cin >> num;
ob = make_sum(num);
ob.show_sum();
return 0;
}