Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ programming below two problems. In these problems, and all future problems, use functions. Provide a function prototype for each function before the main

Use C++ programming below two problems.

In these problems, and all future problems, use functions. Provide a function prototype for each function before the main function. The function prototype should have descriptive names for the function and for each parameter. Put very little code in the main function. Each function should be preceded with a short comment giving:

  • A long line of asterisks as an eye catcher
  • The purpose of the function
  • Parameters, other input, and initial conditions
  • Return values, other results, and final conditions provided

Problem H1

In the main function, define four variables of type int, named: first, second, third, and total. Write a function named getData that asks the user to input three integers and stores them in the variables first, second, and third which are in the main function. Write a function named computeTotal that computes and returns the total of three integers. Write a function named printAll that prints all the values in the format shown in the following sample:

1 + 2 + 3 = 6 

Call the other three functions from the main function.

Test it once, with the values 4, 5, and 6.

Problem H2

In the main function, define five variables of type int, named: first, second, third, fourth, and total. Also in the main function, define three variables of type double named: decimalOne, decimalTwo and decimalTotal Write one function named getData which asks the user for the data and puts it in first, second, third, fourth, decimalOne, and decimalTwo. (You may copy your getData from problem H1 and make additions to manage fourth, decimalOne, and decimalTwo.) Write a function named computeTotal which can take two, or three int arguments and returns an int. Write another function, also named computeTotal which takes four int arguments and returns an int. Write another function, also named computeTotal which takes two double arguments and returns a double. Write a function named printAll which takes three arguments of type int. Write a function named printAll which takes four arguments of type int. Write a function named printAll which takes five arguments of type int. Write a function named printAll which takes three arguments of type double.

In the main function, after calling the getData function make the following function calls:

  • call computeTotal passing first and second, then call printAll to print the results.
  • call computeTotal passing first, second, and third, then call printAll to print the results.
  • call computeTotal passing first, second, third, and fourth, then call printAll to print the results.
  • call computeTotal passing decimalOne and decimalTwo, then call printAll to print the results.

Print the results int the formats shown in the following samples:

For integers: 1 + 2 + 3 = 6 For decimal numbers: 1.10 + 2.20 = 3.30 

Test the program once with the values 4, 5, 6, 7, 8.1234, and 9.5678

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions