mid2010_soln

mid2010_soln - Term: Fall Year: 2010 Student Name:

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Term: Fall Year: 2010 Student Name: ______________________________________________________________________ UW Student ID Number: ______________________________________________________________ Course Abbreviation and Number GEN E 121 (Mechatronics C++) Course Title Digital Computation Section(s) 001 Instructor C. Hulls Date of Exam Monday, October 18, 2010 Time Period Start time: 9:00am End time: 11:00am Duration of Exam 2 hours Allowed Materials: Writing instruments ONE (8.5x11) formula sheet written on ONE side only Disallowed Materials No electronic devices of ANY kind. No hats or containers such a purses, pencil cases, packsacks Notes: You can assume for any programs that any necessary libraries (eg. #include <iostream> ) have been included. All questions will be marked for credit. If you need to make any assumptions to formulate your solution, state your assumptions clearly. Question Maximum Mark Mark 1. 8 2. 10 3. 17 4. 10 5. 20 6. 20 Total 85 University of Waterloo Midterm Examination Fall 2010 GenE 121 (C++) Midterm Page 2 of 10 1. Fill in the Blank [8 Marks Total] a. A variable must be ____defined/declared _____________ before it can be used in a program. b. The ___fmod ________ function returns the remainder from floating point division. c. The * , / , and % operators have the same _______precedence _________. d. The code if ( _______b==0 _______ ) tests whether the integer b is equal to zero. e. A function that does not return anything has a return type of _________void _________. f. For an array of integers called x , the code to set the first element to -1 is x[ _0 _ ] = -1; g. The acos function returns the ___________arccose/inverse cosine _________________ in _____radians _______________ (units). Fall 2010 GenE 121 (C++) Midterm Page 3 of 10 2. Short Answer [10 Marks Total] What is output by the following code? a. [2 Marks] int x = 2, y = -4, z = 3; cout << 3.2 + x * z / y * 0.5 + x % z; 4.7 b. [1 Mark] int i = 4; int j = i++ / ++i; cout << i << " " << j << endl; 6 1 c. [3 Marks] int num[10] = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}; int k = 4; cout << num[k++] << endl; ++num[k]; cout << num[k] << endl; 32 65 d. [4 Marks] int swirl(int & b, int c, int & a) { c += a % b; a = ++b; b += 2; return c; } int main() { int a=6, b=-3, c=4; cout << a << " " << b << " " << c << endl; b = swirl(a, c, c); cout << a << " " << b << " " << c << endl; cin.get(); return 0; } 6 -3 4 9 8 7 Fall 2010 GenE 121 (C++) Midterm Page 4 of 10 3. Short Programs and Short Functions [17 Marks Total] a. [4 Marks] Write a program that prompts for an elapsed time in the following format h : m : s and outputs the time in seconds. For example, Enter elapsed time 1 : 5 : 21 Time is 3921 s int main() { cout<<”Enter elapsed time”; char junk; int hour, minute, second; cin>>hour>>junk>>minute>>junk>>second; cout<<”Time is “<<second+minute*60+hour+3600<<” s”<<endl; system("PAUSE"); return 0; } b. [4 Marks] Write a function that receives...
View Full Document

This note was uploaded on 04/01/2012 for the course GENE 121 taught by Professor Smucker during the Winter '11 term at Waterloo.

Page1 / 10

mid2010_soln - Term: Fall Year: 2010 Student Name:

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online