Programming Fundamentals 1: Exam 4 (Ch 11 & 13)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

You must declare all data members of a class before you declare member functions. -True/False

False

You must use the private access specification for all data members of a class. -True/False

False

What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl; } TestClass() { cout << Hello! << endl; } }; int main() { TestClass test; return 0; } -the program runs but there is no output. -0 -the program will not compile -Hello!

Hello!

The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure. -True/False

True

Whereas object-oriented programming centers on the object, procedural programming centers on functions. -True/False

True

You can use the technique known as a member initialization list to initialize members of a class. -True/False

True

You cannot directly assign an integer value to an enum variable. -True/False

True

Given the following structure declaration, idNum is struct Employee { string name; int idNum; }; -a member -an array -a tag -None of these

a member

Which of the following statements outputs the value of the gpa member of element [1] of the student array? -cout << student1.gpa; -cout << firstStudent.gpa; -cout << student[1].gpa; -None of these

cout << student[1].gpa;

Which of the following assigns a value to the hourlyWage member of employee[2]? -employee[2] -> hourlyWage = 50.00; -employee2.hourlyWage = 7.50; -hourlyWage[2].employee = 29.75; -employee[2].hourlyWage = 75.00; -None of these

employee[2].hourlyWage = 75.00;

A declaration for an enumerated type begins with the ________ key word. -enumerated -enum_type -enum -ENUM -None of these

enum

Given the following declaration: enum Tree {OAK, MAPLE, PINE}; What is the value of the following relational expression? OAK > PINE -true -false -This is an error. You cannot compare enumerators with relational operators.

false

If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used. -global -None of these -scope -variable -ambiguity

scope

Which of the following is required after the closing brace of the structure definition? -square bracket -period -semicolon -colon -None of these

semicolon

What is wrong with the following code? char x = 'a', y = 'a'; if (strcmp(x,y) == 0) exit(0);

strcmp compares C-strings, not characters

Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once? -#include -#ifndef -#endif -None of these -#guard

#ifndef

When you dereference an object pointer, use the -None of these -& operator -dot operator --> operator

-> operator

After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PINE }; -"MAPLE" -2 -'M' -1 -1.0

1

What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: TestClass(int x) { cout << x << endl; } TestClass() { cout << "Hello!" << endl; } }; int main() { TestClass test(77); return 0; } -the program will not compile -77 -the program runs but there is no output. -Hello!

77

Which of the following is an example of a C++ primitive data type? -unsigned short int -long double -unsigned char -All of these -None of these

All of these

You may use a pointer to a structure as a -function parameter -structure member -function return type -All of these -None of these

All of these

What is wrong with the following code? #include <iostream> using namespace std; struct ThreeVals { int a, b, c; }; int main() { ThreeVals vals = {1, 2, 3}; cout << vals << endl; return 0; }

An entire structure cannot be sent to cout

What is wrong with the following code? struct FourVals { int a, b, c, d; }; int main() { FourVals nums = {1, 2, , 4}; return 0; }

An initializer cannot be skipped before the end of the initialization list

You cannot directly assign an enumerator to an int variable. -True/False

False

A destructor function can have zero to many parameters. -True/False

False

A function cannot modify the members of a structure. -True/False

False

Class objects can be defined prior to the class declaration. -True/False

False

Given the structure definition shown, assume that circle1 and circle2 are variables of the Circle type and their members have been initialized. struct Circle { double centerX; double centerY; double radius; }; Then is it true or false that the following statement correctly determines whether the two variables' members contain the same data? if (circle1 == circle2) -True/False

False

In-place member initialization no longer is available in C++11. -True/False

False

It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable. -True/False

False

The constructor function may not accept arguments. -True/False

False

The names of enumerators in an enumerated data type must be enclosed in quotation marks. -True/False

False

While a class's member functions may be overloaded, the constructor cannot be overloaded. -True/False

False

If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr; -It declares an empty structure variable named *pcirc. -It declares a structure pointer called pcirc initialized with a null pointer. -The statement is illegal in C++. -It initializes a null pointer with the value of the Circle pointer. -None of these

It declares a structure pointer called pcirc initialized with a null pointer.

What is wrong with the following code? struct TwoVals { int a, b; }; int main() { TwoVals.a = 10; TwoVals.b = 20; return 0; }

No structure name has been declared. TwoVals is the structure name

The constructor function's return type is -None of these -int -float -char -structure pointer

None of these

The destructor function's return type is -float -int -None of these -Nothing; destructors have no return type -char

Nothing; destructors have no return type

What is wrong with the following code? char string1[] = "Billy"; char string2[] = " Bob Jones"; strcat(string1, string2);

The compiler will not allocate enough space in string1 to accommodate both strings

