Calculate the triangular number for n

Assignment Help Computer Engineering
Reference no: EM132164457

Using C++, you will implement three functions using recursion and write a menu program to call these functions.

1. Write a function that recursively reverses a string. The function will have a single parameter of type string. It will print the reversed characters to the screen followed by a newline character.

Before you start writing code, try to answer these questions to yourself. What is the base case?

Will you print out the characters before or after the recursive function call? You can try it in both ways and see if it makes a difference and choose one way to use in the function.

2. Write a function that recursively calculates the sum of an array. The function should have 2 parameters, the array and an integer showing the number of elements (assume they are all integers) in the array. The function will use a recursive call to sum the value of all elements.

3. Write a recursive function to calculate the triangular number for N. (Or a function that counts the number of pins necessary for a triangular of N rows.) A triangular number is the sum of all items that form a triangle with N rows.

It may help to think of the number of bowling pins if you changed the number of rows.

For example, when N=0, the triangular number is 0; When N=1, the triangular number is 1; When N=2, the triangular number is 1+2=3; When N=3, the triangular number is 1+2+3=6, so on so forth.

You will also need to write a program to demonstrate all three recursive functions. Provide a menu for the user to select which function to run, and after running the function, return to the menu.

For #1, you must prompt the user to enter a string and your program will print the reversed string on screen. For #2, you must prompt for a series of integers to be entered in the array. As your program read the numbers in, increment a count so it knows how many elements the array has.

Use a symbol for users to indicate when they are done with entering numbers (choose any letter you think is proper, but you need to print it on screen at the beginning to let users know which one to enter).

Then your program will print the sum of the array elements on screen. For #3, prompt the user to enter an integer and your program will print the triangular number for that integer. You will need a fourth item in the menu to allow them to exit the program.

Separate the implementation and declaration in cpp and hpp files in your code.

Reference no: EM132164457

Questions Cloud

Rejecting the null hypothesis will make the manufacturer : Hint: Rejecting the null hypothesis will make the manufacturer happy as it will show that standards are being met.
Test the code for all of the given functionality : Memory management should be done dynamically using the appropriate new operator in the constructor and the delete operator in the destructor.
Define the rejection region for test : How would you define the rejection region for this test at a = .001?
Hormone therapy developed cancer : A group conducted a randomized experiment to see if hormone therapy was helpful for? post-menopausal women.
Calculate the triangular number for n : The function will have a single parameter of type string. It will print the reversed characters to the screen followed by a newline character.
Population proportion of employed individuals : Construct a 99% confidence interval for the population proportion of employed individuals the work at home at least once per week.
Critical value approach to test the hypothesis : Use the critical value approach to test the hypothesis at the 1% significance level. Show the five steps.
Identify the claim and state h0 and ha : a) Identify the claim and state H0 and Ha. What is the? claim?
Calculate and tell the user the distance to the basket : Write a program with comments (//comments explaining to user) that uses methods and simulates throwing a rock in a basket in a straight line.

Reviews

Write a Review

Computer Engineering Questions & Answers

  How the total number of nodes considered

Explain how the total number of nodes considered during the search could be reduced by conducting two searches at the same time-one beginning at the initial state while the other searches backward from the goal- until the two meet.

  Create a seating reservation program for podunk airlines

Create a seating reservation program for Podunk Airlines. The air fleet consists of a single plane with a seating capacity of 12.

  They will like on a company''s internet connection

Do you believe that an employee's internet usage at a company should be audited and governed by usage policy? Or, do you think that people should be able to use the internet though they would like on a company's internet connection.

  Design a variation of algorithm treesearch

Design a variation of algorithm TreeSearch for performing the operation find Al(k) in an ordered dictionary implemented with a binary search tree T.

  Write down the entries in the permuterm index dictionary

Consider these documents: Write down the entries in the permuterm index dictionary that are generated by theterm mama

  What is the relationship of data quality to information

what is the relationship of data quality to information governance? why is ig important in healthcare and what role

  Write a driver program to test your function

You would like to know how fast you can run in miles per hour. Your treadmill will tell you your speed. Write a driver program to test your function.

  What would be the ideal mix of regular and low-fat lattes

Assuming that all lattes that are made can be sold, what would be the ideal mix of regular and low-fat lattes to maximize the profit for the airline?

  Build a model evaluation system in programming language

Build a general model evaluation system in your favorite programming language, and set it up with the right data to assess models for a particular problem.

  What do the different colors mean in the wireshark log

This is a flexible and powerful tool. Any network administrator worth his or her salt will know how to run Wireshark. Most professionals use it often.

  Identify a software tool to aid agile software development

Identify a single software tool to aid Agile Software Development. What makes pair programming more effective than two programmers?

  Which of them are changing and into what direction

could you make predictions about future development. Which of them are changing and into what direction.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd