CSCI 1943 (p. 2)

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

Which of the following data types can be used to create files and read information from them into memory? A. ifstream B. istream C. ofstream D. None of these E. instream

A. ifstream

Data types that are created by the programmer are known as

Abstract Data Types (ADTs)

A two-dimensional array of characters can contain ________. strings of different lengths All of these uninitialized elements None of these strings of the same length

All of these

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

All of these

Which of the following statements is NOT valid C++ code? int ptr = &num1; All of these are valid All of these are invalid float num1 = &ptr2; int ptr = int *num1;

All of these are invalid

Look at the following structure declaration. struct Circle { double centerX; double centerY; double radius; } ; Assume that circle1 and circle2 are variables of the Circle type, and their members have been initialized. True/False: The following if statement correctly determines whether the two variables' members contain the same data:

False

True/False: A linear search can only be implemented with integer values.

False

True/False: Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.

False

True/False: Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

False

True/False: In C++ 11, the range-based for loop is best used in situations where you need the element subscript for some purpose.

False

True/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.

False

True/False: Only one file stream object can be declared per C++ program.

False

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

False

True/False: The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.

False

True/False: To write to a file, you use the file_write() function.

False

True/False: Using a binary search, you are more likely to find an item than if you use a linear search.

False

True/False: With pointer variables you can access, but you cannot modify, data in other variables.

False

When data is read from a file, it is automatically stored in a variable. True False

False

Data that is to be sorted in ascending order is ordered

From lowest to highest value

What does the following statement do? vector<int> v(10, 2);

It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.

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

None of these

Which of the following will allow you to access structure members?

The dot operator

True/False: A pointer can be used as a function argument, giving the function access to the original argument.

True

True/False: A vector object automatically expands in size to accommodate the items stored in it

True

True/False: An alternative to using the open member function is to use the file stream object declaration itself to open the file. Example: fstream DataFile("names.dat", ios::in | ios::out);

True

True/False: An anonymous union declaration actually creates the member variables in memory.

True

True/False: An array name is a pointer constant because the address stored in it cannot be changed during runtime.

True

True/False: C++ 11 introduces a function named to_string that converts a numeric value to a string object.

True

True/False: Each individual element of an array can be accessed by the array name and an element number, called a subscript.

True

True/False: File output may be formatted the same way as console screen output.

True

True/False: If a file already exists, you can open it with the flags ios::in | ios::out to preserve its contents.

True

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

True

True/False: If an array is partially initialized, the uninitialized elements will be set to zero.

True

True/False: In C++ 11, the nullptr key word was introduced to represent the address 0.

True

True/False: It is legal to subtract a pointer variable from another pointer variable.

True

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

True

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

True

True/False: The ios::out flag causes the file's existing contents to be deleted if the file already exists.

True

True/False: The isdigit function will return a true if its argument is a digit between 0 and 9.

True

True/False: The number of comparisons made by a binary search is expressed in powers of two.

True

True/False: When using the strcat function, you must be careful not to overwrite the bounds of an array.

True

True/False: 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

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

True

Given the following structure declaration, idNum is struct Employee { string name; int idNum; } ;

a member

Given the following structure declaration, idNum is struct Employee { string name; int idNum; };

a member

Which of the following describes only the general characteristics of an object?

abstraction

Every byte in the computer's memory is assigned a unique

address

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

ampersand (&)

Which of the following can be used as pointers?

array names

The function that accepts a C-string containing a number as its argument and returns the integer equivalent is

atoi

Which of the following converts the string "10" to the integer value 10? itoa("ten"); itoa(10); None of these atoi("ten"); atoi("10");

atoi("10")

The function that accepts a C-string as an argument and converts the string to a long integer is

atol

Which of the following statements displays the address of the variable numb?

cout << &numb;

True/False: Assuming myValues is an array of int values, and index is an int variable, both of the following statements do the same thing.

cout << myValues [index] << endl ; cout << * (myValues + index) << endl ;

Which of the following statements outputs the value of the gpa member of element [1] of the student array?

cout << student[1].gpa;

