In addition to the main function that we've been using, the program will need three programmer-defined...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In addition to the main function that we've been using, the program will need three programmer-defined functions. These functions will work together to repeat a message on the screen. The first function is called getNumber. It should have a return type of int and an empty parameter list. This function should prompt the user to enter a number, store that in a variable, and then return that variable. The second function is called getMessage. It should have a return type of string and an empty parameter list. This function should prompt the user to enter a message, store that in a variable, and then return that variable. The third function (procedure) is called repeat. It should have a void return type. This function requires two parameters: int num and string msg. In the body of the function, use a loop structure to display msg a total of num times to the screen. Lastly, in the main function, you should call your three functions in the appropriate order. Sample Run The following is an example of how your program should run: Enter a number: 6 Enter a message: Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Part B - Function Prototypes For the second part of the lab activity, you will be practicing writing function prototypes. Continue working on the same project from part A. First, rewrite the code so that you are using function prototypes for the functions getNumber, getMessage, and repeat. Remember that the prototypes go at the top of the file, followed by main, then the definitions of the three functions at the end. Second, you will be creating a new function (procedure) called repeatTwo. It should have a void return type. Use the following prototype: void repeat Two (int, string, string); The function is similar to the repeat function. The difference is that, instead of repeating just one message, it's going to repeat two messages. You should use a different loop structure to handle this than the one you used for repeat. Third, you will need to modify the main function to give the user a choice of which repeating function to call. If the user wants the first version, then it should follow the same logic as in part A. But if the user chooses the second version (repeatTwo), then you will need to get an additional message from the user. Hence, you will need an extra function call to getMessage. The following is an example of how your program should run if just repeating once: Sample Run Enter 1 to repeat one message or enter 2 to repeat two messages: 1 Enter a number: 5 Enter a message: Same as part 1. Same as part 1. Same as part 1. Same as part 1. Same as part 1. Same as part 1. And if the user picks to repeat two messages: And if the user picks to repeat two messages: Enter 1 to repeat one message or enter 2 to repeat two messages: 2 Enter a number: 3 Enter a message: This one is different Enter a message: Functions!!! This one is different Functions!!! This one is different. Functions!!! This one is different Functions!!! In addition to the main function that we've been using, the program will need three programmer-defined functions. These functions will work together to repeat a message on the screen. The first function is called getNumber. It should have a return type of int and an empty parameter list. This function should prompt the user to enter a number, store that in a variable, and then return that variable. The second function is called getMessage. It should have a return type of string and an empty parameter list. This function should prompt the user to enter a message, store that in a variable, and then return that variable. The third function (procedure) is called repeat. It should have a void return type. This function requires two parameters: int num and string msg. In the body of the function, use a loop structure to display msg a total of num times to the screen. Lastly, in the main function, you should call your three functions in the appropriate order. Sample Run The following is an example of how your program should run: Enter a number: 6 Enter a message: Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Functions make programming easier! Part B - Function Prototypes For the second part of the lab activity, you will be practicing writing function prototypes. Continue working on the same project from part A. First, rewrite the code so that you are using function prototypes for the functions getNumber, getMessage, and repeat. Remember that the prototypes go at the top of the file, followed by main, then the definitions of the three functions at the end. Second, you will be creating a new function (procedure) called repeatTwo. It should have a void return type. Use the following prototype: void repeat Two (int, string, string); The function is similar to the repeat function. The difference is that, instead of repeating just one message, it's going to repeat two messages. You should use a different loop structure to handle this than the one you used for repeat. Third, you will need to modify the main function to give the user a choice of which repeating function to call. If the user wants the first version, then it should follow the same logic as in part A. But if the user chooses the second version (repeatTwo), then you will need to get an additional message from the user. Hence, you will need an extra function call to getMessage. The following is an example of how your program should run if just repeating once: Sample Run Enter 1 to repeat one message or enter 2 to repeat two messages: 1 Enter a number: 5 Enter a message: Same as part 1. Same as part 1. Same as part 1. Same as part 1. Same as part 1. Same as part 1. And if the user picks to repeat two messages: And if the user picks to repeat two messages: Enter 1 to repeat one message or enter 2 to repeat two messages: 2 Enter a number: 3 Enter a message: This one is different Enter a message: Functions!!! This one is different Functions!!! This one is different. Functions!!! This one is different Functions!!!
Expert Answer:
Related Book For
Management Accounting Information for Decision-Making and Strategy Execution
ISBN: 978-0137024971
6th Edition
Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young
Posted Date:
Students also viewed these programming questions
-
Write Newton's 2nd law of motion. Write the equation for centripetal force. Write the Month and Day of the Assignment Due Date. For example, if the assignment is due on Month-2 Day-27. For an object...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Read the case study "Southwest Airlines," found in Part 2 of your textbook. Review the "Guide to Case Analysis" found on pp. CA1 - CA11 of your textbook. (This guide follows the last case in the...
-
A business had always made an allowance for doubtful debts at the rate of 2 per cent of accounts receivable. On 1 January 2011 the amount for this, brought forward from the previous year, was 300....
-
Use Matlab to solve Problem 12.25
-
Two well-known company names in the transportation industry in Canada are Canadian National Railway Company and Canadian Pacific Railway Limited. Go to either SEDAR (www.sedar.com) or each company's...
-
As demonstrated fluid density differences in a flow may be seen with the help of a schlieren optical system. Discuss what variables affect fluid density and the different ways in which a variable...
-
Investor A buys 100 shares of SLM Inc. at $35 a share and holds the stock for a year. Investor B buys 100 shares on margin. The margin requirement is 60 percent, and the interest rate on borrowed...
-
Projected financial results for the university's cafeteria for next year are shown. Answer each of the following independent questions. Sales (a) How much is the contribution margin and the...
-
The decedent used his own funds in the amount of $80,000 to acquire stock naming himself and his daughter as joint tenants with right of survivor ship. When the father died, the stock was worth...
-
Consider the following LP Model: Maximize Profit: 12x Constraints: 20x 4x I -6x + + + + 1 I, Y gy 5y 100 90 3y Y > 10 Y Y 0 20 0 Complete the following without using any technology tools including...
-
2. What is an equally weighted portfolio of these 5 stocks. What is the variance of that portfolio? * Wherever needed, use sample rather than population (variance, covariance, etc) Month X1 X2 X3 X4...
-
How do we establish a relationship between Strategic Directions and Vision of a company .
-
Doorman Sportswear's articles of incorporation authorize the company to issue 6,000 $7 preferred shares and 850,000 common shares. Doorman issued 1,200 preferred shares at $100 per share. It issued...
-
Suppose a 250. mL flask is filled with 0.60 mol of NO2 and 0.80 mol of O2. This reaction becomes possible: 2NO2(g) 2NO(g) + O2(g) Complete the table below, so that it lists the initial molarity of...
-
Give a tight asymptotic run time analysis ( notation) for the following pseudo-code snippet: L-new linked list containing the values (1, 2, ..., n) for i -1 to n do p - L.head for j 0 to i-1 do...
-
Describe the question Assume that the population variance follows a normal distribution. For the following, determine the breadth to determine the population mean,. A 90% confidence interval; 100...
-
The area of a rectangle is 30 cm 2 and its perimeter is 26 cm. Find the length and width of the rectangle.
-
Product cost distortions with traditional costing, original activity-based costing analysis The Manhattan Company manufactures two models of compact disc players: a deluxe model and a regular model....
-
Salary and job responsibilities Marie Johnston, the manager of a government unemployment insurance office is paid a salary that reflects the number of people she supervises and the number of hours...
-
Sippican Corporation (A)* The decline in our profits has become intolerable. The severe price cutting in pumps has dropped our pre-tax margin to less than 2%, far below our historical 15% margins....
-
Dunkirk Consulting wishes to predict the amount of overhead expense that will be incurred by a consulting contract, to develop more accurate bids for future con- tracts. Dunkirk has the following...
-
Block Commodities has gathered the following information concerning rock salt deliveries to its clients, which it believes are highly seasonal: a. Suppose Block Commodities calculated a set of...
-
The service center at a large automobile dealership is trying to boost revenue by pro- viding no-appointment-necessary oil changes to any type of vehicle that stops by the service center. To quickly...
Study smarter with the SolutionInn App