UML Comp 1010 Finals study guide (HW packets)

studied byStudied by 78 people
5.0(1)
Get a hint
Hint

scanf, fscanf and sscanf return ______.

1 / 248

249 Terms

1

scanf, fscanf and sscanf return ______.

EOF

New cards
2

Write the format specifier used to change the number of decimal places displayed in a floating point number to 3 decimal places.

"%.3f"

New cards
3

The format specifier that always shows the decimal point to display floating point numbers is the percent sign followed by the letter:

f

New cards
4

The special character used to mark the end of a C-string is called the ______ character.

null

New cards
5

The format specifier to display floating point numbers in the shortest notation is the percent sign followed by the letter:

g

New cards
6

When a file fails to open, fopen returns or evaluates as _______.

null

New cards
7

The format specifier to display floating point numbers in scientific notation is the percent sign followed by the letter:

e

New cards
8

______ is the safe function used to get a restricted length c-string from a file or the keyboard.

fgets

New cards
9

All data is input and output as ______ data.

character

New cards
10

When you are finished using a file you should close the file using the function _____.

fclose

New cards
11

Which functions read one character even if that character is a blank space?

fgetc, getc, getchar

New cards
12

"\n" is a ______ and '\n' is a _____.

string, character

New cards
13

The function used to open a file and return a FILE pointer for that file is ______.

fopen

New cards
14

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");

New cards
15

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

New cards
16

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

New cards
17

The fgetc function reads
A) one double value
B) one character value
C) one integer value
D) one float value

B) one character value

New cards
18

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];

New cards
19

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");

New cards
20

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");

New cards
21

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

New cards
22

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

New cards
23

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

New cards
24

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.

New cards
25

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.

New cards
26

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'

New cards
27

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 );

New cards
28

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.

New cards
29

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

New cards
30

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

New cards
31

Which function returns true if the character argument is a digit?
A) isspace
B) islower
C) isdigit
D) isalpha

C) isdigit

New cards
32

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

New cards
33

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

New cards
34

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)

New cards
35

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

New cards
36

+ 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

New cards
37

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 >

New cards
38

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

New cards
39

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 )

New cards
40

The fputc function outputs
A) one float value.
B) one integer value.
C) one double value.
D) one character value.

D) one character value

New cards
41

The formatting options that were discussed for printf do not work for fprintf

F

New cards
42

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

New cards
43

You must use a field width specifier in each format specifier that you want output in a certain field width.

T

New cards
44

FOPEN_MAX is a macro defined in stdlib.h

F

New cards
45

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

New cards
46

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

New cards
47

You may not have more than file open at any one time.

F

New cards
48

'\n' is two characters.

F

New cards
49

FILE pointers may be passed to a function.

T

New cards
50

You may have as many files open at once as you like.

F

New cards
51

Using functions in a program is called ________

Procedural Abstraction

New cards
52

What symbol is used to signify that a parameter is a pointer?

*

New cards
53

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

New cards
54

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

Stub

New cards
55

A function that does not return a value is known as a __________ function

void

New cards
56

What is the correct way to call the following function?
void setDisplay( void );

set Display();

New cards
57

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);

New cards
58

Testing a program with values that are close to values that will change the execution of a program is called _______

Boundary value testing

New cards
59

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

New cards
60

The items passed to a function are called ___________

Arguments

New cards
61

Pre and post conditions for a function should be written (before/after) the function definition is written.

Before

New cards
62

If we want to test if a given function works correctly, we would write a _________ to test it.

driver

New cards
63

A _________ is a main program that only checks that functions execute correctly.

driver

New cards
64

The values or variables listed in the function declaration are called _________ to the function.

Formal parameter

New cards
65

The & operator is called the ___________ operator.

address of

New cards
66

What type of value does a void function return?

Nothing

New cards
67

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

a stub

New cards
68

Which of the following is a legal call to the displayOutput function assuming myTotal is an integer variable?

void displayOutput(int total);

displayOutput(myTotal);

New cards
69

A simplified main program used to test functions is called

a driver

New cards
70

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);

New cards
71

Testing your program should be done

as each function is developed

New cards
72

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

New cards
73

The postcondition of a function

Tells what will be true after the function executes

New cards
74

True or False: A function can call another function

True

New cards
75

When a void function is called, it is known as

an executable statement

New cards
76

To mimic Call-by-reference parameter passing, parameters are passed

thee address of the intended argument

New cards
77

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

New cards
78

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);

New cards
79

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

Mimic pass by reference parameter passing by passing pointers

New cards
80

The deference operator, *, can be applied to

any expression that evaluates as an address

New cards
81

The precondition(s) for a function describe

What must be true before the function executes

New cards
82

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

New cards
83

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

False

New cards
84

The dereference operator * is a unary operator meaning it only has one operand.

True

New cards
85

It is acceptable to have both normal variable and pointer variable parameters in the same function declaration

True

New cards
86

A void function can be used in an assignment

False

New cards
87

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

New cards
88

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

False

New cards
89

Functions can return at most one value

True

New cards
90

A void function can return any value

False

New cards
91

In a function mimicking pass-by-reference parameters, the values of the actual arguments passed to the function are addresses

True

New cards
92

The following is legal in a void function:
return;

True

New cards
93

Constant variables that might be used in different functions should be ____.

global

New cards
94

When you want to execute a function in your program, you would make a function ____.

call or invocation

New cards
95

What is the output produced by the following code fragment?

int i = 3;
printf("%.2f\n", sqrt(pow(i,4.0));

9.00

New cards
96

Converting from one type to another is called ____.

casting

New cards
97

The ____ describes how the function will work.

function body

New cards
98

The absolute value function abs is located in the ____ library.

stdlib.h

New cards
99

#include <math.h> is known as an ____.

include directive

New cards
100

Algorithms are typically described in ____.

pseudo code

New cards

Explore top notes

note Note
studied byStudied by 5 people
... ago
5.0(1)
note Note
studied byStudied by 13 people
... ago
5.0(1)
note Note
studied byStudied by 1 person
... ago
5.0(1)
note Note
studied byStudied by 16 people
... ago
5.0(1)
note Note
studied byStudied by 12 people
... ago
5.0(1)
note Note
studied byStudied by 16 people
... ago
5.0(1)
note Note
studied byStudied by 18 people
... ago
5.0(1)
note Note
studied byStudied by 245 people
... ago
5.0(2)

Explore top flashcards

flashcards Flashcard (86)
studied byStudied by 20 people
... ago
5.0(1)
flashcards Flashcard (102)
studied byStudied by 15 people
... ago
5.0(1)
flashcards Flashcard (59)
studied byStudied by 28 people
... ago
5.0(4)
flashcards Flashcard (53)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (49)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (179)
studied byStudied by 32 people
... ago
5.0(1)
flashcards Flashcard (82)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (41)
studied byStudied by 11 people
... ago
5.0(1)
robot