Sum of series using pointer in C++

#include<iostream>
#include<conio.h>
using namespace std;
class point{
float a;
int sum;
public:
float setnumber(int n){
a=n;
for(int x=a;x<=5;x++){
cout<<"\t"<<x<<endl;
sum=sum+x;
}
}
void display(){
cout<<"     ------\n";
cout<<"Sum is "<<sum<<endl;
}
};
int main(){
point p;
point *p1;
p1=&p;
cout<<"Sum of Series : "<<endl;
p1->setnumber(1);
p1->display();
cout<<"Adress of Sum is : "<<p1;
getch();
return 0;

}

No comments:

Post a Comment