Exam 4: Parameters and Overloading
Exam 1: C++ Basics37 Questions
Exam 2: Flow of Control33 Questions
Exam 3: Function Basics30 Questions
Exam 4: Parameters and Overloading31 Questions
Exam 5: Arrays32 Questions
Exam 6: Structures and Classes37 Questions
Exam 7: Constructors and Other Tools32 Questions
Exam 8: Operator Overloading,friends,and References31 Questions
Exam 9: Strings37 Questions
Exam 10: Pointers and Dynamic Arrays29 Questions
Exam 11: Separate Compilation and Namespaces35 Questions
Exam 12: Streams and File IO43 Questions
Exam 13: Recursion40 Questions
Exam 14: Inheritance30 Questions
Exam 15: Polymorphism and Virtual Functions34 Questions
Exam 16: Templates27 Questions
Exam 17: Linked Data Structures30 Questions
Exam 18: Exception Handling29 Questions
Exam 19: Standard Template Library46 Questions
Exam 20: Patterns and Uml22 Questions
Select questions type
Write a stub for the following function prototype:
double root( double a,double b,double c,int i);
// Precondition: a != 0 and a,b,c are coefficients of
// a quadratic equation a*x*x + b*x + c = 0 The value
// of i is either +1 or -1 to choose which root.
// Postcondition: return value,x,satisfies the
// equation a*x*x + b*x + c = 0
Free
(Essay)
4.8/5
(39)
Correct Answer:
#include <iostream>
// stub functions example
double root(double a,double b,double c,int i)
{
using namespace std;
cout << "executing function\n"
<< "double root(double,double,double)"
<< endl;
return 2.0;
}
There is only one kind of parameter passing in C++,namely call-by-value.
Explain.
Free
(True/False)
4.8/5
(35)
Correct Answer:
False
A call-by-reference parameter may pass data only out of a function.
Free
(True/False)
4.8/5
(31)
Correct Answer:
False
What does the function given here do when called if both the ampersands (&)are removed? Why?
void func(int& x,int& y)
{
int t = x;
x = y;
y = t;
}
(Essay)
4.9/5
(31)
Write a stub for the function whose declaration is given below.Do not write a program that calls this,just write the stub.
Hint: This is very short.
double yield (double pressure,
double density,double temp);
// Precondition: pressure is newtons per square meter
// density is in kilograms per cubic meter
// temp is in degrees Celcius
// Postcondition: Return value is the relative yield of
// a chemical process.It is a number between 0 and 1.
// 0 means no output and 1 means ideal yield.
(Essay)
4.8/5
(28)
The compiler ha no problem distinguishing these two function definitions:
void func(double &x){/*…*/}
void func(double x){/*…*/}
(True/False)
4.7/5
(40)
There is no problem with these two function definitions:
void func(int x){/*…*/}
int func(double x){/*…*/ return something_double;}
(True/False)
4.8/5
(39)
Which of the following overloadings will be invoked by this call? g(1.0,2.0);
(Multiple Choice)
4.9/5
(47)
Given the function,and the main function calling it: What is the output of the following code if you omit the ampersand (&)from the first parameter,but not from the second parameter? (You are to assume this code is embedded in a correct function that calls it. ): #include <iostream>
Using namespace std;
Void func(int & x,int & y)
{
Int t = x;
X = y;
Y = t;
}
Int main()
{
Int u = 3;v = 4;
// )..
Cout << u << " " << v << endl;
Func ( u,v )
Cout << u << " " << v << endl;
// )..
}
(Multiple Choice)
4.8/5
(42)
The position of the ampersand in the function header is of no importance to the proper compiling and execution of code that uses call-by-reference parameters.
(True/False)
4.8/5
(33)
Suppose a programmer supplies the ampersand for call-by-reference in a prototype,but forgets to put the ampersand in the definition.The compiler will nevertheless correctly interpret the programmer's intent and compile the function.
(True/False)
4.8/5
(42)
Write a void function definition for a function called zeroBoth that has two call-by-reference parameters,both of which are variables of type int,and that sets the values of both variables to 0.
(Essay)
4.8/5
(37)
The call-by-reference mechanism is specified in the function declaration and definition,using a $ between the type and the parameter.
(True/False)
4.8/5
(42)
Functions that call other functions can be tested independently of the called functions.
(Essay)
4.9/5
(33)
Which of the following function declarations with default arguments are correct?
(Multiple Choice)
4.7/5
(36)
Consider the revised pizza buying program of Display 4.7.This program provides the following overloading for unitPrice functions for round and rectangular pizza:
double unitPrice(int diameter,double price);
double unitPrice(int length,int width,double price);
Suppose we are faced with the need for the unit price on a square pizza.The problem here is to devise in a 'natural' way to overload unitPrice to compute the price per square inch of a square as well as a round pizza?
(Essay)
4.7/5
(39)
Showing 1 - 20 of 31
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)