CSCI251 Advanced Programming | UOW伍伦贡大学 | C++代写 | exam代考

CSCI251 Exam – Autumn 2021 Page 1 of 5 School of Computing and Information Technology CSCI251 Advanced Programming Family name Other names Student number Table number Examination Paper Autumn Session 2021 Exam duration 3 hours (except for some RA students) Weighting 60% Directions to students This exam contains two parts, for a total of 40 marks. Part A: 16 questions worth 1 mark each. Part B: 12 questions worth 2 marks each. CSCI251 Exam – Autumn 2021 Page 2 of 5 All code provided in this exam is assumed to have appropriate headers. In writing code you should not provide appropriate includes, they will be assumed, unless the question specifically relates to includes. Answer your questions in a file and convert the file to pdf. Name your pdf file with your name and student number, as in Ngoc_007.pdf. DO include your name and student number of each page of your answer paper. DO NOT include the question itself, just the part and number clearly identifying which question an answer relates to. Part A: 16 questions worth 1 mark each. (Total 16 Marks) 1) What do exceptions allow us to separate? Give an example of when this separation is appropriate. 2) Explain what the idea that main() should tell a story means, particularly in procedural programming. 3) Function swapTwo() below is used by which method: pass by value or pass by reference? Explain what is the main difference between two methods. void swapTwo(int& a, int& b){ int tmp = a; a = b; b = tmp; } 4) How many types of overloading in C++? Give examples to illustrate. 5) The following code segment fails to initialize the array elements to 1. State the usage of the keyword auto. Rewrite the code segment so that it could work. int *ptr = new int[7]; for(auto& x : ptr) x = 1; 6) Show two ways to insert “comments” in C++ code 7) An array name is often considered as a “constant pointer” to an array. Consider the following statements and state whether there is any difference in terms of the byte size of ptr1 and ptr2. int ptr1[5]; int * const ptr2 = new int[5]; 8) What a loop in C++ is used for and when you would use one? 9) What is the role of a makefile? How to produce a makefile? 10) What are the roles of constructors and destructors, related to the lifetime of an object? Give an example header for a constructor and destructor for a class X. CSCI251 Exam – Autumn 2021 Page 3 of 5 11) How do static and dynamic libraries differ? Give one advantage of using each. 12) What does it mean to provide .h and .o files to a “client”? Why would we do this? 13) State one advantage of smart pointers (not iterators from STL) over regular pointers. 14) Explain the idea of class templates being blueprints of blueprints. 15) Describe a scenario where the use of an STL vector makes more sense than the use of an STL deque, STL set or STL map. Justify your answer. 16) Describe advantages of using a container class rather the classical array. Part B: 12 questions worth 2 marks each. (Total 24 Marks) 1) Assume that Test is a class provided so the code below compiles, and that Test doesn’t generate additional internal Test objects. Explain where and how many Test objects will be created by the following code. If you provide the correct number with no justification you will receive 0.5 mark. void testOne(Test &C) { cout << “Testing” << endl; } void testTwo(Test C) { cout << “More testing” << endl; } int main() { Test A; Test B = A; testOne(A); testTwo(B); return 0; } 2) Write the definition and implementation of a class Frog, which is derived from Animal. The base class contains private data fields for the name and age, a public constructor that sets both of those data fields, and getter functions for each of the data fields. The derived class contains private fields for the tongue length, mass, and the hop distance. The derived class also contains a constructor for setting all values, and an overloaded insertion operator. You do not need to write the base class. 3) You will write 3 small blocks of code in the sections (TODO…) to demonstrate move constructor. You do not need to write the whole program. The code and the running result below are the suggestions for your code. #include #include using namespace std; class Mouse CSCI251 Exam – Autumn 2021 Page 4 of 5 { private: string name; int age; public: Mouse() = default; ~Mouse(); Mouse(string name, int age); Mouse(const Mouse&); //copy constructor TODO…; //move constructor }; Mouse::~Mouse() { cout << “Destructor” << endl; } Mouse::Mouse(string _name, int _age) { name = _name; age = _age; cout<<“Mouse constructing”< using namespace std; template T findMinArr(T* arr, int s){ TODO… } int main(){ int a[]={7, 8, 1, 2, 4, 12, 4}; char b[]={‘h’, ‘i’, ‘a’,’o’,’w’}; double c[]={7.77, 1.11, 2.22, 3.33, 8.88}; cout<<“Min value of INT array: ” << findMinArr(a, sizeof(a)/sizeof(int))<