Part of lab lesson 8 There are two parts to

 

Part of lab lesson 8

There are two parts to lab lesson 8. The entire lab will be worth 100 points.

Lab lesson 8 part 2 is worth 50 points

For part 2 you will have 40 points if you enter the program and successfully run the program tests. An additional 10 points will be based on the style and formatting of your C++ code.

Style points

The 10 points for coding style will be based on the following guidelines:

  • Comments at the start of your programming with a brief description of the purpose of the program.
  • Comments throughout your program
  • Proper formatting of your code (follow the guidelines in the Gaddis text book, or those used by your CS 1336 professor)
  • If you have any variables they must have meaningful names.

Development in your IDE

For lab lesson 8 (both parts) you will be developing your solutions using an Integrated Development Environment (IDE) such as Visual Studio, Code::Blocks or Eclipse. You should use whatever IDE you are using for your CS 1336 class. Once you have created and tested your solutions you will be uploading the files to zyBooks/zyLabs. Your uploaded file must match the name specified in the directions for the lab lesson. You will be using an IDE and uploading the appropriate files for this and all future lab lessons.

For this and all future labs the name of the source files must be:

lessonXpartY.cpp

Where X is the lab lesson number (8 for lab lesson 8) and Y is the part number (1 for part 1, 2 for part 2).

You will need to develop and test the program in your IDE. Once you are satisfied that it is correct you will need to upload the source file to zyBooks/zyLabs, and submit it for the Submit mode tests. If your program does not pass all of the tests you need to go back to the IDE, and update your program to fix the problems you have with the tests. You must then upload the program from the IDE to zyBooks/zylabs again. You can then run the tests again in Submit mode.

When running your program in Submit mode it is very important that you look at the output from all of the tests. You should then try and fix all of the problems in your IDE and then upload the updated code to zyBooks/zyLabs.

C++ requirements

You are not allowed to use any global variables. Use of global variables will result in a grade of zero for part 1.

Your program must have function main, function presentValue, three read functions, and a display function. Including main this is six functions.

The presentValue function must have the following signature:

double presentValue(double futureValue, double interestRate, int numberYears)

The presentValue needs to calculate the present value and return that back to the calling function. The formula for this is above. Note that the annual interest would be .08 for 8%.

Failure to follow the C++ requirements could reduce the points received from passing the tests.

General overview

In part 2 you will be creating multiple functions to calculate the present value.

You may be asking what a “present value” is. Suppose you want to deposit a certain amount of money into a savings account and then leave it alone to draw interest for some amount of time, say 12 years. At the end of the 12 years you want to have $15,000 in the account. The present value is the amount of money you would have to deposit today to have $15,000 in 12 years.

The formula used needs the future value (F) and annual interest rate (r) and the number of years (n) the money will sit in the account, unchanged. You will be calculating the present value (P).

P = F / ( (1 + r) ^ n)

In the above expression the value (1 + r) needs to be raised to the nth power. Assume that ^ is the power function and x^2 is x to the 2nd power (x squared)

You are not allowed to use any global variables. Use of global variables will result in a grade of zero for part 2.

Three read functions

You must have functions to read in the future value, the annual interest rate, and the number of years. That would be three different functions. Give these functions meaningful names. Note that the order of the values will be future value, annual interest rate, and number of years.

In all cases you need to return any valid value back to the calling function.

For all three functions you will write out to cout as prompt for an input value. You will read in that value from cin. If the value is invalid (zero or negative) you need to display an error message and reread the value (with another prompt). You need to do this in a loop and continue looping until a valid value has been entered. Only the number of years can be an int value. The rest should be of type double.

Here are the prompts for the three values you need to read in:

Enter future value
Enter annual interest rate
Enter number of years

Note that the interest rate will be a number such as 10 or 12.5. These are to be read in as percentages (10% and 12.5%). You will need to divide these values by 100 to convert them into the values needed in the function (.1 and .125 for the above values). This conversion needs to be done before you call the presentValue function (see below). If you do the conversion in the presentValue function your program will fail the unit tests, so do the conversion before you call the calculate function.

Here are the error messages you need to display if the values are negative:

