PracticeKeyFinalExam

PracticeKeyFinalExam - COSC1415/COSC1436 Key - Final Exam...

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

View Full Document Right Arrow Icon
Key - Final Exam Practice Page 1 of 3 Key for Practice Examples I. Reading Data 1. int1 = 5 int2 = 3 (reading stops at the first inappropriate character - if another integer is read input will fail because a decimal is an inappropriate character.) 2. dbl1 = 5.0 dbl2 = 3.2 3. ch1 = '5' ch2 = '3' 4. str1 = "5" str2 = "3.2" 5. ch1 = '5' ch2 = '\n' II. Output 1. _ _432.87 2. _ _ _432.875 3. _ 432.87460 4. 432.9 III. Selection/Looping/Functions 1. int NumDigits(/*in*/ int someNum) //Precondition: The value of someNum is between 0 and 9999 //Postcondition: The number of digits in someNum is returned { if (someNum <= 9) return 1; else if (someNum <= 99) return 2; else if (someNum <= 999) return 3; else return 4; } int NumDigits(int); //prototype numDigits = NumDigits(someNum); //call 2. //Preconditions: The file is open //Postconditions: The number of times 28 appears in the file is returned { int count; int num; count = 0; inData >> num;
Background image of page 1

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

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

Page1 / 3

PracticeKeyFinalExam - COSC1415/COSC1436 Key - Final Exam...

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

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