Please check and correct my Answers Problem #1: [] -----------------------------
ID: 3552704 • Letter: P
Question
Please check and correct my Answers
Problem #1: []
-------------------------------
[Points = 4]
Consider the code below. Supply the MISSING statement.
// Function to display the values in array, first to last.
void Display(int X[], int numValues)
{
int k; // for-loop variable.
_____________________________ // MISSING for
{
cout << X[k];
}//for loop
}//Display
int main()
{
int Score[24]; // Test scores for students in programming course.
//-| Call Display to display the values in array Score.
} //main
NOTE: (1) Use strict inequality (e.g., < or >, not >= or <=)
(2) Use increment (++) or decrement (--) to update loop variable.
-------------------------------
Answer: FOR (K=0; K<NUMVALUES;K++)
----------------
Problem #2: []
-------------------------------
[Points = 4]
Write a statement to declare a 2-dimensional int array named Avg with
4 rows and 2 columns, and initialized to
4 3
1 2
3 5
8 4
-------------------------------
Answer: INT AVG[4][2]={{4,3},{1,2},{3,5},{8,4}};
----------------
Problem #3: []
-------------------------------
[Points = 5]
Consider the declarations:
string Class[18]; // Array of 18 student names.
int k; // for-loop control variable.
ON ONE LINE, write the loop to print out the values in the Class
array in reverse order.
NOTE: (1) Use inclusive inequality (e.g., <= or >=)
(2) DO NOT enclose the loop body in braces
(3) Use increment (++) or decrement (--) to update loop variable.
(4) DO NOT output spaces or new lines (endl or
).
-------------------------------
Answer: FOR (K=17; K>=0; K--) COUT<<CLASS[K];
----------------
Problem #4: []
-------------------------------
[Points = 3]
Consider this problem: The teacher wants to print out the scores on
a test in descending (highest to lowest score) order. There are 37
students in the class.
DIRECTIONS: Write the statement to print out the MEDIAN score, i.e.,
the middle score.
NOTE: Do not insert a new line.
int Score[37];
//-| Read in 37 scores.
...
//-| Sort Score into descending order.
//-| Print the median score.
Answer: cout<<"Median Score: "<<Score[19];
Problem #9: []
-------------------------------
[Points = 2]
When three different objects of a particular class are created, each is
said to be separate ________ of the class.
A) members
B) ADTs
C) instances
D) children
E) None of the above
-------------------------------
Previous Answer: C
Problem #10: []
-------------------------------
[Points = 5]
Consider the class diagram below.
+------------------------------+
| class STUFF |
| |
| +---------------------+ |
| | int x; | |
| +---------------------+ |
| +---------------------+ |
| | set_P(int val); | |
| +---------------------+ |
| |
|----------+ +----------------|
| STUFF(); | | int p; |
|----------+ +----------------|
| |
+------------------------------+
STUFF Q;
Write the body of the default constructor, which initializes
member variable p to 75, and member variable x to 0.
NOTE: Write the body ON ONE LINE, enclosed in { }.
-------------------------------
Answer: {X=0;P=75;}
Problem #11: []
-------------------------------
[Points = 2]
Access to a private data member of a class object can only be done through
a public ________ _________ of the class.
-------------------------------
Answer: METHOD FUNCTION
----------------
Problem #12: []
-------------------------------
[Points = 2]
In OOP terminology, an object's member function is are often called by this
name ___________ .
-------------------------------
Answer: METHODS
----------------
Explanation / Answer
promblem 1
for(k=0;k<numValues;k++)
promblem 2
int Avg[4][2]={{4,3},{1,2},{3,5},{8,4}};
problem 3
FOR (k=17; k>=0; k--) cout<<Class[K];
problem 4
cout<<"Median Score: "<<Score[19]; //(depend on the score all element should be different)
Problem #9:
instances
Problem #10:
{ X=0 , P=75 ;}
problem #11
METHOD FUNCTION
problem #12
Methods