Answer to Question #283182 in C++ for HAM

Question #283182

errors executing this code

|18|error: expected initializer before 'Myclass'|

|22|error: expected declaration before '}' token|


#include<iostream>

using namespace std;

class Myclass {

  private: 

    int u=10;

    int v=20;

    int w=30;

    int x=40;

    int y=50;    

  public:

    Myclass() : x(10), y(x + 10) {}

    void print();

};

void Myclass::print()

{

cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y; 

}

int add Myclass::display()

{

  return x+y;  

}

}

int main()

{

    Myclass objone;

    objone.print();

    objone.display();

    getchar();

    return 0;    

}


1
Expert's answer
2021-12-28T10:03:57-0500
#include<iostream>

using namespace std;

class Myclass {
  private: 
    int u=10;
    int v=20;
    int w=30;
    int x=40;
    int y=50;    

  public:
    Myclass() : x(10), y(x + 10) {}
    void print();
    void display();
};

void Myclass::print()
{
    cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y; 
}

void Myclass::display()
{
  cout << "\nx + y = " << x + y;  
}


int main()
{
    Myclass objone;
    objone.print();
    objone.display();
    getchar();
    return 0;    

}

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