summaryrefslogtreecommitdiff
path: root/662/CH12/EX12.14/Example12_14.sci
blob: 8f846dcdc47ad0f11ca9706883f88646e15f21cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
            //Example 12.14
        //Updating Customer Records
        
Date = struct('month',0,'day',0,'year',0);
lastpayment = Date;
account = struct('Name'," ",'street'," ",'city'," ",'acct_no',0,'acct_type',' ','oldbalance',0,'newbalance',0,'payment',0,'lastpayment',0);
customer = account;

function[] = main()
    printf("CUSTOMER BILLING SYSTEM\n\n");
    printf("How many customers are there?");
    n = scanf("%d");
    
    for i = 1:n;
        customer = readinput(i,customer);
        //determine account status
        if customer(i).payment > 0 then
            if customer(i).payment < (0.1*customer(i).oldbalance) then
                customer(i).acct_type = 'O';
            else
                customer(i).acct_type = 'C';
            end
        else
            if customer(i).oldbalance > 0 then
                 customer(i).acct_type='D';
            else
                 customer(i).acct_type='C';
            end
        end
        //adjust account balance
        customer(i).newbalance = customer(i).oldbalance - customer(i).payment;
    end
    for i = 1:n
        writeoutput(i,customer);
    end
endfunction

function[customer] = readinput(i,customer)
    //read input data and update record for each customer
    printf("\nCustomer no. %d\n",i);
    printf("    Name:    ");
    customer(i).name=read(%io(1), 1, 1, '(a)') ;
    printf("    Street:    ");
    customer(i).street=read(%io(1), 1, 1, '(a)') ;  
    printf("    City:    ");
    customer(i).city=read(%io(1), 1, 1, '(a)') ;
    printf("    Account Number:    ");
    customer(i).acct_no=scanf("%d") ;
    printf("    Previous Balance:    ");
    customer(i).oldbalance=scanf("%d") ;
    printf("    Current Payment:    ");
    customer(i).payment=scanf("%d") ;
    printf("    Payment date (mm/dd/yyyy):\n ");
        printf("Month: ");
        customer(i).lastpayment.month=scanf("%d");
        printf("Day: ");
        customer(i).lastpayment.day=scanf("%d") ;
        printf("Year: ");
        customer(i).lastpayment.year=scanf("%d") ;
    return customer;
endfunction

function[] = writeoutput(i,customer)
    printf("\nName:    ");
    write(%io(2),customer(i).name);
    printf("Account number: %d\n", customer(i).acct_no);
    printf("Street: "); 
    write(%io(2),customer(i).street);
    printf("City:    ");
    write(%io(2),customer(i).city);
    printf("Old balance: %7.2f", customer(i).oldbalance);
    printf("    Current payment: %7.2f", customer(i).payment);
    printf("    New balance: %7.2f\n\n", customer(i).newbalance);
    printf("Account status:    ");
    
    select customer(i).acct_type
    case 'C' then
        printf("CURRENT\n\n");
    case 'D' then
        printf("DELINQUENT\n\n");
    case 'O' then
        printf("OVERDUE\n\n");
    else
        printf("ERROR\n\n");
    end
    return;
endfunction

//calling main()
funcprot(0);
main();