Given the declaration of a class Circle as follows, which of the following state
ID: 3698344 • Letter: G
Question
Given the declaration of a class Circle as follows, which of the following statement is most accurate?
class Circle
{
public:
Circle(){}
~Circle(){}
private:
};
int main()
{
Circle x;
... the rest of the program....
return 0;
}
x is an object of the Circle type.
x contains an int value.
You can assign an int value to x.
x is a pointer to a Circle object.
Analyze the following code.
#include <iostream>
using namespace std;
class B
{
public:
B() { };
private:
int k;
};
int main()
{
B b;
cout << b.k << endl;
return 0;
}
The program displays 0.
The program displays unpredictable number.
The program has a compile error because b.k cannot be accessed.
The program has a runtime error because b.k does not have a value.
The program displays 1
Suppose two header files t1.h and t2.h contain the declarations for class T. What happens if you include both header files in your program?
The program will compile fine and the first header file that is included is used if the header files have the include guard.
You will get multiple declaration error if the header files don't have the include guard.
The program will compile fine and the first header file that is included is used.
The compile will automatically decides which implementation to use.
What is the output of the following code?
#include <iostream>
using namespace std;
class Foo
{
public:
int x; // data field
int y; // data field
Foo()
{
x = 10;
y = 10;
}
void p()
{
int x = 20; // local variable
cout << "x is " << x << " ";
cout << "y is " << y << endl;
}
};
int main()
{
Foo foo;
foo.p();
return 0;
}
x is 10 y is 20
x is 20 y is 20
x is 20 y is 10
x is 10 y is 10
x is an object of the Circle type.
x contains an int value.
You can assign an int value to x.
x is a pointer to a Circle object.
Analyze the following code.
#include <iostream>
using namespace std;
class B
{
public:
B() { };
private:
int k;
};
int main()
{
B b;
cout << b.k << endl;
return 0;
}
The program displays 0.
The program displays unpredictable number.
The program has a compile error because b.k cannot be accessed.
The program has a runtime error because b.k does not have a value.
The program displays 1
Suppose two header files t1.h and t2.h contain the declarations for class T. What happens if you include both header files in your program?
The program will compile fine and the first header file that is included is used if the header files have the include guard.
You will get multiple declaration error if the header files don't have the include guard.
The program will compile fine and the first header file that is included is used.
The compile will automatically decides which implementation to use.
What is the output of the following code?
#include <iostream>
using namespace std;
class Foo
{
public:
int x; // data field
int y; // data field
Foo()
{
x = 10;
y = 10;
}
void p()
{
int x = 20; // local variable
cout << "x is " << x << " ";
cout << "y is " << y << endl;
}
};
int main()
{
Foo foo;
foo.p();
return 0;
}
x is 10 y is 20
x is 20 y is 20
x is 20 y is 10
x is 10 y is 10
Explanation / Answer
1)
class Circle
{
public:
Circle(){}
~Circle(){}
private:
};
int main()
{
Circle x;
... the rest of the program....
return 0;
}
Ans- x is an object of the Circle type.
2) Suppose two header files t1.h and t2.h contain the declarations for class T. What happens if you include both header files in your program?
Ans-The program will compile fine and the first header file that is included is used.
3)
#include <iostream>
using namespace std;
class B
{
public:
B() { };
private:
int k;
};
int main()
{
B b;
cout << b.k << endl;
return 0;
}
Output:
output by compiler
so
Answer- The program has a compile error because b.k cannot be accessed
4)
#include <iostream>
using namespace std;
class Foo
{
public:
int x; // data field
int y; // data field
Foo()
{
x = 10;
y = 10;
}
void p()
{
int x = 20; // local variable
cout << "x is " << x << " ";
cout << "y is " << y << endl;
}
};
int main()
{
Foo foo;
foo.p();
return 0;
}
Output:
x is 20 y is 10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.