CISP 430 Quiz 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What boundary values should we use as test inputs for the day variable in the function date_check of ch1 around page 15 of the textbook.

1, 28, 29, 30, and 31

What is a friend function of a class in C++?

A friend function of a class is a function that is not a member function of a class, but that still can access to private members of some of its parameters.

What is the difference between a formal parameter and an argument?

A function's parameter is referred to as the formal parameter to distinguish it from the value that is passed in during the function call. The argument is the passed value.

Any items that are not explicitly placed in a namespace become part of the so-called ___________________. These items can be used at any point without any need for a using statement or a scope resolution operator.

global namespace

What would be the include directive that must appear before using the sqrt function such as "double sqrt(double x);"?

#include <cmath>

The prototype and precondition/postcondition contract are shown at the following. int date_check(int year, int month, int day); // The three parameters are a legal year, month, and // day of the month. // If the given date has been reached on or before today, // then the function returns 0. Otherwise, the value returned is the number // of days until the given date will occur. Suppose you call the function date_check(2014, 7, 29). What is the return value if today is February 1, 2015?

0

The prototype and precondition/postcondition contract are shown at the following. int date_check(int year, int month, int day); // The three parameters are a legal year, month, and // day of the month. // If the given date has been reached on or before today, // then the function returns 0. Otherwise, the value returned is the number // of days until the given date will occur. Suppose you call the function date_check(2009, 7, 29). What is the return value if today is July 22, 2009?

7

The prototype and precondition/postcondition contract are shown at the following. int date_check(int year, int month, int day); // The three parameters are a legal year, month, and // day of the month. // If the given date has been reached on or before today, // then the function returns 0. Otherwise, the value returned is the number // of days until the given date will occur. Suppose you call the function date_check(2009, 7, 29). What is the return value if today is July 22, 2009?

7

What is a class in C++ programming?

A class is a kind of data type that defines data members and member functions that operate on the data.

Which statement of the following is the most appropriate?

A constructor is a member function that is automatically called to initialize a variable when the variable is declared. Defining constructors increases the reliability of your classes by reducing the chance of using an uninitialized variable.

What is the purpose of a macro guard in C++ ?

A macro guard prevents accidental duplication of a class definition. Normally, if a program includes a header file more than once, compilation will fail. A macro guard directs the compiler to skip duplicate class definitions.

Which statement of the following is the most appropriate?

A second important testing technique is to ensure that your test cases are fully exercising the code. A software tool called a profiler can aid in fully exercising code.

" ______________ a member function" is nothing more than OOP jargon for making a function call to a member function.

Activating

Which kind of functions can access private member variables of a class?

All of the above can access private member variables

What does "using namespace std;" statement do in a C++ program?

Allows all Standard Library items to be used.

What is a global namespace in C++?

Any items that are not explicitly placed in a namespace become part of a global namespace, and can be used without a using statement or a scope resolution operator.

Which statement of the following is the most appropriate?

C++ permits you to define the meaning of operators such as + and == for your new classes.

Which statement of the following is the most appropriate?

C++ provides many prebuilt classes—the Standard Template Library— for all programmers to use.

Which statement of the following is the most appropriate?

C++ provides three common kinds of parameters: With a value parameter, the argument provides only the initial value for the formal parameter. With a reference parameter, any use of the parameter within the body of the function will access the argument from the calling program. A const reference parameter has the efficiency of an ordinary reference parameter, but there is a guarantee that the argument will not be changed by the function.

What could be two properties of good test data?

Choose test data for which you know the correct output. Test inputs should include those that are most likely to cause errors.

Which statement of the following is the most appropriate?

During debugging, you should discover exactly why a test case is failing and limit your changes to corrections of known errors. Once you have corrected a known error, all test cases should be rerun. Use a software tool called a debugger to help track down exactly why an error occurs.

Answer true or false for this statement: True or false: An algorithm with worst case time behavior of 3n takes at least 30 operations for every input of size n=10.

FALSE

Answer true or false for this statement: When programming in teams, the specification of a function should be written by the person writing the code for the function.

FALSE

What statement about "assert(c >= MINIMUM_CELSIUS);" statement in a C++ program is the most accurate?

If the expression (c >= MINIMUM_CELSIUS) is true, then c is valid and the assertion takes no action. On the other hand, if the expression is false, then the precondition has been violated, so a message is printed and the program is halted.

Suppose a function has a parameter named x, and the body of the function changes the value of x. If we want the change affect to the original x, what type of parameter x should we use?

It should be a reference parameter

Suppose a function has a parameter named x, and the body of the function changes the value of x. If we do not want the change affect to the original x, what type of parameter x should we use?

It should be a value parameter.

Which phase of the software life-cycle is usually the most expensive?

Maintenance and evolution

What are two rules, which are suggested in the textbook, for fully exercising code?

Make sure that each line of your code is executed at least once by some of your test data. If part of your code is sometimes skipped during execution, make sure that at least one test input skips this part of your code.

Why is writing easily modifiable code important?

Most real world programs require change at some time.

Express the formula (n - 2)*(n - 4) using big-O notation:

None of the above

Which of the following formulas in big-O notation best represent the expression n2+35n+6?

O(n2)

Which statement of the following is the most appropriate?

Object-oriented programming (OOP) supports information hiding by placing data in packages called objects, which are implemented via classes in C++. Objects are manipulated through functions called member functions, which are defined along with their classes.

Which statement of the following is the most appropriate?

