Programming

Programming questions? Ask a programmer for answers ASAP

Connect one-on-one with {0} who will answer your question

Customer Question

Create an example function definition...

Create an example function definition of a function that takes at least two parameters. At least one of the parameters should be passed by value, and at least one should be passed by reference.

Then show a sample call to your function, along with the declaration of any constants/variables used by the function call. You do not need to write an entire program.

All functions you write will be prototyped. So create prototypes for all of your user-defined functions. The prototypes should be placed above main, and the function definitions should be placed below main.

Program #1

Given the following recursive function, answer the two sub-problems below.

float wk7recur (float value, int num)

{

if (num == 0)

return 1;

else

return ( value * wk7recur (value, num - 1) );

}

Sub-Problem 1:

What would the value of answer be for each of the following? Calculate your answers by hand. You will need to report ALL intermediate answers for each level of recursion (NOT just the final result).

a) float answer = wk7recur (2.0, 4);

b) float answer = wk7recur (3.0, 3);

c) float answer = wk7recur (1.0, 5);

Sub-Problem 2:

Figure out what computation is being performed by the wk7recur function.

What is the name of the math computation performed by this function?

Place the answers to sub-problems 1a-c & 2 in the top of program comments for this program (be sure to show intermediate answers for each level of recursion).

After you complete the subproblems, you will write a program that includes both the recursive version of the function wk7recur (from above) and an iterative version of the function (which you will write) called wk7loop.

The wk7loop function should use iteration (looping) instead of recursion to do the same computation as the wk7recur function.

The main function should first explain to the user what the program will do.

Then it should prompt the user for the floating point number, fnum, and the integer inum, and error check them as follows:

fnum may be any value, positive or negative, but a 0 value will indicate the user wants to exit.

inum may be any positive integer (including 0).

If the user does NOT enter 0 for fnum, then call BOTH of the functions, using fnum and inum as parameters.

The results of both function calls should be printed out to 3 decimal places, with descriptive text. Note that the results should be the same!

Sample Output:

Recursive result = 4.840

Iterative result = 4.840

The only way the user may exit the program is to enter 0 for the value of fnum -- do not ask the user whether to run the program again.

The program should LOOP and continue to compute results for new values until the user enters 0 for the value of fnum. When the user enters 0 for fnum, the program should not ask for the value of inum – it should just exit.

Program #2

Write a modular financial calculator program. Make sure to use the following:

• The indentation and spacing practices introduced in the reading

• double for all floating point values

• Constants for all fixed values

• Prototypes for all user-defined functions

The program should first provide a menu for the user to select what s/he wants to do, with Exit as one of the choices.

The user will be able to choose to do loan or savings calculations, using one of the following four formulas:

• Compute a Loan Payment for a given Loan Amount to be borrowed:

MonthlyPayment = (factor * monthlyInterestRate * LoanAmount) / (factor - 1);

• Compute the Loan Amount you could borrow for a given affordable Monthly Payment:

LoanAmount = ( (factor - 1) * monthlyPayment ) / (factor * monthlyInterestRate);

• Compute the Total amount that will be accumulated for a given Monthly Amount saved:

Total = ( (factor - 1) * monthlyAmount ) / monthlyInterestRate;

• Compute Monthly Amount required to accumulate a given Total amount:

monthlyAmount = ( Total * monthlyInterestRate ) / ( factor - 1 );

For all of these choices, the user will enter an annual interest rate (e.g. 7.25 for 7.25%), and a number of years to borrow or save (e.g. 3.5 for 3½ years), and a monetary amount.

Input Error Checking

Error check the following user input values:

• Yearly interest rate must be between 1% and 30%.

• The number of years to borrow or save must be between 1 year and 50 years.

• Monetary amounts must be positive and non-zero, and must be no more than $ 9,999,999.99.

The program will need to convert the annual interest rate to a monthly interest rate (divide by 100 to get a fractional interest rate, and then divide that by 12 for monthly interest) before using it in the formulas.

All of the formulas also require that you first calculate a factor and then use it in your formula. The factor formula is:

factor = exp( numberOfMonths * log(1 + monthlyInterestRate));

Note that exp and log are predefined mathematical functions, located in the C++ library.

For hand calculating results to test your program, the equivalent algebraic equation is:

Factor = (1 + MonthlyInterestRate) TermInMonths

Output

Calculate and display the results, including the information the user input in the following format:

Sample output (for both Loan calculations):

Sample output (for both Savings calculations):

Total Annual Monthly

