PROGRAMMING ASSIGNMENT #1

Write a C program that calculates and prints the sum, difference, product, quotient, and remainder (modulus) of two integer numbers (shown below).

Once you create, compile, link and run your program, the following should be output from yourprogram:

This program will do some computations.

The 2 numbers used by this program are 63 and 25.

The Sum of 63 plus 25 is 88The Difference of 63 minus 25 is 38 The Product of 63 times 25 is 1575 The Quotient of 63 divided by 25 is 2 with remainder 13

Thanks for using the program.

Note: The coral text represents the "output" from your program and is shown for clarity only here. It isnot required that your output be in this color. (Do not even attempt to try!). The terms sum, difference,product, and quotient refer to the operations of addition, subtraction, multiplication and division.

Also, you do not need to use numbers 63 and 25 in your program. You can use any numbers you wish.Remember however, that the second number should not be zero, or you will get a "divide by zero" errorwhen calculating the quotient and remainder values! The correct spacing is part of the program too.

Hints:

*
This program requires at most 7 integer variables.
*
This program requires about 12 lines of code (not including variable declarations). Don't worry if youneed more lines - that is more like the minimum.
*
You should have a line that may look something like:

int num_1 = 63, num_2 = 25;

Good Luck! :-)


PROGRAMMING ASSIGNMENT #2

Write a C program that determines the miles per gallon for 3 tanks of gasoline that a user fills in his/hercar.

We will explain to the user very clearly what the program will be doing and how they should enter data.

The program should prompt the user to enter the number of gallons used and the number of miles driven for each of the 3 tanks of gas. The program should then calculate and display the miles pergallon obtained for each tank. Once processing is complete for the 3 tanks, the program will calculatethe overall mileage(total gallons / total miles) and display a friendly "Goodbye" message as shownbelow.

Once you create, compile, link and run your program, your program should present the following dialogto the user:

Welcome to the mileage calculator.

This program will calculate the miles per gallon for you for three tanks of gas after you haveentered the gallons used and miles driven.

Enter the number of gallons used for tank #1:

12.8 Enter the number of miles driven: 287.1 *** The miles per gallon for this tank is 22.4

Enter the number of gallons used for tank #2: 10.3 Enter the number of miles driven: 200.2 *** The miles per gallon for this tank is 19.4

Enter the number of gallons used for tank #3: 5.2 Enter the number of miles driven: 120.9 *** The miles per gallon for this tank is 23.3

Your overall average miles per gallon for three tanks is 21.5

Thanks for using the program.

Note: The coral text represents the "output" from your program and is shown for clarity only here. It isnot required that your output be in this color. (Do not even attempt to try!). Also note that what the usertypes in is indicated by the blue area above. Again, for clarity only. The first two lines may be anysuitable message to the user. After that the program should run as above. The output spacing isimportant.

I did not provide an algorithm for this assignment, however I have included several hints below. You are not required to reference these hints for your solution. They are here if you need some help. It isokay to completely ignore them, if you so choose. Some students have told me that the hints actuallyconfused them! :-)

Hints:

*
This program requires 1 variable of type int, and 5 or 6 of type float.
*
This program requires an introductory statement to the user.
*
This program requires a loop structure (for, while or do -- your choice).
*
The loop requires 3 printf statements: 1 to prompt the user for the "number of miles driven"; 1 toprompt for "number of gallons used"; and a third to display the calculated "miles per gallon for thistank".
*
The loop also requires 2 scanf statements: 1 to "read in" the number of gallons used which is inputby the user; and a second to "read in" the number of miles driven, which is also input by the user.
*
This program requires 3 calculations within the loop - one for the current mileage, and twoaccumulators to add up the total miles and total gallons used for the final calculation.
*
This program requires another printf statement (outside the for loop) to display the average for alltanks.
*
The loop index is used to display the current tank calculation.

Good Luck! :-)

(Mission Impossible theme plays in the background....)


PROGRAMMING ASSIGNMENT #3

Write a C program that calculates and prints the average and total of several employee salaries entered by the user. The program should first prompt and edit the user to enter the number of salaries to process(edit so at least two salaries must be entered). It should then prompt the user for each salary. As each salary is entered, the program should ensure that the salary entered is in fact "positive" (i.e., greater than zero). If the salary is not positive, an error message should be displayed (as shown below), and the user should be re-prompted for a positive salary. Once all salaries are entered, the program should calculate and print the average and total of all of the positive salaries entered.

