Structured
Programming in C++
Prof. Gregory Safko
Camden County College
1. Know the material from Exam 1 (since learning the language is cumulative, you should be comfortable with using all of the previously learned concepts)
2. Know the material from Chapter 6 (Modular Programming) & 7 (Simple Data Types) in the book
3. Know the definition of: Top-Down Design, Abstraction, Stubs, and Drivers
4. Know the unary, binary, and ternary operators of C++ (what is the only ternary operator in C++?)
5. Know how to include external files in a workspace (Such as other.cpp)
6. Know how to use #include to include externals files in a program (e.g. #include "other.cpp")
7. Know the difference between an iterative function and a recursive function, and how to immediately recognize the difference.
8. Know the two ways to declare data as a constant (const and #define)
9. Know how to use and interpret an ASCII table
10. Know how to use the char data type. Know how to extract both characters and integers from a char.
11. Know how to use the functions found in <cctype> (tolower, toupper, islower, isupper, ispunct, isdigit, etc.)
12. Know how to declare enums, and how to use them in code.
13. Know how to declare, populate, and traverse an array.
14. Know how to write and prototype overloaded functions
15. Know what a predicate is, and how it is used.
Sample Multiple Choice
1. A function reference parameter is normally used for parameter passing of: (choose best single answer):
A. Input parameters only.
B. Outputs parameters only.
C. Input or output parameters.
D. Output or input /output parameters
2. Which one of these is not true
A. ">" is the opposite of ">="
B. "<" is the opposite of ">="
C. "==" is the opposite of "!="
D. && is the opposite of ||
3. Which of the following is the correct way to do a precompiled define:
A. #define value result
B. #define value = result
C. <define value = result>
D. define value = result;
4. A function declared as _______ can still return results to the calling function by using reference parameters.
A. int
B. sum
C. bool
D. void
5. What value is associated with wednesday in the following expression?
enum dayofweek (monday, tuesday, wednesday, thursday, friday, saturday, sunday);
A. 2
B. Wednesday
C. 3
D. ‘Wednesday’
6. What does the #define statement allow you to do?
A. Define the ASCII code of a variable
B. Replace a character with a constant variable
C. Declare a variable
D. Define p
7. The statement case 'A': is an indication of a(n):
A. if/else statement
B. do/while statement
C. do statement
D. case statement
E. None of the above
8. What is another way to write !(boolean1 && boolean2) ?
A. (!boolean1 && !boolean2)
B. !(boolean1 || boolean2)
C. (!boolean1 || !boolean2)
D. !boolean1 || boolean2
9. Which of the following declarations will cause a compiler error?
10. Pass-by-value is also known as:
A. Pass-by-reference
B. Call-by-reference
C. Call-by-value
D. Cast-by-value
E. None of these
Sample Free Response/Debugging
char myA = "a";
const int a = 10;
a++;
int lottery (3);
lottery (1) = 12;
lottery (2) = 20;
lottery (3) = 28;
Sample Coding
1. Write a function that tests a character value for a number or a letter only (either letter case) and returns true if a letter or number. All other ASCII characters must return false.
2. Write a piece of code which identifies whether the first character of a string is capital letter . Assume the library cctype is included and the string has already been validated to have at least one character. If the first character is not a letter, return false.
3. Write a function that will print out the second character and the number of characters of an input word. There are no restrictions on the length of the input word.
Sample Multiple Choice Answers
1. A
2. A
3. A
4. D
5. A
6. B
7. E (It is an indication of a switch statement)
8. C
Sample Free Response/Debugging Answers
Sample Coding Solutions
1.
bool testChar(char c)
{
if(isDigit(c) || isAlpha(c) )
return true;
return false;
}
2.
bool IsFirstLetterCapital(string inString)
{
char firstLetter = inString[0];
if (isalpha(firstLetter) == false)
{
return false;
}
if (isupper(firstLetter))
{
return true;
}
return false;
}
3.
string inputWord;
cout << “Enter the Word: “;
cin >> inputWord;
for (int posChar =0; posChar < inputWord , inputWord.length(); posChar++)
cout << inputWord.at(2) << endl;
cout << inputWord.length() << endl;