File input and OCCF Flashcards

1
Q

In C++ 11 how do you open a file?

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

When you open a file in C++, how do you test for end of file?

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

In C++ how do you read data from a file?

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

In C++ how do you grab single characters from a file (to build and parse a string youself)?

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

In C++ what are other ways (other than >>) to get input from a file?

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

In C++ how do you close a file and when should you do so?

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

How do you get the most up-to-date string library in C++?

How do you compare two strings?

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

How do you concatenate other data into a string in C++?

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

What does OCCF stand for?

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

What are the four things that every C++ class should have?

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

What is called when an object is deleted in C++?

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

What is the problem with destructors in C++?

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

What is the method called when an object is destructed in Java? When is it called?

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

What is the difference between a “shallow copy” and a “deep copy”?

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

In the attached code, which is a newly created object, shallow and deep copy?

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

In C++ what is the difference between a value parameter and a reference parameter?

A
17
Q

How does this code work with regard to reference parameters?

A
18
Q

What would happen in this code if we attempt to alter firstNode and have it point to newNode?

A
19
Q

Why use reference parameters in C++?

A
20
Q

How do we prevent a reference parameter from being altered in C++?

A
21
Q

How do we make a copy constructor in C++?

A
22
Q

How do default copy constructors work?

A
23
Q

What are the two places where we make a copy of an argument implicitly

A
24
Q

What is the clone method in Java and how do you overide it?

A

Object in Java has a method named clone that you can call vial super (super.clone( ))

Your class must implement a Clonable Interface and override the clone( ) method. clone ( ) might throw CloneNotSupportedException, so you have to throw or handle it as well.

25
Q

What is Assignment in the context of OCCF?

A
26
Q

In general, how to assignment overriding in C++ work?

A
27
Q

How do you code an override for assignment operator in C++?

A
28
Q

How does the assignment operator override in C++ work?

A
  • Assumes that MyObject has a member data, and a method getData() to access it
  • data here is actually this->data (implicitly)
  • In other words, the left operand (of the = operator) is the instance on which we call the assignment “method”
  • One more thing that’s very unusual is there’s a reference (&) in the return type - it’s actually modifying its “left” operand and then returns it (the new version)
29
Q

In general what is overloading?

A
30
Q

What are the OCCF’s so important in C++?

A
31
Q

How does overriding operators work in Java?

A
32
Q

How do you open and then read from a file in C++?

A

ifstream myFile;

myFile.open(“text.txt”);

string line;

getline(myFile, line);