END; require_once "include/calendar.php"; require_once "include/planner-include.php"; require_once "include/header.inc.php"; ?> ../learn/perl/training/day2

## Phone-related exercises

### Text message rates (text.pl)

Read the number of text messages sent from STDIN. Output the total cost of text messages.

### Seconds to pulses (pulses.pl)

Read in the number of seconds. Print out the number of pulses, rounded up. (1 pulse is 6 seconds or a fraction thereof.)

### Converting minutes:seconds to seconds (min2seconds.pl)

Read the number of minutes. Read the number of seconds. Output the total number of seconds.

### Converting seconds to minutes:seconds (seconds2min.pl)

Read the number of seconds. Convert this to standard minutes:seconds format.

### Charging a call according to rate (rate-call.pl)

Read in the type of call (DAY, NGT or SUN) and the duration of the call. Output the cost of the call.

### Special promo (promo.pl)

Let's say that PLDT decides to run a special promo on IDD calls to encourage families to spend more time on the phone this Christmas season. Calls from 0 to 10 minutes are charged at the normal rate. The next 10 minutes will be charged at 75% of the full rate. If the full rate is 40c/minute, then the rate for those minutes will be 30c/minute. The remaining minutes will be charged at 50% of the full rate. If the full rate is 40c/minute, then the rate for the remaining minutes will be 20c/minute.

Illustration: If the call length is 40 minutes and the normal rate is 40c/minute, then the breakdown is as follows:
 10 minutes x 0.40 c/minute \$ 4 10 minutes x 0.30 c/minute \$ 3 20 minutes x 0.20 c/minute \$ 4 Total \$11

If the call length is 15 minutes and the normal rate is 20c/minute, then
 10 minutes x 0.20 c/minute \$ 2 5 minutes x 0.15 c/minute \$ 0.75 Total \$2.75

You would also like to give people a report of how much they saved by taking advantage of this promo.

### Explain call details (details.pl)

Convert obscure acronyms into phrases so that you can easily understand forms. Read the acronym and print out the long form.
 OC Int'l Person/Person Report Chg OG Nat'l Opr Ast-Globe Mobile Phone OR Int'l Person/Person Regular XR Nat'l TeleCharge (within USA) Y5 Nat'l TeleCharge (within USA) ZR Nat'l TeleCharge (within USA)

### Emergency numbers (emergency.pl)

Given an area, print out the emergency numbers for that area.

For example, if the input is Angono, print out

```------------------------------------------------
Angono
------------------------------------------------
Fire: 651-0064
Police: 651-0065

Patrol 117: 117
Bantay Bata: 163
Bisig Bayan: 928-4299
Meralco: 16-211, 631-1111
Manila Water Company, Inc.: 1627
National Poison Control: 524-1078
MMDA: 882-0877, 882-0889
Assn. Of Volunteer Fire Chiefs and Firefighters of the Phils, Inc.:
160-16
Assn. Of Philippine Volunteer Fire Brigades, Inc.: 522-2222
Civil Defense Operation Center: 911-5061
------------------------------------------------
```

### Charging a call according to rate (rate-call.pl)

Assume you are processing an international call. Read in the type of call (DAY, NGT or SUN) and the duration of the call. Output the cost of the call.

### IDD or not IDD? (idd.pl)

Read in the number dialed. Print out the number. If this is an IDD call (starts with 00), print out "IDD". If this is an NDD call (starts with 0), print out "NDD". If it is neither, print "Unknown."

Extend for other call types, like "International operator-assisted call" (108), "National operator-assisted call" (109), "Collect call to US/Hawaii" (1010500).

### String to phone (string-to-phone.pl)

Phone numbers like 19081BULAGA are easier to remember than

1. However, they are hard to dial if you don't have a phone with letters. Write a program that reads in a phone number like "19081BULAGA" and ouputs the corresponding numeric phone number.

### Find the area code for NDD (area.pl)

Read in a number of the form "0" + Area Code + Phone No. Output just the area code. For simplicity, assume the area code is always two digits. Example: If the input is 0322310000, print out 32.

### Find the data corresponding to the area code

Sometimes you need to quickly look up the province based on an area code or the area code based on the toll abbreviation. Flipping through the paper phonebook takes a lot of time. Why not use a program to speed up the work?

national.txt contains a few of the national points reached by PLDT in the form

```Manila to...:Toll destination abbreviation:area code:province
```
(You can add more if you want.)

Write a program that allows you to easily look up data. For example, if you input

```47
```
it should print out all the rows that contain 47.

### Making a Christmas card (christmas-card.pl)

It's Christmas and you'd like to send Christmas cards and gifts to your most important clients based on the volume of business they do with you. Read the name of a person/organization, the type of account (BUS for business or RES for residential), and the total amount billed this year.

Come up with your own rules for determining when to send a card or what kind of gift to give. Some suggestions:

```If the account is a business account
If the total billed amount is greater than or equal to 500,000
Else if the total billed amount is greater than or equal to 250,000
Send sweet ham
Else if the total billed amount is greater than or equal to 100,000
Send a Christmas card
Else # the account is a residential account
If the total billed amount is greater than or equal to 50,000
Else if the total billed amount is greater than or equal to 35,000
Send sweet ham
Else if the total billed amount is greater than or equal to 20,000
Send a Christmas card
```

### Making a Christmas list (christmas-list.pl)

Take a look at clients.txt. This is a list of the form

```name:telephone:type (BUS or RES):total billing
```
clients.pl is a program that extracts the billing information from this and prints out all those with a total billing of at least 20000 (residential) or 100000 (business). Copy this program to christmas-list.pl and modify it to print out a report in this format:

```Name of organization/person:telephone:Gift to give this Christmas
```

### Making a Christmas list (christmas-list.pl)

Another way to reward your most important customers is to give incentives to the top 50 business and residential accounts. For example, you could give Christmas baskets to your top 10, ham to the 11st to the 25th, and cards to the 26th to the 50th.

```name:telephone:type (BUS or RES):total billing
```
top-clients.pl is a program that sorts these by type and then by billing. Copy this program to christmas-list.pl and modify it to print out a report in this format:

```Name of organization/person:telephone:Gift to give this Christmas
```
Write a program that determines the gift to give this Christmas based on the organization/person's position.

### Coverage summary

Look at national.txt again. Write a program that prints out a sorted list of all the provinces that can be reached. Each province should be listed only once.

You will probably need arrays or hashes for this. Please see the printout of perlintro for more help.