Objectives

To design, implement and document simple modular programs that use functions and loops.

Exercise 1

Write a program that calculates the monthly bills for a telecommunications services company.

The company provides three services (telephone, internet and television) and each user can have only one service. The program should prompt the user to enter an account number (type unsigned int) and a service code (type char). Code P means telephone service, code I means internet service and code T means television service. The program should prompt the user until a valid code is entered (both lowercase and uppercase letters should be accepted).

The user should be prompted to provide the service consumption figures in number of minutes (type unsigned int). The rates depend on the service as follows:

Telephone (code P): 15.00 line rental plus 0.05 per minute used.

Internet (code I): 20.00 for the first 1000 minutes of internet connection (flat rate) and 0.02 for each additional minute the user was connected to internet.

Television (code T): TV users can either have a basic or a premium pack (but not both). For TV users, the program should also prompt the user to indicate the pack type. The rate varies depending on the user's TV pack as follows:

  • Basic pack: 5.00 for the first 60 minutes (flat rate)
    0.01 for each additional minute
  • Premium pack: 10.00 for the first 60 minutes (flat rate)
    0.02 for each additional minute

The program should display the account number and the amount due by the user.

The calculation of the amount due should be performed by three functions:

1. telephone(): Function that takes an input argument mins of type unsigned int and returns the amount due as a value of type double. This function should be used to compute the amount to be charged to telephone users.

2. internet(): Function that takes an input argument mins of type unsigned int and returns the amount due as a value of type double. This function should be used to compute the amount to be charged to internet users.

3. television(): Function that takes two input arguments pack_type and mins, both of type unsigned int, and returns the amount due as a value of type double. This function should be used to compute the amount to be charged to television users.

In the test part of your report, specify the results provided by your program for: i) 100 minutes of phone service; ii) 500 minutes of internet service; iii) 2000 minutes of internet service; iv) 1000 minutes of basic TV service; and v) 1000 minutes of premium TV service.

Note: You may want to use the toupper function in your program, which is defined in the ctype.h header file. Check your lecture notes or a C reference for details on how to use it.

Exercise 2

In probability theory and statistics, sometimes it can be useful to compute the value of a metric called kurtosis. This metric is used to describe certain properties of a random variable (i.e., a variable that can take random values). Let x1 ,x2 ,...,xn denote a sequence (vector) of n samples (values) taken from a random variable of interest. Assume in this exercise that all n samples can only take positive real values (including zero). The sample kurtosis of a sequence of n values (x1 ,x2 ,...,xn ) can be computed based on the following expression: see image.

where represents the mean/average value of the sequence, which is given by: see image.

Write a program that computes the sample kurtosis of a sequence of positive real values (including zero) entered by the user. The program should have a maximum capacity of 10 values. The user should be prompted continuously until either of these events occurs:

a) The user enters a negative value (this means that the user has no more values).

b) The maximum capacity is reached (i.e., the user has entered 10 values). When the 10 th value is entered, the program should display a message indicating that the maximum capacity has been reached and more values cannot be accepted.

The program will then compute the sample kurtosis based on the valid values entered by the user (positive and zero) and display them (one per line) as well as the kurtosis, as shown in the following example (note that all indexes are displayed with 2 digits, e.g., Value 01):

Value 01 = 26.34
Value 02 = 4.34
Value 03 = 1.245
--------------------
Kurtosis = 1.5

In the test part of your report, indicate the results provided by your program for these cases:

  • case I: x1 = 10, x2 = 15, x3 = 20, x4 = 25, x5 = 30, x6 = 35
  • case II: xi = i for i = 1, 2, ..., 15

Notes:

  • You should use an array to store the values entered by the user.
  • You should use separate loops to capture the values entered by the user, compute the kurtosis, compute the mean, compute powers, and display the entered values.
  • Your program should be modular and use functions. You should use separate functions to compute the kurtosis, compute the mean, compute powers as well as other tasks.
  • The use of mathematical functions provided by C (e.g., pow ) or any external C library is not allowed. You should implement your own functions to compute kurtosis, mean, powers or any other intermediate calculations required by your program.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.