Amount Number Interest Savings

Saved of Years Rate Required

------------ ---------- -------- ----------

$ 100000.00 7.5 years 7.500% $ 831.13

Note that dollar amounts are calculated to the nearest penny (i.e. rounded to 2 decimal places).

Years should be displayed to one decimal place, and the annual interest rate to 3 decimal places.

After displaying the results, the program should pause and then return to the menu to let the user choose another formula or choose to exit. The only way the user may exit the program is to choose to exit from the menu -- do not ask the user whether to run the program again.

So each time a formula is chosen from the menu, the program will read new inputs, display the results, and loop back to the menu -- until the user chooses to exit.

This program should be modular. You must include the following functions:

• A function to read and validate the interest rate. Pass back both the yearly interest rate and the monthly interest rate, using reference parameters.

• A function to read and validate the number of years to borrow or save. Pass back both the term in years and the term in months, using reference parameters.

• A function to read and validate a dollar amount.

• A function to display the menu and read and validate the user's choice.

• A function to calculate and return the factor, called by a function other than main.

• One or more functions to compute the results.

• Only one or two functions to output the results.

• Each function should perform only one logical task. When breaking down the code into function, look for similarities in the code. Use the functions to minimize the amount of code you have to write.

•

•

• Program and Function Documentation (both programs)

•

• 1) Be sure to include top of program comments as specified in WBW section 1.8.

•

• 2) Make sure you comment any constants/variables whose names are XXXXX XXXXX descriptive.

•

• 3) You must also include a comment above each user-defined function that includes:

•

• What the function does

• Description of the input parameters (if any), used to pass values into the function

• Description of the output parameters (if any), used to pass values back from the function

• Description of what is returned from the function via the return statement (if anything)

Then show a sample call to your function, along with the declaration of any constants/variables used by the function call. You do not need to write an entire program.

All functions you write will be prototyped. So create prototypes for all of your user-defined functions. The prototypes should be placed above main, and the function definitions should be placed below main.

Program #1

Given the following recursive function, answer the two sub-problems below.

float wk7recur (float value, int num)

{

if (num == 0)

return 1;

else

return ( value * wk7recur (value, num - 1) );

}

Sub-Problem 1:

What would the value of answer be for each of the following? Calculate your answers by hand. You will need to report ALL intermediate answers for each level of recursion (NOT just the final result).

a) float answer = wk7recur (2.0, 4);

b) float answer = wk7recur (3.0, 3);

c) float answer = wk7recur (1.0, 5);

Sub-Problem 2:

Figure out what computation is being performed by the wk7recur function.

What is the name of the math computation performed by this function?

Place the answers to sub-problems 1a-c & 2 in the top of program comments for this program (be sure to show intermediate answers for each level of recursion).

After you complete the subproblems, you will write a program that includes both the recursive version of the function wk7recur (from above) and an iterative version of the function (which you will write) called wk7loop.

The wk7loop function should use iteration (looping) instead of recursion to do the same computation as the wk7recur function.

The main function should first explain to the user what the program will do.

Then it should prompt the user for the floating point number, fnum, and the integer inum, and error check them as follows:

fnum may be any value, positive or negative, but a 0 value will indicate the user wants to exit.

inum may be any positive integer (including 0).

If the user does NOT enter 0 for fnum, then call BOTH of the functions, using fnum and inum as parameters.

The results of both function calls should be printed out to 3 decimal places, with descriptive text. Note that the results should be the same!

Sample Output:

Recursive result = 4.840

Iterative result = 4.840

The only way the user may exit the program is to enter 0 for the value of fnum -- do not ask the user whether to run the program again.

The program should LOOP and continue to compute results for new values until the user enters 0 for the value of fnum. When the user enters 0 for fnum, the program should not ask for the value of inum – it should just exit.

Program #2

Write a modular financial calculator program. Make sure to use the following:

• The indentation and spacing practices introduced in the reading

• double for all floating point values

• Constants for all fixed values

• Prototypes for all user-defined functions

The program should first provide a menu for the user to select what s/he wants to do, with Exit as one of the choices.

The user will be able to choose to do loan or savings calculations, using one of the following four formulas:

• Compute a Loan Payment for a given Loan Amount to be borrowed:

MonthlyPayment = (factor * monthlyInterestRate * LoanAmount) / (factor - 1);

• Compute the Loan Amount you could borrow for a given affordable Monthly Payment:

LoanAmount = ( (factor - 1) * monthlyPayment ) / (factor * monthlyInterestRate);

