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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

60 Day 2<br />

<strong>C++</strong>Builder automatically adds sentries to units that you create as a<br />

result of creat<strong>in</strong>g new forms or components. You should add sentries to<br />

any headers you create for classes used outside the <strong>C++</strong>Builder VCL<br />

framework.<br />

A header file can conta<strong>in</strong> more than one class or structure declaration. Us<strong>in</strong>g a separate header<br />

for each class or structure helps keep your project organized and makes it easier to reuse classes<br />

and structures <strong>in</strong> other programs. Sometimes you will group related classes together <strong>in</strong> one<br />

header. For <strong>in</strong>stance, you may have a class that implements a helper class to carry out its<br />

duties. In that case, both the ma<strong>in</strong> class and the helper class would be declared <strong>in</strong> the same<br />

header. Ultimately, it’s up to you how you organize your headers.<br />

Don’t be too concerned if this is all a little fuzzy right now. It will probably take some<br />

experience writ<strong>in</strong>g real programs for all this to come together for you.<br />

An Example Us<strong>in</strong>g Structures<br />

List<strong>in</strong>g 2.4 conta<strong>in</strong>s a program that has the user <strong>in</strong>put three names and addresses and stores<br />

those records <strong>in</strong> an array of structures. After the names are <strong>in</strong>put, they are displayed on the<br />

screen. The user is asked to choose one of the records. When the user chooses one of<br />

the records, it is displayed on the screen. List<strong>in</strong>g 2.5 conta<strong>in</strong>s the header file for the<br />

mail<strong>in</strong>gListRecord structure used <strong>in</strong> the MAILLIST program shown <strong>in</strong> List<strong>in</strong>g 2.4.<br />

List<strong>in</strong>g 2.4. MAILLIST.CPP.<br />

1: #<strong>in</strong>clude <br />

2: #<strong>in</strong>clude <br />

3: #<strong>in</strong>clude <br />

4: #pragma hdrstop<br />

5: #<strong>in</strong>clude “structur.h”<br />

6: void displayRecord(<strong>in</strong>t, mail<strong>in</strong>gListRecord mlRec);<br />

7: <strong>in</strong>t ma<strong>in</strong>(<strong>in</strong>t, char**)<br />

8: {<br />

9: //<br />

10: // create an array of mail<strong>in</strong>gListRecord structures<br />

11: //<br />

12: mail<strong>in</strong>gListRecord listArray[3];<br />

13: cout

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

Saved successfully!

Ooh no, something went wrong!