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.

74 Day 3<br />

Putt<strong>in</strong>g It Together<br />

Let’s try to tie together what you have learned <strong>in</strong> the previous section. I’ll take the MAILLIST<br />

program from Day 2, “Wad<strong>in</strong>g In Deeper,” and modify it so that it uses dynamic memory<br />

allocation. This will require a few changes. First, take a look at the modified program, and<br />

then I’ll expla<strong>in</strong> the changes. List<strong>in</strong>g 3.1 conta<strong>in</strong>s the modified MAILLIST program.<br />

List<strong>in</strong>g 3.1. POINTER.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 po<strong>in</strong>ters to<br />

11: // the mail<strong>in</strong>gListRecord structure<br />

12: //<br />

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

<strong>14</strong>: //<br />

15: // create an object for each element of the array<br />

16: //<br />

17: for (<strong>in</strong>t i=0;ilastName) - 1);<br />

31: cout address,<br />

33: sizeof(listArray[<strong>in</strong>dex]->address) - 1);<br />

34: cout city,<br />

36: sizeof(listArray[<strong>in</strong>dex]->city) - 1);<br />

37: cout state,<br />

39: sizeof(listArray[<strong>in</strong>dex]->state) - 1);<br />

40: char buff[10];<br />

41: cout

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

Saved successfully!

Ooh no, something went wrong!