UML Comp 1010 Finals study guide (HW packets)

5.0(1)
studied byStudied by 79 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/248

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

249 Terms

1
New cards

scanf, fscanf and sscanf return ______.

EOF

2
New cards

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

"%.3f"

3
New cards

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

f

4
New cards

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

null

5
New cards

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

g

6
New cards

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

null

7
New cards

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

e

8
New cards

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

fgets

9
New cards

All data is input and output as ______ data.

character

10
New cards

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

fclose

11
New cards

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

fgetc, getc, getchar

12
New cards

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

string, character

13
New cards

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

fopen

14
New cards

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

15
New cards

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

16
New cards

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

17
New cards

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

B) one character value

18
New cards

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

19
New cards

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

20
New cards

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

21
New cards

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

22
New cards

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 display(FILE out);
D) void display(FILE out);
E) A and C

E) A and C

23
New cards

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

24
New cards

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.

25
New cards

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.

26
New cards

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'

27
New cards

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

28
New cards

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.

29
New cards

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

30
New cards

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

31
New cards

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

C) isdigit

32
New cards

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

33
New cards

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

34
New cards

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)

35
New cards

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

36
New cards

+ 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

37
New cards

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 >

38
New cards

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

39
New cards

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 )

40
New cards

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

D) one character value

41
New cards

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

F

42
New cards

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

43
New cards

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

T

44
New cards

FOPEN_MAX is a macro defined in stdlib.h

F

45
New cards

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

46
New cards

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

47
New cards

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

F

48
New cards

'\n' is two characters.

F

49
New cards

FILE pointers may be passed to a function.

T

50
New cards

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

F

51
New cards

Using functions in a program is called ________

Procedural Abstraction

52
New cards

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

*

53
New cards

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

54
New cards

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

Stub

55
New cards

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

void

56
New cards

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

set Display();

57
New cards

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

58
New cards

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

Boundary value testing

59
New cards

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

60
New cards

The items passed to a function are called ___________

Arguments

61
New cards

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

Before

62
New cards

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

driver

63
New cards

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

driver

64
New cards

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

Formal parameter

65
New cards

The & operator is called the ___________ operator.

address of

66
New cards

What type of value does a void function return?

Nothing

67
New cards

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

a stub

68
New cards

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

void displayOutput(int total);

displayOutput(myTotal);

69
New cards

A simplified main program used to test functions is called

a driver

70
New cards

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

71
New cards

Testing your program should be done

as each function is developed

72
New cards

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

73
New cards

The postcondition of a function

Tells what will be true after the function executes

74
New cards

True or False: A function can call another function

True

75
New cards

When a void function is called, it is known as

an executable statement

76
New cards

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

thee address of the intended argument

77
New cards

Which of the following comments would be the best post-condition for this swap function?

void swap(int left, int right);

//Postcondition: the value at the addresses held in left and right are exchanged

78
New cards

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

79
New cards

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

Mimic pass by reference parameter passing by passing pointers

80
New cards

The deference operator, *, can be applied to

any expression that evaluates as an address

81
New cards

The precondition(s) for a function describe

What must be true before the function executes

82
New cards

Which of the following function prototypes are not valid?

void doSomething(int x, int y);

void doSomething(int* x, int y);

void doSomething( int x, int y);

All are not valid.

All are valid.

All are valid

83
New cards

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

False

84
New cards

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

True

85
New cards

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

True

86
New cards

A void function can be used in an assignment

False

87
New cards

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

88
New cards

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

False

89
New cards

Functions can return at most one value

True

90
New cards

A void function can return any value

False

91
New cards

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

True

92
New cards

The following is legal in a void function:
return;

True

93
New cards

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

global

94
New cards

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

call or invocation

95
New cards

What is the output produced by the following code fragment?

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

9.00

96
New cards

Converting from one type to another is called ____.

casting

97
New cards

The ____ describes how the function will work.

function body

98
New cards

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

stdlib.h

99
New cards

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

include directive

100
New cards

Algorithms are typically described in ____.

pseudo code