Assignment #2
Due: Thursday, June 1
Objective
This assignment will involve practice with basic I/O, as well as practice
with selection statements
Task
Write the following programs, each in a separate file. Filenames should
be:
(Note that the filenames are all lowercase)
Exercise 1
Filename: triangle.c
Write a program that does the following:
Prompt the user and let them enter three integers. Determine and print
out whether these three numbers could be the lengths of the sides of a
right triangle. Your output should look like mine below in the
sample runs (i.e. print the numbers and the message). The numbers can be
entered in any order.
Recall that a right triangle must satisfy the pythagorean theorem, so that
if x and y are the legs of the triangle, and z is the hypotenuse, the
following algebraic formula is true:
x2 + y2 = z2
(Also note that "Myers' First Law of Common Sense" says that the sides of
a triangle must have positive lengths! :-)
Sample Runs
(user input is underlined, to distinguish it from output)
Sample run 1
Input three integers: -2 0 5
The numbers -2, 0, and 5 CANNOT be the sides of a right trangle.
Sample run 2
Input three integers: 3 4 5
The numbers 3, 4, and 5 CAN be the sides of a right triangle.
Sample run 3
Input three integers: 6 11 8
The numbers 6, 11, and 8 CANNOT be the sides of a right triangle.
Exercise 2
Filename: credit.c
This program will obtain entry of credit card information for a single
month, then will print a small summary and determine whether the credit
limit has been exceeded or not. Do the following:
- Prompt the user, and allow them to enter the following information (in
this order):
- Account number (an integer value)
- Credit limit for the account
- This month's starting balance
- This month's total charges
- This month's total credits
The account number is an integer, but all other values are monetary
values. For monetary values, use type double in this program
- Compute the new balance (starting balance + charges -
credits), and print a summary for the account.
- The format of the summary is given in the sample runs below. Your
output must match mine exactly
- All monetary values must print to 2 decimal places (i.e. the nearest
cent).
- The four lines of output for old balance, charges, credits, and new balance must line up
vertically on the decimal point. You may assume that the largest
possible monetary value in this output will be $9999999.99
- Since the credit is subtacted from the balance when computing the new
balance, it is written inside < > marks to indicate that it's a
negative value. This should appear on your credits output.
- Once the summary is printed, determine whether the new balance has put
the account over the credit limit or not, and print the appropriate
message.
- If the new balance exceeds the credit limit, print a message saying
so, and by how much
- If the new balance doesn't exceed the limit, print a message that
indicates how much available credit there is now on the account
- Appropriate format for these messages is illustrated in the sample
runs below. Format your output the same as mine.
Sample Runs
(user input is underlined, to distinguish it from output)
Sample Run 1
Enter the account number: 123
Enter the credit limit for the account: 5000.00
Enter the starting balance for this month: 3465.12
Enter the total charges for this month: 1699.34
Enter the credits for this month: 500.00
** Summary for account # 123 **
Starting balance: $ 3465.12
Monthly charges: $ 1699.34
Monthly credits: <$ 500.00>
-----------
New Balance: $ 4664.46
Available credit: $ 335.54
Sample Run 2
Enter the account number: 2453
Enter the credit limit for the account: 2500.00
Enter the starting balance for this month: 2005.45
Enter the total charges for this month: 1348.32
Enter the credits for this month: 747.43
** Summary for account # 2453 **
Starting balance: $ 2005.45
Monthly charges: $ 1348.32
Monthly credits: <$ 747.43>
-----------
New Balance: $ 2606.34
Credit limit of $2500.00 exceeded by $106.34
Requirements for both programs
- No global variables
- All input and output must be done with printf and
scanf, using the library stdio.h
- You may only use the stdio.h library (you should not need
any others for these tasks)
- The programs should compile with the Visual C++ compiler
- Readable and well-documented source code
Submitting:
Submit only your source code files through the web submission page. As
there are two of them, this will require filling out the submission page
twice. Make sure to click on "Assigment 2" both times. Submit the files:
triangle.c
credit.c