Midterm Pratice Flashcards
Which of the following statements allows us to simply type “cout” instead of “std::cout” everytime we wish to use the cout variable?
using namespace std;
Using the same string variable called ‘name’ from the previous question, display the name to the console in a single line of code followed by an end of line.
Answers marked incorrect by the auto-grader will be manually reviewed for correctness and partial credit by your instructor.
cout «_space;name «_space;endl;
Assume there is a string called ‘name’ that has already been defined. In a single line of code, read the user’s ENTIRE name into the string from the console.
Answers marked incorrect by the auto-grader will be manually reviewed for correctness and partial credit by your instructor.
getline(cin,name);
Assume that there is a string variable named “title” with some phrase of length 10 or more. Display the 7th character to the console and nothing else.
cout «_space;title[7];
Which of the following also known as an instance of a class?
Object
A struct is declared as follows:
struct NameType { char first[10]; char last[20]; int age; } The first letter in the first name is stored in location 1000. Each letter takes one location and an integer takes 2 locations. What is the address of last[2]?
1,012 (with margin: 0)
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
Compile-time error.
#include using namespace std;
class Test { public: Test(); };
Test::Test() {
cout «_space;“Constructor Called” «_space;endl;
}
int main() { cout << "Start" << endl; Test t1(); cout << "End" << endl; return 0; }
Start
End
#include using namespace std;
class Test { public: Test(); };
Test::Test() {
cout «_space;” Constructor Called. “;
}
void fun() { static Test t1; }
int main() { cout << " Before fun() called. "; fun(); fun(); cout << " After fun() called. "; return 0; }
Before fun() called. Constructor Called. After fun() called.
#include using namespace std; class Point { Point() { cout << "Constructor called"; } };
int main() { Point t1; return 0; }
Compiler Error
Using the same double pointer, gpaPtr, from the previous question, delete its memory.
delete gpaPtr;
int *p; int i, k; i = 142; k = i; p = &i; Which of the following statements changes the value of i to 143 ?
*p = 143;
In a function, passing a parameter by value does not necessarily protect the contents of the caller’s data structures from being affected by the function under which of the following conditions?
The value parameters are pointer variables
Which of the following also known as an instance of a class? Member Variables Friend Functions Object Member Functions
Object
Assume that a class called Weapon exists that has a default constructor. Create a pointer to a Weapon (named myWeapon) and the Weapon associated with it.
Weapon* myWeapon = new Weapon();