The dialog with the user is sampled below (you should change the introductory greeting):

Welcome to the Sears Employee Calculator Program.

This program calculates the average and total of as many employee salaries as you wish to enter.

First, enter the number of salaries to process: 4

Now enter the 4 salaries to be averaged.

Enter salary #1: 10000 Enter salary #2: 8000 Enter salary #3: -20000 *** Invalid entry. Salary must be positive. *** Enter salary #3: 25000 Enter salary #4: -3333 *** Invalid entry. Salary must be positive. *** Enter salary #4: 52000

The Average of the 4 salaries entered is: $ 23750.00

The Total of the 4 salaries entered is: $ 95000.00

Recall: The coral text represents the "output" from your program and is shown for clarity only here. It is not required that your output be in this color. (Do not even attempt to try!). Also note that what the user types in is indicated by the blue area above. Again, for clarity only. A user-friendly message of your choosing should precede the dialog and explain the program(you should change the first sentence). I would like you to line up the total and average by the decimal points.

We know that there are limitations to the size of float variables, so be careful not use salaries that exceed those limits as you test your program.

I did not provide an algorithm for this assignment, however I have included several hints below. You are not required to reference these hints for your solution. They are here if you need some help. It is okay to completely ignore them, if you so choose.

Hints:

*
This program requires variables of type int and type float.
*
Use printf and scanf statements to first prompt the user for the number of salaries to be processed.
*
This program requires at least 3 loop structures (for, while or do – use your judgment).
*
A loop requires some a printf and scanf statement to prompt user for a salary.
*
A loop also requires selection structures (if, or if else) statement to check for negative salary and entry numbers.
*
The selection structures require printf statements to output error messages.
*
A loop requires a calculation to keep track of the sum of salaries entered (accumulator).
*
Once all salaries are entered (after the end of the loop), this program requires a calculation to determine average, and then a printf statement to display the average.
*
To line up the decimal places – you can use a format specifier like: % 12.2f

Good Luck! :-)

(Darth Vader theme music plays in the background…..)


PROGRAMMING ASSIGNMENT #4

Write a C program that allows the user to make some simple banking transactions. The program should first prompt the user to enter the current balance of his/her bank account (in dollars and cents, not less than zero). The program should then prompt the user to enter the number of withdrawals to make, and then the number of deposits to make. For this assignment, let's set a maximum of 50 deposits and 50 withdrawals, you'll see why as you read on.

Using a loop, the program should then prompt the user to enter the amount of the first deposit (a positive amount to add to the bank account balance), the amount of the second deposit, the third, & etc., until the number of deposits have been processed.

Using a second loop, the program should then prompt the user to enter the amount of the first withdrawal (a positive amount to subtract from the bank account balance, if possible), the amount of the second withdrawal, the third, & , etc. until the number of withdrawals have been processed. Once all deposits and withdrawals have been made, the program should output the ending balance.

Read all the specifications carefully. I did not show all of the editing features you are required to do.

The dialog with the user should look similar to the following, only with your special introductory statement(s) as you wish:

Welcome to the Sears Banking System (or whatever you wish here) Please enter your first name: Jim Hello Jim. Jim, please enter your current balance in dollars and cents: 256.40 Enter the number of withdrawals: 2 Enter the number of deposits : 3 Enter the amount of deposit #1: 10.50

Enter the amount of deposit #2: 12.25

Enter the amount of deposit #3: 125.30 Enter the amount of withdrawal #1: 120.35 Enter the amount of withdrawal #2: 35.60

*** The closing balance Jim is $248.50 ***

(there is more to the output …. See below)

At this point, the program should also output one of the following messages based on the closing balance, with the name inserted. That is:

If the closing balance is greater than or equal to 50000.00, output: "*** Jim it is time to invest some money! ***"

If the closing balance is between 15000.00 and 49999.99, output: "*** Jim maybe you should consider a CD. ***"

If the closing balance is between 1000.00 and 14999.99, output: "*** Jim keep up the good work! ***"

If the closing balance is between 0.00 and 999.99, output: "*** Jim your balance is getting low! ***"

So, in the above example, the last line of sample output would be:

*** Jim your balance is getting low! ***