• Compute the Total amount that will be accumulated for a given Monthly Amount saved:

Total = ( (factor - 1) * monthlyAmount ) / monthlyInterestRate;

• Compute Monthly Amount required to accumulate a given Total amount:

monthlyAmount = ( Total * monthlyInterestRate ) / ( factor - 1 );

For all of these choices, the user will enter an annual interest rate (e.g. 7.25 for 7.25%), and a number of years to borrow or save (e.g. 3.5 for 3½ years), and a monetary amount.

Input Error Checking

Error check the following user input values:

• Yearly interest rate must be between 1% and 30%.

• The number of years to borrow or save must be between 1 year and 50 years.

• Monetary amounts must be positive and non-zero, and must be no more than $ 9,999,999.99.

The program will need to convert the annual interest rate to a monthly interest rate (divide by 100 to get a fractional interest rate, and then divide that by 12 for monthly interest) before using it in the formulas.

All of the formulas also require that you first calculate a factor and then use it in your formula. The factor formula is:

factor = exp( numberOfMonths * log(1 + monthlyInterestRate));

Note that exp and log are predefined mathematical functions, located in the C++ library.

For hand calculating results to test your program, the equivalent algebraic equation is:

Factor = (1 + MonthlyInterestRate) TermInMonths

Output

Calculate and display the results, including the information the user input in the following format:

Sample output (for both Loan calculations):

Sample output (for both Savings calculations):

Total Annual Monthly

Amount Number Interest Savings

Saved of Years Rate Required

------------ ---------- -------- ----------

$ 100000.00 7.5 years 7.500% $ 831.13

Note that dollar amounts are calculated to the nearest penny (i.e. rounded to 2 decimal places).

Years should be displayed to one decimal place, and the annual interest rate to 3 decimal places.

After displaying the results, the program should pause and then return to the menu to let the user choose another formula or choose to exit. The only way the user may exit the program is to choose to exit from the menu -- do not ask the user whether to run the program again.

So each time a formula is chosen from the menu, the program will read new inputs, display the results, and loop back to the menu -- until the user chooses to exit.

This program should be modular. You must include the following functions:

• A function to read and validate the interest rate. Pass back both the yearly interest rate and the monthly interest rate, using reference parameters.

• A function to read and validate the number of years to borrow or save. Pass back both the term in years and the term in months, using reference parameters.

• A function to read and validate a dollar amount.

• A function to display the menu and read and validate the user's choice.

• A function to calculate and return the factor, called by a function other than main.

• One or more functions to compute the results.

• Only one or two functions to output the results.

• Each function should perform only one logical task. When breaking down the code into function, look for similarities in the code. Use the functions to minimize the amount of code you have to write.

•

•

• Program and Function Documentation (both programs)

•

• 1) Be sure to include top of program comments as specified in WBW section 1.8.

•

• 2) Make sure you comment any constants/variables whose names are XXXXX XXXXX descriptive.

•

• 3) You must also include a comment above each user-defined function that includes:

•

• What the function does

• Description of the input parameters (if any), used to pass values into the function

• Description of the output parameters (if any), used to pass values back from the function

• Description of what is returned from the function via the return statement (if anything)

Show More

Show Less

Was this answer helpful?

Describe your issueThe assistant will guide you

Chat 1:1 with a programmerLicensed Experts are available 24/7

100% satisfaction guaranteeGet all the answers you need

Related Programming Questions

I'm having issues writing a program. C# The repayment amount

The repayment amount on a loan with a fixed rate of interest can be calculated using the formulaPayment = r (PV) / (1 – (1+r) –n)Where :n is the number of payments r is the rate of interest PV is the present value of the loanWrite a program to calculate the Monthly Repayment (to the nearest cent) for the following inputs: 1. the number of payments 2. the rate of interest – note this is a fixed interest loan 3. the present value of the loanIt is important to keep the rate per period and number of periods consistent with one another in the formula. If the loan payments are made monthly, then the rate per period needs to be adjusted to the monthly rate (r / 12) and the number of periods would be the number of months on the loan.Format you output appropriately.(Hint x = Math.Pow(y,n) returns yn to the variable x) – demo needed I have 30 minutes to do it … read more

You need to write a program that calculates monthly payments

You need to write a program that calculates monthly payments on a loan when the user provides the amount of the loan, the number of months for the loan, and the annual percentage interest rate. The fo… read more

These are all for VB 2010 1. The American Heart Association

