[cpp] help with c++ |
haelly
Assistant
Registration Date: 27.12.2007
Posts: 4
Location: LONDON
Level: 8 [?]
Experience: 569
Next Level: 674
 |
|
Read input from a data file rather than from the keyboard , add the account number and the customer name and phone to the set of data for each water bill.
Create a structure type invoice with the field for customer name(a character array of length 15), phone (a character array of length 13 to accommodate a three-digit area code , a dash, a three-digit exchange , another dash, and a four-digit number),account number (long) ,volume in gallons(double),and bill amount (double),and bill amount (double). Instead of parallel arrays for separate elements of the bill, use an array of Invoice structures bills[].
Create an input file using a ext editor .use an object of the library type fstream to open the file in the ios::in mode. Define the file name as a constant character array FIN[] , supply either a full fie name , e.g., “c\data\invoices.dat” , or default directory file name , e.g. , “invoices.dat”; to be able to use the default directory that your compiler uses as the default directory. After defining a file object , test whether the operation failed ; print a message and terminate the program if the file cannot be opened.
In the data file, place the data for each water bill on a separate line .Allocate enugh space for the customer name and phone number , e.g. 16 character and 14 characters , at the beginning of the line .Format account number and volume in columns. Here is an example of a short input file:
Smith 617-353-2566 101808 200
Brown 508-790-9313 102313 300
Black 212-517-6770 10541 400
In the infinite input loop, use get() to read up to 15 characters into a local character array name[]; break the loop I the operation raises the end of file indicator. Use operator >> to read data into local variables ‘phone’ , ‘account’ , and ‘gallons’. Use get() again to through away the new line character at the end of the line (|to avoid confusing get() when it is called again).Break the input loop when there is no more space in the array of invoice objects invoices[].
If the input is valid and the array space is available compute the amount of the bill , copy the character arrays, (use strcpy()) and numeric data into the appropriate element of the array invoices[].
Modify program output to accommodate additional data e.g.,
Name Phone Account Volume Amount
Smith 617-353-2566 101808 200.00 22.00
Brown 508-790-9313 102313 300.00 27.00
Black 212-517-6770 105411 400.00 32.00
Total
haelly has attached these images (downsized versions):
|
|
28.12.2007 17:38 |
|
|
krsmichael
Software Engineer
 
Registration Date: 27.04.2005
Posts: 30
Location: California
Level: 21 [?]
Experience: 33,471
Next Level: 38,246
 |
|
How much does this job pay?
|
|
12.02.2008 05:37 |
|
|
macabre13
Chief Software Engineer

Registration Date: 14.01.2008
Posts: 127
Location: Poland/ Wroclaw Jabber: adamski.jaroslaw@jab
ber.wroc.pl
Level: 18 [?]
Experience: 15,755
Next Level: 17,484
 |
|
And next, people wonder why London does not have a good software developers.
__________________ - ebm - noise - industrial -
I always could be wrong.
Lets share knowledge!
|
|
12.02.2008 10:02 |
|
|
stinos
CTO

Registration Date: 15.01.2006
Posts: 199
Level: 28 [?]
Experience: 169,711
Next Level: 195,661
 |
|
| quote: |
Originally posted by macabre13
And next, people wonder why London does not have a good software developers. |
because the're unable to do their simple homework assignements
LOL
__________________ madinsjamania
|
|
13.02.2008 11:16 |
|
|
|