Vous êtes sur la page 1sur 3

CSC201 Fundamentals of Programming II Faculty of Computer Science and Information Technology

Sheet 2 7-10-2017

Question one:
1. A class has four exams in one term. A student needs an average score of 60 or more in order to pass. Write a
program that will read in a student four exam scores and will output the students average for the exams as
well as tell whether or not the student has passed the course. Define a function to compute the average.
2. The formula to convert temperature from Celsius to Fahrenheit is F=C*1.8 + 32.Use it to write a
program that prints charts showing the Fahrenheit equivalents of all Celsius temperatures from 0 to
10 degrees.
3. Write a Function that calculates the cost. Customer can enter number of items and price of the items
then program should add items' prices then subtracts Tax from final cost. Tax = 0.05 of the cost
Function takes number of items and price then calculate Total Cost
Function takes Total Cost then subtracts Tax
Question two: Choose the correct answer
1. If you need to write a function that will compute the cost of some candy, where each piece costs 25
cents, which would be an appropriate function declaration?
a. int calculateCost(char name);
b. char calculateCost(int count);
c. int calculateCost int count;
d. int calculateCost(int count);
2. What is the value returned by the following function?
int function()

int value = 35;

return value + 5;

value += 10;

a. 35
b. 40
c. 50
d. 10
3. If you have the two functions as shown,
int someFunction(int value);

float someFunction(float value);

and a variable x, which is a double, which function is called by the following statement?
cout << someFunction(x);

a. void someFunction(int value);


b. void someFunction(float value);
c. Nothing, it is a syntax error
d. both functions are called
4. Multiple arguments to a function are separated by
CSC201 Fundamentals of Programming II Faculty of Computer Science and Information Technology
Sheet 2 7-10-2017

a. comments
b. semicolons
c. colons
d. commas
e. periods
5. What is the value of i after the following function call?
//function definition

int doSomething(int value)

value = 35;

return value;

value = 13

//fragment of main program

int i=0;

cout << doSomething(i);

a. 13
b. 35
c. 48
d. 0
6. Which of the following are not legal function declarations?
a. int ave3(int a, int b, int c);
b. int 3ave(int a, int b, intc);
c. int ave3(int, int, int);
d. int ave_3(int a1, int a2, int a3);
7. What is the output of the following function call?
//function body

int factorial(int n)

int product=0;

while(n > 0)

product = product * n;

n--;
CSC201 Fundamentals of Programming II Faculty of Computer Science and Information Technology
Sheet 2 7-10-2017

return product;

//function call

cout << factorial(4);

a. 4
b. 0
c. 24
d. 48

Question three:indicate whether the following statements are true or false:


1. A function may return more than one item
ANSWER: False

2. It is possible to have a function that has no parameters


ANSWER: TRUE

3. Functions may have multiple return statements.


ANSWER: TRUE

Vous aimerez peut-être aussi