One good method for specifying what a function is supposed to do is to provide a precondition and postcondition for the function. These form a contract between the programmer who uses the function and the programmer who writes the function. Using the assert function to check preconditions can significantly reduce debugging time, and the assertion-checking can later be turned off if program speed is a consideration.

How may boundary values for a function be found?

Pick values that are one step away from different behavior.

Which statement of the following is the most appropriate?

Place the documentation and class definition for a new class in a separate header file. Place the implementations of the member functions in a separate implementation file.

Which software tool will best help you determine whether your test cases are fully exercising your code?

Profiler

Which statement of the following is the most appropriate?

Pseudocode is a mixture of C++ (or some other programming language) and English (or some other natural language). Pseudocode is used to express algorithms so that you are not distracted by details of C++ syntax.

Suppose that the foo class does not have an overloaded assignment operator. What happens when an assignment a=b; is given for two foo objects?

The automatic assignment operator is used

What is the normal action of an assignment y = x, if x and y are objects?

The automatic assignment operator will copy the member variables of x to y.

Find the error with the following constructor prototype: void throttle(int size);

The keyword void should be removed. Constructors do not have a return type.

What does a run-time analysis usually count?

The number of arithmetic and other operations required for the program to run

What statement about "return EXIT_SUCCESS;" statement in a C++ program is the most accurate?

The return value of EXIT_SUCCESS tells the operating system that the program ended normally, and the operating system can then proceed with its next task. The EXIT_SUCCESS constant is defined in cstdlib (or stdlib.h). For most operating systems, this constant is defined as zero (which is why you may have used return 0).

Which statement of the following is the most appropriate?

Three important examples of big-O analyses are linear (O(n)), quadratic (O(n2)), and logarithmic (O(log n)).

Which statement of the following is the most appropriate?

To avoid conflicts between different items with the same name, your work should be placed in a namespace. When choosing a name for the namespace, use part of your real name or email address to avoid conflicts with other namespaces.

What is the primary purpose of a default constructor?

To initialize each object as it is declared.

When should you use a const reference parameter?

Whenever the data type might be many bytes, and the function does not change the parameter within its body.

Is it possible for a member function of a class to activate another member function of the same class?

Yes, both public and private member functions can be activated within another member function.

Which of the following formulas is(are) quadratic:

a, b, c, and e

What are the correct statements about C++ bool type? a. A bool value may be true or false; no other values are permitted. b. The built-in relational operators (==, !=, <, <=, >, >=) produce a bool value. c. The binary "and" operator (&&) combines two bool arguments, producing a true result only if both arguments are true. The binary "or" operator (||) combines two bool arguments, producing a true result if either of its arguments is true. The "not" operator (!) is applied to a single bool argument, producing a false result from a true argument, and vice versa. d. User-defined functions may also compute and return bool values. e. A bool value may be used as the controlling expression of an if-statement or a loop.

a, b, c, d, and e

List the following formulas in order of running time analysis, from greatest to least time requirements, assuming that n is very large: a. n2 + 1; b. 50 log n; c. 1,000,000; d. 10n + 10,000.

a, d, b, c

The value semantics of a class determines how values are copied from one object to another. In C++, the value semantics consists of two operations: ___________________________________________________

an assignment operator and a copy constructor

Which of these statements will always cause a program to halt? (x is an int variable).

assert(10 < 0);

_________________, which determines the average number of operations required for a given n.

average-case analysis

Which of the three forms a. using namespace main_savitch_2A; b. using main_savitch_2A::throttle; c. main_savitch_2A::throttle apollo; should be used when part of a namespace needs to be used within an actual header file?

c

A class head is the head of the definition of a class which consists of the C++ keyword _____________, followed by the name of the new class.

class

In C++, the mechanism to create objects and member functions is called a(an) _______________.

class

A _______________________________ may examine the status of an object, but changing the object is forbidden.

constant member function

Which of the following formulas is(are) O(n)

d only

A ____________________________ is a value that will be used for an argument when a programmer does not provide an actual argument.

default argument

Which of the following formulas is(are) O(log n)

f and g

The following is part of a C++ programming. void throttle::shut_off( ) // Precondition: None. // Postcondition: The throttle has been turned off. { position = 0; } We use the term _________________ to describe a full function definition such as above.

function implementation

The following is part of a C++ programming. void throttle::shut_off( ) // Precondition: None. // Postcondition: The throttle has been turned off. { position = 0; } We use the term _________________ to describe a full function definition such as above.

function implementation

The _______________________________ pair forms a contract between the programmer who uses a function and the programmer who writes that function.

precondition/postcondition

When we pretend that we do not know how a function is implemented, we are using a form of information hiding called ___________________________.

procedural abstraction

Please refer to Ch2 throttle class, which of these function calls could change the value of a point p: cout << rotations_needed(p); rotate_to_upper_right(p);

rotate_to_upper_right(p);

There is one difference between using old header file names (such as <iostream.h> or <stdlib.h>) and the new names (such as <iostream> or <cstdlib>). All of the items in the new header files are part of a feature called the _________________________________________. For now, when you use one of the new header files, your program should also have this statement after the include directives: ________________________.

standard namespace, also called std; using namespace std;

What values can a bool variable hold?

true and false


Ensembles d'études connexes

PrepU Patho Chapter 32 Structure and Function of the Kidney

View Set

Small Business Finance Ch. 3 Homework

View Set

BNS (VNSG 1323) CH. 6 PRACTICE QUESTIONS

View Set

Topic 1: Risk Management: A Helicopter View

View Set