Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
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