Contact Us
Order Here
Get Help
More
English
Español
Português
Français
Deutsch
Italiano
Русский
close
Contact Us
Order Here
Get Help
Starting from:
$9.99
$3.99
Buy now
Quiz Solution
Question 1
1. Based on the program below, which implementation of the 'square' function is most appropriate?
int main ()
{
int a = 0;
int b = 0;
int c_squared = 0;
printf ("Enter a: ");
scanf ("%d", &a);
printf ("Enter b: ");
scanf ("%d", &b);
c_squared = square(a) + square(b);
return 0;
}
int square (int x)
{
return x^2;
}
int square (int x)
{
return pow(x,2)+pow(x,2);
}
int square (int x)
{
return x*x;
}
int square (int x)
{
return x*x + x*x;
}
10 points
Question 2
1. Why do functions differ from symbolic constants?
Symbolic constants can substitute for multiple values while functions return a single value
Functions can return multiple values while symbolic constants represent a single value
Functions are executed during program run-time, while symbolic constants are substituted before compilation
Symbolic constants are executed during program run-time, while functions are substituted before compilation
10 points
Question 3
1. Why is it important to seed the random number generator?
To ensure that each set of random numbers are indeed random
To ensure that all sets of random numbers are identical
To ensure that sets of random numbers originate from the same function
To ensure that each random number is between a given range
10 points (Extra Credit)
Question 4
1. What is the value 33 called in the code below?
int main ()
{
...
print_int (33);
}
Symbol
Parameter
Argument
Symbolic constant
10 points
Question 5
1. Why is the use of functions important?
Its the primary tool programmers have for limiting syntax errors in terms of functional programming
Its the primary tool programmers have for encapsulating logical expressions
Its the primary tool programmers have for controlling code execution to improve efficiency and limit latency.
It is the primary tool programmers have for controlling code complexity by dividing programs into small components.
10 points
Question 6
1. What is the purpose of this statement:
srand( time(NULL) )
Set the random number generator to start the null value
Set the random number generator to start at the current time value
Seed the random number generator with null
Seed the random number generator with current time
10 points (Extra Credit)
Question 7
1. What is wrong with the program below?
int square (int x)
{
return x*x;
}
int main ()
{
int num;
printf ("Enter number to be squared: ");
scanf ("%d", & num);
printf ("The square of %d is %dn", num, square());
return 0;
}
The parameter is incorrect for the 'square' function.
There is no argument for the funtion call
The 'square' function can not be called directly inside a 'printf' function call.
The 'square' function return the 'pow' function.
10 points
Question 8
1. What are n1 and n2 called in the code below?
double average (double n1, double n2 )
{
return (n1 + n2) / 2.0;
}
Parameters
Arguments
Symbols
Symbolic constants
10 points
Question 9
1. What is a library?
A collection of programs
A collection of algorithms
A collection of functions
A collection of files
5 points
Question 10
1. What is wrong with this function?
void DoStuff (int x, int y)
{
...
return pow(x,y) + x*x;
}
The return statement mixes arithmetic operations and functions
The function is void
Proper precedenece was not followed
The function has more than one parameter
10 points
Question 11
1. Which line contains the function prototype?
1. int square (int x);
2. int main ()
{
int value = 0;
int value_squared = 0;
printf ("Enter value to be squared: ");
scanf ("%d", &value);
3. value_squared = square(value);
printf ("The square of %d is %dn", value, value_squared);
return 0;
}
4. int square (int x)
{
return x*x;
}
2
3
1
4
10 points
Question 12
1. What is the expected output of the code snippet?
void print_int (int y)
{
x = 20;
printf ("%d", y);
}
int main ()
{
...
x = 33;
y = 15;
print_int (x);
}
Nothing
33
20
15
10 points
Question 13
1. Where can function protypes be defined?
Before the function definition, but after the main function
Anywhere before the function definition in the same file as the main function only
Anywhere before the function definition, even in other files
Only at the beginning of the program in which the main function is defined
$9.99
Starting from:
$3.99
Buy now
1 file (22.0KB)
More products
$6.00 OFF
ASSIGNMENT # 4 Packages, Triggers, and Collections Solution
$35
$29
Buy now
$6.00 OFF
ASSIGNMENT # 3 Database Interactions
$35
$29
Buy now
$6.00 OFF
DATABASE PROGRAMMING ASSIGNMENT # 2 SOLUTION
$35
$29
Buy now