Write a program that defines a class called MyClass with one private data member of type int called x and two member functions.
The first member function called setx(int myvalue) will set the value of x to its parameter myvalue.
The second member function is called getx()
, is of type int and returns a value of x.
Make an instance of the class and use the object to access both member functions.
You can use the following code structure.
#include <iostream> int main() { //your code here }
#include <iostream> class MyClass { private: int x; public: void setx(int myvalue) { x = myvalue; } int getx() { return x; } }; int main() { MyClass o; o.setx(123); std::cout << "The value of x is: " << o.getx(); }