These are all for VB 2010 1. The American Heart Association suggests that at most 30 percent of the calories in our diet come from fat. Although food labels give the number of calories and amount of f… read more

I have a programming question that needs to be answered using

I have a programming question that needs to be answered using a given recursive function. Can anybody help? It's in c++.… read more

Please tell me how to calculate with a 10% at the end payment

Please tell me how to calculate with a 10% at the end payment for a Lease PMT(RATE,NPER,PV,FV,TYPE) BUT NEED A FINAL PAYMENT OF 10%… read more

Can someone help me convert my Java program to a GUI interface

Can someone help me convert my Java program to a GUI interface with user input? It does not have to be fancy at all. Write the program in Java (with a graphical user interface) and have it calculate a… read more

This question is for Kevin The Home Finance Company uses

This question is for "Kevin" The Home Finance Company uses the strange formulas below to calculate the monthly mortgage payments: Principal and Interest – 2.1 times the original home value, divided by… read more

You have been hired by a bank to manage their loan department.

You have been hired by a bank to manage their loan department. One of your responsibilities is to write a JavaScript program that will compare loans with various interest rates. Your program should fi… read more

You have been hired by a bank to manage their loan department.

You have been hired by a bank to manage their loan department. One of your responsibilities is to write a JavaScript program that will compare loans with various interest rates. Your program should fi… read more

Program #1 Write a program to calculate and print out cellular

Program #1 Write a program to calculate and print out cellular phone bills for one month, and write a test plan to test the program. The rates will vary depending on the calling plan of the customer: … read more

Write a program that will calculate a loan repayment plan to

Write a program that will calculate a loan repayment plan to be paid off in equal monthly installments over a certain number of months. Prompt the user for the loan amount, Annual Percentage Rate (APR… read more

Hi Ramesh, I am looking for this file, see below http //wikisend.com/download/440070/l

Hi Ramesh, I am looking for this file, see below http://wikisend.com/download/440070/loan amortization table.zip Do you still have this code available. I have a similar project that I can use that for… read more

TO RAFAEL MARTINS I need to take the code you created

TO RAFAEL MARTINS I need to take the code you created and make it where the program expects three entires: Mortgage Amount Interest Term in years Then it outputs the three things entered and shows the… read more

need these answers for a VB 8 class. All the files you provide

need these answers for a VB 8 class. All the files you provide must be in VB8 format and I should have three files to submit for each question. Here are the submission instructions for each file. Beca… read more

write a program to solve the following problem. If an amount

write a program to solve the following problem. If an amount A is borrowed the formula is: i(1+i)^N A _________ (1+i)^N-1 where i is the annual rate of interest divided by 12, and N is twelve times th… read more

Please help me get past this error import java.swing.*; import

Please help me get past this error import java.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.*; import java.Math; import java.text.DecimalFormat; import javax.swing… read more

Can you help me with this problem, I need to Write the program

Can you help me with this problem, I need to Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans: - 7 year at 5.35% - 15 year a… read more

I HAVE A 5000 PERSON MAIL LIST WITH THE AMOUNTS EACH PERSON

I HAVE A 5000 PERSON MAIL LIST WITH THE AMOUNTS EACH PERSON OWES ON THERE HOME MORTGAGE. HOW CAN I CREATE A CALCULATOR THAT WOULD SHOW WHAT THAT PERSONS PAYMENT WOULD BE AT A FIXED RATE OVER 30 YEARS … read more

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.

JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.

Web sites like justanswer.com/legal

...leave nothing to chance.

...leave nothing to chance.

Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.

Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.

I will tell you that...the things you have to go through to be an Expert are quite rigorous.

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

New York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

Los Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

Hesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

Kernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

Woodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

Elkton, Maryland

< Previous | Next >

LogicPro

Computer Software Engineer

35,211 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

unvadim

Computer Software Engineer

1,170 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

The-PC-Guy

Software Engineer

936 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

Rafael Martins

Computer Software Engineer

449 satisfied customers

Desktop, Mobile and Web Developer. 10+ years of experience. Creative solutions provider.

Ramesh Patil

Computer Software Engineer

406 satisfied customers

MCA, 3+ years of experience in Asp.Net, C#, SSIS, VB.Net, Ms-SqlServer2005, MySql, Javascript,

Arty

Computer Software Engineer

377 satisfied customers

15+ years of programming, C, C++, Java, PHP, awk, ruby, shell, ASM, Forth, Raptor, M.A.R.I.E, Excel

< Previous | Next >

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.