Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CS1124 Exam 1 Mock
- 1. Declare a pointer to an int that:
- a) is a constant pointer
- b) will point to a constant int
- c) is both a and b
- 2. When defining a class the keyword "this" is:
- a. an object of that class
- b. a pointer to the specific instance of that class
- c a parameter passed automatically to each method by the compiler
- d a pointer to null
- 3. true/false? circle answers that are true.
- a. when passing a pointer by value, you can't change the original pointer or its contents
- b. creating an object of any class is called instantiation
- 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.
- d. to get the size of a vector, you use the method size()
- 4. what does the following code do?
- class A {
- int foo;
- };
- class B : public A {
- int bar;
- };
- int main() {
- B myB;
- A myA = myB;
- }
- a. compilation error
- b. slicing problem
- c. a and b
- d. none
- 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.
- struct Person
- {
- string name, number;
- };
- Sample file:
- John Sterling
- 1-111-222-3333
- Linus Torvalds
- 1-888-555-9999
- 6. Write a function to delete all the data created in the previous problem.
- 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.
- 8. Write a class Employee to model the employees in a company PolyCo.
- * In PolyCo, each employee has a name, can have one boss and zero or more sub-employees.
- * The CEO of PolyCo doesn't have a boss, of course, but every other employee does.
- * When employees are created, there are the following two possibilities:
- * They can be told who their boss is right away.
- * They can be created without a boss.
- * 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.
- * Write a display function that will give the output as shown.
- * Important: Only write the class Employee!
- * Assume that there will be no duplicate employees added to a boss employee.
- * Here's a sample main and the sample output it produces.
- int main() {
- Employee sterling("John Sterling");
- Employee yan("Yan", &sterling);
- Employee jeremy("Jeremy");
- Employee mike("Mike");
- yan.addToTeam(jeremy);
- yan.addToTeam(mike);
- yan.display();
- cout << endl;
- sterling.display();
- cout << endl;
- }
- _Output:_
- Name: Yan
- Boss: Professor Sterling
- Team...
- Jeremy
- Mike
- Name: Professor Sterling
- Boss: I am the boss.
- Team...
- Yan
Add Comment
Please, Sign In to add comment