The future value must be greater than zero
The annual interest rate must be greater than zero
The number of years must be greater than zero

You will also need a function called presentValue with the following signature:

double presentValue(double futureValue, double interestRate, int numberYears)

The presentValue needs to calculate the present value and return that back to the calling function. The formula for this is above. Note that the annual interest would be .08 for 8%.

Note that the interest rate will be a number such as 10 or 12.5. These are to be read in as percentages (10% and 12.5%). You will need to divide these values by 100 to convert them into the values needed in the function (.1 and .125 for the above values). This conversion needs to be done before you call the presentValue function (see below). If you do the conversion in the presentValue function your program will fail the unit tests, so do the conversion before you call the calculate function.

The display function

You also need a function that displays the present value, future value, interest rate, and number of years. The function needs to display the interest rate as %, so .05 would display as 5.000%. Give your display function a meaningful name. You will be passing a number of values to this function.

Here is the sample output for a present value of $69,046.56, a future value of $100,000, an interest rate of 2.5% and a number of years of 15,

Present value: $69046.56
Future value: $100000.00
Annual interest rate: 2.500%
Years: 15

Note that the present value and future value have three digits of precision to the right of the decimal point but the interest rate only has one digit to the right of the decimal point.

The main function will be the driver for your program.

Your program will only be processing one set of valid values for future value, annual interest rate and number of years.

Get the values for these by calling the read functions you created above.

Once you have the values you need to call your presentValue. Using the result from the presentValue and the input values you read in with your read functions you need to call your display function (written above) to display the values.

The main function

The main function will be the driver for your program. All of the non-main functions are called from main.

For the following sample run assume the input is as follows:

1000000.0
5.0
25

Your program should output the following:

Enter future value
Enter annual interest rate
Enter number of years
Present value: $295302.77
Future value: $1000000.00
Annual interest rate: 5.000%
Years: 25

Here is an example with some invalid data

Input values:

-100
0
1000000.0
5.0
25

Output:

Enter future value
The future value must be greater than zero
Enter future value
The future value must be greater than zero
Enter future value
Enter annual interest rate
Enter number of years
Present value: $295302.77
Future value: $1000000.00
Annual interest rate: 5.000%
Years: 25

Failure to follow the requirements for lab lessons can result in deductions to your points, even if you pass the validation tests. Logic errors, where you are not actually implementing the correct behavior, can result in reductions even if the test cases happen to return valid answers. This will be true for this and all future lab lessons.

Expected output

There are eight tests. The first test will run your program with input and check your output to make sure it matches what is expected. The next three tests are unit tests. The unit tests will directly call the presentValue function. The compilation of the unit test could fail if your presentValue function does not have the required signature. The final four tests will run your program with various input values and make sure you are calculating the correct answers.

You will get yellow highlighted text when you run the tests if your output is not what is expected. This can be because you are not getting the correct result. It could also be because your formatting does not match what is required. The checking that zyBooks does is very exacting and you must match it exactly. More information about what the yellow highlighting means can be found in course “How to use zyBooks” – especially section “1.4 zyLab basics”.

Finally, do not include a system("pause"); statement in your program. This will cause your verification steps to fail.

Note: that the system("pause"); command runs the pause command on the computer where the program is running. The pause command is a Windows command. Your program will be run on a server in the cloud. The cloud server may be running a different operating system (such as Linux).

Error message “Could not find main function”

Now that we are using functions some of the tests are unit tests. In the unit tests the zyBooks environment will call one or more of your functions directly.

To do this it has to find your main function.

Right now zyBooks has a problem with this when your int main() statement has a comment on it.

For example:

If your main looks as follows:

int main() // main function

You will get an error message:

Could not find main function

You need to change your code to:

// main function
int main()

If you do not make this change you will continue to fail the unit tests.

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

Why is it important to understand management style in a

  Why is it important to understand management style in a human relations course? Discuss at least three points. Exercise Instructions:  You are required to submit a 2-Page (Title Page and Content Page), APA formatted paper with substantial content. Substantial content requires staying on topic and fully addresses the assignment

In reference to U.S. presidential elections, answer the following in

