Why is this c++ program not working? -


write program have base class number , 2 derived classes: square , cube . calculate square number (a*a ) , cube of number (a*a*a)

#include <iostream> #include <conio.h>  using namespace std; class number  { protected:     int ;     int y; public:      a*a = y;     a*a*a=y  };  class square : number  {     int , y; public:      (a*a) = y; };  class cube : number {     int a, y; public:     (a*a*a) = y; }; int main() {     int a;     cout << "enter number "<< endl;     cin >> >>endl ;      cout << " square of number : " << (a*a);      cout << "enter number ";     cin >> a;     cout << " cube of number : " << (a*a*a);     return (0); } 

public:    a*a = y;   a*a*a=y  

is not function. the

private: protected: public: 

sections define how function or variable can seen outside of class. cannot assignment within them: need put assignments function, such function int multiply() or similar:

class number  { protected:     int ;     int y; public:      int squared(int a);     int cubed(int a); };  int number::squared(int a) {     y = * a;     return y; }  int number::cubed(int a) {     y = * * a;     return y; } 

your compiler errors coming fact you're doing (a*a) = y, is

  1. outside of function, and
  2. incorrectly formatted assign value of (a*a) y. need y = (a*a) instead.

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -