Exam 2 Flashcards

(93 cards)

1
Q

A void function can be used in an assignment

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

It is acceptable to have both call by value and call by reference parameters in a function?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In a function with call-by-reference parameters, the values of the actual arguments are called through the function?

A

False. The memory address is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Testing a function or program using test values that are at or near the values that change the outcome of the program is known as using _____ values?

A

Boundary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

It is illegal to call other functions from inside a function definition?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A stub is a function that is completely defined and well tested?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A simplified main program for testing is called?

A

a driver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In a function with call-by-reference parameters, any changes to the formal parameters will change the actual arguments passed to the function?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

void something(int a, int& b)

{
int c;
c= a + 2;
a = a*3;
b = c+a;
}

r =1;
s=2;
t=3;
something(t,s);

cout &laquo_space;r &laquo_space;’ ‘ &laquo_space;s &laquo_space;’ ‘ &laquo_space;t &laquo_space;endl;

A

1 14 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If you were to write a function for displaying the cost of an item to the screen. which function prototype would be appropriate?

void display();
void display(float myCost);
int display(float myCost);
float display();
A

void display(float myCost);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In the following function, what is passed to the first parameter?

void f1(int& value1, int value2);

int x,y;
f1(x,y);

  1. The value of x
  2. Nothing, it is a void function
  3. The value of y
  4. The variable x(or its memory location)
A
  1. The variable x(or its memory location)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Functions can return at most one value

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

the following is legal in a void function

return;

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If a function needs to modify more than one variable, it must be a…

A

Call by reference function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

a void function may not be used in an output statement

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

if you write a function that should use call-by-reference, but forget to include the ampersand..

A

the program will run with incorrect results. it will pass it with a call by value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Given the following function definitions and program fragments, what is the output?

void f2(int &z, int &q);

int x=3, y=4;
f2(y,x);
cout &laquo_space;x &laquo_space;” “ &laquo_space;y &laquo_space;endl;

A

3 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Testing your program should be done as each ____ is developed

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Call by reference parameters are passing

A

The address of the actual argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Call by reference should be used when the function needs to change __________

A

The value of one or more arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

A simplified version of a function which is used to test the main program is called a

A

stub

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
void shift(int& a, int&b)
{
a = b;
b = a;
}

what is the output after the following:

int first = 0, second =10;

shift (first, second);

cout &laquo_space;first &laquo_space;” “ &laquo_space;second &laquo_space;endl;

A

10 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
int myInt;
float myFloat;
char ch;
void someFunction(int & first, float second, char third);

Which is invalid?

someFunction(1,2.0,ch);
someFunction(myInt, myFloat, ch);
someFunction(myInt,2.0,’c’);
someFunction(myInt,myFloat,’1’);

A

