Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a test that I previously failed. I get to retake the test but they wont

ID: 665739 • Letter: T

Question

This is a test that I previously failed. I get to retake the test but they wont tell me which questionss I got wrong or what material I need to study.

Question 1.1. (TCO 2) What is the value of data after the following code executes?
unsigned char data = 0xA5;
data = data & 0xF0; (Points : 6)

       0xA0
       0xF0
       0xF5
       0x5A

Question 2.2. (TCO 2) A variable declared before and outside all function blocks… (Points : 6)

       is visible only in main
       is visible to all functions
       is visible to all functions except main
       is not visible to any functions

Question 3.3. (TCO 2) C++ selection statements include:
(Points : 6)

       for, while, do-while
       cout and cin
       if, if-else, if-else if, switch
       #include and using namespace std;

Question 4.4. (TCO 2) Which of the following expressions is correct if you want to end a while-loop when the character variable keepgoing is anything other than character y in either upper or lower case? (Points : 6)

       while (keepgoing == "y" || keepgoing == "Y")
       while (keepgoing == 'y'  && keepgoing == 'Y')
       while (keepgoing == "y" | |  keepgoing == "Y")
       while (keepgoing == 'y' | |  keepgoing == 'Y')

Question 5.5. (TCO 2) What is wrong with the following switch statement?
switch(x)
{
case 0:
    cout << x;
case 2:
    cout << 2 / x;
    break;
default:
    cout << “error”;
    break;
} (Points : 6)

       The value of x could be something other than 1 or 2.
       There is no break statement for case 1.
       There is no semicolon after the closing bracket.
       All of the above.

Question 6.6. (TCO 2) The following code fragment:

struct student
{
            string name;
            double gpa;
};
student thisStudent;
cout << “Enter this student’s name: “ << flush;
cin >> thisStudent.name;
cout << “Enter this student’s GPA: “ << flush;
cin >> thisStudent.gpa;
student nextStudent = thisStudent; (Points : 6)

       copies both thisStudent’s name and GPA to nextStudent
       displays the name and GPA of thisStudent
       causes a compiler error
       causes a run-time error

Question 7.7. (TCO 2) 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] = i * 2;
            } (Points : 6)

       Compiler, due to out-of-bounds array subscript.
       Run-time, due to out-of-bounds array subscript.
       Compiler, due to invalid array initialization.
       None of the above. It does not create any type of error.

Question 8.8. (TCO 2) Given the following code fragment, what is the data type of thisStudent?

struct student
{
            string name;
            double gpa;
};
student thisStudent; (Points : 6)

       string
       const pointer to student
       student
       double

Question 9.9. (TCO 2) Which of the following functions is taking an array of MyStruct structures as a pass-by-value parameter? (Points : 6)

       void MyFunc( MyStruct data[ ] );
       void MyFunc( MyStruct &data[ ] );
       void MyFunc( MyStruct *data[ ] ) ;
       not allowed in C++

Question 10.10. (TCO 2) If the function square(x) returns the square of x, then x should be passed by: (Points : 6)

       value so it is protected (cannot be changed)
       reference so it is protected (cannot be changed)
       pointer so it is protected (cannot be changed)
       None of the above. x cannot be protected; square can change the value of x regardless of how it is passed

Question 11.11. (TCO 2) Which of the following is an invalid declaration to overload the following function?
double foo(int); (Points : 6)

       double foo(double);
       int foo(int);
       double foo(double *):
       double foo(int *);

1. (TCO 2) When organizing a program into three files (main, class implementation, and class header), which is not a .cpp file? (Points : 6)

       main
       none are .cpp
       class header
       class implementation

Question 2.2. (TCO 2) Creating classes with private data members is an example of: (Points : 6)

       encapsulation
       polymorphism
       inheritance
       abstraction

Question 3.3. (TCO 2) Which of the following is a valid declaration to overload the following function?
int whatever (double x); (Points : 6)

       double whatever (double x);
       int whatever (int x);
       int whatever2 (double x);
       int overload (double x);

Question 4.4. (TCO 2) Variables defined to be of a user-declared class are referred to as: (Points : 6)

       attributes
       member variables
       primitive variables
       objects

Question 5.5. (TCO 2) Given the following class definition and lines of code, what, if anything, is wrong with Line 6 in main?
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
} (Points : 6)

       It will not compile because feet is private and cannot be directly accessed.
       Distance d1; should be changed to int d1;
       ::d1.feet = 5; should be changed to d1(feet) = 5;
       It will compile, but causes a run-time error because d1.feet has not been declared.