Regarding error checking on all user input, the following check should be made while users are entering the withdrawal amounts: If the withdrawal amount exceeds the current balance (including the new deposits), the program should issue the following error message:

*** Withdrawal amount exceeds current balance, please re-enter. ***

The program should then re-prompt for a lower withdrawal amount. But, if the current balance goes to zero, no more withdrawals should be made and an appropriate message should appear (that one's up to you! Use some polite creativity!)

Finally you are to print out a “Bank Record†as shown in the sample below. So, for example, a complete sample run of the program with error checking might look like:

Welcome to the Sears Banking System Please enter your first name: Jim Hello Jim. Jim, please enter your current balance in dollars and cents: -56.40

Error: Beginning balance must be at least zero, please re-enter! Jim, please enter your current balance in dollars and cents: 256.40

Enter the number of withdrawals: 2

Enter the number of deposits: -3 Error: Number of deposits must be at least zero, please re-enter.

Enter the number of deposits: 3

Enter the amount of deposit #1: 10.50 Enter the amount of deposit #2: 12.25 Enter the amount of deposit #3: 125.30

Enter the amount of withdrawal #1: 5000.00 *** Withdrawal amount exceeds current balance, please re-enter. *** Enter the amount of withdrawal #1: 120.35 Enter the amount of withdrawal #2: 35.60

*** The closing balance Jim is $248.50 *** *** Jim your balance is getting low. ***

*** Bank Record ***

Starting Balance: $ 256.40
Deposit #1: 10.50
Deposit #2: 12.25
Deposit #3: 125.30
Withdrawal #1: 120.35
Withdrawal #2: 35.60
Ending Balance: $ 248.50

It is hard to see this in HTML, but I want you to align the decimal points in the bank record.

You are to keep track of all of the deposits and all of the withdrawals so that you can print them out in "record" form. You do this by storing them in arrays. You will have one array to hold the deposit amounts entered by the user, and another array to hold the withdrawal amounts. You want to be sure that the size of the arrays are large enough to handle 50 deposits and 50 withdrawals. Perhaps:

float deposits[50], withdrawals[50];

Notice the test above for "Too many deposits". You want to be sure that the user does not want to enter more information than you can store in your array. In my example above, I made the array sizes "50". That means that I can store up to 50 deposits and 50 withdrawals. So, I want to test that the user does not plan to enter more than that. The same error checking should be done on the code that prompts for withdrawals.

NOTE: There are some bothersome complications with the entry and storage of some float numbers. Because of the way data is stored the float number 22.39 may be stored as 22.389999, and this may cause a problem with your final if statements and even with balance equaling zero. This is a well known anomaly in C.

You may not encounter these problems, I just wanted to warn you of the potential problem.

(Darth Vader theme plays in background…..)


PROGRAMMING ASSIGNMENT #5 (Your last one!!!)

This program is similar to programming assignment #4: Data error checking for all inputs as in #4. Your program is to behave in the exact same manner as assignment #4, however how you structure your code is a different story. Now we will use functions.

Recall Assignment #4:

Write a C program that allows the user to make some simple banking transactions. The program should first prompt the user to enter the current balance of his/her bank account (in dollars and cents). The program should then prompt the user to enter the number of deposits to make, and then the number of withdrawals to make. For this assignment, let's set a maximum of 50 deposits and 50 withdrawals. (etc.)

Here is the change for program #5: There should be at least three non-trivial functions in the program! (by that I mean a function that does more than just print a line of text). For example, one function may be to find out how many deposits will be entered, or accepts the opening balance, or provides the message before the bank record. etc. For these you will need to supply the function with an argument, or the function will return some value to the main program.

Hints: Your code from assignment #4 does not need to be modified too much to solve this problem. The algorithm is the same. Outputting the contents of the arrays in "record form" is pretty straightforward, and should be done in a loop. (This could be a good place for a function.) Take concepts from my solution to problem #4, but please do not copy mine verbatim.

For example: You can use void as the function type and use an argument(s) (e.g. you can have void print_deposits_out ( float deposits [ ], int number_of_deposits) as a prototype.) And you could use a similar one for the withdrawals. Or, you could put the comment before the bank record into a function by sending the closing balance into the function. BONUS: if you use more than three functions, I will grant you some minor errors that I would normally take off for(-2 or -3 points) for each function used (to a maximum of 100 for a grade). Now that's an incentive!

Good luck!

James Bond theme in background……