Please revise the program and correct the errors of the program and make varaibles a and b not accessible by ".". For example, obj_X.a=0 should be wrong and it should be replaced by obj_X.setA(0); Note: keep the meanings of the main function. The output should be: ------------------- Here are a and b: 0 1 --------------------- Submit the correct code and the running result. #include using namespace std; struct X { int a; int b; public: int getA() { return b; } int getB() { return b; } void setA(int x) { a=y; } void setB(int y) { b=x; } }; int main() { X obj_X; obj_X.a = 0; obj_X.b = 1; cout << "Here are a and b: " << obj_X.a << " " << obj_X.b << endl; }
Please revise the program and correct the errors of the program and make varaibles a and b not accessible by ".".
For example, obj_X.a=0 should be wrong and it should be replaced by obj_X.setA(0);
Note: keep the meanings of the main function.
The output should be:
-------------------
Here are a and b: 0 1
---------------------
Submit the correct code and the running result.
#include <iostream>
using namespace std;
struct X {
int a;
int b;
public:
int getA() { return b; }
int getB() { return b; }
void setA(int x) { a=y; }
void setB(int y) { b=x; }
};
int main() {
X obj_X;
obj_X.a = 0;
obj_X.b = 1;
cout << "Here are a and b: " << obj_X.a << " " << obj_X.b << endl;
}
Step by step
Solved in 3 steps with 1 images