C++ Final Chapters 7 8 9 10

Array indexes must be less than the size of the array.
What is wrong with the following code fragment?

const int SIZE = 5;

float scores[SIZE];

for(int i = 0; i <= SIZE;i ++) { cout << "Enter a scoren"; cin >> scores[i];

}

0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6
What is the output of the following code fragment?

int array[4][4], index1, index2;

for(index1 = 0;index1 < 4;index1 ++) for(index2 = 0;index2 < 4;index2 ++) array[index1][index2]=index1 + index2; for(index1 = 0;index1 < 4;index1 ++) { for(index2 = 0;index2 < 4;index2 ++) cout << array[index1][index2] << " "; cout << endl; }

We will write a custom essay sample on
C++ Final Chapters 7 8 9 10
or any similar topic only for you
Order now
0-24
What are the valid indexes for the array shown below?

int myArray[25];

for(i = 0;i < SIZE;i ++) cin >> array[i];
Which of the following will read values from the keyboard into the array?
(Assume the size of the array is SIZE).
void f1(int pages[ ][30], int size);
Which of the following function declarations will accept the following two-dimension array?

int pages[10][30];

result = search(array, target, numberOfElements);
Given the following function definition for a search function, and the following variable declarations, which of the following are appropriate function invocations?

const int SIZE = 1000;

int search(const int array[ ], int target, int numElements);

int array[SIZE], target, numberOfElements;

Add another parameter to indicate where to start searching.
Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of target in the array?

int search(const int array[ ], int target, int numElements)

{

int index = 0;

bool found = false;

while((!found) && (index < numElements)) { if(array[index] == target) found = true; else index ++; } if(found == true) return index; else return -1; }

scores[24]
Given an array named scores with 25 elements, what is the correct way to access the 25th element?
nothing
What is wrong with the following code?

float scores[10], total;

float array[3][5];
Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles?
int search(const int array[ ], int target, int numElements);
If we want a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate?
5
The following function definition has an error in it. What line is this error on?

0. void f1(const double array[ ], int size)

1. {

2. int i = 0;

3. while(i < size) 4. { 5. array[i] += 2; 6. cout << array[i]; 7. i ++; 8. } 9. }

for(i = 0;i < SIZE;i ++) array1[i] = array2[i];
Which of the following will correctly assign all the values in one array to the other array? (Assume both arrays are of the same type and have SIZE elements)
no
Given the following function definition, will repeated calls to the search function for the same target find all occurrences of that target in the array?

int search(const int array[ ], int target, int numElements)

{

int index = 0;

bool found = false;

while((!found) && (index < numElements)) { if(array[index] == target) found = true; else index ++; } if(found == true) return index; else return -1; }

pass by array.
Arrays are always passed to a function using
If you declare and initialize an integer array of size 10, but only list 5 values, what values are stored in the remaining 5 indexed variables?
void f1(const int array[ ], int size);
Which of the following function declarations correctly guarantee that the function will not change any values in the array argument?
void input(int array[ ], int &numElements, int MAX_SIZE);
Which of the following function declarations could be used to input data from the keyboard into the array?
It adds space for 3 integers to the base address of the array.
Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located?
the size of the c-string -1.
If you want to read into a c-string, you must ensure that the user does not enter more characters than
str1 = “toaster”;
Which assignment statements will copy the value ” toaster” into a string variable (str1)?
a c-string.
A character array terminated with the null character is most correctly called
any data type.
The base type for a vector can be
char s1[10];
Which of the following declarations correctly creates a c-string that can hold the value “phonebook”?
The values do not constitute a c-string.
What is wrong with the following attempted c-string declaration and initialization?

char str1[5] = {‘a’, ‘b’, ‘c’};

getline(fin, line);
Which of the following would correctly read an entire line from an input file stream named fin into a string variable named line?
vector < string > names;
What is the proper way to declare a vector of strings named names?
char s1[10] = “phonebook”;
Which of the following will declare a c-string and initialize it to the value of “phonebook”?
str1.insert(4,str2);
Given the following code, what is the correct statement to insert the string str2 into str1, directly after the ‘d’?

string str1 = “abcdefg”;

string str2 = “ABCDE”;

str1 does not have enough room.
What is wrong with the following code fragment?

char str1[10] = “Mark”,
str2[15] = “What’s my name”;

strcpy(str1,str2);

strcpy(str,”toaster”);
How can you assign the value “toaster” to a c-string name str?
numbers.push_back(newValue);
To add an element to a vector of integers named numbers at the next available position in the vector, you would use ________.
it skips all white spaces.
When the extraction operator is used to read data into a string,
str.length( )
Which is the proper way to determine how many characters are in the string variable named str?
the empty string
What is the value of str after the following code?

string str;

all the values in the vector are copied.
When a vector is assigned to another vector
100
What is the value of numbers.capacity( ) after the following code?

vector < float > numbers;

numbers.reserve(100);

The last 10 elements are removed.
If a vector named numbers has 20 elements in it, what is the result of executing the following statement?

numbers.resize(10);

What is the value of numbers.size( ) after the following code?

vector < float > numbers;

numbers.reserve(100);

What is the value of numbers.size( ) after the following code?

vector < float > numbers;

out_file.open(fileName.c_str( ));
If the name of a file to open is in the string variable name fileName, which of the following will correctly open the file for output?
100
What is the value of numbers.size( ) after the following code?

vector < float > numbers(100);

cout << *p1;
Which of the following statements correctly prints out the value that is in the memory address that the pointer p1 is pointing to?
int *p1, *p2, *p3;
Which of the following correctly declare 3 integer pointers?
p1 = &value;
Which of the following assigns to p1 the pointer to the address of value?
2
What is the output of the following code fragment?

int v1 = 2, v2 = -1, *p1, *p2;

p1 = & v1;

p2 = & v2;

p2 = p1;

cout << *p2 << endl;

the dot operator.
You specify an individual member of a struct by using
cout << person.birthday.year;
Given the following structure definitions, what is the correct way to print the person’s birth year?

struct DateType

{

int day;

int month;

int year;

};

struct PersonType

{

int age;

float weight;

DateType birthday;

};

PersonType person;

DateType today = {1,1,2000};
Given the following structure definition, what is the correct way to initialize a variable called today?

struct DateType

{

int day;

int month;

int year;

};

assignment or extraction operator.
To assign values to a structure variable, you use the
member names.
In a structure definition, the identifiers declared in the braces are called
missing semicolon
What is wrong with the following structure definition?

struct MyStruct

{

int size;

float weight;

}

×

Hi there, would you like to get such a paper? How about receiving a customized one? Check it out