someFunction(1,2.0,ch);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A void function can return any value

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
If you need a funtion to get both the number of items and cost per item from a user, which would be a good function declaration? ``` int, float getData(); int getData(float cost); void getData(int count, float cost) void getData(int& count, float& cost); ```
void getData(int& count, float& cost);
26
If the user types the characters 10 and your program reads them into an integer variable, what is the value stored into that integer?
10
27
To open a file with a user supplied name, you would need to store the name in a variable. If the file name was to have no more than 20 characters, which is an appropriate declaration? ``` char filename[21]; char filename[20]; char filename; char filename(20); ```
char filename[21];
28
When is the external name of the file used in the program?
When opening the file stream
29
The command outFile.precision(2) displays...
All floating point values sent to OutFile with 2 decimal places
30
What is the include directive necessary for file I/O?
#include < fstream >
31
What is the include directive necessary for setw?
#include < iomanip >
32
Write the correct way to determine if a file stream named inFile opened correctly
if(inFile.fail()) { }
33
The command outFile.width(10) is used to
display the next value in at least 10 characters
34
What is wrong with: ``` while (!filein.eof()) { fileIn >> value; fileOut << value; } ```
We have read past the end of the input file and attempt to output a nonexistent value
35
Which of the following will read all the data in the file assuming that each record is 2 integers and you will need to read into IntOne and the other into intTwo while(InFile >> intOne >> intTwo); while(inFile << intOne << intTwo); while(infFile(intOne,intTwo)); while(inFile);
while(InFile >> intOne >> intTwo);
36
If the name of the input file was a variable named filename, what is the correct way to open the input stream named inFile and associate it with this file?
inFile.open(filename);
37
You must use a width statement before each variable that you want to output in a certain width
True
38
To open an output file named project.txt and add to the end of the data already in the file you would write
outFile.open("project.txt", ios::app);
39
Two different objects of the same class have a different set of member functions
False
40
Data that is sent to an output stream representing a file will be immediately saved to disk
False
41
Which function returns TRUE if the character argument is a letter?
isalpha
42
Which function returns TRUE if the character argument is a digit?
isdigit
43
Which function returns TRUE if the character argument is uppercase?
isupper
44
In order to read data from a file you must know the ______ in the file
kind of data
45
After a stream is opened, before it is used for input and output it should be
checked to see if it opened correctly
46
The member function setf stands for
set flag / set the flags
47
C++ standard stays return 0 can be omitted on void functions
true
48
Which symbol calls memory location and declares it is a call by reference parameter?
&
49
call by reference is less secure than call by value
true
50
Procedural abstraction means your __ and function ___ should be sufficient for black box analogy
comment and prototype
51
precondition comment
what is assumed to be true
52
post condition comment
effects of function call
53
which include directive is necessary for assert?
#include < cassert >
54
___ if this is false, program will abort and have a safe exit from the program
assert assert(n>0);
55
File input allows for ___ data storage
permanent
56
file I/O first step is the include directive of
#include < fstream >
57
file I/O second step is the declaration of
ifstream and ofstream file variables ifstream inputFile; ofstream outputFile;
58
file I/O third step is the opening of
input and output files inputFile.open("myfile.txt"); outputFile.open("yourfile.txt");
59
file I/O fourth step is checking
to ensure file opened
60
file I/O final step is to
close the files inputFile.close(); outputFile.close();
61
Extraction >> operators can be used normally on properly declared files
True
62
Insertion << operators can be used on properly declared output files
True
63
Char has how many bytes
1
64
int has how many bytes
4
65
Arrays must be
Sequential in memory and all the same data type
66
Closing files reduces the chances of ____
corruption
67
___ operators call member functions
dot
68
The ___ determines member functions of an object
class
69
the include directive for exit
#include < cstdlib >
70
unsetf(ios::showpos) will...
unset the positive flag
71
setw() does?
can set the width when used in the print out command directly cout << setw(4) << 10 << setw(4) << 100 << endl;
72
'get'
reads one char from an input and stores as type char, including spaces and newline characters char next_symbol; cin.get(next_symbol);
73
Properly write the end of file boolean statement to continue a loop to read until end of file (using get)
if(!in_stream.eof()) { in_stream.get(next); }
74
char alphabet[25]; What is the value in brackets called and what does it refer to?
Subscript or index and refers to how many elements are within the array
75
Can you go past and read past a declared array?
yes, but there will be junk in that file
76
Which of the following function declarations can be passed the following array? char myArray[6][8] 1. void f1(char a[][], intsizeOfFirst); 2. void f1(char a[][8], intsizeOfFirst); 3. void f1(char & a, intsizeOfFirst); 4. void f1(char a[6][8], intsizeOfFirst);
1 and 4
77
Which line is the error on? void f1(const double array[], int size) { int i = 0; while (i < size) { array[i] +=2; i++; } }
line 0 this is declared as const and then tries to change array in definition
78
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?
0
79
Given the following, what needs to be modified to the search function so that it finds all occurrences of target? ``` 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;
Add another parameter to indicate where to start searching
80
Name 3 reasons to use a constant for the SIZE of an array
Readability Easier to make changes Reduce logic errors
81
adding what in the functino declaratinos guarantees that the function will not change any values in the array argument?
const
82
the following array declaration is legal: double scores[]={0.1,0.2,0.3};
True
83
is this legal? float scores[10], total;
yes
84
What is the output of this code? int arr[] = { 1, 2, 3 }; for(int &element:arr) element+=10; for (int element : arr) cout << element << endl;
11 12 13
85
Which is an appropriate function invocation? const int SIZE = 1000; int seach(const int array[], int target, int numElements); int array[SIZE], target, numberofElements; 1. search(array[0], target, numberOfElements); 2. result = search(array[0], target, numberOfElements); 3. result = search(array, target, numberOfElements); 4. result = search(array, target, SIZE);
3
86
Correctly use C++11's range-based for statement to iterate through every element of the array variable arr
for(auto x : arr)
87
Do both of these declare and initiate an array of 5 characters to some known values? char array[5]={'a','b','c','d','e'}; char array[5]={"};
Yes
88
Arrays can be passed to functions
True
89
Which of the following declarations would accept the following 2D array? 1. void f1(int pages[][], int size); 2. void f1(int pages[][30], int size); 3. void f1(int pages[10][], int size); 4. void f1(int&pages, int size);
2
90
A 2D array can be thought of as a ___ and an ____
table, array of arrays
91
If you need a function that will handle multi dimensional arrays, you must specify the following sizes inside the square brackets
all sizes except the first dimension
92
Arrays are always passed to a function using
Pass by array
93
Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located?
It adds space for 3 integers to the base address of the array.