Write a C++ program that opens a file named data.txt which contains data written in three lines. Each line starts with a word that represents one of the following mathmetical functions: sin, cos, tan, asin, acos, atan, exp, log, log10, pow, sqrt, ciel, floor, min, and max. The word is followed by either one or two double floating-point values which represent the input**(s)** for the function. Notice that functions pow, min, and max will be followed by two values while all other functions will be followed by a single value. The program should read the data in the file and compute the result for each line. Lastly, the program should output the results on the console using the table format shown in the sample test case and in the deascending order of the mathmatical functions names in the file. Notice that the width of the first column in the table (which contains the function name) is 5 and it is aligned to the left. The second column in the table which contains the input**(s)** for the function enclosed by paranthesis has a width of 15. Notice that each input value must be printed using exactly four fractional digits. The third column always contains the three characters: " = ". Lastly, the fourth column contains the result of each line printed with exactly four fractional digits. 1/0 Program Input: The data that is read from the file data.txt. Program Output: The data and the output in the table • Do not add any cout statements except for the final outputs as shown in the sample case. Do not add "Enter the file name", "the result =" or any similar prompts. • The width of each table column is given in the problem statement. Do not add any extra spaces. . In the third column, there is exactly one space before the assignment operator and one space after it. • Your program must use data.txt as the name of the file. • Your program must produce correct results for any possible values for the functions and the floating point numbers in the file data.txt. However, notice that the floating point numbers in the file are always in the range from 0 to 10 exclusive (i.e. 0 and 10 are not part of the range). • Your program can assume that the names of the functions in the data.txt file are always different and in lowercase and must be printed in lowercase as well. • You can include other libraries in your code if needed.

icon
Related questions
Question
Write a C++ program that opens a file named
data.txt which contains data written in three
lines. Each line starts with a word that
represents one of the following mathmetical
functions: sin, cos, tan, asin, acos, atan, exp,
log, log10, pow, sqrt, ciel, floor, min, and max.
The word is followed by either one or two
double floating-point values which represent
the input**(s)** for the function. Notice that
functions pow, min, and max will be followed
by two values while all other functions will be
followed by a single value.
The program should read the data in the file
and compute the result for each line. Lastly,
the program should output the results on the
console using the table format shown in the
sample test case and in the deascending order
of the mathmatical functions names in the file.
Notice that the width of the first column in the
table (which contains the function name) is 5
and it is aligned to the left. The second column
in the table which contains the input**(s)** for
the function enclosed by paranthesis has a
width of 15. Notice that each input value must
be printed using exactly four fractional digits.
The third column always contains the three
characters: " = ". Lastly, the fourth column
contains the result of each line printed with
exactly four fractional digits.
1/0
Program Input:
The data that is read from the file
data.txt.
Program Output:
The data and the output in the table
format shown in the sample test case
and described above.
Sample Test Case
Input:
Suppose the contents of the file data.txt
are as follow:
floor 7.74327
asin 0.87564
pow 1.5 4
Output:
(1.5000, 4.0000) =
pow
floor (7.7433)
asin (0.8756)
• Do not add any cout statements
except for the final outputs as
shown in the sample case. Do not
add "Enter the file name", "the
result =" or any similar prompts.
• The width of each table column is
given in the problem statement. Do
not add any extra spaces.
. In the third column, there is exactly
one space before the assignment
operator and one space after it.
• Your program must use data.txt
as the name of the file.
• Your program must produce
correct results for any possible
values for the functions and the
floating point numbers in the file
data.txt. However, notice that the
floating point numbers in the file
are always in the range from 0 to
10 exclusive (i.e. 0 and 10 are not
part of the range).
• Your program can assume that the
names of the functions in the
data.txt file are always different
and in lowercase and must be
printed in lowercase as well.
• You can include other libraries in
your code if needed.
Transcribed Image Text:Write a C++ program that opens a file named data.txt which contains data written in three lines. Each line starts with a word that represents one of the following mathmetical functions: sin, cos, tan, asin, acos, atan, exp, log, log10, pow, sqrt, ciel, floor, min, and max. The word is followed by either one or two double floating-point values which represent the input**(s)** for the function. Notice that functions pow, min, and max will be followed by two values while all other functions will be followed by a single value. The program should read the data in the file and compute the result for each line. Lastly, the program should output the results on the console using the table format shown in the sample test case and in the deascending order of the mathmatical functions names in the file. Notice that the width of the first column in the table (which contains the function name) is 5 and it is aligned to the left. The second column in the table which contains the input**(s)** for the function enclosed by paranthesis has a width of 15. Notice that each input value must be printed using exactly four fractional digits. The third column always contains the three characters: " = ". Lastly, the fourth column contains the result of each line printed with exactly four fractional digits. 1/0 Program Input: The data that is read from the file data.txt. Program Output: The data and the output in the table format shown in the sample test case and described above. Sample Test Case Input: Suppose the contents of the file data.txt are as follow: floor 7.74327 asin 0.87564 pow 1.5 4 Output: (1.5000, 4.0000) = pow floor (7.7433) asin (0.8756) • Do not add any cout statements except for the final outputs as shown in the sample case. Do not add "Enter the file name", "the result =" or any similar prompts. • The width of each table column is given in the problem statement. Do not add any extra spaces. . In the third column, there is exactly one space before the assignment operator and one space after it. • Your program must use data.txt as the name of the file. • Your program must produce correct results for any possible values for the functions and the floating point numbers in the file data.txt. However, notice that the floating point numbers in the file are always in the range from 0 to 10 exclusive (i.e. 0 and 10 are not part of the range). • Your program can assume that the names of the functions in the data.txt file are always different and in lowercase and must be printed in lowercase as well. • You can include other libraries in your code if needed.
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer