Midterm Flashcards
- Arrays in C++ must have a fixed size that is determined at the time of declaration.
- Elements in an array are stored in contiguous memory locations.
- It is possible to have arrays with a variable size that can be changed at runtime.
The Lie is #?
3
arrays must have a fixed size that is determined at the time of declaration and can not be changed later.
- The index of the first element in an array is always zero (0).
- The size of an array is stored as a member variable of the array.
- It is possible to initialize an array in C++ using a loop.
The lie is #?
2
Array doesn’t have any member variable to store the size of an array.
- It is possible to pass an entire array as an argument to a function.
- The elements of an array in C++ are stored in the order they are declared.
- It is possible to have a multidimensional array using only one pair of square brackets.
The lie is #?
3
To have a multidimensional array, multiple pairs of square brackets are required, one for each dimension.
- It is not possible to copy the values of one array to another array using the assignment operator.
- The for-each loop can be used to iterate through the elements of an array.
- C++ arrays have a built-in method to sort their elements in ascending or descending order.
The lie is #?
1
It is possible to copy the values of one array to another array using the assignment operator in C++ using (=).
- It is possible to create an array of pointers in C++.
- A single-dimensional array can be passed to a function as a reference.
- It is not possible to use the relational operators such as <, >, <=, >= to compare two arrays.
The lie is #?
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.
What is a type of array that can store multiple arrays with the same data type?
Multidimensional
What is Function?
Subprogram that performs task.
What is function overloading in C++?
Using same function name multiple times.
What are function parameters in C++?
Using same function name multiple times.
What are function parameters in C++?
Information passed to a function.
What is function return type?
Data type of returned value.
Can a function return multiple values?
No, only one value returned
What are user-defined function types?
Custom data types.
A function that calls itself
Recursion
Can a function be declared inside main?
Yes
What is the purpose of function overloading in C++?
To use same name, different tasks.
What is a default argument in C++?
Predetermined value for parameter.
T/F Function overloading allows multiple functions with same name.
True
T/F Default arguments are mandatory in C++.
False
T/F Function prototypes are only used for functions with no return type.
False
T/F Inline functions can only be declared inside main.
False
T/F Reference parameters are alternative to values.
False
What is the purpose of function parameters?
To pass information to a function.
What is the purpose of default arguments?
To provide predetermined values for parameters.
What is the purpose of function return type?
To specify data type of returned value.
What is the purpose of user-defined function types in C++?
To create custom data type for functions.
What is the purpose of function overloading in C++?
To use same function name for different tasks.
The code “int max (int num1, int num2);” is a Function _____
Declaration
What are the mandatory parts of a function declaration?
Return type and function name
A type of variable inside a function
Local
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
All of the mentioned
A function can be called from another function using its __
name
Which of the following is NOT included in a function declaration?
Colon :
function_name
semicolon ;
parameter list
colon :
Which of the following is NOT a proper function prototype (definition)?
func(int x)
void funct();
int secondfunct (char x, char y) ;
char letter();
func(int x)
Where does the “return statement” return the execution of the program?
main function
include <iostream></iostream>
using namespace std;
void f1()
{
cout «1;}
int main()
{
f1();
goto x;
cout «_space;“hello”;
x: cout «_space;“hi”;
return 0;}
What is the output of the following code?
Error
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)
void myPassingGrade(int x, int y)
Which value will it take when both user and default values are given?
user value
What is the return value of the following function: double myRewards(double x, double y)?
double
In order to return a value from a function you must use:
return
include <iostream></iostream>
What is the output of the program?
using namespace std;
int fun(int=0, int = 0);
int main()
{
cout «_space;fun(5);
return 0;
}
int fun(int x, int y)
{ return (x+y); }
5
It refers to merging of two strings
concatenation
Compares the C string str1 to the C string str2
strmcp()
Returns true if the provided character expression is a printing character other than whitespace, a digit, or a letter; otherwise returns false.
ispunct()????
Returns true if character expression is either a letter or a digit otherwise false
isalnum()
Returns true provided character expression is a lowercase letter otherwise it returns false
islower()
Returns true provided character expression is a whitespace character, such as the blank or newline character, otherwise, returns false
isspace()
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 «_space;“Correct answer!”
return 0;
}
Missing semicolon
Which of the following function allows you to read on a character?
get()
put()
strcpy()
getline()
get()
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 «_space;“The first “ «_space;i «_space;” characters are alphanumeric.\n”;
return 0;
}
What is the value of i?
4
Returns true if character expression is a letter of the alphabet otherwise false
isalpha()
Which of the following operator can be used also in strings?
Group of answer choices
+
@
-
+
What is the header file for the string class?
include <string></string>
The append operator is denoted by:
- +=
include <iostream></iostream>
What is the output of the following program?
using namespace std;
int main () {
string str1 = “Hello”;
int len = str1.size();
cout «_space;len «_space;endl;
return 0;
}
5
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;
}
14
The sequence of contiguous characters in memory is called _________
Character Strings
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;
}
H
Which of the following functions gets the length of a string?
length()
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;
#####
An operation where in data is added to the existing data of file
Append
What is the correct syntax for declaring a file pointer?
FILE *fp;
What does the following code do?
while( (ch = getchar()) != ‘\n’) {
putc(ch, fp); }
Gets a character, put it into a file pointer until an enter is pressed
It represents a sequence of bytes on the disk where a group of related data is stored.
File
Creates a new file or open an existing file
fopen()
When will the cin can start processing of input?
After pressing return key
By default, all the files in C++ are opened in _________ mode.
Text
What is the return type open() method?
int
A C++ library that allows working with files
fstream
Which of the following header file is required for creating and reading files?
stream
fstream
ifstream
ofstream
fstream
Which of the following has a correct C++ class definition?
class Student {};
class Student;
class Student ()
class Student {}:
class Student {};
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
Members of a class are private by default and members of struct are public by default.
What operator is used to access a data member or a member function?
== operator
& operator
dot (.) operator
+ operator
dot (.) operator
Which of the following best defines a class?
Blueprint of an object
Scope of an object
Parent of an object
Instance of an object
Blueprint of an object
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
Code must contain at least one class
What symbol is used to define a function outside of the class?
<>
&
::
:
::
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;
Car SportsCar;
An object is a _________________ of a class
an instance
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);
Fruits Apple;