81. The following function call doesn’t agree with its prototype:
cout << BoxVolume( 10, 5 );
int BoxVolume(int length = {1}, int width = {1}, int height = {1});
T__ F__
82. The following function is implemented to swap in memory the
argument-values passed to it:
void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
T__ F__
83. A function such as the following is written to get user input.
The parameter values are restored in the variables that are passed as
arguments.
void getValues(int &x, int &y)
{
cout << "Enter a number: ";
cin >> x;
cout << "Enter another number: ";
cin >> y;
}
T__ F__
84. You can’t use keyword ‘const’ when you declare reference parameters, like
void CalculateSquare(const int& n, int& result)
T__ F__
85. What value does this program display?
void inc( int x );
int main()
{
int x{1};
inc( x );
cout << x;
}
void inc( int x )
{
x++;
}
A. -1 B. 0 C. 1 D. 2
86. Compiler complains because the following function uses an uninitialized
variable s:
void Fun1(int x, char c)
{
static int s;
cout << "s = " << s << endl;
s++;
cout << "x = " << x << " c = " << c << endl;
}
T__ F__
87. The following program is syntactically incorrect:
#include <iostream>
using namespace std;
void func1(double,int);
int main()
{
int x{};
double y{1.5};
cout << x << " " << y << endl;
func1(y,x);
cout << x << " " << y << endl;
return 0;
}
void func1(double a, int b)
{
cout << b << " " << a << endl;
a{};
b{10};
cout << b << " " << a << endl;
}
T__ F__
88. The following code is flagged with syntax-errors:
#include <iostream>
using namespace std;
int square( int x )
{
cout << "square of integer " << x << " is ";
return x * x;
}
double square( double y )
{
cout << "square of double " << y << " is ";
return y * y;
}
int main()
{
cout << square( 7 ) // calls int version
<< endl;
cout << square( 7.5 ) // calls double version
<< endl;
}
T__ F__
89. The following template definition is syntactically correct:
template <class T>
T Square(T number)
{
return number * number;
}
T__ F__
90. How many asterisks are output by the following segment ?
size_t i, j;
for (i=0; i < 3; i++)
for (j=0; j < 2; j++)
cout << '*';
cout<< endl;
A. 2 B. 6 C. 10 D. None
81. False.
Expalnation: int BoxVolume(int length = {1}, int width = {1}, int height = {1}) prototype declares that all params have default value, so if you won't pass any of these params, it will automatically pick 1 as a default value for it. So the mentioned function call is correct.
82. False.
Explanation: The function is a call by value and not call by reference. So it will swap the numbers unless we pass the pointer of the parameters address. You have to change the function params to void swap(int &a, int &b) for swapping values.
83. True. Yes as there is address pointer is passed as explained above, it will restore the new values.
84. False. You can use const and it will not give any compile error but you will not be able to change the value of const variable even if its address pointer is passed.
85. c.) 1
Explanation: Same as 82, address pointer is not passes so its a call by value and new value will not affect the passed aparameter.
81. The following function call doesn’t agree with its prototype: cout << BoxVolume( 10, 5...
61. The following program is accepted by the compiler: int sum( int x, int y ) { int result; result = x + y; } T__ F__ 62. The following implementation is accepted by the compiler: void product() { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; ...
31. The following code segment is syntactically correct: int number{20}; cout << number << setbase(16) << " " << number << setbase(10) << " " << number << showpos << " " << number << endl; T__ F__ 32. The following statement wants to determine if ‘count’ is outside the range of 0 through 100: if (count < 0 && count > 100) T__ F__ 33. There is...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
41. Executing the "continue" statement from within a loop causes control to go A. to the next line of code B. out of the loop C. to the beginning of the loop D. to check the loop condition for repeating the loop E. none of the above 42. The 'default' statement inside a 'switch()' is optional. T__ F__ 43. The following 'switch' implementation is legal: int i = 2; ...
Three of these function overloads are considered identical by the compiler and would conflict with each other. The other would be considered different- choose the one that is considered different from others. Int foo ( int x, double y ) ; Int foo ( double x, int y ) ; Void foo ( int x, double y ) ; Int foo ( int day, double temp ) ; Consider the following incomplete code: Int f ( int number ) }...
Design a swap function with the following interface: void swap( int *x, int *y) { } In your main( ), you perform the following test: int main( ) { int a = 10, b = 20; cout << “a = “ << a << “ b= “ << b << endl; swap( a, b); cout << “a = “ << a << “ b= “ << b << endl; return 0; … }
When running the program at the destructor an exception is being thrown. Can someone help me out? vararray.h: #ifndef VARARRAY_H_ #define VARARRAY_H_ class varArray { public: varArray(); // void constructor int arraySize() const { return size; } // returns the size of the array int check(double number); // returns index of element containg "number" or -1 if none void addNumber(double); // adds number to the array void removeNumber(double); // deletes the number from the array ...
USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...
How to turn this file into a main.cpp, a header which contains the function declaration, and a implementation fiel containing the function definition ? #include<iostream> #include<string> #include<iomanip> using namespace std; #define NUM 1 #define MULT 4 void getPi(int iter); int main() { int it; cout << "Enter the number of iterations needed to find PI: "; cin >> it; while (it < 1) { cout << "Error!!! Iteration input should be positive." << endl;...
Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...