Week 12 : C++/Java/OOP - Attempt #2 Time Remaining: page 1 1. (TCO 4) What outpu
ID: 3648241 • Letter: W
Question
Week 12 : C++/Java/OOP - Attempt #2Time Remaining:
page 1
1. (TCO 4) What output does the following code produce?
cout << fixed << setprecision(3);
double pi = 3.14159;
cout << pi << endl;
(Points : 7)
3.14159
3.142
3.14
None of the above
2. (TCO 4) What is the data type of the number 5.0 in int y = 5.0 + 2? (Points : 7)
char
int
double
float
3. (TCO 4) What is the result of 56 % 5? (Points : 7)
1
11
11.2
12
4. (TCO 4) How many times does the following loop body execute?
for(int i = 0; i < 10; i++)
{
cout << i << endl;
}
(Points : 7)
0
1
9
10
5. (TCO 4) What is the output from the following C++ code?
for (i = 1; i > 0; i--)
{
cout << "*";
}
cout << endl;
(Points : 7)
*
**
no output
infinite loop
6. (TCO 4) Which of the following statements is true? (Points : 7)
C++ supports declaring arrays of any dimension.
C++ only supports one and two dimensional arrays.
C++ allows declaring arrays up to 10 dimensions.
None of the above
7. (TCO 4) The following code fragment
double data[50][100];
for(int i = 0; i < 50; ++i)
{
for(int j = 0; j < 100; ++j)
{
cout << data[i][j] << endl;
}
}
(Points : 7)
outputs all values of the data array, one per line.
causes a compiler error due to out of bounds array subscripts.
causes a run-time error due to out of bounds array subscripts.
outputs all values of the data array, 50 per line.
8. (TCO 4) Assign the value 987.6 to the element in the 10th row and 6th column of data.
double data[100][500]; (Points : 7)
data[6][10] = 987.6;
data[10][6] = 987.6;
data[5][9] = 987.6;
data[9][5] = 987.6;
9. (TCO 4) Which of the following function definitions is passing pointers? (Points : 7)
int myFunc( int * x, int * y );
int myFunc( int x, int y )
int myFunc( int & x, int & y )
int myFunc( int @value1, int @value2 )
10. (TCO 4) Which of the following is not part of a function's signature? (Points : 7)
Function name
Function parameters
Return data type
None
11. (TCO 4) If a function has a type double parameter that it needs to read but not write to, pass it by _____. (Points : 7)
value
reference
pointer
address
12. (TCO 4) An overloaded function or operator is an example of _____. (Points : 7)
encapsulation
polymorphism
inheritance
abstraction
13. (TCO 4) Organizing programs into three files (main, class implementation, and class header) supports which important Object-Oriented principle? (Points : 7)
Inheritance
Information hiding
Overload
Polymorphism
14. (TCO 4) Given the following method definition for some class in C++,
int getFeet() const;
this method is declared const so:
(Points : 7)
The method cannot write to passed parameters.
The method cannot write to the data members of the class to which it belongs.
The method cannot read the data members of the class to which it belongs.
All of the above
15. (TCO 4) What is the name of a member function of a class that is responsible for initialization of the member variable(s)? (Points : 7)
Accessor
Constructor
Destructor
Mutator
16. (TCO 4) When organizing a program into three files (main, class implementation, and class header), where are the functions for the user-defined data types implemented? (Points : 7)
main.cpp
class.cpp
class.h
main.h
17. (TCO 4) Given the definition of some class called Employee, and given an Employee pointer variable called myData which is pointing to an array of 20 Employee objects, which of the following statements correctly accesses the getSalary method of the last employee which takes no parameters and returns a double value. (Points : 7)
cout << *(myData + 20).getSalary( );
cout << myData[20].getSalary( );
cout << myData->getSalary[19];
cout << myData[19].getSalary( );
18. (TCO 4) If the following program compiles, what is the data type of foo2?
#include
using namespace std;
int main ()
{
int foo;
int *foo2;
foo2 = &foo;
foo = 1234;
cout << *foo2 << end1;
return 0;
}
(Points : 7)
int
pointer to int
object
address
19. (TCO 4) Assume that Distance is a class. Which is a valid statement to assign a new value to pDist?
Distance * pDist;
Distance d2(1, 2.3);
(Points : 7)
pDist = d2;
pDist = *d2;
pDist = &d2;
pDist = #d2;
20. (TCO 4) What can you say about the following Java class?
public class MyApp extends JFrame, JPanel { & }
(Points : 7)
MyApp will contain methods from both the JFrame and JPanel classes.
MyApp will not compile because multiple inheritance is illegal in Java.
MyApp inherits from JFrame and implements the JPanel interface.
MyApp is allowed to implement both the JFrame and JPanel interface.
21. (TCO 4) Given a JTextArea object called output, how would you add the string "More data" to the existing contents of the output object? (Points : 7)
output.addText("More data");
output.setText("More data");
output += "More data";
output.append("More data");
22. (TCO 4) Which of the following creates an object with a fixed display size of 20 lines which has scrolling capability? (Points : 7)
JTextField display = new JTextField(20, 20);
JTextArea display = new JTextArea(20, 20);
JScrollPane scroller = new JScrollPane(new JTextArea(20,20));
All of the above
23. (TCO 4) Which of the following is not true for a JTextField? (Points : 7)
Can be used to display uneditable text
Can be used to display editable text
Enables users to enter data from the keyboard
Displays a list of fields
24. (TCO 4) What does the following Java code do?
JPanel pane = new JPanel( );
pane.setLayout( new gridLayout(2, 3) );
(Points : 7)
Creates a panel which will organize its components into five distinct cells
Creates a panel which displays a grid containing the numbers 2 and 3
Creates a panel which will organize its components into two rows of three columns
None of the above
25. (TCO 4) In order to handle an event from a JButton object button1, what does a programmer need to do? (Points : 7)
Create a nested inner class that implements the ActionListener interface.
Create an object of the nested inner class as the event handler object.
Invoke the addActionListener method on button1 to register the event handler object with the event source.
All of the above
Time Remaining:
Explanation / Answer
1.
Consider the Code segment:
cout << fixed << setprecision(3);
double pi = 3.14159;
cout << pi << endl;
Output for the above code is: 3.142
2.
The data type of the number 5.0 in the statement int y = 5.0 + 2; is int.
3.
The result of the expression 56%5 is 1.
4.
For-loop is executed 10 times.
5.
Consider the Code segment:
for (int i = 1; i > 0; i--)
{
cout << "*";
}
cout << endl;
Output for the above code is: *
Because i iterate once and exit from the loop
6.
C++ supports declaring arrays of any dimensions
7.
Outputs all values of the data array, one per line.
8.
Assign the value for the 10th row and 6th column is data[9][5]=987.6, because index variables always starts with 0.
9.
The function which passes pointers is int myFunc(int * x, int * y);
10.
In function signatures return datatype is not a part.
11.
If a function has a type double parameter that it needs to read but not write to, pass it by value.
12.
An overloaded function or operator is an example of polymorphism.
13.
In information hiding, programs are organized into three files (main, class implementation, and class header).
14.
int getFeet() const;
this method is declared const so, the method cannot write to the data members of the class to which it belongs.
15.
Constructor is the name of a member function of a class that is responsible for initialization of the member variable(s).
16.
When organizing a program into three files (main, class implementation, and class header), the functions for the user-defined data types implemented are implemented in class.cpp.
17.
cout << myData[19].getSalary( );
This statement accesses the getSalary method for the last employee. Because, the index of the array getSalary starts at zero.
18.
#include
using namespace std;
int main ()
{
int foo;
int *foo2;
foo2 = &foo;
foo = 1234;
cout << *foo2 << end1;
return 0;
}
In the above code segment, the data type of foo2 is int.
19.
Distance * pDist;
Distance d2(1, 2.3);
For the above code segment, pDist = &d2 is a valid statement to assign a new value to pDist.
20.
My App is allowed to implement both JFrame and Jpanel interface.
21.
output += "More data";
22.
JScrollPane scroller = new JScrollPane(new JTextArea(20,20));
23.
Displays a list of fields
24.
Creates a panel which will organize its components into two rows of three columns
25.
Invoke the addActionListener method on button1 to register the event handler object with the event source.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.