What is wrong with the following code? struct Names { string first; string last; }; int main() { Names customer = "Smith", "Orley"; cout << customer.first << endl; cout << customer.last << endl; return 0; }

The initialization of the list of the customer variable must be enclosed in braces

What is wrong with the following code? char str[] = "Stop"; if (isupper(str) == "STOP") exit(0);

The isupper function can only be used to test a character, not a string

What is wrong with the following code? struct Values { string name; int age; }

The semicolon is missing after the closing brace

Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr; -None of these -The statement defines a Rectangle pointer variable named *BoxPtr. -The statement is illegal in C++. -The statement assigns the value of *BoxPtr to the object Rectangle. -The statement declares an object of the class Rectangle.

The statement defines a Rectangle pointer variable named *BoxPtr.

What is wrong with the following code? struct { int x; float y; };

The structure declaration has no tag

A private member function is useful for tasks that are internal to the class but it is not directly called by statements outside the class. -True/False

True

A struct can contain members with varying data types. -True/False

True

Any mathematical operation that can be performed on regular C++ variables can be performed on structure members. -True/False

True

Constructor functions are often used to allocate memory that will be needed by the object. -True/False

True

Destructor functions are often used to free memory that was allocated by the object. -True/False

True

If a function is legally prototyped to return an integer value, it can return a structure member that is an integer data type. -True/False

True

If you do not declare a destructor function, the compiler will furnish one automatically. -True/False

True

In C++11 if you want to retrieve a strongly typed enumerator's underlying integer value, you must use a cast operator. -True/False

True

It is possible for a structure to contain, as a member, a pointer to its own structure type. -True/False

True

It is possible for a structure variable to be a member of another structure variable. -True/False

True

More than one constructor function may be defined for a class. -True/False

True

Structure variables may be passed as arguments to functions. -True/False

True

The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s. -True/False

True

The expression s->m; indicates that s is a structure pointer and m is a structure member. -True/False

True

When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type. -True/False

True

When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor. -True/False

True

When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them. -True/False

True

When you use a strongly typed enumerator in C++11 you must prefix the enumerator with the name of the enum followed by the :: operator. -True/False

True

Given the following structure declaration, Employee is struct Employee { string name; int idNum; }; -a member -an array -a tag -None of these

a tag

Data types that are created by the programmer are known as -variables -abstract data types (ADTs) -functions -parameters -None of these

abstract data types (ADTs)

Which of the following describes only the general characteristics of an object? -initialization -abstraction -detailed specification -initiation -None of these

abstraction

What is wrong with the following code? char numeric[5]; int x = 123; numeric = atoi(x);

atoi converts a string to an integer, not an integer to a string

In OOP terminology, an object's member variables are often called its ________ and its member functions can be referred to as its behaviors or its ________. -None of these -attributes, methods -values, morals -data, activities -attributes, activities

attributes, methods

When a constructor has a member initialization list, the initializations take place -after any statements in the body of the constructor execute -None of these -before any statements in the body of the constructor execute -when a member is used in the execution of the program

before any statements in the body of the constructor execute

When a structure is passed ________ to a function, its members are NOT copied. -by reference -by value -Either of these -Neither of these

by reference

A structure ________ contain members of the same data type. -cannot -can -shouldn't -None of these

can

When a member function is defined outside of the class declaration, the function name must be qualified with the -private access specifier -class name, followed by a semicolon -name of the first object -class name, followed by the scope resolution operator -None of these

class name, followed by the scope resolution operator

In C++11 you can have one constructor call another constructor in the same class by using -in-place initialization -constructor delegation -None of these -a member initialization list

constructor delegation

A ________ is a member function that is automatically called when a class object is ________. -destructor, created -constructor, created -None of these -static function, deallocated -utility function, declared

constructor, created

A class is a(n) ________ that is defined by the programmer. -function -attribute -data type -None of these -method

data type

In a procedural program you typically have ________ stored in a collection of variables and a set of ________ that perform operations on the data. -data, functions -None of these -strings, operators -numbers, arguments -parameters, arguments

data, functions

Objects are created from abstract data types that encapsulate ________ and ________ together. -integers, floating-point numbers -numbers, characters -data, functions -addresses, pointers -None of these

data, functions

Before a structure can be used it must be -declared -dereferenced -initialized -All of these -None of these

declared

When a constructor function accepts no arguments, or does NOT have to accept arguments because of default arguments, it is called a(n) -default constructor -None of these -empty constructor -stand-alone function -arbitrator function

default constructor

Members of the class object are accessed with the -cin object -extraction operator -None of these -dot operator -stream insertion operator

dot operator

Passing a structure as a constant reference parameter to a function -can potentially result in changes to the structure's members -guarantees not to result in changes to the structure's members -will always change the structure's members -None of these

