COSC1337 Exam 1 Review Notes

Here are some notes to help you review for the first exam in this course.

The material we have covered up to this point is basically a review of material you already should know, but this time, the focus is on using C++ syntax. The concepts are those you learned in your previous course.

Note

There are a few things in here that we did not specifically go over in class. However, you should have seen these things either in your reading or in your previous class. If anything comes up in a test question that we did not go over in class, I will not be grading that hard. But, you should know these things by now.

Language Introduction

  • basics of names and numbers (basic rules for creating names)
  • Built-in data types (integers, floats, chars, string, bool and double sized variants)
  • reserved words (if, else, while, etc)
  • Top level program components (global declarations, functions)
  • Hello world basic pattern (required function for a C++ program)
  • Style rules (where should you indent code?)
  • Processing a source file to produce an executable (describe the steps to go from an idea to a running program.)
  • Supporting libraries (iostream, math)

Sample problems:

  • identify legal and illegal literal values and declarations
  • Write the code needed for “hello world” (memorize this!)
  • Fix bad style example
  • Explain how your source code gets into an executable

Expressions and Interaction

  • Standard Input/Output (cin and cout)
  • setting up (#include and std stuff)
  • basic input mechanism (cin into variable)
  • Basic output mechanism (cout from literal or variable)
  • Mathematical Expressions (basic rules for mixing integers and floats)
  • Operator precedence (who gets evaluated first?)
  • Simple constants (literal values, named
  • No magic numbers - why? (a magic number is one sitting in your code with no name, why is this bad?)

Sample problems

  • Show how we perform basic input and output using standard I/O
  • Use operator precedence to evaluate an expression
  • Explain how the processor will handle an expression with mixed types
  • Show how to define constants in C++
  • Why are magic numbers bad?

Basic Loops

  • While loop
  • Infinite loop
  • loop counters
  • Do loop
  • for loop

Sample Questions

  • How do we set up an infinite loop (and why)?
  • How do you break out of it?
  • Create a counted loop using a while loop.
  • Show the correct style for all the loop statements.

Basic Functions

  • Interface (what do we need to define for the user and producer of a function? Think headers)
  • Name (picking a name for a function)
  • Return type (Setting one up, and returning a value)
  • Parameters (setup and calling. Types: call by value, call by reference)
  • Interface as a contract
  • Implementation
  • Assembling the parts (why do we compile the header in both the calling code and in the implementing code?)
  • Header files (the preprocessor directive stuff at the top and bottom of the header: #ifndef, #define, #endif)
  • Functions and decomposition (why do we use functions in the first place?)
  • Creating function stubs (Remember baby steps? Start off with a very simple function that works!)
  • Using functions to encapsulate part of a program
  • Testing functions (how would you test just a single function?)

Sample Questions

  • Describe how we set up a complete C++ function for a project.
  • Why do we need to establish an interface contract for a function?
  • How do we hook together a program made up of multiple files?
  • How can using functions help in decomposing a program and testing it during development?

Functions and Parameters

  • Parameter types (address and value parameters)
  • Value parameters (why do we use them?)
  • Address parameters (why do we use them. Array example)
  • How functions work
  • Calling a function
  • Returning from a function
  • Global and local variables (why is it bad to design a function that uses global variables?)

Sample Questions

  • how do value parameters work?
  • How do address parameters work?
  • How do default parameters work?
  • Explain how we decide if a name is visible to us in a C++ program (scope).