A variable declared before and outside all function

  

1. Question : (TCO 4) A variable declared before and outside all function blocks
is visible only in main.
is visible to all functions.
is visible to all functions except main.
is not visible to any functions.
2. Question : (TCO 4) What is the value of i after the following code fragment executes?
int i = 2;
int k = 5 ;
i *= k + 1;
7
11
12
14
3. Question : (TCO 4) How many times will variable i be printed to the screen?
for (i = 1 ; i <= 20 ; i = i + 2);
{
cout << “ “ << i ;
}
10
20
1
0
4. Question : (TCO 4) Which looping statement is best if the number of iterations is known?
If/Else
For
While
Do/While
5. Question : (TCO 4) C++ selection statements include
for, while, do-while.
cout and cin.
if, if-else, if-else if, switch.
#include and using namespace std;.
6. Question : (TCO 4) If firstName and lastName are string object variables, which statement can be used to combine (append or concatenate) the two into a single string variable?
fullName = firstName + lastName;
fullName = firstName, lastName;
fullName = firstName & lastName;
fullName = firstName && lastName;
7. Question : (TCO 4) Which type of error does the following code fragment cause?
int main (void)
{
int MAX;
cout << “Enter array size: “ <> MAX;
int foo [MAX];
for (int i = 0; i <= MAX; i++)
{
foo = i * 2;
}
Compiler: Array size must be known at compile time.
Compiler: Variable MAX cannot be all uppercase.
Compiler: Array subscript out of bounds.
Run-time: User cannot enter a value for MAX.
8. Question : (TCO 4) The code below computes the length of a C-style string. What should the value of FLAG be?
char name[20]= “Lancilot”;
int length=0;
while(name[length] != FLAG)
{
length = length+1;
}
cout << length << endl;
‘’
20
NULL
0
9. Question : (TCO 4) Which type of error does the following code fragment cause?
const int MAX = 500;
int main (void)
{
int foo [MAX];
for (int i = 0; i <= MAX; i++)
{
foo = i * 2;
}
Compiler, because of out-of-bounds array subscript
Run-time, because of out-of-bounds array subscript
Compiler, because of invalid array initialization
None of the above. It does not create any type of error.
10. Question : (TCO 4) What is the declaration for a C-style string that can hold a name with up to 3 printable characters (for example, “Ron”)?
int name [3];
char name [3]
int name [4];
char name [4];
11. Question : (TCO 4) What is the output of the following code?
void func(int x)
{
x = x * 2;
}
int main( )
{
int x = 10;
func(x);
cout << x << endl;
}
20
30
10
5
12. Question : (TCO 4) Which of the following function definitions uses pass-by-values?
int myFunc( int * x, int * y );
int myFunc( int x, int y ) ;
int myFunc( int & x, int & y ) ;
int myFunc( int @ value1, int @ value2 ) ;
13. Question : (TCO 4) Which of the following statements call the following function correctly?
int MultiplyValues (int, int);
int a = MultiplyValues (int x, int y);
int a = MultiplyValues (10, 20);
double d = MultiplyValues (int 10, int 20);
All of the above
14. Question : (TCO 4) What is the output of the following code?
void func(int *x)
{
*x = *x * 3;
};
int main()
{
int x = 10;
func (&x) ;
cout << x << endl ;
}
20
30
10
5
15. Question : (TCO 4) A Distance class has two private members, ‘feet’, of type int, and ‘inches’, of type double. Which prototype correctly declares the copy constructor for such class?
Distance Distance(const Distance &);
Distance(const Distance &);
int Distance(int, double);
Distance(feet, inches);
16. Question : (TCO 4) The word const inside the parentheses of the following declaration of isEqual
bool isEqual (const Distance & rightSideObject) const;
ensures the member variables of the called objects are protected (cannot be changed).
ensures the argument passed in to the function is protected (cannot be changed).
ensures the return value of the function is protected (cannot be changed).
ensures the return value is routed to the proper variable.
17. Question : (TCO 4) Given the following class definition and lines of code, Line 1 in main is a call to what?
class Distance
{
private:
int feet;
double inches;
public:
Distance( );
Distance(int initFt, double initIn);
void setFeet(int feetIn);
void setInches(double inchesIn);
int getFeet() const;
double getInches( ) const;
};
int main( )
{
Distance d1; //Line 1
const int MAX = 100; //Line 2
Distance list[MAX]; //Line 3
Distance d2(1, 2.3); //Line 4
Distance * pDist; //Line 5
d1.feet = 5; //Line 6
// etc. – assume the remaining code is correct
}
The 0-argument Distance constructor
The 2-argument, int, double, Distance constructor
The 2-argument, double, int, Distance constructor
The 1-argument, int, Distance constructor
18. Question : (TCO 4) Creating one class from another in a parent/child hierarchy is an example of
encapsulation.
polymorphism.
inheritance.
abstraction.
19. Question : (TCO 4) Which of the following is a valid declaration to overload the following function?
int whatever (double x);
double whatever (double x);
int whatever (int x);
int whatever2 (double x);
int overload (double x);
20. Question : (TCO 4) How many parameters are required to overload the pre-increment operator for a class as a member function?
None
1
2
No limit
21. Question : (TCO 4) Given the following definitions and statements,
void myFunction (double * dptr);;
double data [10];
which of the following statements correctly calls the function passing in the address of the data array?
myFunction(data);
myFunction(&data);
myFunction(*data);
myFunction(data[0]);
22. Question : (TCO 4) Assume you have to write a class that makes use of dynamic memory allocation (the class needs to allocate and de-allocate memory). According to best practices, where would the keyword ‘delete’ be placed?
Classes are smart data types. The compiler takes care of calling new/delete
It is in the constructor.
It is in the destructor.
It is in a separate, dedicated function.
23. Question : (TCO 4) When writing a class, the compiler automatically creates some support functions for the class. What are some of these functions?
Assignment operator function
Copy constructor
Assignment operator and copy constructor
None of the above
24. Question : (TCO 4) Assume you have to write a class that makes use of dynamic memory allocation (the class needs to allocate and de-allocate memory). According to best practices, where would the keyword ‘new’ be placed?
Classes are smart data types. The compiler takes care of calling new/delete.
In the constructor
In the destructor
In a separate, dedicated function
25. Question : (TCO 4) What is wrong with the following C++ statements?
int * iptr;
double d = 123.321;
iptr = &d;
cout << *iptr;
The cout statement does not contain an endl.
The space following the ampersand should not be there.
The iptr variable cannot be given an address of a double.
All of the above

 

Calculate Your Essay Price
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more