In reference to U.S. presidential elections, answer the following in 2-3 sentences each: Do you think voting should be made mandatory/compulsory for citizens? Why or why not? Suppose people were able to cast their vote online. What would be one advantage and one disadvantage of online voting? What do you think

Concept Oriented Reading Instruction Please use the link below to

Concept Oriented Reading Instruction Please use the link below to read about the Concept Oriented Reading Instruction https://www.readingrockets.org/article/concept-oriented-reading-instruction-cori (Links to an external site.) Please view the video on the CORI strategy for reading comprehension https://youtu.be/6Yi5UfDeY1k (Links to an external site.) CORI Video Resource https://youtu.be/UxZNKBhHKWU (Links to an external site.) Review the information on

Consider the lesson plan you are developing and select a

 Consider the lesson plan you are developing and select a vocabulary word you are planning to introduce to your students. Develop an activity that will help your students build further understanding and application of the vocabulary word. While you are free to gather ideas from other activities, your submission must

Create a patient case where one of these modalities would

  Create a patient case where one of these modalities would be beneficial to include in their POC. Modalities are :  1 Blood Flow Restriction Therapy 2 Deep oscillation Therapy 3 Dry Needling Therapy Please include impairment, subjective, and objective data to support appropriateness of modality. Then, justify why the

Religious studies: Sholay Bollywood Movie Journal

For each question, students should compose a well-constructed paragraph or two in response. The length may vary, but for each film unit (each set of questions), the total should be approximately 1.5-2 single spaced pages (about 700-900 words). Formatting and Technical Requirements – Standard 1” margins around all sides; 12

1.The battle of the sexes lives on still today. Since

 1.The battle of the sexes lives on still today. Since admission standards do not address gender whatsoever, there should be an equally diverse group of men and women in school, but do they perform equally well. Using the sample of 200 students, conduct a hypothesis test for two independent samples

A Survey of 30 people to find out if they

A Survey of 30 people to find out if they are left-handed or right-handed, and use the following chart to create a contingency table with the information. Left handed= 6  Right handed = 24 Total Female lefty =4 righty=16 Male lefty Total= 2 righty=8 Answer the following questions about the

Based upon your careful reading of chapter 21, in what

Based upon your careful reading of chapter 21, in what ways did the struggles for independence of African and Asian peoples in the twentieth century parallel that of the “new nations” in the Americas of the eighteenth and nineteenth centuries?  In what ways did they differ?  Your response should discuss

American Southwest History-Texas – Premium Paper Help

Premium Paper Help is a professional writing service that provides original papers. Our products include academic papers of varying complexity and other personalized services, along with research materials for assistance purposes only. All the materials from our website should be used with proper references.

When you think of an Olympic host, what comes to

When you think of an Olympic host, what comes to mind? Do you think or the controversy-ridden Sochi 2014 Winter Olympics, with allegations of cost overruns, civil rights violations, and political infighting or the awe-inspiring majesty of the 2016 Rio Summer Olympic opening and closing ceremonies? Both Sochi and Rio

Part 1 IDOC (2022) lists 15 prison facilities in Indiana

Part 1 IDOC (2022) lists 15 prison facilities in Indiana for adult males. These facilities differ in several aspects, such as size and security levels. Consequently, they are classified into a minimum, medium, and maximum facilities. Minimum prisons are the least restrictive and only house, nonviolent offenders. In total, Indiana

comment from post 1 Nursing Assignment Help

At the beginning of my career as a nurse, I started working as a licensed practical nurse (LPN) at a nursing home. I used to work at least 72 hours a week with the same residents. Initially, when I witnessed death at work, it was very difficult for me because

Based on the required topic Resources, write a reflection about

Based on the required topic Resources, write a reflection about worldview and respond to following: In 250-300 words, explain the Christian perspective of the nature of spirituality and ethics in contrast to the perspective of postmodern relativism within health care. In 250-300 words, explain what scientism is and describe two

Design your own chocolate showpiece concept Include a detailed drawing

  Design your own chocolate showpiece concept Include a detailed drawing of your concept to scale with measurements. The drawing should be approximately 8″x11″ in size List the colours used and where the colours are applied List shapes in order to create each element List the techniques that would be