Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please do it in C++ code and put comments on each line explaining what it does? Thank You! EGR 126 Program 3 -

image text in transcribedCan you please do it in C++ code and put comments on each line explaining what it does? Thank You!

EGR 126 Program 3 - Calculating Polar Coordinates The objective of this Program is to illustrate and understand the use of files for input and output, to use the cmath library, and to format numerical output. You are to write a C++ program that will perform a conversion from Cartesian Coordinates (x, y) to Polar Coordinates (r, 0). You should be familiar with graphing points in both Cartesian and Polar Coordinates. If you are not, you may want to review these concepts. Given Cartesian Coordinates (x, y), use the following formulas to convert to Polar Coordinates: y=r sind r = 1x2 + y2 0 = tan-1() Yr cose The cmath function for tan-2 (also known as arctangent) is atan. The syntax to call the arctangent function is result = atan (parameter): So you might use a statement like: theta = atan( ycoord/xcoord); The function returns a value in radians, so the value theta will be in radian measure. Please read and follow the directions carefully. You will use two different files: one for data input, and one for data output. Your input data file will contain two real values that represent the x and y coordinates of a point in Cartesian Coordinates. Write a computer program that: opens the input file, reads in the first line of the file, which contains the file format information, reads in two floating point numbers, one for x and one for y, calculates the r and values, (O will be in radians) calculates the equivalent value in degrees, and writes identical information to both the screen and to a file, consisting of: your usual identifying info, the input and output filenames, the input file format information, the numbers read in, the value for r, the value for 0 in both radians and degrees. Your input file should be set up as follows, using 1 sentence describing the format of the file 3.4641 The name of the input file is read from the screen. The name of the output file is assigned in the program. (NOTE: this is opposite of the examples in the document File Input & Output) The output to both the file and the screen should be identical, with the exception of the screen input for the filename. The output to both the file and the screen should be well formatted for readability and clarity. Use 4 decimal places of precision. Your submission document should include a copy of the input file, a copy of the output file, and a copy of the screen output, together with a copy of your source code

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

More Books

Students also viewed these Databases questions