C++
Review for Test 1: List of Topics Covered
This is a list of topics intended as a checklist to help you recall
what topics have been covered, both in lecture class and in the textbook.
General Computer and Programming Concepts
- Components (CPU, RAM, disk storage, I/O devices)
- bits and bytes
- evolution of programming languages
- interpreted vs. compiled languages
- Steps involved in software development
- Creation of a C++ program (source code, preprocessing, compilation,
linking, execution)
- syntax vs semantics
C++ Basics
General structure
- sequence of statements
- Can consist of multiple code files and libraries
- A program starts with main()
- Types of statements (including compound statements)
- Pre-compiled libraries, #include
Atomic Data Types
- integer types -- char, short, int, long
- signed and unsigned versions
- floating point types -- float, double, long double
- bool
- system dependent sizes (but common sizes currently in use today were
discussed)
Declaring and Intializing Variables
- naming rules for identifiers
- declaration format
- difference between declaring and initializing
- how to initialize built-in variable types with values
- Declaring variables with const (constants)
- "Declare before use" rule
Literals:
- integer, floating-point, character, string
- Escape sequences for special characters
- used for writing character literals, and used in string literals
- Know the common ones
Comments:
- // Line comments
- /* Block-style coments */
Input and Output with Streams
- objects cin, cout
- Library <iostream>
- insertion and extraction operators << and >>
- Know which operator used with which objects (cout, cin, etc)
- Know what can be used on the right side of each operator
- Cascading the << and >> operators
- Special formatting calls for floating-point numbers
- Fixed format vs. scientific format
- showpoint flag
- setting decimal precision
- Know how to set each of these
- namespace "std" (and using statements)
Operators:
- General Concepts
- operators and operands
- Arity (unary, binary, ternary)
- Precedence and associativity
- Cascading
- Arithmetic operators: + - / * %
- understand int vs. floating-point division (/ and %)
- increment and decrement: ++ --
- Post-increment vs. Pre-increment: x++ vs. ++x
- Post-decrement vs. Pre-decrement: x-- vs. --x
- assignment operator: =(single equal sign)
- Understand the concept of L-value vs R-value
- automatic type conversions
- using static_cast for explicit type-conversion
- Logical operators: == != < <= > >=
- Boolean operators: && (AND), || (OR), !
(NOT)
- short-circuit evaluation of && and ||
Control Structures
- Flow of Control concepts:
- sqeuential
- Selection (branching)
- Repetition (looping)
- The if/else selection statement
- Syntax format and rules for if and for if/else
statements
- How the test expression is evaluated
- Syntax vs. readability conventions (indentation, etc)
- Know when to use a block
- The switch selection statement
- Keywords switch, case, default,
break
- Understand how switch blocks work
- only works with integer and character expressions
- know when to use break
- while and do-while loops
- Syntax format and rules for both
- How the test expression is evaluated
- Know the difference between while and do-while
- Know when to use a block
- Know when the loop repeats and when it quits
- for loops
- Three parts to the header: initial condition, test expression,
iterative expression
- Good for counting-controlled loops
- scope of loop control variable (if declared inside header)
- Special statements affecting loop control
Functions
Function Basics
- Know what a function is
- Reasons for writing functions (divide-and-conquer, reusability)
- Perspective: builder vs. caller
Using Functions
- Know how to call a function
- syntax
- passing arguments
- using the returned value
- Understand how they are like mathematical functions
- Declare-before-use policy
- Predefined functions
- Functions in libraries - especially sqrt() and pow() as discussed in class
- Know how to use #include to include them in a program
Building Functions
- Declaration -- name, return type, parameter list
- Know the format
- Know what to specify in the parameter list
- Definition -- header, along with function body
- the keyword return -- returning values from functions
- using the formal parameters in the function
- Scope (and how it relates to functions)
- Meaning of scope
- Global scope
- Variables local to function blocks
- Scope of function parameters
- void as a return type
- Empty parameter lists
Test 1 Practice
Format of Test
Format of the test will consist of 50 questions answered on scantron (scantrons provided at exam)
- multiple choice, true/false,
legal/illegal
- Code-Reading -- problems involving reading a segment of code and
answering some question about it.
Some Practice Coding Problems
- Write a program that asks the user to enter three integers, then
computes their decimal average and prints the result
- Write a function that takes in three integer parameters and returns
their decimal average. (How does this differ from the previous
problem?)
- Write a function that takes in two integer parameters and returns true
if the first parameter is a multiple of the second, and false otherwise.
(Hint: The % operator can help you determine factors and
multiples)
- Write a function that takes in three integer parameters and decides if
they could be the lengths of the sides of a right triangle. If so, return
true. Otherwise, return false. (Hint: Pythagoras had a little theorem,
it's hypothesis was white as snow...)
- Write a program that has the user enter the radius of a circle, then
compute and print the diameter, the circumference, and the area. Use the
value 3.14159 for pi.
- Write a function that takes in two integer parameters, x and y, and
computes and returns x raised to the y power. Do this without using any
<cmath> library functions
- Write a function that takes in a positive integer parameter N, and
then returns the sum of all the positive numbers that are less than or
equal to N. (i.e. add up all numbers from 1 through N -- you'll
need a loop).
- Write a function that does the same as the previous exercise, but adds
up only the odd numbers from 1 to N
- Write a function that takes in three double parameters and
returns the smallest of the three values
- Write a function that takes in three integer parameters and returns
true if they are all even numbers, and false otherwise