guarantees not to result in changes to the structure's members

The process of object-oriented analysis can be viewed as the following steps: -identify objects, then define each object's attributes, behaviors, and relationships -declare public and private variables, prototype functions, and then write code -write the main() function, then determine which classes are needed -None of these -define data members and member functions, then assign the class name

identify objects, then define each object's attributes, behaviors, and relationships

Where are class declarations usually stored? -in their own header files -None of these -in .cpp files, along with function definitions -on separate disk volumes -under pseudonyms

in their own header files

In C++11 you can use ________ to initialize a member variable in its declaration statement. -default initialization -None of these -general member initialization -in-place initialization -initialization overload

in-place initialization

The following code shows an example of ________ class Point { private: double y = 5.70; double z = 3.0; public: //Public member functions go here }; -in-place initialization -an illegal initialization -a default constructor creation -constructor delegation

in-place initialization

When the body of a member function is defined inside a class declaration, it is said to be -static -conditional -inline -None of these -global

inline

With an enumerated data type, the enumerators are stored in memory as -strings -integers -characters -doubles

integers

A function ________ return a structure. -may -may not -will always -can never -None of these

may

Assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? -None of these -myCar::accelerate(); -Car -> accelerate(); -myCar.accelerate(); -myCar:accelerate();

myCar.accelerate();

How many default constructors can a class have? -None of these -any number -only one -two or more -only two

only one

If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p; -output the dereferenced value pointed to by p -result in a compiler error -output the address stored in p -output the value stored in a -None of these

output the dereferenced value pointed to by p

If you do NOT declare an access specification, the default for members of a class is -public -private -inline -None of these -global

private

Which type of member function may only be called from a function that is a member of the same class? -None of these -private -global -local -public

private

f you do NOT declare an access specification, the default for members of a class is -inline -global -None of these -public -private

private

Examples of access specifiers are the key words -near and far -None of these -table and row -opened and closed -private and public

private and public

The type of member function that may be called from a statement outside the class is -undeclared -global -private -public -None of these

public

In C++11, you can use a new type of enum known as a(n) ________ (also known as an enum class) to have multiple enumerators with the same name, within the same scope. -universal enum -auto enum -multi-cast enum -strongly typed enum -None of these

strongly typed enum

A C++ class is similar to a(n) -structure -header file -inline function -library function -None of these

structure

Objects in an array are accessed with ________. -parentheses -subscripts -output format manipulators -#include statements -None of these

subscripts

The name of a structure is referred to as its -data type -argument -parameter -tag -None of these

tag

If Circle is a structure tag, then the following statement can be the header line for a function that ________. Circle doSomething(Circle c2) -determines and returns the area of a circle -takes a Circle structure as a parameter, does something, and returns a Circle structure -operates on a constant reference to a Circle structure -takes two Circle parameters and does something -None of these

takes a Circle structure as a parameter, does something, and returns a Circle structure

A structure pointer contains -the address of a structure variable -the dereferenced address of a structure tag -the name and address of the structure tag -the address of a structure tag -None of these

the address of a structure variable

The constructor function always has the same name as -the first private data member -None of these -the class -the first public data member -the first object of the class

the class

Which of the following is automatically called when an object is destroyed? -None of these -the constructor function -the specification deallocator -the destruction function -the destructor function

the destructor function

Which of the following will allow you to access structure members? -the structure access operator -the dot operator -the #include directive -the getmember function -None of these

the dot operator

Which of the following is used to protect important data? -the protect member function -the class protection operator, @ -None of these -the public access specifier -the private access specifier

the private access specifier

What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; } -77 -0 -the program will not compile -the program runs but there is no output.

the program will not compile

A good reason to pass a structure as a constant reference is -to prevent changes to the structure's members -to ensure changes to the structure's members -to slow down the function's execution which helps prevent errors -to speed up the function's modification of the structure's members -None of these

to prevent changes to the structure's members

The following statement ________. bookList[2].publisher[3] = 't'; -is illegal in C++ -will change the name of the second book in bookList to 't' -will store the character 't' in the fourth element of the publisher member of bookList[2] -will result in a runtime error -None of these

will store the character 't' in the fourth element of the publisher member of bookList[2]

For the following code, which statement is NOT true? class Point { private: double y; double z; public: double x; }; -All of these are true. -x is available to code that is written outside the class. -The name of the class is Point. -z is not available to code that is written outside the class. -x, y, and z are called members of the class.

z is not available to code that is written outside the class.


संबंधित स्टडी सेट्स

Ch. 13 - Contract Performance, Breach, and Remedies

View Set

Ch. 18 Module 1: Section 18.01 Dynamic Study Module

View Set