APS 105 — Computer Fundamentals Lab 2: More Complex Calculations

$30.00

Category: Tags: , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (7 votes)

In this laboratory, you will be writing a C program to perform more complex calculations (compared to lab 1) with variables and arithmetic operators. As in lab 1, your solution will be marked by your TA during your scheduled lab period, and should also be submitted through the ECF computer system by the end of your scheduled lab period. Your TA will mark your solution based on its style and your verbal answers to a few questions. The course material necessary for completing this lab will be found in your lecture notes and you should also be able to find the necessary details through an online search. Preparation Read through this entire document carefully, and prior to the lab do the work to create the programs that are described in below. If you have problems, try one of these things: 1. Read the class bulletin board on Piazza, to see if others had similar problems. If you don’t see anything helpful there, ask a question. Don’t ask for, or ever give, though, a solution in the form of the full computer program! 2. The TA in your lab can give you help. 3. Ask your TA in your weekly tutorial period. Important note for reading these lab documents: You are being asked to write programs that take in input from a user (which will be you most of the time) typing on the computer keyboard, and produce specific output. Below (and in all labs) we will provide examples of what that input might be (typed by the user) and what the corresponding output is. In those examples, the input typed by user is displayed using a bold font. The text stands for the user pressing the enter key on the keyboard. On some keyboards, the enter key may be labeled return. When you execute your programs, the user’s text will not be displayed in bold and will not be shown. Throughout this lab, there is a single space after the colon (:) in each output line. Cost of Borrowing Mr. Maltete decided to borrow money to buy things. He would make a purchase on credit, then pay the money off over N months. Devise a program that calculates the monthly payments Mr. Maltete would have to make on a purchase, and how much he would end up paying for the purchase after paying the credit interest and the initial cost. The monthly payment 𝑐 can be calculated using the formula: 𝑐 = 𝑟 1 − (1 + 𝑟) −𝑁 ∗ 𝑃 Where 𝑃 is the cost of the item 𝑟 is the interest rate per month for borrowing 𝑁 is the number of months over which the item is paid for This formula takes care of the fact that the amount due is being reduced every month and therefore is not subject to interest charges for following months. Here is a sample input/output sequence from the program: Enter the purchase price of the item: 30.33 Enter the interest rate per year as a percentage: 5.0 Enter the number of months for repayment: 6 The monthly payment is : 5.13 The total cost of the purchase is: 30.77 Although this is the result you should see, 6*5.13 is not 30.77! Can you figure out why this is so? (The program you write should be simple and not correct this apparent problem.) Current (Jan 2019) yearly credit card interest rates are about 20%, while interest on a car loan is 5-6%, and mortgage rates are about 3.4%. For our purposes, you can divide those rates by 12 to get a monthly rate to use in the formula. There is nothing owing after 𝑁 months. Note that the purchase price and interest rates are not necessarily integer values, but the number of months is integer, and that the interest rate is put in as a percentage, so 5.0 in the example is 5%, but 𝑟 from the formula is therefore 0.05 . Outputs should have two decimal places. Consider all inputs to be positive. Note also that the formula will not work with an interest rate of zero (what happens if you make the interest rate zero?? Does the program crash and give an error message??) Your C program must go in a file named Lab2.c. Try the following real-life examples:  Buying a car for $15,000 and using credit for a 5 year term at 5%  Buying a condo for $500,000 (after down payment) and using a 25 year mortgage at 3.5%. Advanced: You might want to write another program that calculates how much you pay for something if you put it on a credit card, wait a year (with no payments) then pay off the item and the accumulated interest charges. Remember that the interest due in month M is also subject to interest in month M+1! Grading by TA and Submitting Your Program for Auto-Marking There are a total of 10 marks available in this lab, marked in two different ways: 1. By your TA, for 4 marks out of 10. Once you are ready, show your program to your TA so that we can mark your program for style, and to ask you a few questions to test your understanding of what is happening. Programs with good style have been described in Lab 1, but once again, they are:  Clear comments that describe what is happening in the program.  Good choices for variable names that indicate their purpose. Please adopt the naming convention where if you have a variable that is described by multiple words, user lower case for the first letter of the first word, and Upper case for all subsequent words – e.g. inputCode.  Properly indented code.  Proper use of named constants, rather than putting constants (such as 125) directly into the code. The TA will also ask you some questions to be sure that you understand the underlying concepts being exercised in this lab. 2. By an auto-marking program for 6 marks out of 10. You must sumbit all of your program files through the ECF computers for marking. We will use a software program to compile and run your program, and test it with different inputs. Long before you submit your program for marking, you should run the exercise program that compiles and runs your program and gives it sample inputs, and checks that the outputs are correct. Similar to Lab 1, you should run the following command: /share/copy/aps105s/lab2/exercise within the directory that contains both your solution programs. This program will look for the file Lab2.c in your directory, compile them, and run them on a some of the test cases that will be used to mark your program automatically later. If there is anything wrong, the exercise program will report this to you, so read its output carefully, and fix the errors that it reports. IMPORTANT: YOU WILL HAVE TO COPY BOTH OF YOUR FILE – Lab2.c – TO BE IN THE SAME FOLDER/DIRECTORY WHERE YOU WILL RUN THE SUBMIT COMMAND. 3. Once you have determined that your program is as correct as you can make it, then you must submit your program for auto-marking. This must be done by the end of your lab period as that is the due time. To do so, go into the directory containing your solution files and type the following command: /share/copy/aps105s/lab2/submit This command will re-run the exercise program to check that everything looks fine. If it finds a problem, it will ask you if you are sure that you want to submit. Note that you may submit your work as many times as you want prior to the deadline; only the most recent submission is marked. The exercise program (and the marker program that you will run after the final deadline) will be looking for the exact letters as described in the output in this handout, including the capitalization. When you test your program using the exercise program, you will see that it is expecting the output to be exactly this, so you will have to use it to see if you have this output correct. Important Note: You must submit your lab by the end of your assigned lab period. Late submissions will not be accepted, and you will receive a grade of zero. You can also check to see if what you think you have submitted is actually there, for peace of mind, using the following command: /share/copy/aps105s/lab2/viewsubmitted This command will download into the directory you run it in, a copy of all of the files that have been submitted. If you already have files of that same name in your directory, these files will be renamed with a number added to the end of the filename. After the Final Deadline — Obtaining Automark Briefly after all lab sections have finished you will be able to run the automarker to determine the automarked fraction of your grade on the code you have submitted. To do so, run the following command: /share/copy/aps105s/lab2/marker This command will compile and run your code, and test it with all of the test cases used to determine the automark grade. You will be able to see those test cases output and what went right or wrong.