12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

130 Day 4<br />

Quiz<br />

Q Do I have to understand every aspect of file I/O to program <strong>in</strong> <strong>C++</strong>Builder?<br />

A No. <strong>C++</strong>Builder has plenty of built-<strong>in</strong> file I/O through its use of components. A<br />

basic understand<strong>in</strong>g of file I/O is a good idea <strong>in</strong> any case. As always, it depends on<br />

what your program does.<br />

Q Can I open a file <strong>in</strong> such a way that I can read from and write to the file as<br />

needed?<br />

A Yes. In addition to the file I/O classes I discussed <strong>in</strong> this chapter, there is also a class<br />

called fstream. This class allows you to read from a file, write to the file, and<br />

reposition the file po<strong>in</strong>ter as needed.<br />

1. How do classes and structures differ <strong>in</strong> <strong>C++</strong>?<br />

2. What is the purpose of hav<strong>in</strong>g private data members and functions?<br />

3. How can you keep data members private, yet allow users to read and set their<br />

values?<br />

4. How and when is a class’s destructor called?<br />

5. What does it mean to override a function of the base class?<br />

6. How can you override a base class function and still get the benefit of the operation<br />

the base class function performs?<br />

7. What does an <strong>in</strong>itializer list do?<br />

8. Can a class conta<strong>in</strong> other class <strong>in</strong>stances as data members?<br />

9. How can you get the functionality of two separate classes all rolled <strong>in</strong>to a s<strong>in</strong>gle<br />

class?<br />

Exercises<br />

1. Write a class that takes a person’s height <strong>in</strong> <strong>in</strong>ches and returns the height <strong>in</strong> feet.<br />

2. Derive a class from the class <strong>in</strong> exercise 1 that also returns the height <strong>in</strong> meters,<br />

centimeters, or millimeters. (H<strong>in</strong>t: There are 25.4 millimeters <strong>in</strong> an <strong>in</strong>ch.)<br />

3. Write a program that takes user <strong>in</strong>put and writes it to a data file.<br />

4. Modify the program <strong>in</strong> exercise 3 so that it reads the data file and displays the<br />

output after the file is written.<br />

5. Take a day off from work. You’ve earned it!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!