Question 6.6. (TCO 2) 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? (Points : 6)

       myFunction(data);
       myFunction(&data);
       myFunction(*data);
       myFunction(data[0]);

Question 7.7. (TCO 2) Given the following definitions, select the statement which is illegal.
                  int * iptr;
                  double * dptr;
                  int j = 10;
                  double d = 10.0; (Points : 6)

       iptr = &j;
       dptr = &d;
       iptr = 0;
       dptr = &j;

Question 8.8. (TCO 2) What is wrong with the following C++ statements?
int * iptr;
double d = 123.321;
iptr = &d;
cout << *iptr; (Points : 6)

       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

Question 9.9. (TCO 2) The x, y drawing coordinate system used in Java graphics (Points : 6)

       uses character units.
       has the origin in the upper left corner of the display area.
       uses the x coordinate for the vertical axis.
       All of the above

Question 10.10. (TCO 2) What is the result of the following code?
     JFrame frame = new JFrame( );
            frame.add(new JButton(“One”), BorderLayout.NORTH);
            frame.add(new JButton(“Two”), BorderLayout.NORTH);
            frame.setVisible(true); (Points : 6)

       Two buttons are added side by side at the top of the display.
       Button One was added first, so it is the only button at the top of the display.
       Button Two was added last, so it is the only button at the top of the display.
       The Java compiler will not allow you to add two buttons to the same area.

Question 11.11. (TCO 2) In order to guarantee that only one JRadioButton is selected at any time: (Points : 6)

       add each JRadioButton object to a different panel
       create a ButtonGroup object and add the JRadioBttons to it
       have a JCheckBox object manage the three JRadioButtons
       This cannot be done in Java.

Question 12.12. (TCO 2) Which of the following creates a class that properly handles ActionEvents? (Points : 6)

       class handler implements ActionListener
     {public void actionPerformed(ActionEvent e){//code for event handler} }
       class handler extends ActionListener
     {public void handleEvent(ActionEvent e){//code for event handler} }
       class handler implements ActionListener
     {public void ActionListener(ButtonEvent e){//code for event handler} }
       class handler implements ActionListener
     {public void actionPerformed(ActionListener e){//code for event handler} }

Question 13.13. (TCO 2) In order to be able to use the JFrame, JPanel, and JButton classes, you must: (Points : 6)

       include the Swing header file (“Swing.h”)
       import the Swing class
       import javax.Swing.*;
       import java.awt.*;

Question 14.14. (TCO 2) The Graphics class in Java provides methods to: (Points : 6)

       draw lines between any two points
       draw test strings starting at any point
       draw shapes such as rectangles, ovals, etc.
       All of the above

Question 1.1. (TCO 2) What is the value of data after the following code executes?
unsigned char data = 0xA5;
data = data & 0xF0; (Points : 6)

       0xA0
       0xF0
       0xF5
       0x5A

Question 2.2. (TCO 2) A variable declared before and outside all function blocks… (Points : 6)

       is visible only in main
       is visible to all functions
       is visible to all functions except main
       is not visible to any functions

Question 3.3. (TCO 2) C++ selection statements include:
(Points : 6)

       for, while, do-while
       cout and cin
       if, if-else, if-else if, switch
       #include and using namespace std;

Question 4.4. (TCO 2) Which of the following expressions is correct if you want to end a while-loop when the character variable keepgoing is anything other than character y in either upper or lower case? (Points : 6)

       while (keepgoing == "y" || keepgoing == "Y")
       while (keepgoing == 'y'  && keepgoing == 'Y')
       while (keepgoing == "y" | |  keepgoing == "Y")
       while (keepgoing == 'y' | |  keepgoing == 'Y')

Question 5.5. (TCO 2) What is wrong with the following switch statement?
switch(x)
{
case 0:
    cout << x;
case 2:
    cout << 2 / x;
    break;
default:
    cout << “error”;
    break;
} (Points : 6)

       The value of x could be something other than 1 or 2.
       There is no break statement for case 1.
       There is no semicolon after the closing bracket.
       All of the above.

Question 6.6. (TCO 2) The following code fragment:

struct student
{
            string name;
            double gpa;
};
student thisStudent;
cout << “Enter this student’s name: “ << flush;
cin >> thisStudent.name;
cout << “Enter this student’s GPA: “ << flush;
cin >> thisStudent.gpa;
student nextStudent = thisStudent; (Points : 6)

       copies both thisStudent’s name and GPA to nextStudent
       displays the name and GPA of thisStudent
       causes a compiler error
       causes a run-time error

Question 7.7. (TCO 2) 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] = i * 2;
            } (Points : 6)

       Compiler, due to out-of-bounds array subscript.
       Run-time, due to out-of-bounds array subscript.
       Compiler, due to invalid array initialization.
       None of the above. It does not create any type of error.

Question 8.8. (TCO 2) Given the following code fragment, what is the data type of thisStudent?

struct student
{
            string name;
            double gpa;
};
student thisStudent; (Points : 6)

       string
       const pointer to student
       student
       double

Question 9.9. (TCO 2) Which of the following functions is taking an array of MyStruct structures as a pass-by-value parameter? (Points : 6)

       void MyFunc( MyStruct data[ ] );
       void MyFunc( MyStruct &data[ ] );
       void MyFunc( MyStruct *data[ ] ) ;
       not allowed in C++

Question 10.10. (TCO 2) If the function square(x) returns the square of x, then x should be passed by: (Points : 6)

       value so it is protected (cannot be changed)
       reference so it is protected (cannot be changed)
       pointer so it is protected (cannot be changed)
       None of the above. x cannot be protected; square can change the value of x regardless of how it is passed

Question 11.11. (TCO 2) Which of the following is an invalid declaration to overload the following function?
double foo(int); (Points : 6)

       double foo(double);
       int foo(int);
       double foo(double *):
       double foo(int *);

1. (TCO 2) When organizing a program into three files (main, class implementation, and class header), which is not a .cpp file? (Points : 6)

       main
       none are .cpp
       class header
       class implementation

Explanation / Answer

1) After executing it goes and operation between address and results 0xA0...correct option is a
2)Declaring variable before all functions means it is global variable or constant...so
it is visible to all functions..so correct option is b
---------------------------------------------
3) selection statements..having choice to select or leave from available options.
so using if, if-else, if-else if, switch..we can achieve..so correct options is c

-------------------------------------------------------
4) we denote char with single quote..and string with double quotes.
and we have accept either y or Y...so or operation denotes ||
therefore correct option is d
--------------------------------------------------------
5) "There is no break statement for case 1." is correct option.
if we didnt kept break..it continues to execute case 2..where it throws error undefined (2/x ==>2/0)
-----------------------------------------
6) It simply copies.....strcuture is nothing but array of elements containing ifferent type
so it simply copies....so correct option is "copies both thisStudent’s name and GPA to nextStudent"

