Computer Science Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

In the following code segment, int main() { ifstream infile; // create ifstream objectinfile.open("example.txt");string instuff;infile >> instuff; // calls operator>>(infile, instuff) } The contents for the string variable instuff are being written to the file "example.txt".

False

Like function overloading, when redefining a base class member function in a derived class it is required to maintain the function name and return type but the argument list is changed

False

To open a file for input only, use the name of the file (e.g., file.txt) as an argument to the constructor call for the creation of an ifstream object. That is, ifstream infile("file.txt");

False

As you move down an inheritance relationship from parent to child, you typically move from a general to specific description.

True

Base Class functions may be redefined in Derived Class but it is not required that they are redefined

True

Both the of the following are valid definitions and initialization a C++ style string string mystring = "This is a string"; string mystring("This is a string");

True

C++ style strings are indexable.

True

Class destructors are called automatically when an object of the class goes out of scope.

True

Destructor calls are opposite the order of Constructor Calls

True

For reading from and writing to files, C++ uses the concept of a stream much like sending data to and from the terminal screen

True

If a base class has 3 integer variables: x, y and z in the private, protected and public interfaces, respectively, then the member access of these variables in a class which is derived by protected inheritance will be: protected: z, protected: y, x is not accessible by derived class.

True

If a member function in Base Class B is not declared to be virtual and is not redefined in Derived Class D, then any access to the member function through a reference to a Derived Class object will result in executing the Base Class version of the member function

True

In C++ classes, member data and member functions in the private interface are fully accessible by member functions of the class.

True

In C++, Abstract Base Classes are often pure interface classes that are not intended to be instantiated and have no member data

True

In C++, operators that cannot be overloaded include: the scope resolution operator (::) dot operator (.) conditional ternary operator (?:)

True

Inheritance is a capability of C++ to represent increased specialization that is often found in real world relationships.

True

Polymorphic behavior is only possible when an object is referenced by a reference variable or a pointer

True

Protected member access, allows the class the member belongs to (base class) and also derived classes to access the member. Protected members are not accessible from outside the class

True

The classes for different file access are: ifstream - reading from a file only ofstream - writing to a file only fstream - reading from and writing to a file

True

The syntax for declaring DerivedClass to publicly inherit from BaseClass is given by class DerivedClass : public BaseClass {...}

True

You can think of static binding as the compiler binding function calls on objects at compilation time and dynamic binding as the program binding function calls on objects at run time

True

For the Complex number class that was was discussed in the lecture topic on operator overloading, the line of code: Complex c3 = c1 + c2; // c1, c2 are Complex objects is interpreted by the compiler as _____________________?

c1.operator+(c2);

From the examples of the student class in the lecture slides, what is the name of the operator that allows access to public member data (name, id) for the student object s1 in the following statement: cout << "student s1 name and id: " << s1.name << ", " << s1.id << endl;

dot operator

In C++, the fstream class is derived from the _____________ class.

iostream

Inheritance between a child and parent object exhibits an "__________" relationship.

is a

A Complex number class includes the following member and non-member functions for overloaded operator+ : Complex operator+(const Complex &c); // mf Complex operator+(const int &, const Complex &);// non-mf Which one is called when executing a statement such as: Complex c2 = c1 + 10; // c1 is a Complex object

member function version

Will the following statement compile char city[10] = "Cincinnati";

no

A class constructor that takes a number of arguments and uses the arguments to initialize the private member data of the class is known as a __________________ constructor?

non-default

Given the statement char myarrary[10] = "no"; what is stored in myarray[9]?

undefined

The syntax for declaring a member function void Z(int); to be virtual is __________?

virtual void Z(int);

C style strings are always terminated with what?

'\0'

In a .cpp implementation file, the syntax for calling the base class constructor from the derived class construct or is ______________?

Derived::Derived(int arg1) : Base(arg1)

C++ style strings are actually objects of the string class.

True

Virtual functions enable dynamic binding → functions bound at run time to objects they belong to. Without virtual member functions, C++ uses static (compile time) binding

True

When redefining base class member functions, the rule for calling these member functions is: Objects of base class use base class version of function; objects of derived class use derived class version of function

True

You can think of file access as first opening the door to a file, sending and/or receiving things through the door to the file and finally, closing the door to the file.

True

A class constructor that takes no arguments and typically initializes private member data items with default values is known as a ___________________ constructor?

default

Given an object of the Complex number class, c, the statement cout << c << endl; is interpreted by the compiler as_________________?

ostream &operator<<(ostream &, const Complex &)

To use the objects in C++ designated for file IO operations you must #include ____________?

<fstream>

Given the definition and initialization string mascotname("Bearcat"); What does cout << mascotname.size() << endl; print out?

7 byes

Given the definition and initialization char mascotname[]= "Bearcat"; What does cout << sizeof(mascotname) << endl; print out?

8 byes

Consider this situation: Class BaseClass defines functions x() and y(). x() calls y() Class DerivedClass inherits from BaseClass and redefines function y() An object D of class DerivedClass is created and function x() is called When x() is called, which y() is used, the one defined in BaseClass or the the redefined one in DerivedClass?

BaseClass::y()

Given the C++ string definition and initialization, string team("Cincinnati Reds"); What is printed out by the statement, cout << team[0] << ", " << team[8] << ", " << team[14] << endl;

C, a, d

From the following diagram, if the member functions const double getArea(); const double getPerimeter(); are declared as (non-pure) virtual functions in the GradedActivity class, they must be overridden in all derived classs

False

In C++, objects are limited to having a maximum of 2 constructors.

False

The private data members of a base class are directly accessible by a derived class that privately inherits from the base.

False

When writing a getter function for your class that returns a private data member of type double, it is required to make the return type of the function double &.

False

The class relationship shown below is known as ____________________?

Multi-level inheritance

From the inheritance diagram shown below, if the goal is to enable dynamic binding of the getLetterGrade() member function, the keyword virtual must be used in the function declarations for which classes?

GradedActivity class only

Given the function definition, size_t stringlength(char str[]) { return strlen(str); } what is printed out by the following statement in main(), cout << "Length of string is " << stringlength("Ohio River") << " characters" << endl;

Length of string is 10 characters

The C++ property that enables the appropriate member function call in an inheritance structure to be determined dynamically, at run time is known as ___________?

Polymorphism

Which of the following is considered a hallmark property of Object Oriented Programming?

Polymorphism

Early versions of the FORTRAN language are examples of _______________?

Structured Programming

In the code segment shown below, if the keyword virtual is not used in the base class GradedActivity for the member function getLetterGrade(), then the call to displayGrade(test) will display ___________?

The activity's numeric score is 72.0 The activity's letter grade is C

In the following code segment, what terminates the while loop? int main() { ifstream infile; infile.open("example.txt"); string instuff; while(infile >> instuff) cout << instuff << endl; return 0;}

The call to operator>>(infile, instuff) returns '0' at the end of infile

Given the following code segment, int main() { fstream fsfile; string value; fsfile.open("example.txt"); fsfile >> value; if (value == "Test") fsfile << "Yes"; else fsfile << "No"; } How is the file "example.txt" closed?

The destructor for the fsfile object will be called before leaving the scope of the main() function. It will close the file.

In C++, objects are generally created by making a call to the object's ______________?

constructor

The three primary classes for file IO in C++ are ____________?

ifstream, ofstream, fstream

Will the following code compile? class Base { int x; }; class Derived : public Base { public: void print() { cout << x << endl;} };

No

Which of the following accurately describes levels of access restriction in C++?

Private > Protected > Public


Ensembles d'études connexes

Securities Registration Quiz II (65)

View Set

Repaso de Entornos Tecnológicos y Virtuales del Aprendizaje

View Set

Chapter 28 the fetal GI system questions

View Set

What is Anthropology? What is Culture

View Set