Some sample exam 1 questions (note that homework questions are in many
cases also good samples of exam questions):
1. Define the following terms:
Computer Hardware
Computer Software
Top-Down Programming
Structure Chart
Global Declaration
Reserved Word
Comment
Literal Constant
Memory Constant
Associativity
Precedence
Side Effect
Implicit Casting
2. Prepare a structure chart/outline for how you would purchase a bottle
of Coke in the cafeteria (be specific on the actions you to take).
3. Given the structure chart/outline you produced in the previous
question, produce the corresponding outline/structure chart.
4. In the following program circle five syntax errors and indicate what is
wrong for each of the things you circle:
include
const PI = 3.14159;
int main () {
int x; y1;
character c1;
printf("Enter a value for three times X);
scanf("%i",x);
printf("x times three is %f\n",x,PI * x);
}
5. Assume:
X = 2;
Y = 7;
Z = 9;
A = 0;
B = 1;
What are the values of:
X + Y * Z
X * Y + Z
X - Y - Z
X / Y * Z
Y % X
sqrt(Z)
pow(X,Y)
rint(7.6)
floor(7.6)
ceil(7.6)
X + Y - Z * X + Z - X % Y
X && Y
A || B
!A
!A && B
!B || A
(X < Y) && Z > X
6. A field specification may have width and precision values, how
are these used?
7. What is meant by the term prompting for input? What are
characteristics of a good prompt. Show an example.
8. Rich needs help, he needs to produce a piece of code showing a table
similar to the one below. He has written part of the code but needs you
to complete it.
The table would be the following if the number of Hammers,
Nails, and Screws purchased are 2, 150, and 20 respectively:
Item # Cost
-------------------
Hammer 2 $ 35.00
Nail 150 $ 7.50
Screw 20 $ 5.00
Here is the code so far:
#include
#define HAMMER_COST 17.50
#define NAIL_COST 0.05
#define SCREW_COST 0.25
int main () {
int num_hammers;
int num_nails;
int num_screws;
/* YOU MAY WANT TO ADD EXTRA VARIABLES */
printf("Please enter the number of hammers, nails and screws purchased: ");
scanf("%d%d%d",&num_hammers,&num_nails,&num_screws);
/* YOUR CODE GOES HERE */
}
9. Rich wants to write a function that prompts a user for three pieces
of information: an id number (integer), a salary (floating-point) and
a favorite letter (character). Help Rich out and write this function.
Your function should prompt the user for each value and the function
should produce the three values.
10. Show the output for this program fragment (make sure to indicate
space characters):
int x = -5;
float y = 3.14159;
char z = 'X';
printf("We the %c People \nin Order to %-5d form a more",z,x);
printf("perfect\n\n%7.3f %1.4fuNiOn",y,y);
printf("%c",'A');
printf("%3c establish justice, \n%06d insure domestic %.2f",'B',5,3.119);
printf("Tranquility!\n");
11. Given the following declarations
int I;
float R;
char C1, C2;
Assume that the user types the characters below to the keyboard (where
spaces are shown as underscore '_' characters) for EACH of the scanf
commands below:
- 4 2 . 0 _ _ 1 3 _ O _ X
Show the contents of the variables assuming the user types the above line
for each scanf:
scanf(" %f %d %c %c",&R,&I,&C1,&C2); I:___ R:____ C1:___ C2:___
scanf("%f %c%d%c",&R,&C1,&I,&C2); I:___ R:____ C1:___ C2:___
scanf("%c %d %f %c",&C2,&I,&R,&C1); I:___ R:____ C1:___ C2:___
12. Also, you may want to see if you can produce the right output
for the program at this link .