Skip to main content


By January 4, 2021留学咨询

Page 1 of 6 Office Use Only Monash College SAMPLE EXAM Diploma of Information Technology EXAM CODES: TITLE OF PAPER: EXAM DURATION: MCD4720 Foundations of C+ + 3 hours writing time READING TIME: 10 minutes THIS PAPER IS FOR STUDENTS STUDYING AT:( tick where applicable) o Berwick x Clayton o Malaysia o Off Campus Learning o Open Learning o Caulfield o Gippsland o Peninsula o Enhancement Studies o Sth Africa o Pharmacy o Other (specify) During an exam, you must not have in your possession, a book, notes, paper, electronic device/s, calculator, pencil case, mobile phone or other material/item which has not been authorised for the exam or specifically permitted as noted below. Any material or item on your desk, chair or person will be deemed to be in your possession. You are reminded that possession of unauthorised materials in an exam is a discipline offence under Monash Statute 4.1. No examination papers are to be removed from the room. AUTHORISED MATERIALS CALCULATORS o YES x NO OPEN BOOK o YES x NO SPECIFICALLY PERMITTED ITEMS o YES x NO if yes, items permitted are: Candidates must complete this section if required to write answers within this paper STUDENT ID __ __ __ __ __ __ __ __ DESK NUMBER __ __ __ __ Page 2 of 6 Instructions to Candidates: 1. The examination is out of 100 marks. Marks for individual sections and questions are clearly indicated throughout the exam paper. 2. Answer all questions in the provided exam script books, NOT in the exam paper. 3. You may answer the questions in any order. Boldly number your answers to all questions. Commence all sections on a new page. 4. Write your answers on the lined pages of the exam script. You may use the blank sides of the page for workings, however these pages will not be marked. 5. State any assumptions that you make regarding any question. 6. Your final exam will be 2 hours, the number of questions will be less than this paper. 7. The answer of this paper will be released, at the end of week 12. Page 3 of 6 Section A: Short Answer Questions (30 marks total) 1. #include and using namespace std; are two lines of code wetypically include in our c++ programs. What do these two lines do? Why do wetypically need them? [3 marks]2. A break statement is common in most switch statements, however it is not mandatory.What is the purpose of including a break statement in a switch statement? What willhappen if it is not included? [3 marks]3. A well authored header file can be all we need to understand how to use a pre-existingclass. Explain why this is so by describing what we typically include in a header file fora class. [3 marks]4. Vectors and Arrays are 2 of the main storage options for keeping collections of data inC++. Describe the similarities and differences between these two, highlighting whenyou would likely choose one over the other. [3 marks]5. What is considered good programming practice to do when you’ve created an objectwith the new command? Why? [3 marks]6. What do we mean by “dereferencing” a pointer? Provide example in code of when wemay use a pointer normally and dereferenced. [3 marks]7. In C++ we can have multiple constructors for one class, but only one destructor.Explain why this is the case using code to highlight why. [3 marks]8. What is operator overloading? Provide a practical example of when we would use this.[3 marks]9. Polymorphism allows us to keep collections of different types of related objects.Explain how this is so using a practical example [3 marks]10. Singletons and Factory are two object-oriented design patterns that we can utilise inour program design. Briefly explain each and provide a practical example of when wemay choose to use that design pattern. [3 marks] Page 4 of 6 Section B: Short Coding Questions (40 marks total) 1. The following code does not perform as expected. What is happening? Fix the code so that it performs the task correctly. [6 marks] int main() { int num1 = 13; int num2 = 7; numberModifier(num1, num2, 3); cout << "The MODIFIED value of number one is " << num1 << endl; cout << "The MODIFIED value of number two is " << num2 << endl; } void numberModifier (int a, int b, int modifier) { a = a/modifier; b = b%modifier; } 2. Write a program to perform an analysis of the rolling of two dice. Your program should use rand()%6 + 1 to roll the first dice and then again to roll the second dice. With each dice roll, the outcome of the rolls should be tallied in a 6 x 6 two-dimensional array that represents all possible combinations of dice rolls (as seen below). For example, if the first number rolled is a 2, and the second number a 3, then the value in the spot indicated with an ‘x’ below would be incremented by 1. Repeat this dice roll process 10,000 times. On completion, display a report that shows the total counts. [8 marks] 1 2 3 4 5 6 1 2 x 3 4 5 6 Page 5 of 6 3. Write a program to load a vector with 50 random integers between the numbers 0-49. Once the vector is loaded, display a report of how many numbers are in the range 0-9, 10-19, 20-29, 30-39, and 40-49. [8 marks] 4. You have a class called “Customer” which has a number of data members (m_nID, m_sName, m_nPhoneNum) as well as accessor functions for these data members called getID, getName, and getPhoneNum. The constructor for the class accepts two integers and a string to set the values of these data members. Using C++ code, declare a vector to hold pointers to Customer objects and create 3 customers in the vector. Write code to display a report of the customers stored in the vector. Finally, write code to delete the customers appropriately for when the program ends. [8 marks] 5. The company that utilises the Customer class as described above has now added a new tier of customer, a Gold Customer, that has the same attributes, but also has a number of other attributes. These include they number of years they have been a member, and a discount rate that the customer now gets on all purchases. Write a class that inherits from the Customer class that adds these data members as well as a function that can get the discount rate. Your constructor should set the initial values to 1 year of membership and a 10% discount rate. You should then update your collection of customers from the previous question so that it can hold and work with both normal customers and gold customers. [10 marks] Page 6 of 6 Section C: Object Design & Implementation (30 marks total) You are to design a basic Pacman game. The game consists of a maze that is populated by Pacman, 2 ghosts, and pellets for you to eat. It is your job to eat all the pellets in the maze without being caught by the ghosts. Your score increases with each small pellet you eat. When you eat a large pellet (top left & bottom right) you can eat the ghosts for a short period of time. The game ends when all pellets are eaten or if a ghost eats Pacman. Below is an image to show you the maze, the game characters, and the pellets: The maze can be represented by a 2-dimensional array. Each spot in the array can hold either a piece of the maze wall, Pacman, a ghost, a small pellet, a large pellet, or nothing. In the following questions describe your approach to designing a solution to this game problem. Clearly state any assumptions you make. You ARE NOT expected to code the game. 1. Given the scenario above, write an overview of how you will structure an object-oriented design. Write a brief overview in plain English of your approach to designing a solution. Describe how you might use inheritance and polymorphism. [10 marks] 2. Describe the classes your C++ game will have. For each class: a. Describe the purpose of the class in one or two lines. Also indicate if it is a base class or inherits from another class. b. List the data members each class may have. Indicate the data type you will use to represent each data member and the visibility of each. c. Describe the member functions that each class would have. Indicate the visibility of each function and write one line that indicates what the job of the function is. Also indicate if the function has any special characteristics (for example, is static , virtual, a friend, etc.). [15 marks] 3. Detail the functionality your main function will have. Also list and describe any other functions your game will use that are not part of a class detailed above. [5 marks] 欢迎咨询51作业君


Author admin

More posts by admin

Leave a Reply