Module: Real numbers


Problem

4/6

Input and output of real numbers

Theory Click to read/hide

Input

You can enter several real variables from the input stream and write them into variables in the standard way:
float x, y;
cin >> x >> y;
The first number falls into the \(x\) variable, the second into \(y\) variable

Output

When outputting real numbers, the default is 6 decimal places, while the scientific format or with a fixed comma is automatically selected.
You can configure the output as needed by the condition of the task. For this, an additional iomanip library is used - manipulators that control the output.
The fixed command is used to output in fixed-point format, and scientific is used for the scientific format. Then you need to determine the number of digits in the fractional part using the setprecision command. Using the setw  command, you can specify the total number of positions allocated to output the number

Example:
float x = 1.0/6;
cout << fixed << setprecision (9);  // установили вывести 9 цифр в дробной части
cout << setw(12) << x;                            
The screen outputs
_0.166666672                  
All commands can be written in one line:
cout << fixed << setprecision(9) << setw(12) << x;

Problem

Complete the tasks in order:
1. In the 8th line, format the \(y\) variable output in a fixed-point format, with the default number of characters in the fractional part
2. In the 9th line, format the \(y\) variable output in a fixed-point format so that the entire number is displayed in 10 positions, with 4 characters assigned to the fractional part
3. In the 10th line, format the \(y\) variable output so that the number is displayed in a scientific format with three digits in the fractional part
Each output statement must print a number on a new line.