CPE 212 Sample Exam II Problems 06-10 are based upon the following class declara
ID: 3717779 • Letter: C
Question
CPE 212 Sample Exam II
Problems 06-10 are based upon the following class declaration appearing in unknown.h All member functions will be defined in the file unknown.cpp class Unknown private: public: int a; Unknown (); void SetA (int aa); // Sets a equal to aa int GetA const;// Returns value of a // Initializes a to 0 06. VWhich of the following is a valid implementation for SetA(... )? A) void SetA) const B) void Unknown:: SetA(int aa) C) void Unknown:: SetA) aa = a D) void Unknown:: SetA(int aa) const E) None of the answers provided 07. Which of the following is a valid function heading for the function Unknown? A) void Unknown(); B) void Unknown::Unknown() C) int Unknown::Unknown() D) Unknown::Unknown) E) None of the answers provided 08. Which of the following is a valid function heading for the function GetA ? A) int Unknown::GetA0) B) void GetA0) C) void Unknown::GetA) D) int Unknown::GetA() const E) None of the answers provided 09. Suppose that a client program has a variable X of type Unknown. Which of the following statements correctly outputs the current value of the member a of the variable X? A) coutExplanation / Answer
6)
B is the answer.
if we declare the function using the const keyword.Then we cannot call the function without a const object.
But we declared that the function is not having any constraint such that it should only be called by the const object.
The declared function is having one parameter that is int type.
Hence the both conditions are satisfied by the Option B.
Hence we declare it as in option B.
7)
D is the right answer.
A constructor will never return any value.Not even the void.
Hence the Option D is correct.
8)
Option D is the right answer.
The function is declared as the const.
This means the function can be called only by the const objects.
The Option D satisfies the given condition.
Hence Option D is the answer.
9)
Option A is right answer.
"." is the member selection operator in CPP.
hence X.a gives the value of a of the object X.
Hence Option A is the right answer.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.