Which of the following statements opens a file named info.txt for both input and output?

dataFile.open("info.txt", ios::in | ios::out);

A declaration for an enumerated type begins with the ________ key word.

enum

To determine whether a character entered is whitespace, use the ________ function.

isspace

A(n) ________ search uses a loop to sequentially step through an array.

linear

The ________ is adequate for searching through small arrays.

linear search

null terminator

marks the end of a string

A pointer variable is designed to store

memory address

Outside of a C++ program, a file is identified by its ________while inside a C++ program, a file is identified by a(n) ________.

name, file stream object

The function that reverses the order of a C-string is

none of these

The name of a structure is referred to as its

none of these

The ________ is automatically appended to a character array when it is initialized with a string constant.

null terminator

Which of the following is the data type that can be used to create files and write information to them but cannot be used to read information from them?

ofstream

In order, the three-step process of using a file in a C++ program involves

open the file, read/write/save data, close the file

Which of the following is the member function that writes a single character to a file?

put

Closing a file causes any unsaved information still held in the file buffer to be

saved to the file

A ________ algorithm is a method of locating a specific item of information in a larger collection of data.

search

A ________ algorithm is a method of locating a specific item of information in a larger collection of data. linear

search

A function may return a pointer but the programmer must ensure that the pointer

still points to a valid object after the function ends

An array of string objects that will hold 5 names would be declared using which statement?

string names[5];

The function that accepts a pointer to a C-string as an argument and returns the length of the C-string, not including the null terminator is

strlen

How many elements does the following array have? int bugs [1000] ;

1000

What will the following code output? int *numbers = new int[5] ; for (int I = 0 ; I <= 4; i++) * (numbers + i) = i; cout << numbers [2] << endl;

2

What will the following code output? int *numbers = new int[5] ; for (int i = 0; i <= 4; i++) * (numbers + i) = i; cout << numbers [2] << endl;

2

Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared.

20,000

What is the last legal subscript that can be used with the following array? int values [5] ;

4

When a structure is passed ________ to a function, its members are NOT copied.

by reference

Which of the following is a valid C++ array definition? float $payments[10]; int array[0]; int array[10]; void numbers[5]; None of these

int array [10]

Which of the following is the state bit that is set when an attempted operation fails?

ios : : failbit

Which of the following access flags, when used by itself, causes a file's contents to be deleted if the file already exists?

ios::out

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

isdigit

The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 to size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with array[start] End For

selection sort

The ________ sort usually performs fewer exchanges than the ________ sort.

selection, bubble

A two-dimensional array is like ________ put together.

several identical arrays

The advantage of a linear search is its

simplicity

Array elements must ________ before a binary search can be performed.

sorted

Algorithms used to arrange random data in some order are ________ algorithms.

sorting

If Circle is a structure tag, then the following statement can be the header line for a function that ________. Circle doSomething(Circle c2)

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

If Circle is a structure tag, then the following statement can be the header line for a function that ________.Circle doSomething(Circle c2)

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

When you work with a dereferenced pointer, you are actually working with

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

In C++11, assuming mychar is a char variable and mystring is a string, what is the value of mychar after the following statement executes?mychar = mystring.front();

the first character of mystring

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

the memory address of the variable named num1

The ________ function will change a character argument from lowercase to uppercase.

toupper

What is the result after the following statement executes? char var1 = tolower('A');

var1 stores the ASCII value for lowercase 'a'

Which statement correctly uses C++ to initialize a vector of ints named n with the values 10 and 20?

vector<int> n { 10, 20 };

If you leave out the size declarator in an array definition:

you must furnish an initialization list


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

fina4210 exam 2 ch3, recap, ch 4, ch 5

View Set

Chapter 40: Fluid, Electrolyte, and Acid-Base Balance

View Set

Ch. 24 - The Male Reproductive System

View Set

WH Prieto Chapter 7 Sec. 3-4 Review

View Set

ECON 401 Midterm (Chapters 4, 5, 6 & 7)

View Set

Med Surge (Lewis) Exam 1 - Evolve Q&A

View Set