Midterm Flashcards

1
Q
  1. Arrays in C++ must have a fixed size that is determined at the time of declaration.
  2. Elements in an array are stored in contiguous memory locations.
  3. It is possible to have arrays with a variable size that can be changed at runtime.

The Lie is #?

A

3

arrays must have a fixed size that is determined at the time of declaration and can not be changed later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. The index of the first element in an array is always zero (0).
  2. The size of an array is stored as a member variable of the array.
  3. It is possible to initialize an array in C++ using a loop.

The lie is #?

A

2

Array doesn’t have any member variable to store the size of an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. It is possible to pass an entire array as an argument to a function.
  2. The elements of an array in C++ are stored in the order they are declared.
  3. It is possible to have a multidimensional array using only one pair of square brackets.

The lie is #?

A

3

To have a multidimensional array, multiple pairs of square brackets are required, one for each dimension.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. It is not possible to copy the values of one array to another array using the assignment operator.
  2. The for-each loop can be used to iterate through the elements of an array.
  3. C++ arrays have a built-in method to sort their elements in ascending or descending order.

The lie is #?

A

1

It is possible to copy the values of one array to another array using the assignment operator in C++ using (=).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. It is possible to create an array of pointers in C++.
  2. A single-dimensional array can be passed to a function as a reference.
  3. It is not possible to use the relational operators such as <, >, <=, >= to compare two arrays.

The lie is #?

A

3

it is possible to use the relational operators such as <, >, <=, >= to compare two arrays, as long as the arrays are of the same type and size.

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

What is a type of array that can store multiple arrays with the same data type?

A

Multidimensional

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

What is Function?

A

Subprogram that performs task.

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

What is function overloading in C++?

A

Using same function name multiple times.

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

What are function parameters in C++?

A

Using same function name multiple times.

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

What are function parameters in C++?

A

Information passed to a function.

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

What is function return type?

A

Data type of returned value.

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

Can a function return multiple values?

A

No, only one value returned

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

What are user-defined function types?

A

Custom data types.

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

A function that calls itself

A

Recursion

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

Can a function be declared inside main?

A

Yes

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

What is the purpose of function overloading in C++?

A

To use same name, different tasks.

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

What is a default argument in C++?

A

Predetermined value for parameter.

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

T/F Function overloading allows multiple functions with same name.

A

True

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

T/F Default arguments are mandatory in C++.

A

False

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

T/F Function prototypes are only used for functions with no return type.

A

False

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

T/F Inline functions can only be declared inside main.

A

False

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

T/F Reference parameters are alternative to values.

A

False

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

What is the purpose of function parameters?

A

To pass information to a function.

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

What is the purpose of default arguments?

A

To provide predetermined values for parameters.

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

What is the purpose of function return type?

A

To specify data type of returned value.

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

What is the purpose of user-defined function types in C++?

A

To create custom data type for functions.

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

What is the purpose of function overloading in C++?

A

To use same function name for different tasks.

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

The code “int max (int num1, int num2);” is a Function _____

A

Declaration

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

What are the mandatory parts of a function declaration?

A

Return type and function name

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

A type of variable inside a function

A

Local

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

In C++, which of the following is TRUE?

All of the mentioned

Function can have no argument but no return value

Functions can have no argument and no value

Function can have no argument but return value

A

All of the mentioned

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

A function can be called from another function using its __

A

name

33
Q

Which of the following is NOT included in a function declaration?

Colon :

function_name

semicolon ;

parameter list

A

colon :

34
Q

Which of the following is NOT a proper function prototype (definition)?

func(int x)

void funct();

int secondfunct (char x, char y) ;

char letter();

A

func(int x)

35
Q

Where does the “return statement” return the execution of the program?

A

main function

36
Q

include <iostream></iostream>

using namespace std;
void f1()
{
cout «1;}
int main()
{
f1();
goto x;
cout &laquo_space;“hello”;
x: cout &laquo_space;“hi”;
return 0;}

What is the output of the following code?

A

Error

37
Q

Which of the following doesn’t return a value?

void myPassingGrade(int x, int y)

double myPassingGrade (double p, double q)

int myPassingGrade (double p, double q, double r)

int myPassingGrade(int z)

A

void myPassingGrade(int x, int y)

38
Q

Which value will it take when both user and default values are given?

A

user value

39
Q

What is the return value of the following function: double myRewards(double x, double y)?

A

double

40
Q

In order to return a value from a function you must use:

A

return

41
Q

include <iostream></iostream>

What is the output of the program?

using namespace std;

int fun(int=0, int = 0);

int main()

{

cout &laquo_space;fun(5);

return 0;

}

int fun(int x, int y)

{ return (x+y); }

A

5

42
Q

It refers to merging of two strings

A

concatenation

43
Q

Compares the C string str1 to the C string str2

A

strmcp()

44
Q

Returns true if the provided character expression is a printing character other than whitespace, a digit, or a letter; otherwise returns false.

A

ispunct()????

45
Q

Returns true if character expression is either a letter or a digit otherwise false

A

isalnum()

46
Q

Returns true provided character expression is a lowercase letter otherwise it returns false

A

islower()

47
Q

Returns true provided character expression is a whitespace character, such as the blank or newline character, otherwise, returns false

A

isspace()

48
Q

include <cstring></cstring>

What is the error in the following program?

using namespace std;

int main ()

{

char key[] = “apple”;

char buffer[80];

do {

 cout << "Guess my favorite fruit? ";

 cin.getline(buffer,80);

} while (strcmp (key,buffer) != 0);

cout &laquo_space;“Correct answer!”

return 0;

}

A

Missing semicolon

49
Q

Which of the following function allows you to read on a character?

get()

put()

strcpy()

getline()

A

get()

50
Q

include <iostream></iostream>

Check the following program

using namespace std;

int main ()

{

int i;

char str[]=”c3po…??”;

i=0;

while (isalnum(str[i])) i++;

cout &laquo_space;“The first “ &laquo_space;i &laquo_space;” characters are alphanumeric.\n”;

return 0;

}

What is the value of i?

A

4

51
Q

Returns true if character expression is a letter of the alphabet otherwise false

A

isalpha()

52
Q

Which of the following operator can be used also in strings?
Group of answer choices

+

@

-

A

+

53
Q

What is the header file for the string class?

A

include <string></string>

54
Q

The append operator is denoted by:

A
  • +=
55
Q

include <iostream></iostream>

What is the output of the following program?

using namespace std;

int main () {

string str1 = “Hello”;

int len = str1.size();

cout &laquo_space;len &laquo_space;endl;

return 0;

}

A

5

56
Q

include <cstring></cstring>

What is the output of the following program?

using namespace std;

int main()

{

char str1[] = "C++";

string str = "Programming";

int len1 = strlen(str1);

int len2 = str.length();

cout << len1+len2;

return 0;

}

A

14

57
Q

The sequence of contiguous characters in memory is called _________

A

Character Strings

58
Q

include <string></string>

What is the output of the following program?
#include <iostream></iostream>

using namespace std;

int main () {

string myString = "Hello";

cout << myString[0];

return 0;

}

A

H

59
Q

Which of the following functions gets the length of a string?

A

length()

60
Q

include <iostream></iostream>

What is the output of the following program?

//faggot
#include <string></string>

using namespace std;

int main () {

string str3(5, '#');

cout << str3;

return 0;

A

#####

61
Q

An operation where in data is added to the existing data of file

A

Append

62
Q

What is the correct syntax for declaring a file pointer?

A

FILE *fp;

63
Q

What does the following code do?

while( (ch = getchar()) != ‘\n’) {

    putc(ch, fp);

}
A

Gets a character, put it into a file pointer until an enter is pressed

64
Q

It represents a sequence of bytes on the disk where a group of related data is stored.

A

File

65
Q

Creates a new file or open an existing file

A

fopen()

66
Q

When will the cin can start processing of input?

A

After pressing return key

67
Q

By default, all the files in C++ are opened in _________ mode.

A

Text

68
Q

What is the return type open() method?

A

int

69
Q

A C++ library that allows working with files

A

fstream

70
Q

Which of the following header file is required for creating and reading files?

stream

fstream

ifstream

ofstream

A

fstream

71
Q

Which of the following has a correct C++ class definition?

class Student {};

class Student;

class Student ()

class Student {}:

A

class Student {};

72
Q

What is the difference between struct and class in C++?

Group of answer choices

All of the given

Members of a class are private by default and members of struct are public by default.

All members of a structure are public and structures don’t have constructors and destructors

All members of a structure are public and structures don’t have virtual functions

A

Members of a class are private by default and members of struct are public by default.

73
Q

What operator is used to access a data member or a member function?

== operator

& operator

dot (.) operator

+ operator

A

dot (.) operator

74
Q

Which of the following best defines a class?

Blueprint of an object

Scope of an object

Parent of an object

Instance of an object

A

Blueprint of an object

75
Q

Which concept of OOP is false for C++?

A class must have member functions

At least one object should be declared in code

Code must contain at least one class

Code can be written without using classes

A

Code must contain at least one class

76
Q

What symbol is used to define a function outside of the class?

<>

&

::

:

A

::

77
Q

If a class is named Car and you will create an object named SportsCar, what would be the statement?

Car<SportsCar>;</SportsCar>

Car (SportsCar);

Car SportsCar;

SportsCar Car;

A

Car SportsCar;

78
Q

An object is a _________________ of a class

A

an instance

79
Q

If a class is named Fruits and you will create an object named Apple, what would be the statement?

Apple@Fruits;

Apple Fruits;

Fruits Apple;

Fruits(Apple);

A

Fruits Apple;