CSCI 102 - Fall 2023 Fundamentals of Computation

HW 4

Part 1

You are trying to track your favorite movies. Unfortunately, your opinions change often.

Each time you see a new movie:

For example, if your top 4 favorite movies are as follows:

  1. HiddenFigures
  2. LOTR
  3. Parasite
  4. Selma

Then after you watch WonderWoman your favorites would be:

  1. WonderWoman
  2. HiddenFigures
  3. Selma
  4. Parasite

Idioms Used

Study and consider how to use some or all of the following idioms:

Hint: Think about the order to assign your variables and how to swap variables.

Other Instructions and Requirements

We have provided a starting point (skeleton program) on Vocareum that you must use and modify!!. In the skeleton you will see assignment statements setting up your initial rankings and then the code will prompt for two new movies. After each prompt, reorder your favorites as described above.

To receive credit, you may not hard-code the strings of the movie names to the correct order. Instead, you must use variables and swapping techniques.

This exercise is not very difficult. Don’t be surprised if you feel it is easy.

This assignment will be submitted through Vocareum.

When you start the assignment in Vocareum you should see a file movierank.cpp in the work area in the left hand window pane. Click movierank.cpp to open the file in the editor. You should see some comments in the editor. Enter your name and email in the indicated lines. From there you can read the other comments and then either delete them or simply leave them and start your program code beneath the comments.

Write your program (it will save automatically when you click outside of the editor window). When your ready to test it, you can:

Repeat the build and run process until you believe your code works. Then click the Submit button. This will submit your code. You are allowed to submit as many times as you like. When you click Submit, our scripts will automatically run a few (not all) of our grading test cases through your program and report the results. Look at those results to ensure your code is passing these basic tests. If everything passes, you are done! Your code is submitted. If something fails, you can simply go back edit, build, run, and submit again (as much as you like).

If you have submitted on Vocareum at this point you are done! The instructions below are only if you want to use some other editor/compiler to write your code.

You can write your program using any editor and compiler (if you have one installed on your machine) but will eventually need to upload your code in a file named movierank.cpp to Vocareum.

When you believe your program is finished leave that browser tab/window open and in a new tab/window, login to Vocareum, start the assignment (LeapYear Part), and in the upper-left of the resulting window, click New..File. A textbox will appear where you can type in the filename (leave the work/ portion there and) just type movierank.cpp. In the left window pane you should now see movierank.cpp appear (it must be named movierank.cpp) and you can click on it to open it. A blank window should appear on the right. Cut/paste your code from your other tab/window to this window and you can click Submit. When you click submit it should run a few automated tests to let you know if it compiled and passed some basic sanity checks. Look at the output to ensure things are working. If not, you’ll need to modify your code in Vocareum or back in your other tab/window and then cut/paste back to Vocareum.

Be sure you click submit otherwise your code will just be saved, but not submitted!!

Part 2 - Loan Payment

Write a program to compute the monthly Loan Payment Amount which is given by:

\[\Large Payment = ( \frac{r*LoanAmount}{1-(1+r)^{-n}})\]

where LoanAmount is the initial loan amount in integer dollars, r is the annual interest rate expressed as percentage (e.g. 3.25% should be entered as 3.25 and n is the number of payments.

However, the user will NOT enter the number of payments but the number of years for the life of the loan. Since you need to output the monthly payment, you should convert the number of years that the user entered to the number of monthly payments. You will also need to make the rate entered (e.g. 3.25) into an appropriate decimal (e.g. 0.0325) and then scale it to the rate per month (i.e. a 6% annual rate is a 0.5% monthly rate).

The user will type in: LoanAmount AnnualRate Years in that order. Receive the input, compute the correct monthly payment, and output it to the screen (on a line all by itself, without other text.)

You must follow the formatting instructions given in the skeleton code comments.

ALSO, you must output the amount accurate to exactly 2 decimal places.

This assignment will be submitted through Vocareum.

When you start the assignment in Vocareum you should see a file payment.cpp in the work area in the left hand window pane. Follow the similar procedure you used for the previous part of the assignment to edit, compile, run, and submit your code.

You can write your program using any editor and compiler (if you have one installed on your machine) but will eventually need to upload your code in a file named payment.cpp to Vocareum. Follow the procedure outline in the previous part of the assignment for naming/uploading your code and submitting it.