COSC1337 Programming Fund II

Ace your homework & exams now with Quizwiz!

A constructor is defined as computer (int= 512, int=2, double =1000.00);Which of the following is a legal statement that uses the constructor? a. Computer myMachine(128); b.Computer myMachine(1234.56); c.Computer myMachine(256, 899.99); d. all of the above are legal.

a. Computer myMachine(128);

A constructor has been defined as Painting(string = "oil", int=0); Which of the following can you use to declare an oil painting valued at $0? a. Painting myArtWork; b. Painting myArtwork(); c. Painting myArtWork(0,"oil") d. Two of the above

a. Painting myArtWork;

Which of the following is a legal constructor definition for the class named Table? a. Table(); b. void Table(); c. TableConstructor(); d. All of the above legal

a. Table();

The measure of the strength of the connection between two functions is called__________. a. coupling b. cohesion c. pathological d. blending

a. coupling

You create a class in two sections called________. a. declaration and implementation b. typical and atypical c. common and protected d. abstract and concrete

a. declaration and implementation

When an object goes out of scope, a ____________ is called automatically. a. destructor b. constructor c. overload function d. operating system error message

a. destructor

A general principle of objected-oriented error handling is that a function that might cause an exception should _______________. a. detect an exception but not handle it b. handle an exception but not detect it c. both detect and handle exceptions d. not allow exceptions to occur

a. detect an exception but not handle it

The most common use of constructors is to ________________. a. initialize data fields b. perform mathematical calculations c. call mutator functions d. deallocate memory

a. initialize data fields

When you overload the<< operator to work with an object, you must ______________. a. make the operator function a friend function b. make the operator function a member function c. return an object of the same type as the parameters d. return a simple built-in type

a. make the operator function a friend function

Within a block or function, a local variable ___________ a global one. a. overrides b. overloads c. accedes to d. replaces

a. overrides

In C++ program, all function names are always followed by a pair of__________. a. parentheses b. square brackets c. angle brackets d. curly braces

a. parentheses

The feature that allows the same operations to be carried out differently depending on the context is__________. a. polymorphism b. polygamy c. inheritance d. multitasking

a. polymorphism

A technique that programers use to provide object encapsulation is to usually make objects' data__________. a. private b. polymorphic c. accessible d. static

a. private

If a field named someField is public int he parent class, and a child class inherits with private access, then within the child class someField is_____________. a. private b. protected c. public d. inaccessible

a. private

Which of the following is an advantage of passing an address of a variable to a function? a. the function can alter the original variable in the calling function b. the function can alter only one value, making it more secure c. you need to use no special notation when passing an address d. the function automatically makes a copy of the passed variable

a. the function can alter the original variable in the calling function

Both a function header and its prototype contain___________. a. the return type b. a coded description of what the function does c. actual parameters d. square brackets

a. the return type

Which of the following could coexist in a program with void functions(double, int): with no ambiguity possible? a. void function (double); b. void function (double,int); c. void function (double=2.2, int = 3.3); d. all of the above

a. void function (double);

You create a class named Car with private non-static data fields named year, make, and price. The Car class contains a public non-static function named setYear () whose header is void Car::setYear(int year). Within this function, which statement correctly sets an object's field to the value of the parameter? a. year= year b. Car::year=year c. year= Car::year; d. Two of the above are correct

b. Car::year=year

A constructor has been defined as Painting (string = "oil" , int =0); . The first argument is used to set the Painting's medium and the second sets the price. Which of the following can you use to declare an oil painting value at $2000? a. Painting myArtWork (2000); b. Painting myArtWork ("oil",2000); c. Painting myArtWork; d. Two of the above

b. Painting myArtWork ("oil",2000);

If you have correctly overloaded the * operator to multiply two members of the Furniture class, and you have declared two Furniture objects, aDesk and aChair, then which of the following is a legal expression? a. Furniture* Furniture b. aDesk * aChair c.Furniture * aChair d. all of the above

b. aDesk * aChair

Parent class is to child class as ___________. a. subclass is to superclass b. base class is to derived class c. derived class is to driven class d. child class is to superclass

