scanf, fscanf and sscanf return ______.
EOF
Write the format specifier used to change the number of decimal places displayed in a floating point number to 3 decimal places.
"%.3f"
The format specifier that always shows the decimal point to display floating point numbers is the percent sign followed by the letter:
f
The special character used to mark the end of a C-string is called the ______ character.
null
The format specifier to display floating point numbers in the shortest notation is the percent sign followed by the letter:
g
When a file fails to open, fopen returns or evaluates as _______.
null
The format specifier to display floating point numbers in scientific notation is the percent sign followed by the letter:
e
______ is the safe function used to get a restricted length c-string from a file or the keyboard.
fgets
All data is input and output as ______ data.
character
When you are finished using a file you should close the file using the function _____.
fclose
Which functions read one character even if that character is a blank space?
fgetc, getc, getchar
"\n" is a ______ and '\n' is a _____.
string, character
The function used to open a file and return a FILE pointer for that file is ______.
fopen
Which statement correctly opens a file named project.txt for reading and holds the address of the FILE object in a variable named in_file?
A) in_file = project.txt
B) fopen(in_file, "project.txt", "r");
C) in_file = fopen("project.txt", "r");
D) in_file = "project.txt";
C) in_file = fopen("project.txt", "r");
The command fprintf(outfile, "%.2f", x);
A) outputs the floating point value x sent to outFile with 2 decimal places
B) writes integers as floating point numbers
C) set all output to the file designed in the FILE pointer outFile to have 2 decimal places
D) truncates x to 2 decimal places changing the value of x
A) outputs the floating point value x sent to outFile with 2 decimal places
The command fprintf(outFile, "%*d", width, x); is used to
A) set the filename of outFile to width characters
B) change the number of characters in the output
C) display the integer x in at least width characters
D) Use an entire line to output x
C) display the integer x in at least width characters
The fgetc function reads
A) one double value
B) one character value
C) one integer value
D) one float value
B) one character value
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 in it, which would be an appropriate declaration of the file name variable?
A) char filename(20);
B) char filename[20];
C) char filename;
D) char filename[21];
D) char filename[21];
To open an output file and add to the end of the data already in the file using the FILE pointer fp you would write _______.
A) append(fp, "project.txt");
B) fp = fopen("project.txt", APPEND);
C) fp = fopen("project.txt", "a");
D) *fp = fopen("project.txt", "a");
C) fp = fopen("project.txt", "a");
If the name of the input file was in a c-string variable named filename, which of the following is the correct way to open the file for reading and associate it with the FILE object referred to by the FILE pointer named inFile?
A) inFile = filename;
B) inFile = fopen(filename, "r");
C) inFile = "filename";
D) inFile = fopen("filename", "r");
B) inFile = fopen(filename, "r");
The function isalpha( arg )
A) returns true if arg is an alphabetical character
B) changes arg to be an alphabetical character
C) returns true if arg is in alphabetical order
D) sorts arg into alphabetical order
A) returns true if arg is an alphabetical character
Which of the following function declarations will correctly pass a FILE pointer to the function?
A) void display(FILE* out);
B) void display(out* FILE);
C) FILE<b> display(FILE</b> out);
D) void display(FILE out);
E) A and C
E) A and C
A(n) ________ is a variable that has unkown structure and is only modified through a pointer
variable called a handle through function calls.
A) class
B) opaque object
C) int
D) float
B) opaque object
What is wrong with the following code?
int test = 1;
while(test != EOF )
{
test = fscanf(fileIn, "%d", value); fprintf(fileout, "The next value is %d\n", value);
A) We have read past the end of the input file and output one garbage value.
B) We have written past the end of the output file.
C) nothing
D) A and B
A) We have read past the end of the input file and output one garbage value.
In order to read data from a file correctly you
A) do not need to know the kind of data in the file.
B) should prompt the user for the data you are looking for.
C) must know the kind of data in the file.
D) A and C
C) must know the kind of data in the file.
What is the output of the following code? char ch = 'G'; printf("%d\n", tolower(ch));
A) g
B) G
C) the integer value of 'G'
D) the integer value of 'g'
D) the integer value of 'g'
Which of the following is the correct way to close a file referred to by the FILE pointer variable
named outFile? 27)
A) fclose(outFile, "project.txt");
B) fclose(outFile );
C) close("outFile.txt");
D) close(outFile);
B) fclose(outFile );
If a file did not open correctly, you should
A) exit the program immediately. B) continue on anyway.
C) display an error message and take some suitable action such as exit.
D) display an error message and continue on.
C) display an error message and take some suitable action such as exit.
If the user types in the characters '1' and '0', and your program reads them into an integer variable
with no spaces in between using scanf and %d, what is the value stored into that integer?
A) 0
B) 1
C) 10
D) none of the above
C) 10
After a file is opened, before the FILE pointer is used for input and output, it should be
A) closed.
B) checked to see how big the file is.
C) checked to see if it opened correctly.
D) none of the above
C) checked to see if it opened correctly
Which function returns true if the character argument is a digit?
A) isspace
B) islower
C) isdigit
D) isalpha
C) isdigit
Which of the following is not used when using files for input and output?
A) opening the file
B) prompting the file to ask for data
C) ensuring that the file opened
D) closing the file
B) prompting the file to ask for data
We have a file that has a name in it, but the name is written one character per line. We need to write
this name to the screen without the newlines. What is wrong with the following code?
FILE *fileIn;
fileIn = fopen("file.txt", "r");
char ch;
while((ch = fgetc(fileIn)) != EOF)
{
putc(ch, stdout);
}
A) Our output has new lines in it.
B) cannot use put with cout
C) eof is not a member of an ifstream object.
D) Nothing is wrong.
A) Our output has new lines in it
Which of the following loop condition statements will read all the data in the file assuming that
each record in the file is two integer values, and you will read the first one into a variable named
intOne, and the other into intTwo?A) while(inFile)
B) while(fscanf(inFile, "%d%d", &intOne, &intTwo))
C) while(fscanf(inFile, "%d%d", &intOne, &intTwo) = = 2)
D) while(fscanf(inFile, "%d%d", intOne, intTwo))
E) A and B
C) while(fscanf(inFile, "%d%d", &intOne, &intTwo) = = 2)
When is the external name of the file used in the program?
A) never
B) any time you read or write to the file
C) when opening the file
D) only when reading from the file
C) when opening the file
+ is a format specifier flag that 36) A) displays a + in front of all numbers.
B) displays a + in front of positive numbers.
C) can be used to find the absolute value of an integer.
D) all of the above
B) displays a + in front of positive numbers
Which include directive is necessary for file IO?
A) #include < stdlib.h >
B) #include <stdio.h >
C) #include < iostream.h>
D) #include < fileIO.h >
B) #include <stdio.h >
The command fprintf(outFile, "%5d", x); is used to
A) change the number of characters in the output.
B) display the integer x in at least 5 characters.
C) always use 5 characters to display the output.
D) set the filename of outFile to 5 characters.
B) display the integer x in at least 5 characters
Which of the following is the correct way to determine if a file referred to in the FILE pointer
named inFile failed to open correctly after calling fopen?
A) if( inFile is not open )
B) if( inFile != NULL )
C) if( fail(inFile) )
D) if( inFile = = NULL )
D) if( inFile = = NULL )
The fputc function outputs
A) one float value.
B) one integer value.
C) one double value.
D) one character value.
D) one character value
The formatting options that were discussed for printf do not work for fprintf
F
Since the type FILE is an opaque object type and we only interact with it through pointers and
functions, we should never dereference a FILE pointer.
T
You must use a field width specifier in each format specifier that you want output in a certain field width.
T
FOPEN_MAX is a macro defined in stdlib.h
F
the fgets function will stop reading in characters if it encounters any whitespace character or the
end of file and makes sure that you cannot read more characters than indicated by the max
parameter.
F
The function gets is designed to read a c-string from standard input but is considered unsafe and should not be used because you do not list the buffer size in the argument list.
T
You may not have more than file open at any one time.
F
'\n' is two characters.
F
FILE pointers may be passed to a function.
T
You may have as many files open at once as you like.
F
Using functions in a program is called ________
Procedural Abstraction
What symbol is used to signify that a parameter is a pointer?
*
Given the following function definition fragment, fro which values of myInt should the function be tested?
int doSomething(int myInt)
{
if(myInt < 0)
{
//do some stuff here
}
return -1;
}
-1, 0, 1
A __________ is a simplified version of a function used to test the main program
Stub
A function that does not return a value is known as a __________ function
void
What is the correct way to call the following function?
void setDisplay( void );
set Display();
What is the most appropriate way to call the doThings function? Assume that you have two variables named var1 and var2 defined as follows.
int var1;
float var2;
void doThings(float x, int y);
doThings(var1, var2);
Testing a program with values that are close to values that will change the execution of a program is called _______
Boundary value testing
When the address of the actual argument is passed to the formal parameter, this allows us to mimic a parameter passing mechanism called __________
passed by reference
The items passed to a function are called ___________
Arguments
Pre and post conditions for a function should be written (before/after) the function definition is written.
Before
If we want to test if a given function works correctly, we would write a _________ to test it.
driver
A _________ is a main program that only checks that functions execute correctly.
driver
The values or variables listed in the function declaration are called _________ to the function.
Formal parameter
The & operator is called the ___________ operator.
address of
What type of value does a void function return?
Nothing
A simplified version of a function which is used to test the main program is called
a stub
Which of the following is a legal call to the displayOutput function assuming myTotal is an integer variable?
void displayOutput(int total);
displayOutput(myTotal);
A simplified main program used to test functions is called
a driver
If you were to write a function for displaying the cost of an item to the screen which function prototype would be most appropriate?
void display(float myCost);
Testing your program should be done
as each function is developed
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
boundary values
The postcondition of a function
Tells what will be true after the function executes
True or False: A function can call another function
True
When a void function is called, it is known as
an executable statement
To mimic Call-by-reference parameter passing, parameters are passed
thee address of the intended argument
Which of the following comments would be the best post-condition for this swap function?
void swap(int<b> left, int</b> right);
//Postcondition: the value at the addresses held in left and right are exchanged
If you need a function to get both the number of items and the cost per item from a user, which would be a good function declaration to use?
void getData(int count, float cost);
If a function needs to modify more than one variable, it must
Mimic pass by reference parameter passing by passing pointers
The deference operator, *, can be applied to
any expression that evaluates as an address
The precondition(s) for a function describe
What must be true before the function executes
Which of the following function prototypes are not valid?
void doSomething(int<b> x, int</b> y);
void doSomething(int* x, int y);
void doSomething( int x, int y);
All are not valid.
All are valid.
All are valid
A stub is a function that is completely defined and well tested
False
The dereference operator * is a unary operator meaning it only has one operand.
True
It is acceptable to have both normal variable and pointer variable parameters in the same function declaration
True
A void function can be used in an assignment
False
A function that passes the address of a variable as a parameter is allowed to make changes to the argument through the dereference operator.
True
It is illegal to call other functions from inside a function definition
False
Functions can return at most one value
True
A void function can return any value
False
In a function mimicking pass-by-reference parameters, the values of the actual arguments passed to the function are addresses
True
The following is legal in a void function:
return;
True
Constant variables that might be used in different functions should be ____.
global
When you want to execute a function in your program, you would make a function ____.
call or invocation
What is the output produced by the following code fragment?
int i = 3;
printf("%.2f\n", sqrt(pow(i,4.0));
9.00
Converting from one type to another is called ____.
casting
The ____ describes how the function will work.
function body
The absolute value function abs is located in the ____ library.
stdlib.h
#include <math.h> is known as an ____.
include directive
Algorithms are typically described in ____.
pseudo code