COMP270 Practice for Exam 2 -- OOPS, NEED TO UPDATE

Instructions: There are 30 questions on this test. It is written in a style very similar to the REAL exam 2. Choose the best answer from among those given. Click the GRADE button on the bottom of the form when you want the exam graded.

Note: You can practice this test as many times as you desire; the system will cook you up a fresh batch of questions each time you access this page.

Your Name: @ 3.147.69.132

1. According to the way "MyFunct" is being used below, what is its prototype?

int x,y;
float z;
//
//Program logic to fill x and y with data here
//

z=MyFunct(x, y);

a) void MyFunct(int, int);
b) double MyFunct(double, int);
c) float MyFunct(int, int);
d) None of these

2. What output will be produced by the DO loop below?

int i=2;

do  {
     i++;
     if (i==7) continue;
     printf("%d", i);
     }
     while(i<10);

a) 3 4 5 6 7 8 9
b) 2 3 4 5 6 7 8
c) 3 4 5 6 8 9 10
d) None of the above

3. In C, a logical AND is indicated by what operator?

a) &&
b) ||
c) ++
d) None of the above

4. How many passes does the C compiler make through the source code?

a) 1
b) 2
c) 3
d) None of the above

5. What will be in variable 'A' after executing the following code?

int a,b;

b = 24;
a = ++b + 10;

a) 34
b) 35
c) 33
d) None of the above

6. A certain function is written as follows:

MyFunct(int x)
{
return(x * x);
}
What is the data type returned by this function?

a) char
b) int
c) float
d) None of the above

7. What conditions must be present for the fragment below to print the message "B is too small?"

if (a<20)
     printf("Too Small.");
     else
     if (b >= 10)
         printf("Everything is OK.");
         else
         printf("B is too small.");

a) (a < 20)
b) (a > 20) and (b >= 10)
c) (a>=20) and (b < 10)
d) None of the above

8. Given that A=25 and B=10, what will the output of the fragment below be?

if (a<20)
     printf("Too Small.");
     else
     if (b >= 10)
         printf("Everything is OK.");
         else
         printf("B is too small.");

a) Too Small.
b) B is too small.
c) Everything is OK.
d) None of the above

9. Given the declarations:

char szData[64];
int i;

i=314;

Supposed that we wish to place a text message into szData that shows the value in variable i. Which of the statements below would accomplish this?

a) strcpy( szData , "i = %d", i);
b) sprintf( szData , "i = %d" , i );
c) strcat( szData , i , "i = %d" );
d) None of these

10. What is the effect of a return statement within MAIN()?

a) The program starts over at the first statement in MAIN()
b) The program ends and control goes back to the operating system
c) The last executed instruction repeats
d) None of the above

11. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };


double GetMagnitude(Complex* lpStr)
{
//...
}

To access the member 're' within the function, what notation would be used?

a) lpStr->re
b) lpStr.re
c) re
d) None of the above

12. What two pieces of information are needed by 'FOPEN()' ?

a) A drive letter and file mode specifier
b) A filename and file mode specifier
c) A file mode specifier and system password
d) None of the above

13. Why is it important to open a file in the binary mode when reading and writing in-memory contents such as structures?

a) To avoid undesired translation of certain memory content values
b) To allow automatic error checking of the file contents by the operating system
c) To minimize disk space requirements
d) None of the above

14. Which standard library function below is used to move the file position indicator when implementing a random-access binary file system?

a) fopen()
b) fseek()
c) fputs()
d) None of the above

15. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };

If a DOUBLE uses 8 memory locations, how much memory is used up?

a) 8 locations
b) 16 locations
c) 0 locations
d) None of these

16. What must be done with any objects created through the 'NEW' operator prior to termination of a program?

a) The objects must be tested to see if they hold proper values
b) The objects must be tested with the 'OLD' operator
c) The objects must be deleted from memory
d) None of the above

17. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };

Complex Values[10];

If a DOUBLE uses 8 memory locations, how much memory is used up?

a) 160
b) 80
c) 40
d) None of these

18. Which stream below is normally associated with the keyboard?

a) stdout
b) stderr
c) stdprn
d) stdaux
e) None of the above

19. When a text file has been opened and a newline '\n' character is written into it by a C program, what character sequence is actually created in the file?

a) '\n' (LF)
b) '\r' (CR)
c) '\r' '\n' (CR - LF)
d) None of the above

20. What is a stream?

a) A path of communication between a program and the operating system
b) A method for writing to the video screen
c) A method for checking the contents of variables
d) None of the above

21. The method of a class that is called automatically when objects of that class are instantiated is called the:

a) Constructor
b) Initializer
c) Destructor
d) None of the above

22. In what file would you find the definition (prototypes) for a class called CGhostBuster?

a) GhostBuster.h
b) GhostBuster.cpp
c) CGhostBuster.c
d) None of the above

23. Suppose that a function has the following prototype:

void DonutLove(int& nLamars );

How will the calling function be passing its value?

a) By reference (implied pointer)
b) By pointer (explicit pointer operation required)
c) By value
d) None of the above

24. What is the primary difference between objects defined with Class versus those defined with Struct?

a) The Class objects have active behaviors
b) The Struct objects have built-in data protection
c) There's no functional difference between them
d) None of the above

25. Suppose that the following memory allocation is performed:

Class CDonuts MyDonuts[100];

Which statement will execute the method TasteTest() in the sixth element of the array of objects?

a) TasteTest.MyDonuts[5];
b) MyDonuts[5].TasteTest();
c) CDonuts.TasteTest.MyDonuts(5);
d) None of the above

26. What is the default access type for members of a class?

a) Public
b) Private
c) Protected
d) None of the above

27. If a class member is defined as "private," who can access it?

a) Only functions within the same program
b) Any function within any process running on the computer
c) Only methods within the class itself
d) None of the above

28. Which statement will correctly and dynamically allocate room for 13 (baker's dozen) CDonut objects?

a) CDonuts* NoSprinkles = new CDonuts[13];
b) CDonuts NoSprinkles[13];
c) NoSprinkles[13]->CDonuts[13];
d) None of the above

29. Supposed that an array of CDonut objects called "OurDonuts" has been instantiated dynamically. What is the correct method for deleting the array from memory?

a) delete OurDonuts;
b) delete []OurDonuts;
c) delete AllDonuts;
d) None of the above

30. What parameter passing method of C++ gives the advantage of passing values by pointer, yet avoids the use of pointer notation in both the calling and called functions?

a) Passing by value
b) Passing by reference
c) Passing by array
d) None of these

Extra information for Exam 1:


You will be asked to write two short programs. In one program, you will instantiate an array of objects of a predefined type, and call one or more methods of each object. In the second program, you will write the code to overload two of the built-in operators for objects of a class. Make sure you know and understand the "formulas" for overloading operators!


Grade Exam!