162 Flashcards

1
Q

What is the class specification file?

A

A header file that contains a class declaration

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

What is the class implementation file?

A

.cpp file where member function definitions are stored

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

What is the client program?

A

Program that contains main function and is compiled and linked with the .cpp file. AKA client code.

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

what is #ifndef?

A

include guard. Prevents header file from accidentally being included more than once.

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

What is the include file directory

A

Directory or folder where all of the standard C++ header files are located. Use angled brackets. Quotations for header files mean that file is located in current project directory

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

What is using namespace for?

A

backwards compatibility

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

What is the process for compiling?

A
  1. preprocessor runs
  2. Parser and lexer run
  3. Compiler translates code into assembly
  4. Assembler turns it into object
  5. Linker combines libraries and turns into executable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the -c mean?

A

partial compilations

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

what is #pragma

A

suggestion to compiler. #pragma once tells compiler only include this once. support not as wide spread

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

What are typical contents of make file?

A

rules, targets, dependencies, variables.

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

What is CC

A

name of c compiler

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

What is CXX

A

name of c++ compiler

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

what are CFLAGS?

A

tools to compile but not to link

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

What is LDFLAGS?

A

linker flags, like math library or pthread library. Anything you want to include that has to be specified when linking

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

what is -g?

A

debugging

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

What is @?

A

substitutes name of target

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

What is name of gnu debugger?

A

gdb

18
Q

what is where?

A

prints backtrace. Also can type backtrace or bt.

19
Q

How do you combine several file open mode flags when a file is being opened?

A

The bitwise “or” operator |

for example,

fstream dataFile;
myFile.open(“myfile.dat”, ios::in | ios::out);

20
Q

What is ios::app flag?

A

new data added to the end of a file

21
Q

What is ios::noreplace flag?

A

specifies that an attempt to open a file for output should fail if the file already exists

22
Q

What is ios::ate flag?

A

Initial output to the file will take place at the end of the file

23
Q

What is ios::binary flag?

A

Binary mode. When a file is opened in binary mode, information is written to or read from it in pure binary format.

24
Q

What is ios::trunc?

A

If the file already exists, its contents will be deleted (truncated). This is the default mode used by ios::out

25
Q

What is the fail function of a file stream object?

A

returns true if an I/O operation was not successfully completed.

26
Q

What is the eof function?

A

Testing for the end of a file. Not the best way to determine whether there is still data left in the file when reading from the file using the extraction operator.

27
Q

What is continue?

A

causes current iteration of loop to end immediately.

In while loop, this means program jumps to the test expression at top of loop. If expression is still true, the next iteration begins.

In do-while loop, the program jumps to the test expression at bottom of loop, which determines if next iteration will begin.

28
Q

What is the syntax to declare a friend function?

A

friend return type function name (parameter type list)

29
Q

How to make a programmer-defined copy constructor for the class NumberArray?

A

NumberArray::NumberArray(NumberArray &obj)

30
Q

Why use const parameters in copy constructors?

A

Because the purpose of a copy constructor is to make a copy of the argument, there is no reason the constructor should modify the argument’s data.

31
Q

11.5 When are copy constructors called?

A

Generally, only when an object is being INITIALIZED, not assigned.

whenever an object is being created by initializing it with another object of the same class OR when a function call receives a value parameter of the class type, OR whenever a function returns an object of the class by value.

32
Q

What is the syntax/format for operator overloading prototype?

A

return type - function name - parameters

void operator=(const NumberArray &right)

33
Q

If for the class NumberArray, the overloaded operator is void operator=(const NumberArray &right), how do you assign left to right below?

Number Array left(3, 10.5);
NumberArray right(5, 20.5);
A

left.operator=(right);
OR
left = right;

34
Q

Parameters to operator functions must be passed by reference or declared const. True or False?

A

False.

35
Q

Modify the following definition of the operator to make it be able to do this -> a = b = c

void NumberArray::operator=(const NumberArray &right)
{
   if (arraySize > 0) delete [] aPtr;
   arraySize = right.arraySize;
   aPtr = new double[arraySize[;
   for (int index = 0; index
A
NumberArray NumberArray::operator=(const NumberArray &right)
{
   if (arraySize > 0) delete [] aPtr;
   arraySize = right.arraySize;
   aPtr = new double[arraySize];
   for (int index = 0; index
36
Q
What happens in the following code:
class Weird
{
private: 
   int value;
public:
   Weird(int v)
      {value = v; }
   void operator=(const Weird &right)
     { cout
A

10 will be displayed on the screen

37
Q

Which operators cannot be overloaded?

A
?:
.
.*
\::
sizeof
38
Q

Why would you make an overloaded operator a member function of a class?

A

so it can access private members of the class. It also allows the function to use the implicit this pointer parameter to access the calling object.

If you make the overloaded member function a separate, stand-alone function, you need to declare it as a friend in order to access the private members of the class

39
Q

What are some operators that need to be overloaded as stand-alone function?

A

the stream input and output operators:&raquo_space; and «

40
Q

Why is it better to overload binary operators that take parameters of the same type as stand-alone functions?

A

Because unlike stand-alone operator overloading, member-function overloading introduces an artificial distinction between the two parameters by making the left parameter implicit.

41
Q

Given the following code how would you implement the operator?

Length Length::operator++()
{
   len_inches++;
   return *this;
}
A

++b
OR
b.operator++()

For postfix, the only difference is that it takes a dummy parameter & and it needs a temp value to capture and return the object’s value before it was postfixed.