b. base class is to derived class

When you use the name of a function where you want it to execute within a program, you are ____________ the function. a. prototyping b. calling c. iterating d. defining

b. calling

To indicate that class Xis a child of class y, and that inheritance is public, the class definition is _____________. a. class X :: public class Y b. class X: public Y c. class Y::public class X d. class Y: public X

b. class X: public Y

Which of the following correctly calls a function that has the prototype void computePrice(int, double, int);? a. computePrice(5129.95, 8, 36); b. computePrice(5000, .075, 24); c. computePrice(10000, .10, 4.5); d. computePrice(2000, .090);

b. computePrice(5000, .075, 24);

A constructor that requires no arguments is an example of a ___________ constructor. a. no fault b. default c. faultless d. static

b. default

Using the same function name with different parameter lists is called __________ functions. a. overriding b. overloading c. overcompensating d. overreacting

b. overloading

If a field named someField is public int he parent class, and a child class inherits with protected access, then within the child class someField is_____________. a. private b. protected c. public d. inaccessible

b. protected

The term C++ programmers use for the extent to which a variable is known is ____________. a. breadth b. scope c. scale d. reach

b. scope

The pointer that is automatically supplied when you call a non-static class member function is the _________ pointer. a. public b. this c. implicit d. reference

b. this

When a function sends an error message to the calling function, the function is said to _____________ an exception. a. try b. throw c. catch d. create

b. throw

Which is a legal destructor for the Game class? a. Game(); b. ~Game(); c. void~Game(); d. Two of the above are legal destructors for the classGame

b. ~Game();

A constructor is defined as LightBulb (int =60);. The parameter is assigned to a field named watts. When you define object as LightBulb oneBulb(90);, the watts variable will be set to __________. a. 0 b. 60 c. 90 d.150

c. 90

Which statement is true in C++? a. a child class can have multiple parents b. A parent class can have multiple children c. Both of the above are true d. None of the above is true

c. Both of the above are true

An object is_________. a. a category of classes b. a name given to a class c. an instance of a class d. the same as a class

c. an instance of a class

The primary reason you want to use #define, #ifdef, and #endif is to __________. a. provide names for class constructors and deconstructors b. save memory c. avoid declaring a class twice d. ensure a class has been declared before using it

c. avoid declaring a class twice

A function that has been declared to be a friend of a class has access to the __________data in the class. a. public b. private c. both of the above d. none of the above

c. both of the above

If a member of a base class named Base is protected, then it can be used by functions that are____________. a. members of Base b. members of children of Base c. both of the above d. none of the above

c. both of the above

Suppose you have a C++ program that contains an integer variable named yearOfBirth. To call a function with the prototype void calculateAge(int ) ;, you use the statement___________. a. void calculateAge(); b. calculateAge(int); c. calculateAge(yearOfBrith); d. calculateAge(int yearOfBirth);

c. calculateAge(yearOfBrith);

A local variable is one that____________. a. is known to functions only within its own file b. is automatically declared by C++ c. ceases to exist when its block ends d. has a value that does not change during its life

c. ceases to exist when its block ends

A derived class also can be called a ___________. a. super b. base c. child d. parent

c. child

A ___________ is called automatically each time an object is created. a. compiler b. builder c. constructor d. destructor

c. constructor

Which of the following is a valid prototype for a function that accepts an integer argument and returns a double value? a. int function(double); b. int function(double) c. double function (int); d. double function (int)

c. double function (int);

Which of the following is equivalent to double money = 4.56;? a. double 4.56 = money; b. money double= 4.56; c. double money(4.56); d. float money =4.56;

c. double money(4.56);

Errors that occur during a program's execution are called____________. a. faults b. omissions c. exceptions d. exclusions

c. exceptions

A variable that is known to all functions within a file is said to be ______________. a. notorious b. worldly c. global d. famous

c. global

The best functions have ____________ a. low cohesion and loose coupling b. low cohesion and tight coupling c. high cohesion and loose coupling d high cohesion and tight coupling

c. high cohesion and loose coupling

You should use an inline function when _____________. a. it is large b. it takes no arguments c. it is called infrequently d. it requires parameters that are addresses.

