using an array of structures for a telephone company

This is my code for this program I'm just real confused on what to do with it.
#include<stdio.h>
struct customer{char phone_num[17];
                               char name[25];
                               float s_time, e_time, duration, charge;
                               };

void compute bill(struct customer[], int);
void output(struct customer[], int);
main
{
      int num = 10;
      struct customer[10]= {
            {"Janet E. Franklin"
             "3"
             "(412) 386-2043", 23:45, 0:15,
             "(508) 394-2149", 12:35, 12:50,
             "(374) 404-2148", 8:20, 10:05,
             "John L. Golden"
             "3"
             "(218) 414-2040", 3:15, 4:05,
             "(405) 303-2084", 22:50, 1:10,
             "(505) 287-4129", 18:30, 20:05,
             "William S. Hunts"
             "4"
             "(202) 427-2129", 8:15, 9:30,
             "(303) 481-4848", 7:15, 10:05,
             "(425) 391-4941", 17:55, 18:25,
             "(505) 913-9193", 14:50, 16:15 ,
            }};
        compute bill(customer, num);
        output(customer, num);
}

void compute bill(struct customer[], int n)
 {
  int i;
  struct  *customers_p;

  customers_p = customer;
  for(i=0; i<n; i++, customers_p++)
      customers_p->bill = customers_p->s_time * customers_p->e_time;
  return;
 }
void output(struct customer[], int n)
 {
  int i;
  struct *customers_p;

  customers_p = customer;
  printf("\n%12s%25s%10s%10s%10s\n\n", "phone_num", "name",
                                          "start time","end time", "duration");
  for (i=0;, i<n; i++, customer p++)
      printf("%12s %-25s%10.2f%10.2f%10.2f\n", customers_p->phone_num, customers_p-> name,
                                    customer p->rate, worker p->s_time);
  return;
 }

This is the instruction that were given to me.
The Eastern Atlantic Telephone Company has the following rate structure for long distance calls:

a.      The regular rate for a call is $0.25 per minute.
b.      Any call started after 8:00 a.m. (8:00) but before 6:00 p.m. (18:00) is charged full price.
c.      Any call started after 6:00 p.m. (18:00) but before 8:00 a.m. (8:00) is discounted 40%.
d.      Any call longer than 60 minutes receives a 10% discount on its cost (after all applicable discounts are subtracted but before the tax is added).
e.      All calls are subject to a 8% federal tax.

Write a program to calculate telephone charges for the Eastern Atlantic Telephone Company.  The program should get input from an input file (the file proj4.dat contains test data) and should write output to an output file. The names of the input and output files should be given by the user from the commend line.  The program should check if the input and output files are opened and closed successfully.  The program should be able to process multiple customers and also be able to process multiple calls for each customer.  

The following is the format of the input file

Janet E. Franklin
3
(412) 386-2043  23:45   0:15
(508) 394-2149  12:35  12:50
(374) 404-2148   8:20  10:05
John L. Golden
3                  
(218) 414-2040   3:15   4:05
(405) 303-2084  22:50   1:10
(505) 287-4129  18:30  20:05
William S. Hunts
4                              
(202) 427-2129   8:15   9:30      
(303) 481-4848   7:15  10:05      
(425) 391-4941  17:55  18:25      
(505) 913-9193  14:50  16:15

The number of customers is unknown.  For each customer, the first line gives the name of the customer, the second line gives the number of calls made, and each of the following lines gives information on one call.  For each call, it has the called telephone number including area code, the starting time and the ending time. The starting time and ending time are based on a 24-hour clock.  Because the program will read from a file, it is not necessary to prompt the user for input and it is not necessary to check for input errors.

      You have the freedom to design the format of the output file.  On the top or bottom of the output file, give information about the programmer.  The output for each customer should look like a telephone bill.  It should have the name of the customer, information for each call, total number of calls, total cost, tax amount and the total amount due.  Information for each call should include the called number, starting time, ending time, duration of the call and the cost of the call.  The file proj4.out in the public folder is an example.

Define and use a struct to represent a telephone call.  Use an array of structs to represent all telephone calls made by a customer.  Use a function to read input for each customer from the input file.  Use another function to calculate the charge for each customer.  Assume that no calls last more than 24 hours, i.e., a call started at 23:30 and ended at 1:30 should have a duration of 2 hours, rather than 26 hours or 50 hours.  Also assume that the duration of each call is nonnegative.  For the above example, the duration should be 2 hours, rather than  -22 hours.  Use another function to write to the output file.

The following is the content of the example output file:



     Summary for Customer Janet E. Franklin

Call  (area code) number  Starting Time   Ending Time    Duration     Charge

  1    (412) 386-2043          23:45           0:15          30        4.50
  2    (508) 394-2149          12:35          12:50          15        3.75
  3    (374) 404-2148           8:20          10:05         105       23.62


Total number of calls               3
Total time used (in minutes)      150.00
Total charge for the calls   $     31.88
Tax                                 2.55
                            _____________

Total amount due                   34.42


     Summary for Customer John L. Golden

Call  (area code) number  Starting Time   Ending Time    Duration     Charge

  1    (218) 414-2040           3:15           4:05          50        7.50
  2    (405) 303-2084          22:50           1:10         140       18.90
  3    (505) 287-4129          18:30          20:05          95       12.82


Total number of calls               3
Total time used (in minutes)      285.00
Total charge for the calls   $     39.22
Tax                                 3.14
                            _____________

Total amount due                   42.36


     Summary for Customer William S. Hunts

Call  (area code) number  Starting Time   Ending Time    Duration     Charge

  1    (202) 427-2129           8:15           9:30          75       16.88
  2    (303) 481-4848           7:15          10:05         170       22.95
  3    (425) 391-4941          17:55          18:25          30        7.50
  4    (505) 913-9193          14:50          16:15          85       19.12


Total number of calls               4
Total time used (in minutes)      360.00
Total charge for the calls   $     66.45
Tax                                 5.32
                            _____________

Total amount due                   71.77


Number of customers processed :            3

Total number of calls         :           10

Total time used (minutes)     :          795

Total amount                  :$         137.55

Total tax amount              :           11.00

I would appreciate your help thanks alot.
salfamAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vvijaykConnect With a Mentor Commented:
First of all you should correct the struct u r using. You should make two structers since the no of customers is dynamic and so are the no of phone calls made by each customer. It should be like this:

struct ph_call
{ char ph_num[25];
  float s_time,e_time,duration,charge;
};

struct customer
{ char name[50];
  int num_of_calls;
  ph_call *ph_calls;
};

When you start the program, if u have any way of knowing the no of customers, create an array of customers having that many entries OR chose a max no of customers, say 100.

struct customers cust[100];

Then start reading the file or input. When u come to the no of phone calls entry, create an array of ph_calls struct with that many elements.

cust[i].ph_calls=(struct ph_call*)malloc(cust[i].num_of_calls*sizeof(ph_call));

I guess u can proceed from here.
0
 
kamenimCommented:
You want someone to make it or you want any ideas of how to do it on yourself?
Because thr program above is obviously wrong :)
0
 
salfamAuthor Commented:
I was still wondering how to set up the actual input file.
0
 
salfamAuthor Commented:
Hey kamenim well if it's obviously wrong can you point me in the direction on how to actually do it.
0
All Courses

From novice to tech pro — start learning today.