CSCI 1170 Final Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Suppose the file numbers.dat does not exist. If the following snippet was in your main function, what would be the output?
std: :ofstream my_file;
my_file. open (“numbers. dat”) ;
if ( !my_file ){
std: : cout &laquo_space;“Potato” &laquo_space;std::endl;
} else {
std: :cout &laquo_space;“Success” &laquo_space;std::endl; }

A

Success

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

In the following function definition (line numbers provided for reference:
1 void B(int a, int b){
2 b + a+3;
3 cout &laquo_space;a &laquo_space;” “ &laquo_space;b &laquo_space;endl;
4 }

Line 1 in the definition above is referred to as the ____?

A

Function Header

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

Read the following program.
#include <iostream></iostream>

void ClaculateSum (int &sum) {
sum = 0;
for (int i = 0; i < 5; i++)
sum +=i;
}
int main(){
int sum = 0;
CalculateSum(sum);
std::cout &laquo_space;sum &laquo_space;std::end;
}

What is the printed value at the end of execution?

A

10

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

Given the following definition:
int values [5] = {1,2,3};
What will the following statement display?
std::cout &laquo_space;values[3] &laquo_space;std::endl;

A

0

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

Given the following assignment statement: double result = 15 / 16;
What is the value stored in the result?

A

2.0

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

Which of the following code snippets does not produce the same output as the rest?

int x = 1;
While (x <= 5) (
std:: cout « “I’m here!”
&laquo_space;std: :endl;
}
for(int i = 10; 1> 0; 1 == 4)1
std:: cout <
“I’m here!”
&laquo_space;std:: endl;
}
int x = 0;
while (x<5) (
x++;
std:: cout « “I’m here!”
« std: :endl;
}
for (int i = 1; 1 < 5; i++) (
std:: cout «
“I’m here!”
< std:: endl;
}

A

for (int i = 1; 1 < 5; i++) (
std:: cout «
“I’m here!”
< std:: endl;
}

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

Every C++ program MUST have a—–?

A

main function

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

Read the following code:

std::string first_name = “Locke”;
char middle_init = ‘L;
std: string last_name = “Lamora”;
std::cout &laquo_space;last_name &laquo_space;middle_init &laquo_space;first_name «< ‘In’;
What is printed out after the above code is executed?

A

LamoraLLocke

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

Assume that in_file has been defines as a file object you can read from.
int value;
in_file&raquo_space; value;
The statements above would create a variable called value and repeatedly read from the file until no values were left in it.

A

False

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

Consider the following function definition:
___ getGrade (double score)
{ if (score >= 90.0)
return ‘A’;
else if (score >= 80.0)
return ‘B’:
else if (score >= 60)
return ‘D’;
else
return ‘F’;

What should the return type of the function be?

A

char

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

Read the function definition:
void myFunction(int value) {
if (value !=0) {
cout &laquo_space;“Hello” &laquo_space;endl;
} else {
return;
}
}

The return statement causes an error when trying to compile. (T or F)

A

False

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

Read the following function prototypes:
int DoSomething (int value, int size) ; double DoSomething (double value, int size) ;
float DoSomething (float value, int size) ; void DoSomething (int value, int size) ;
Would all of these functions be allowed in a single program in C++ as overloaded functions?
MacBook Pro

A

No because the integer returning function and the void function have the same function signature due to the return type being ignored when looking at a function’s signature.

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

Read the following code snippet:
int = = 0;
int k;
while (i < 10) (
for (k = 4; k <= 6; k++) {
sta:: cout «< “Hello”
&laquo_space;std: :endl;
}
i +=2:
}
How many times total is “Hello” printed?

A

15

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

The following array declaration would create an array of size 10 and initialize all values in the array to 0.
int numbers [10];

A

False

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

What would be output by the following code?
bool even = false;
if (even = true);
{
std::cout &laquo_space;“It is even!”;
} else {
std::cout &laquo_space;“It is odd!”;
}

A

It is even!

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

In C++ the name (identifier) of an array is really the address of the beginning/first element. (T o F)

A

True

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

Suppose x = 1, y = -1, and z = 1. What willbe displayed by the following statement?
(remember that indentation doesn’t matter in C++)
1f
(x > 0)
if (y > 0)
std:: cout < “x > 0 and y > 0” « std:: endl;
else if (z > 0)
std:: cout
&laquo_space;“x < 0 and z > 0” < std: :endl;

A

x < 0 and z > 0

18
Q

What data type uses the most memory?

A

double

19
Q

The decision structures in the following two code snippets are equivalent. That is to say, both will produce the same output given the same values for a, b, and c.
One
if (a > b if (a > c)(
std:cout <くaく<Nn’;
) else 1
std: cout «< c«< In’ ;
} else {
if (b > c)(
std:cout <^b^^1n’:
) else (
std:cout <^ c<s Nn’:

Two
if (a > b 8& a > c
std:cout &laquo_space;a &laquo_space;In’ ;
I else if (b >= a && b > c) (
std:cout «b&laquo_space;Nn’ ;
} else {
std:cout &laquo_space;c «< In’ :

A

True

20
Q

Assume all variables have been declared properly and all includes are there.
The following is a valid assignment statement: sqrt(b b + c c) =a;

A

False

21
Q

The following statement would result in [2, 3, 4, 5] being placed in an array of size 4 because the compiler can determine how large it should be based on the initialization syntax.
int myarray [] = (2, 3, 4, 5);

A

True

22
Q

The following statement would result in what values being in the array?
int myarry[5] = {3};

A

3 0 0 0

23
Q

Read the following code snippet (assume that my_file has been created and opened correctly such that it can be written to)
my_file « “John” &laquo_space;” “ &laquo_space;“D” «
“ “ &laquo_space;“Doe”;
std:: cout &laquo_space;std: :endl;
my_file « “Sally &laquo_space;” “ &laquo_space;“S” «< “ “ « “Sandy” &laquo_space;std:: cout &laquo_space;std::endl;
What is the output?

A

John D DoeSally S Sandy

24
Q

Read the following code:
std::string name_one = “BROCK”
std::string name_two = “BRANDON”
if (name_one > name_two) {
std::cout &laquo_space;“BROCK is greater than BRANDON\n”;
} else {
std::cout &laquo_space;“BRANDON is greater than BROCK\n”;
}
What would the output be?

A

BROCK is greater than BRANDON

25
Q

How many bytes of memory does the following array declaration use?
char alphabet[26];

A

26

26
Q

Which header file would you need to include if you wanted setprecision?

A

<iomanip>
</iomanip>

27
Q

Given the following array definition:
double my_array[20];
How much memory in bytes will this array use?

A

160

28
Q

Read the following program.
#include <iostream></iostream>

void ClaculateSum (int sum) {
sum = 0;
for (int i = 0; i < 5; i++)
sum +=i;
}
int main(){
int sum = 0;
CalculateSum(sum);
std::cout &laquo_space;sum &laquo_space;std::end;
}

What is the printed value at the end of execution?

A

0

29
Q

A byte consists of how many bits?

A

8

30
Q

A while loop is ideal for performing ____ iterations?

A

0 or more

31
Q

What is the name and operator used to send get input from cin?

A

Extraction Operator&raquo_space;

32
Q

Read the following program.
#include <iostream></iostream>

void ClaculateSum (int sum) {
sum = 0;
for (int i = 0; i < 5; i++)
sum +=i;
}
int main(){
int sum = 0;
CalculateSum(SUM);
std::cout &laquo_space;sum &laquo_space;std::end;
}

What is the printed value at the end of execution?

A

Argument

33
Q

If you try to open a file to read from it, and the file does not exist, the program will fail to compile

A

False

34
Q

Recall from math that the slope formula is:
m =
y2-y1
———
x2-x1

Assume the variable names y2, y1, x2, and x1 already exist in your program as integer values. Which of the following assignment statements would correctly calculate the slope and store it in a floating-point variable called m.

A

double m = static_cast<double>(y2-y1) / (x2 - x1);</double>

35
Q

Read the following code:
std::string name_one = “Betty”;
std::string name_two = “betty”;
if (name_one == name_two) {
std::cout &laquo_space;“Names are the same \n”;
} else {
std::cout &laquo_space;“Names are different\n”;
}
What would the output be?

A

Names are different

36
Q

Given the following array definition:
int values (] = 12, 6, 10, 14};
What would the following output statement display? std:: cout &laquo_space;values [-1]
< std:: endl;

A

Unknown, the program will compile but -1 is not within the bounds so we can’t guarantee anything.

37
Q

The for loop is a post test loop.

A

False

38
Q

Which of the following logical expressions would be true if the value of count is between 0 and 100 inclusive?
* ( count >= 0 || count <= 100)
* ( count >= 0 && count <= 100)
* ( count 0 || count < 100)
* ( count > 0 && count < 100)

A

( count >= 0 && count <= 100)

39
Q

Which header file would you need to include to use various mathematical functions such as sqrt() and pow()?

A

<cmath>
</cmath>

40
Q

The if statement is also known as repetition structure.

A

False

41
Q

What is the name and operator used to send output to count?

A

Insertion Operator «