Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****C++ Programming Help, Will Upvote.**** Thank you For this lab, write a program that first generates two random decimal numbers within the range -100 to

****C++ Programming Help, Will Upvote.**** Thank you

For this lab, write a program that first generates two random decimal numbers within the range -100 to 100 inclusive. Next, generate a random number between 1 and 4 inclusive to correspond to each of our math operators (+, -, *, /). Finally, write out to a file called mathWorksheet.txt the following format:

A o B = ?

With A and B replaced by the two random numbers that were generated and o replaced by the random math operator. A complete example is shown below:

-15.15 * 82.311 = ?

We now want to write a program that will read that file in. It needs to read in the values of A, o, and B by reading in the file. The pseudocode for what you'll want to do is shown below:

// Declare two doubles to store A and B // Declare a character to store the math sign // Open the file // Read in A // Read in math sign // Read in B // Close the file

Once we've determined A, o, and B, write to the standard out (a.k.a. cout) the solution to the problem. An example is shown below:

-15.15 * 82.311 = -1247.01

we'd like to be more precise and make values easier to read. Specifically, we want to always display three decimal places and align the decimal points when outputting the results.

Using the appropriate I/O manipulators, modify your program from Lab3B to match the following output exactly (with specific numbers replaced to match your prior output):

 -15.150 * 82.311 =========== -1247.012

You'll need to use a combination of I/O manipulators and turn settings on/off to accomplish this task. Do not make the padding by outputting spaces. Instead, be sure to be setting an appropriate width for the column. This also applies to the row dividers. The tildes should not be hard coded in, but instead the appropriate I/O manipulators need to be used. For instance, the following is incorrect:

cout << " " << A << " * " << B << " =========== " << A*B << endl;

Note that the extra spaces and all the equal signs are hard coded in. Instead, we'll want to use the appropriate width, align, and fill I/O manipulators.

Print the formatted output to both the standard out (cout) and to an external file.

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

Students also viewed these Databases questions