# CPTR 124 Fundamentals of Programming Test 2 Study Guide

The material presented in this guide covers the concepts emphasized on Test 2. It is meant to guide students studying and reviewing for Test 2; it is not guaranteed to be comprehensive. Actual test questions will differ from the examples given here. Students should use this guide in addition to other study activities (like reading Chapters 8-10, reviewing completed lab assignments, old quizzes, etc.) Knowledge of Chapters 1-7 is assumed, but the emphasis is on material in Chapters 8-10.

• Know the following concepts. Understand where they apply and when they should or could be used.

• Be able to read, write, and debug control statements involving conditional statements and loops.
• Know how to use the standard library functions we covered and know what they do. These functions include `sqrt`, `pow`, `time`, `toupper`, `tolower`, `rand`, and `srand`.

• Be able to read, write, and debug programmer-defined functions. Be familiar with the following function-related concepts: formal and actual parameters, pass by value, pass by reference, local variables, return values, reference parameters, pointer parameters, global variables, and recursion.

• Pointers: declaring, assigning, dereferencing

• Be able to do the following tasks.

• Answer multiple choice questions about a given function—what it does or how it does something. For these problems you are "playing computer;" that is, examining the code in a function and predicting its behavior. This may be in the form of answering questions such as:

• What is returned by the given function call?
• What must be passed to a function so that it returns a given value?

For example, given the function

int func(int a, int b) { int s = 0; while (a < b) { s++; a++; b--; } return s; }
what is the value of `func(3, 12)`?

• Writing C++ functions.

Be able to write a C++ function given its specification. The code may involve any of the concepts in Chapters 2-10. Thus, in order to write the code you may need to:

• be able to declare and use variables
• be able to do arithmetic
• be able to construct conditional statements and loops from scratch
• be able to properly package the code within a function; the function's parameters and code must be consistent with the specifications
• understand the differences between local and global variables

For example, complete the following function named `is_reduced` that accepts two integer parameters, `numerator` and `denominator`. The function returns true if numerator/denominator represents a fraction reduced to lowest terms; otherwise, it returns false if the fraction numerator/denominator can be reduced. For example, `is_reduced(1, 2)` would evaluate to true, but `is_reduced(2, 4)` would evaluate to false. Improper fractions are acceptable, but the function should return false whenever `denominator` is zero.

bool is_reduced(int numerator, int denominator) { }

During your study, take some time to reflect on what you have done in the labs. If you have mastered the labs, then you should not be overly challenged by the programming part of the test.

Also, take time to review all the code we have developed in class. It has all been uploaded to the course repository on GitHub
( https://github.com/halterman/124_W19).