Final Exam CSCI 130
Fall 2013
- Please answer each question fully, carefully and thoughtfully.
- No credit will be given for unreadable answers, please write neatly.
- Answer the questions in any order, but please number each answer.
- Make sure that your name is on your test.
- Functions
- [10 points] Give the outline of a program which includes a function. Include examples of, and clearly label each of the following.
- Function Prototype
- Function call (invocation)
- Function definition
- Parameter List
- Arguments.
- [3 points] Describe the properties an argument and parameter must have in common.
- [6 points] Name and describe the two kinds of parameters. When should a programmer employ each kind of parameter?
- Scope/Lifetime
- [1 points] Define the scope of an identifier.
- [2 points] Describe the scope rules for C++.
- [2 points] What is a global variable and why should programmers avoid employing global variables?
- [1 points] What is the lifetime of a variable?
- [3 points] What is functional cohesion?
- Employing Functions
- [3 points] Why is repeated code a problem in a program?
- [2 points] How can programmers solve the problem of repeated code?
- [3 points] Write a function which takes an integer between 0 and 9 and returns the English name of that integer. For example, if the input is 5, the output should be "five".
- [4 points] Write a void function which takes a string and reverses the order of the characters in that string. For example, the string "Hello World!" would become "!dlroW olleH"
- [5 points] Write function which takes a string and returns true if the string is a perfect palindrome. A perfect palindrome reads the same in each direction, "able was I ere I saw elba" is a perfect palindrome, but "Race caR" is not. You may use the function from the previous question as part of your solution.
- [5 points] Write a program which reads a series of phrases from the file "sayings.dat". Each phrase occupies a single line. For each phrase, your program should print out "Perfect Palindrome" if the phrase is a perfect palindrome. You may use the code from the previous questions to solve this problem.