Student Content Assessments
Instrument 21: Encapsulation in C++ Classes Practice Booklet Problem Set 1
Project: Assessing the Feasibility and Impact of Using Online Problem-Solving in Computer Science
Ramapo College of New Jersey
Funding Source: NSF - Undergraduate education (DUE)
Purpose: To evaluate efficacy of an online problem-solving tutor.
Administered To: Students in C++ programming course
Topics Covered:
- Content Specific Assessment: C++ programming
Format/Length: 20 close-ended questions
Encapsulation in C++ Classes Practice Booklet Problem Set 1
Spring 2003
| |
|
|
| Question 1. |
| |
|
|
| class SchoolClass |
| { |
|
|
| |
public: |
| |
|
bool difference; |
| }; |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
SchoolClass cloneObject; |
| |
cloneObject.difference = true; |
| |
cout << cloneObject.difference; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 2. |
| |
|
|
| class EmployeeClass |
| { |
|
|
| |
public: |
| |
|
bool rating; |
| }; |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
EmployeeClass lastObject; |
| |
cout << lastObject.rating; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 3. |
| |
|
|
| class EmployeeClass |
| { |
|
|
| |
private: |
| |
|
long double step; |
| }; |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
EmployeeClass originalObject; |
| |
originalObject.step = 87.008; |
| |
cout << originalObject.step; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 4. |
| |
|
|
| class AccountClass |
| { |
|
|
| |
public: |
| |
|
short increment; |
| |
|
void read(); |
| }; |
|
|
| |
|
|
| void AccountClass::read() |
| { |
|
|
| |
cout << increment; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
AccountClass copyObject; |
| |
copyObject.increment = -57; |
| |
copyObject.read(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 5. |
| |
|
|
| class CompanyClass |
| { |
|
|
| |
public: |
| |
|
long length; |
| |
|
void verify(); |
| |
protected: |
| |
|
void redirect(); |
| }; |
|
|
| |
|
|
| void CompanyClass::verify() |
| { |
|
|
| |
length = -8355; |
| } |
|
|
| |
|
|
| void CompanyClass::redirect() |
| { |
|
|
| |
cout << length; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
CompanyClass firstObject; |
| |
firstObject.verify(); |
| |
firstObject.redirect(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 6. |
| |
|
|
| class AccountClass |
| { |
|
|
| |
protected: |
| |
|
short balance; |
| }; |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
AccountClass cloneObject; |
| |
cloneObject.balance = -93; |
| |
cout << cloneObject.balance; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 7. |
| |
|
|
| class CompanyClass |
| { |
|
|
| |
public: |
| |
|
void verify(); |
| |
|
void filter(); |
| |
private: |
| |
|
bool depth; |
| }; |
|
|
| |
|
|
| void CompanyClass::verify() |
| { |
|
|
| |
depth = true; |
| } |
|
|
| |
|
|
| void CompanyClass::filter() |
| { |
|
|
| |
cout << depth; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
CompanyClass copyObject; |
| |
copyObject.verify(); |
| |
copyObject.filter(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 8. |
| |
|
|
| class BrandClass |
| { |
|
|
| |
public: |
| |
|
void project(); |
| |
private: |
| |
|
long double number; |
| }; |
|
|
| |
|
|
| void BrandClass::project() |
| { |
|
|
| |
cout << number; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
BrandClass lastObject; |
| |
lastObject.project(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 9. |
| |
|
|
| class ServiceClass |
| { |
|
|
| |
public: |
| |
|
long part; |
| |
private: |
| |
|
void join(); |
| }; |
|
|
| |
|
|
| void ServiceClass::join() |
| { |
|
|
| |
cout << part; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
ServiceClass lastObject; |
| |
lastObject.part = 5514; |
| |
lastObject.join(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 10. |
| |
|
|
| class BrandClass |
| { |
|
|
| |
public: |
| |
|
char volume; |
| |
|
void compute(); |
| |
|
void input(); |
| |
protected: |
| |
|
char units; |
| |
private: |
| |
|
char weight; |
| }; |
|
|
| |
|
|
| void BrandClass::compute() |
| { |
|
|
| |
volume = 'R'; |
| |
units = 'v'; |
| |
weight = '9'; |
| } |
|
|
| |
|
|
| void BrandClass::input() |
| { |
|
|
| |
cout << volume; |
| |
cout << units; |
| |
cout << weight; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
BrandClass lastObject; |
| |
lastObject.compute(); |
| |
lastObject.input(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 11. |
| |
|
|
| class SchoolClass |
| { |
|
|
| |
public: |
| |
|
long step; |
| |
|
void redirect(); |
| |
|
void invert(); |
| |
protected: |
| |
|
long length; |
| |
private: |
| |
|
long duration; |
| }; |
|
|
| |
|
|
| void SchoolClass::redirect() |
| { |
|
|
| |
length = 4586; |
| |
cout << length; |
| } |
|
|
| |
|
|
| void SchoolClass::invert() |
| { |
|
|
| |
cout << duration; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
SchoolClass cloneObject; |
| |
cloneObject.step = -4018; |
| |
cloneObject.redirect(); |
| |
cloneObject.invert(); |
| |
cout << cloneObject.step; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 12. |
| |
|
|
| class BrandClass |
| { |
|
|
| |
public: |
| |
|
char step; |
| |
|
void verify(); |
| |
protected: |
| |
|
char status; |
| |
private: |
| |
|
void threshold(); |
| |
|
char number; |
| }; |
|
|
| |
|
|
| void BrandClass::verify() |
| { |
|
|
| |
number = 'E'; |
| |
step = 'q'; |
| } |
|
|
| |
|
|
| void BrandClass::threshold() |
| { |
|
|
| |
cout << step; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
BrandClass lastObject; |
| |
lastObject.step = '%'; |
| |
lastObject.verify(); |
| |
lastObject.threshold(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 13. |
| |
|
|
| class CompanyClass |
| { |
|
|
| |
public: |
| |
|
void select(); |
| |
|
void transform(); |
| |
|
int length; |
| |
protected: |
| |
|
int id; |
| |
private: |
| |
|
int volume; |
| }; |
|
|
| |
|
|
| void CompanyClass::select() |
| { |
|
|
| |
id = 897; |
| |
volume = -441; |
| } |
|
|
| |
|
|
| void CompanyClass::transform() |
| { |
|
|
| |
cout << volume; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
CompanyClass lastObject; |
| |
lastObject.length = 368; |
| |
lastObject.select(); |
| |
lastObject.transform(); |
| |
cout << lastObject.id; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 14. |
| |
|
|
| class StudentClass |
| { |
|
|
| |
public: |
| |
|
void select(); |
| |
|
void redirect(); |
| |
protected: |
| |
|
long number; |
| }; |
|
|
| |
|
|
| void StudentClass::select() |
| { |
|
|
| |
number = 1049; |
| } |
|
|
| |
|
|
| void StudentClass::redirect() |
| { |
|
|
| |
cout << number; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
StudentClass newObject; |
| |
newObject.select(); |
| |
newObject.redirect(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 15. |
| |
|
|
| class BrandClass |
| { |
|
|
| |
public: |
| |
|
void calculate(); |
| |
|
int duration; |
| |
protected: |
| |
|
int count; |
| |
private: |
| |
|
int index; |
| }; |
|
|
| |
|
|
| void BrandClass::calculate() |
| { |
|
|
| |
index = -224; |
| |
count = -584; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
BrandClass duplicateObject; |
| |
duplicateObject.duration = 532; |
| |
duplicateObject.calculate(); |
| |
cout << duplicateObject.duration; |
| |
cout << duplicateObject.index; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 16. |
| |
|
|
| class StudentClass |
| { |
|
|
| |
public: |
| |
|
long double step; |
| |
|
void filter(); |
| |
|
void convert(); |
| |
protected: |
| |
|
long double duration; |
| |
private: |
| |
|
long double count; |
| }; |
|
|
| |
|
|
| void StudentClass::filter() |
| { |
|
|
| |
duration = -29.931; |
| |
count = -3.753; |
| } |
|
|
| |
|
|
| void StudentClass::convert() |
| { |
|
| |
cout << duration; |
| |
cout << count; |
| |
|
|
| void main() |
| { |
|
|
| |
StudentClass originalObject; |
| |
originalObject.filter(); |
| |
originalObject.convert(); |
| |
cout << originalObject.step; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 17. |
| |
|
|
| class BrandClass |
| { |
|
|
| |
public: |
| |
|
short area; |
| |
|
void reorder(); |
| |
protected: |
| |
|
void output(); |
| |
|
short count; |
| |
private: |
| |
|
short part; |
| }; |
|
|
| |
|
|
| void BrandClass::reorder() |
| { |
|
|
| |
part = 84; |
| |
count = -38; |
| |
area = -2; |
| |
cout << part; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
BrandClass specialObject; |
| |
specialObject.reorder(); |
| |
specialObject.output(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 18. |
| |
|
|
| class SchoolClass |
| { |
|
|
| |
public: |
| |
|
float principal; |
| }; |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
SchoolClass cloneObject; |
| |
cout << cloneObject.principal; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 19. |
| |
|
|
| class StudentClass |
| { |
|
|
| |
public: |
| |
|
void transform(); |
| |
|
void reorder(); |
| |
private: |
| |
|
bool limit; |
| }; |
|
|
| |
|
|
| void StudentClass::transform() |
| { |
|
|
| |
limit = true; |
| } |
|
|
| |
|
|
| void StudentClass::reorder() |
| { |
|
|
| |
|
cout << limit; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
StudentClass specialObject; |
| |
specialObject.transform(); |
| |
specialObject.reorder(); |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| |
|
|
| Question 20. |
| |
|
|
| class StudentClass |
| { |
|
|
| |
public: |
| |
|
void transform(); |
| |
|
int volume; |
| |
protected: |
| |
|
int index; |
| |
private: |
| |
|
int count; |
| }; |
|
|
| |
|
|
| void StudentClass::transform() |
| { |
|
|
| |
count = 451; |
| |
index = 352; |
| } |
|
|
| |
|
|
| void main() |
| { |
|
|
| |
StudentClass cloneObject; |
| |
cloneObject.volume = 822; |
| |
cloneObject.transform(); |
| |
cout << cloneObject.volume; |
| |
cout << cloneObject.count; |
| } |
|
|
| |
|
|
| |
|
|
| Check all that apply to the above code: |
| Problem Set 1: Answers to Odd-Numbered Questions |
| |
|
| Question 1. |
Code OK |
| Question 3. |
Syntax Error: Accessing private variable |
| Question 5. |
Syntax Error: Accessing protected function |
| Question 7. |
Code OK |
| Question 9. |
Syntax Error: Accessing private function |
| Question 11. |
Semantic Error |
| Question 13. |
Syntax Error: Accessing protected variable |
| Question 15. |
Syntax Error: Accessing private variable |
| Question 17. |
Syntax Error: Accessing protected function |
| Question 19. |
Code OK |
| |
|
| |
| Problem Set 1: Answers to Even-Numbered Questions |
| |
|
| Question 2. |
Semantic Error |
| Question 4. |
Code OK |
| Question 6. |
Syntax Error: Accessing protected variable |
| Question 8. |
Semantic Error |
| Question 10. |
Code OK |
| Question 12. |
Syntax Error: Accessing private function |
| Question 14. |
Code OK |
| Question 16. |
Semantic Error |
| Question 18. |
Semantic Error |
| Question 20. |
Syntax Error: Accessing private variable |
|