CEG220: Introduction to C
Programming for Engineers – I
Section 2
Midterm Examination
Any
of following material will be covered on this examination:
· Pseudo Code
· Simple Types
· Function use
· Boolean Math
· remember that 0 is false, anything else is true
· remember that (a = b) makes a equal to b and then evaluates that expression to a
· Flow Control
· Modular Programming
· Functions vs. Procedures
· User-defined Functions
·
Anything covered in any of the past projects
Midterm
Review Questions:
1) Write Pseudo code to solve the following problems:
a. Computes the area of a triangle given SSS (Side Side Side)
b. Computes Fibonacci(n). The series of Fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13, ...
Fibonacci(0) = 0
Fibonacci(1) = 1
Fibonacci(2) = 1
Fibonacci(3) = 2
...
2) Evaluate the following statements given the variables below. Assume that TRUE = 1 and that FALSE = 0 – as they are in C.
double dValue =2;
float fValue = 2;
int iRowValue = 6, iColValue = 3;
bool thisIsHard = FALSE, thisIsEasy = TRUE;
a) (dValue == (fValue = iRowValue / iColValue))
b) (fValue == dValue)
c) Evaluate this statement: ((dValue == fValue) && (iRowValue = 7))
What are dValue, fValue, iRowValue, and iColValue equal to after this statement is executed?
d) What type is iRowValue / fValue ?
e) What type is iColValue / dValue ?
3) Compute the following values. Ensure that your answers to all trig functions are in DEGREES. Also make sure to mention any libraries that need to be #included.
a. sin-1( 32 / 52 )
b. sin-1( 3.02 / 52 )
c. tan-1 (1)
d. integrateRRAM( f(x) = √(1 – x2), -1, 1, 1000 )
e. 5 / 2 + 8 – 9 + 13
4) Write out the truth table for the following:
a. A && B
b. A xor B
c. A || (B && A)
d. A || B || C
5) Write an if/else chain that outputs a message if a number is > 10, another output message if a number is < 10, and a third message if the number is equal to 10.
6) Write an if/else chain that, given a balance, determines the type of bank account that the user has and displays the account type along with that account’s interest rate. “Platinum” level accounts have more than 10,000 dollars and carry an interest rate of 5%, “Gold” level have more than 5,000 dollars and have an interest rate of 2.5%, “Silver” level have more than 2,000 dollars and an interest rate of 1.25%, and “Bronze” level accounts have more than 1,000 dollars and earn no interest.
7) What are the fundamentals of modular programming?
8) What is a function? A procedure? When do you use functions as opposed to procedures?
9) Write a function that
a. computes the cube root of a given number (double)
b. computes the sixth root of a given number given sqrt and the function in (a)
c. computes Fibonacci(n)
10) Write a
procedure that (a) displays a menu, (b) notifies the user that the program is
waiting for the user to press enter before continuing, and (c) reads in the
character with fread, only allowing the user to continue if they press enter
(which is the ‘\n’ character)