+ 1
Why it is not executing ??
what's wrong here #include <iostream> using namespace std; class series { int n,i,sum; public: int read(); int compute(); int display(); }; int read() { std::cout<<"Enter the value of n:"; cin>>n; } int compute() { for (i=1,sum=0;i<=n;i++) { sum = sum+ i*i; } int display(); { std:: cout<<"value of the series:"<<sum; } }; int main() { series s s.read(); s.compute(); s.display(); return(0); }
3 Respuestas
0
to declare the bodies of class members, you either declare them in the class itself, or write the function name as "class_name::method_name".
eg - instead of writing int read() when you write the body of the method outside the class, write it as 
int series::read(){ 
// method body
}
0
Dear Ashish,
Since you are defining member functions outside the class body,   make following  corrections in your code and it will  work 
sing namespace std;
class series{
   int n,i,sum;
   public:
   int read();
   int compute();
   int display();
};
 int series :: read(){
   std::cout<<"Enter the value of n:";
   cin>>n;
} 
int series :: compute(){
   for (i=1,sum=0;i<=n;i++){
      sum = sum+ i*i; 
   }
 int series :: display(){
     cout<<"value of the series:"<<sum; 
   }
0
write
int series::read ()
int series::compute()
int series::display ()
use classifier if you are defining function outside of class else if you want to write like this then define functions inside class itself. 



