NEWS
COURSE INFO
TUTORS & LAB HOURS
GRADING & HOMEWORK
FAQs
|
CSE 5a: Practice Final
- This is closed book examination
- There are 8 questions.
- The maximum is 30 points.
- Please present your ID to your TA before you turn in this exam.
-
~~~~~Begin Practice Final~~~~~
1.
Write a program that reads in a 5 digit number from user
input, have the program count the number of times each
even number occurs, and print out (in tabular form) the
even digit and it's number of occurences.
For example, the output may be:
Input a number: 11285
0 occurs 0 times
2 occurs 1 times
4 occurs 0 times
6 occurs 0 times
8 occurs 1 times
2.
The function fun below is fun!
int fun(int z)
{
int x=4;
while (z == 0)
return (z ? -5: x++);
if(z == 0)
return --z;
if(z > 0)
if(z == 5)
return 1;
else return 0;
return -1;
}
Rewrite fun using good formatting style so that the
function is easy to read and understand. Feel free
to add braces where necessary or for clarity
(be careful with them though).
What does fun(z) return for:
z=0:
z=-1:
z=5:
z=2:
3.
Suppose you want to figure out your grade for the class.
Assume 8 homework assigments work 5 points each, a midterm
worth 30 points and a final worth 30 points. Scores
should be read in via user input. Use an array to
store the scores. Then write a function to compute the
total score and print out a letter grade according to
the breakdown below:
90%-100% A
80%-89% B
70%-79% C
60%-69% D
< 60% F
*(this is not the real class grade breakdown).
4.
Assume you are an inventory manager for a TV/VCR retail chain.
Write a program using structures to tabulate the data of 30
products. Store information such as the brand name, price,
quantity in stock, and model numbers for each product.
Write a function to print out the cheapest product.
5.
What is(are) the errors in the following program?
void addone(float f)
{
f = f+1;
return;
}
void main(void)
{
int x=-5, y=10;
while (x != 0)
{
addone(x);
printf("%d",x);
}
return 0;
}
Hint: This program is supposed to take x and print out
its value until it equals zero. The addone function
is supposed to add one to x.
6.
Write a program to read in a string and determine
whether or not it is a palindrome. You can use the
strlen(string) function in string.h. A palindrome is a
string that reads the same forward or backward (i.e. abba
or aba).
7.
What are the values of a and b printed out by
the program below?
int a=0;
void uhoh(int *b)
{
int z;
for(z=0; z < 4; z++)
{
*b=*b + z;
a *= *b;
}
}
void main(void)
{
int b=1, *z;
z=&b;
uhoh(z);
printf("%d %d", a, b);
}
8.
Write a program to calculate the factorial (product
of all integers up to that number) of a digit entered
by the user.
(i.e. if the user enters 5, the program should
calculate 1*2*3*4*5=120)
Comments? eMail Webmaster
|
|