---------------------------------------------------------------
7) None of the above. It does not create any type of error.
It does not create any error....declaring aray with some constant value..it is fine.
---------------------------------------------------------------------------------------
8)const pointer to student...is correct
Structure iis not restricted to single type..it is combination of all types
-----------------------------------------------------
9)void MyFunc( MyStruct data[ ] ); ..........is correct
for pass by value ..need not have any referrence while declaring.

-----------------------------------------------
10) ...actually options given are not perfect...but this one is fine
" reference so it is protected (cannot be changed)"
when we pass reffference then it will change value
when we pass by value then it cannot change value.
--------------------------------------------------------------------
11)
double foo(double);
data types are changing
--------------------------------------------------
1)class header
it will be dclared as xxxxxxx.h
------------------------------------------
2)encapsulation
it totally encpsulates all data...hiding information from others
-----------------------------------------------------
3)int whatever (int x);
function name and type must be sme...signatures may have different
------------------------------------------------------------
4)
objects
...direct answer...
---------------------------------------
5) It will compile, but causes a run-time error because d1.feet has not been declared.
since we declared empty constructor..so on compile it accepts...but while running it throws error
since it cant find
-----------------------------------------------------------
6)myFunction(&data);
we should address of our array...to achive pass by referrence
--------------------------------------------
7)dptr = &j;
cnt initlaise integer value to double
---------------------------------------------
8)The iptr variable cannot be given an address of a double.
------------------------------------------------
9)
All of the above
--------------------------------------------
10) Two buttons are added side by side at the top of the display.
it willa add....side by side
-----------------------------------
11)This cannot be done in Java.
only thing that we have to do for this question is...declare only radio buttons
-------------------------------------------------------------------
12)
class handler implements ActionListener
{public void actionPerformed(ActionEvent e){//code for event handler} }

-------------------------------------------------------
13)import java.awt.*;
it includes these all things
------------------------------
14)All of the above
we can draw any thing.using graphics   
5)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote