C++ Programming Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

what does code display #include< iostream> using namespace std; int getValue(int); int main() { int x=2; cout<< getValue(x)<<endl; return 0; } int getValue (int num) {return num + 5;}

7

In object aggregation, one object is an attribute of another object, which creates a __________ relationship.

"has a"

what is the output of the following segment of code if the value 4 is entered? int num; int total =0; cout<< "enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: total=0; case 2: total =5; case 3: total =10; case 4: total =total +3; case 8: total =total +6; default total =total +4; }

13

what is the value of my_value if the user enters 0 con >>my_value; if (my_value>5) ```my_value=my_value+5; else if(my_value>2) ```my_value=my_value+10; else ```my_value=my_value+15;

15

assume a class named Numbers has the following static member funciotn declaration static void showTotal (); write a statement that calls the showTotal function

Numbers::ShowTotal();

struct Point { int x; int y; }; write statements that defines a Point structure variable named center then assigns 12 to the x member of center and 7 to the y member of center

Point center; center x=12; center y=7;

The term _________ means the ability to take many forms.

Polymorphism

if Circle is a structure what does the following statement do Circle *pcirc=nullptr;

it declares a structure pointer called pcirc initialized with a null pointer

Write a C++ statement that correctly assigns the character m to a variable named letter.

letter='m'

This type of variable is defined inside a function and is not accessible outside the function.

local

This is a control structure that causes a statement or group of statements to repeat:

loop

The default behavior when an object is assigned the value of another object of the same class is...

memberwise assignment

The name of an array stores the ________ of the first array element.

memory address

What is required after the closing brace of a structure definition?

semicolon ;

What will the following code output? int number = 22; int *var = &number; cout << var << endl;

The memory address of number

To test whether a character is a numeric digit character, use the ________ function.

isdigit

which statments uses C+11 to initialize a vector of ints named n with values 10 and 20?

vector<int> n {10,20};

A ______________ of a base class expects to be overridden in a derived class.

virtual function

Which directive is 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?

#ifndef

what header files must be included in the following program int main() { double amount =89.7; cout<< showpoint<<fixed; cout<< setw(8)<< amount<<endl; return 0; }

#include <iostream> #include <iomanip>

what are the errors in the code #include <iostream>; using namespace std; int main () { const int number1, number 2, product; cout<< "Enter two numbers and i will multiply \n"; cout<< "them for you.\n"; cin >> number1>>number2; product =number1* number2; cout<< product return 0; }

#include <iostream>; <- no ; const int number1, number2, product; <- no const cout<< product <- needs ;

What preprocessor directive needs to be included in a program that has string variables?

#include <string>

what id the value of x int x; x=3/static_cast<int>(4.5+6.4);

0

what will the following code display int numbers [4]={99,87}; cout<< numbers[3]<<endl;

0

After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PRINE };

1

what is the assigned to the variable result give the statement below with the following assumptions: x=10,y=7, and x, result, and y are all int variables result =x>y;

1

what is the output int n=1; while (n<=5) ```cout<< n<< ' "; ```n++;

1 1.... goes forever

given the following function void calc(inta, int&b) { int c; c=a+2; a=a*3; b=c+a; } what is the output of the code segment that invokes calc(): int x=1; int y=2; int z=3; calc(x,y); cout<< x<< " "<< y<<" "<< z<< endl;

1 6 3

What is the value stored in num after the following statement executes? num = atoi("1000");

1000

What will the following code output? int number = 22; int *var = &number; cout << *var << endl;

22

what will the code display int x=23,y=34, z=45; cout<<x<<y<<z<<endl;

23,34,45

What is the value of length after this code executes? const int SIZE = 10; char name [SIZE] = "Sue"; int length = strlen(name);

3

what is the value of the number after the following statements execute int number; number =18/4;

4

what will the following code display int number=6; cout<< number++<< endl;

6

what will the following code display int number =6; number++; cout<< number << endl;

7

what will code display int number [ ]={99,87,66,55,101} for (int i=1; i<4; i++) ```cout<< numbers[i]<< " ";

87, 66, 55

The _________ operator always follows the cin object, and the ________ operator always follow the cout object (#1, #2).

>>, <<

True or False: The C++ compiler performs strict array bounds checking when it encounters an array of characters.

False

True or False: The string class is a built-in, primitive data type like int or char.

False

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

False

Which type of function is not a member of a class but has access to the private members of the class?

Friend

In OOP, ____________ allows you to create new classes based on existing classes.

Inheritance

True or False: A static member function does not need to be called by a specific object of the class.

True

True or False: A struct can contain members with varying data types.

True

True or False: If the expression on the left side of the following is true, the expression on the right side will not be checked. (a >= b) | | (c == d)

True

True or False: If you do not furnish a constructor, destructor or copy constructor, a default one will be provided by the compiler.

True

True or False: More than one class may be derived from a base class.

True

True or False: Preprocessor directives are not C++ statements and as such should not end with a semicolon

True

True or False: When arguments must be passed to the base class constructor, they are passed from the derived class constructor's header line.

True

True or False: When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.

True

True or False: When you add a value to a pointer, you are adding that value times the size of the data type being referenced by the pointer.

True

True or False: You may use the <, >, <=, >=, == and != relational operators is to compare string objects.

True

The escape sequence that represents the null terminator is ...

\0

The ________, also known as the address operator, returns the memory address of a variable.

ampersand &

Unlike regular variables, ______________ can hold multiple values.

arrays

What is being protected in the following statement? class Car : protected vehicle

base class members

The ____________ constructor is called before the __________ constructor (#1, #2).

base, derived

A function is executed when it is

called

Write a C++ statement that defines a C-string capable of storing a name of up to 25 characters.

char name[26];

Write a C++ cin statement that will read input into each of these variables: int age; double pay; char section;

cin >> age >> pay >> section;

What causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed?

cin object

Write a C++ statement that declares a Poodle class. The class should be derived from the Dog class with public base class access.

class Poodle:public dog

Write a C++ statement that declares a SoundSystem class. Use multiple inheritance to base the class on the CDPlayer class, the Tuner class, and the MP3Player class. Use public base class access in all cases.

class Soundsystem:public CDPlayer, public Tuner, public MP3Player

given the following header for the funciton named computeValue, which of the following is a valid call to the function void computeValue(int value)

computeValue(10);

Write a C++ statement that defines a constant named TAX_RATE that hold the value of 0.075.

const double TAX_RATE = 0.075;

if you do not furnish a __________, a default one will be provided by the compiler

constructor, destructor, copy constructor

int numbers [ ] { 10, 20, 30 } Write a statement that prints out the second element of the numbers array using pointer notation.

cout << *(numbers +1)

Write a C++ statement that outputs the value of the gpa member of element[1] of the student array.

cout << student[1].gpa;

If you intend to place a block of statements within an if statement, you must place __________ around the block.

curly braces {}

A class is a(n) ______________ that is defined by the programmer.

data type

Before a structure can be used, it must be

declared

When a constructor function accepts no arguments, or does not have to accept arguments because of the default arguments, it is called a(n)...

default constructor

a program contains the following method void display (int arg1, double arg2, char arg3) { cout << "the values are " << arg1<< ", " << arg2<< ", and " << arg3 << endl; } write a statement that calls this function and passes the following variables as arguments char initial ='T'; int age =25; double income =50000.00;

display (initial, age, income);

convert the following while loop to a do while loop int x=1; while (x>0) { cout<< "enter a number: "; cin >>x; }

do { cout<< "Enter a number:"; cin>>x; }while (x>0);

Write the definition for a double array named lightYears with 1,000 elements.

double lightYears[1000];

write a function definition named timesTen. the functor should accept a double argument and return a double value that is ten times the value of the argument

double timesTen(double argument) { double value; value=argument*10; return value; }

Write a C++ statement that assigns a value to the hourlyWage member of employee[2].

employee[2].hourlyWage=75.00;

in a cout statement, what two things will advance the output position to the beginning of the next line? (#1, #2)

endl, \n

True or False: Assume array1 and array2 are the names of two arrays. To assign the contents of array2 to array1, you would use the following statement: array1 = array2;

false

what is the output if the user enters 0 int x=-1; cout<< "enter a 0 or a 1: "; cin>>x; if (x) ```cout<< "true:<<endl; else ```cout<< "false" <<endl;

false

write a loop that displays the following set of numbers 0, 10, 20, 30, 40, 50, .....1000

for (int x=0; x<=1000; x+=10) ```cout<< x<< ", "<< endl;

to allow file access in a program you must use the include which header file

fstream

A collection of statements that performs a specific task is a(n)

function

Every complete C++ program must have a a. comment b. function named main c. cout statement d. namespace

function named main

what is the output #include <iostream> using namespace std; class TestClass { public: ```TestClass (int x); ```{cout<< x<< endl;} ```TestClass() ```{cout<< "Hello!"<<endl;} }; int main { TestClass test; return 0; }

hello!

write an if statement that prints the message "The number is valid" if the variable grade is within the range 0 through 100 inclusive

if (grade=0 && grade=100) ```cout<< "the number is valid";

assume str1 and str2 and string objects that have been initialized with different values. write a if else statement that compares the tow objects and displays the one that is alphabetically greatest

if (str1>str2) ```cout<< str1; else ```cout<< str2;

What is the data type of the following function prototype's return value? int myFunction(double);

int

Assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Write a C++ statement that calls the accelerate function.

myCar.accelerate();

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?

outFile << number;

When a variable is assigned a number that is too large for its data type, it ...

overflows

The while loop is a ________________ loop

pre-test

A statement that starts with a hashtag (or pound) symbol (#) is called a ...

preprocessor directive

The ____________ members of a base class are never accessible to a derived class.

private

What access specifier is used to protect important data?

private access specifier

A function ___________ eliminates the need to place a function definition before all calls to the function.

prototype

The type of member function that may be called from a statement outside the class is...

public

Write a statement that dynamically allocates a Rectangle structure variable and use r to point to it.

r = new Rectangle;

C++ requires that a copy constructor's parameter be a(n)...

reference object

The special value that marks the end of a list of values is a ...

sentinel

What are the two primary ways C++ stores strings in memory? (#1, #2)

string class, character array, c_strings

When you work with a dereferenced pointer, you are actually working with... a. a variable whose memory has been allocated. b. a copy of the value pointed to by the pointer variable. c. the actual value of the variable whose address is stored in the pointer variable. d. None of these

the actual value of the variable whose address is stored in the pointer variable.

If you place a semicolon after the statement: if (x < y );

the compiler will interpret the semicolon as a null statement

When the final value of an expression is assigned to a variable, it will be converted to ...

the datatype of the variable

What will the following statement output? cout << &num1;

the memory address of the variable num1

what is the output #include <iostream> using namespace std; class TestClass { private: ```int val; ```{cout<< val<< endl;} public: ```TestClass (int x); ```{val= x;} }; int main { TestClass test(77); test.showVal(); return 0; }

the program will not compile

what will be displayed int num1=5; int num2=3; cout<<"the result is : "<< (num1*num2+10)<< end;

the result is 25

An array can store a group of values, but the values must be

the same data type

which of the following is true about the statement int *ptr= nullptr;

the variable named *ptr will store an asterisk and an integer variable

what is the output int x=5; if (x=2) ```cout<< "This is true!"<<endl; else ```cout<< "THis is false!"<<endl; ```cout<<"That's all folks!"<<endl;

this is true! that's all folks!

A(n) ________ is a special built-in pointer that is available to a class's member function.

this pointer

which of the following is true sum += *ptr++;

this statement assigns the dereferenced pointer's value then increments the pointer's address

Write a C++ statement that declares that a program will be accessing entities whose names are part of the namespace std.

using namespace std;

Assume that RetailItem is the name of a class, and it contains a void member function named setPrice which accepts a double argument. Write a C++ statement that correctly uses the scope resolution operator in the member function definition.

void RetailItem::setPrice(double p)

Write a prototype for a function named showValues. It should accept an array of integers (called 'arr') and an integer for the array size (called size) as arguments. The function should not return a value.

void showValues(int arr[], int size);

the following statement bookList[2].publisher[3]='t';

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

why do you need to know about c-strings as a C++ programmer

you may encounter legacy code that uses c-strings; some C++ library functions only work with c-strings; it is not unusual for C++ programmers to work with specialized libraries that are written in C

If you leave out the size declarator in an array definition

you must furnish an initialization list.


Kaugnay na mga set ng pag-aaral

Ch 104 client centered experience

View Set

Basic and Optional Parts of a Professional Business Letter

View Set

Lecture 7: Historical Development of US Health Insurance

View Set

NCLEX Review Study Guide (Summer 2022)

View Set

Chapter 8: Concepts and Generic Knowledge

View Set