CS 401

Introduction to Computer Science

Assignment 3

Handed out: Thursday, February 11, 1999 during class.

Due: A hard copy of your source code, a floppy disk containing your source code (.cpp) and executable code (.exe -- using a STATIC project), and a completely filled out Assignment Information Sheet at the beginning of lecture on Thursday, February 25, 1999

You have been hired by the U.S. National Weather Service to write a software system for an automatic phone answering service for a local weather department. People will call into the system and request a service by pushing buttons if they have a touch-tone phone. The services to be provided include the air temperature in Fahrenheit, the wind speed in miles per hour, the relative humidity, the wind chill factor, and the heat index. The customer can ask for multiple services, one after the other. Thus, the system first greets the customer and tells the customer that he/she needs a touch-tone phone to proceed. If they have a touch-tone phone, they push the # button. Otherwise they hang up, which will be simulated by the * button push. As the first activity when a customer calls, the system reads the temperature, wind speed, and humidity from a file (Note: the file is read for each caller). The system then provides the menu of services and asks the caller to request a service by pushing the appropriate button. The system responds to the request for a particular service. The following chart outlines what action the system takes for each button. After servicing the request, the system tells the caller if he/she have another request to push the 9 button; otherwise push 0 to terminate the call. When the caller finally terminates the call by pushing the 0 button, the system thanks the caller for using the service and continue to process calls. With each caller, the system logs the requests from the caller into a file.

The services corresponding to each number are listed in the following table.

 

Phone button

Action

1

Respond by printing the current date and time.

2

Respond with the temperature read from the file.

3

Respond with the wind speed read from the file.

4

Respond with the humidity read from the file.

5

Respond by computing the wind chill factor.

6

Respond by computing the heat index

9

Service another request from the caller.

0

Terminate the call and check if there is another caller

 

 

Your assignment is to implement a C++ program to simulate the above actions. That is,

instead of creating a program for a phone system, you will be creating a program that interacts with the caller by the keyboard and monitor. There are certain requirements for the program. Because you are a temporary employee, you have to make sure your program is readable. Therefore you are to use enumerated types for the phone buttons. (e.g., button 0 is Terminate, button 1 is Time, button 2 is Temperature, button 3 is Wind , button 4 is Humidity, etc.). However, remember that you cannot do I/O with enum types. You should also use a switch statement in implementing the service requests. Functions are required to compute the wind chill factor and the heat index. You should consider using a nested while loop to process customer requests, with the inner loop processing one customer's requests. You should log the requests using strings to represent the caller's requests. For example, the log file may look like the following:

caller 1: time temperature wind-chill

caller 2: wind wind-chill time temperature

caller 3: time

etc.

The following provides information about how to compute the current date and time, wind chill factor and heat index.

  1. To compute the date and time:
  2. Include the following files (note you may need others such as the math and fstream libraries).

    #include <iostream.h>

    #include <cstring.h>

    #include <classlib/time.h>

    {

    TTime T; // declare T to be an object of TTime.

    string times = T.AsString(); // times has the current time which can be printed out.

    }

    Once the time is set, it remains set for that time object. So, to change the time, you have to have the declaration within a block as shown and perhaps in a loop for servicing callers.

  3. To compute the wind chill factor:
  4. Write a function WindChill that returns a double floating point number and has two double parameters temp and wind representing temperature and wind speed. The wind chill factor is the perceived temperature when taking temperature and wind speed into account. The standard formula for wind chill factor is

    where wind is the current wind speed in miles per hour and temp is the current Fahrenheit temperature.

  5. To compute the heat index:

Write a function HeatIndex() that returns a double floating point number with two double parameters T and R representing temperature and relative humidity. The heat index is the perceived temperature taking temperature T and relative humidity R into account. The formula

for Fahrenheit heat index is:.

16.293 + 0.185212*T + 5.37941*R - 0.100254*T*R

+ 9.41695e-3*T2 + 7.28898e-3*R2 - 3.45372e-4*T2*R

- 8.14971e-4*T*R2 + 1.02102e-5*T2*R2 - 3.8646e-5*T3

+ 2.91583e-5*R3 + 1.42721e-6*T3*R + 1.97483e-7*T*R3

- 2.18429e-6*T3*R2 + 8.43296e-10*T2*R3 - 4.81975e-11*T3 * R3.

To execute the program, first create an input file that has a number of records of the following type:

.

There should be at least 10 records in the file, allowing for 10 customers. Note the input file is an unrealistic part of the assignment. In a real situation, monitoring devices would be adding information to the file as the temperature, wind speed and humidity change. Thus, you would not be able to create a file at the very beginning of the execution of the system.

Notes

If you want to do some extra credit, here are some suggestions. If you have other suggestions, please ask me whether they are suitable for extra credit.

  1. Look up the classification of wind speeds - windy, tornado, etc and print out the classification when the caller requests the wind speed (as well as the wind speed).
  2. Print out a heat alert, based on the heat index when the caller requests the temperature.

See exercise 5.42 on page 264.