c. it is called infrequently

Object-oriented programmers primarily focus on ____________. a. procedures to be performed b. the step by step statements needed to solve a problem c. objects and the task that must be performed with those objects d. the physical orientation of objects within a program.

c. objects and the task that must be performed with those objects

A class named Apartment contains a non-static public function named showRent () that neither takes nor receives arguments. The correct function header for the showRent() function is _________________. a. showRent() b. Apartment::showRent() c. void Apartment::showRent d. void Apartment.showRent()

c. void Apartment::showRent

Which of the following is a legal example of the way overloading functions is ____________. a. you can use one function name for every operation you want to perform with a class b. you can use one class name for many types of items c. you can use one function name for similar operations, regardless of the data type involved d. you do not have to write separate code for the bodies of functions that perform similar tasks

c. you can use one function name for similar operations, regardless of the data type involved

A constructor has been defined as FlowerSeed(int =7);. Which of the following constructors could coexist with the defined constructor without any possible ambiguity? a FlowerSeed(int); b. FlowerSeed(); c. FlowerSeed (int=10, int= 18); d. FlowerSeed (int, double);

d. FlowerSeed (int, double);

You have defined a class named Invoice that contains two non-static private fields, invoiceNumber and amount. When you write a main() function and declare one Invoice object named anInvoice, you can display the object's amount field with the statement? a. cout<< anInvoice(amount); b. cout << Invoice.amount; c. cout << anInvoice.amount; d. None of the above

d. None of the above

You create a class named Car with private non-static data fields named year,make, and price. The Car class contains a public non-static function named setMake() whose header is void Car::setMake(string carMake). Within this function, which statement correctly sets an object's field to the value of the parameter? a. make= carMake; b. this->make=carMake; c. carMake = make; d. Two of the above are correct

d. Two of the above are correct

If you have correctly overloaded the * operator to multiply two members of the Furniture class, and you have declared two Furniture objects, aDesk and aChair, then which of the following is a legal expression? a. aChair.operator*(aDesk) b. aChair * aChair c. aChair * aDesk d. all of the above

d. all of the above

The most common arrangement for class is that ______________. a. data members are static and functions are not b. data members are not static and functions are c. data members are public and functions are not d. data members are not public and functions are

d. data members are not public and functions are

If a field named someField is private int he parent class, and a child class inherits with public access, then within the child class someField is_____________. a. private b. protected c. public d. inaccessible

d. inaccessible

An overload subtraction operator subtracts two Shipment objects from each other, returning an integer that represents the difference in their totalWeight variables. The subtraction operator works as expected, with the object to the right of the minus sign being subtracted from the object to the left. The function header is int Shipment::operator- (Shipment ship). Within the function, which of the following is correct? a. int difference = ship - totalWeight; b. int difference = totalWeight - ship; c. int difference = ship.totalWeight-totalWeight; d. int difference = totalWeight - ship.totalWeight;

d. int difference = totalWeight - ship.totalWeight;

The feature in object-oriented programs that allow the same operation to be carried out differently, depending on the object, is___________. a. encapsulation b. inheritance c. pointer creation d. polymorphism

d. polymorphism

A program contains the function prototype void displayData (char[] , int= 0);. Which of the following is a legal function call? a. displayData(); b. dispalyData("Roberts"); c. displayData("Gonzales", 345); d. two of the above are legal.

d. two of the above are legal.

1. In different programming languages, program modules are known as all of the following except____________. a. functions b. procedures c. methods d. variables

d. variables

A class named Carpet contains three data fields, int length, int width, and double price. A program declares Carpet myRug (129.95);. You know that ___________. a. the length is 129.95 b. the width is 129.95 c. the price is 129.95 d. you know none of the above

d. you know none of the above

When you create a data structure or a class object, you access the object's fields using the __________ operator. a. insertion b. extraction c. modification d. dot

d.dot


Related study sets

Service Cloud Certification Prep

View Set

Chapter 4 - Videos ( extra credit)

View Set

7 ARTICLES OF THE US CONSTITUTION

View Set