- (10%) Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Accessing the Data Members of a Class (P.367)
#include <iostream>
using std::cout;
using std::endl;
CLASS CCircle
{
public:
int x;
int y;
int r;
};
int main()
{
CCircle aCircle;
aCircle.x = 10;
aCircle.y = 10;
aCircle.r = 5;
cout << aCircle.x + aCircle.y << endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Class Constructors (P.374)
#include <iostream>
using std::cout;
using std::endl;
class CCircle
{
public:
int x;
int y;
int r;
CCircle(int a, int b, int c)
{
x = a;
y = 5;
r = c;
}
};
int main()
{
CCircle aCircle(10, 10, 5);
cout << aCircle.x + aCircle.y << endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Pointers to Class Objects (P.401)
#include <iostream>
using std::cout;
using std::endl;
class CCircle
{
public:
int x;
int y;
int r;
CCircle(int a, int b, int c)
{
x = a;
y = 5;
r = c;
}
};
int main()
{
CCircle aCircle(10, 10, 5);
CCircle* pCircle = &aCircle;
cout << pCircle->r << endl;
return 0;
}