Guest User

Untitled

a guest
Jan 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. CS1124 Exam 1 Mock
  2.  
  3. 1. Declare a pointer to an int that:
  4. a) is a constant pointer
  5. b) will point to a constant int
  6. c) is both a and b
  7. 2. When defining a class the keyword "this" is:
  8. a. an object of that class
  9. b. a pointer to the specific instance of that class
  10. c a parameter passed automatically to each method by the compiler
  11. d a pointer to null
  12. 3. true/false? circle answers that are true.
  13. a. when passing a pointer by value, you can't change the original pointer or its contents
  14. b. creating an object of any class is called instantiation
  15. c. if class A has a private data member: int x, and class B derives from class A, class B can access and change the data member int x.
  16. d. to get the size of a vector, you use the method size()
  17. 4. what does the following code do?
  18. class A {
  19. int foo;
  20. };
  21. class B : public A {
  22. int bar;
  23. };
  24.  
  25. int main() {
  26. B myB;
  27. A myA = myB;
  28. }
  29.  
  30. a. compilation error
  31. b. slicing problem
  32. c. a and b
  33. d. none
  34. 5. Write a function that reads from a file of person objects and stores their locations as a _vector of Person pointers_ . The struct and the sample file are given below. Assume the file is already opened.
  35. struct Person
  36. {
  37. string name, number;
  38. };
  39.  
  40. Sample file:
  41.  
  42. John Sterling
  43. 1-111-222-3333
  44.  
  45. Linus Torvalds
  46. 1-888-555-9999
  47.  
  48. 6. Write a function to delete all the data created in the previous problem.
  49.  
  50. 7. Write a function to search the vector from the problems above. The function should accept the phone number of the person, and return their name.
  51.  
  52. 8. Write a class Employee to model the employees in a company PolyCo.
  53. * In PolyCo, each employee has a name, can have one boss and zero or more sub-employees.
  54. * The CEO of PolyCo doesn't have a boss, of course, but every other employee does.
  55. * When employees are created, there are the following two possibilities:
  56. * They can be told who their boss is right away.
  57. * They can be created without a boss.
  58. * Employees should be able to be added and removed from the list of sub-employees at any time in the future. Provide support for this. Think about the fact that employees in the team need to know who their boss is, and the boss needs to know who's in his team.
  59. * Write a display function that will give the output as shown.
  60. * Important: Only write the class Employee!
  61. * Assume that there will be no duplicate employees added to a boss employee.
  62. * Here's a sample main and the sample output it produces.
  63.  
  64. int main() {
  65. Employee sterling("John Sterling");
  66. Employee yan("Yan", &sterling);
  67. Employee jeremy("Jeremy");
  68. Employee mike("Mike");
  69. yan.addToTeam(jeremy);
  70. yan.addToTeam(mike);
  71. yan.display();
  72. cout << endl;
  73. sterling.display();
  74. cout << endl;
  75. }
  76.  
  77. _Output:_
  78.  
  79. Name: Yan
  80. Boss: Professor Sterling
  81. Team...
  82. Jeremy
  83. Mike
  84.  
  85. Name: Professor Sterling
  86. Boss: I am the boss.
  87. Team...
  88. Yan
Add Comment
Please, Sign In to add comment