Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ please Write a program that prompts the user for polar coordinates (radius and angle) and converts this representation to cartesian coordinates (x, y). Study

C++ please

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Write a program that prompts the user for polar coordinates (radius and angle) and converts this representation to cartesian coordinates (x, y). Study the tests below to help you understand program behavior. Use the following tests and your own tests to run against your solution in Develop mode. These are the same tests that your solution will be executed against when you submit your work in Submit mode. User input is in bold: Sample Runs (Program Behavior) User in put is in bold: Test 1 >run Enter radius: 1 Enter polar angle (degrees): 0 Cartesian coordinates: (1,0) Test 2 >run Enter radius: 1 Enter polar angle (degrees) : 30 Cartesian coordinates: (0.866025,0.5) Test 3 >run Enter radius: 1 Enter polar angle (degrees): 240 > run Enter radius: 12 Enter polar angle (degrees) : 260 Cartesian coordinates: (2.08378,11.8177 ) Programming Assignment Your solution will be graded based upon program behavior (passing tests). Your solution will not receive full credit (or receives no credit) if you fail to follow these restrictions: - Your program must compile and run. Otherwise it will receive a zero. - Add your solution to the provided code template. - Use descriptive variable names. Avoid too short variable names, especially single letter variable names. - DO NOT start a variable name with a capital letter. - DO NOT use explicit type casting. Instead use coercion (see lecture notes). - DO NOT unnecessarily use parenthesis in an expression, e.g. an equation or formula. Parenthesis should only be used for grouping portions of an expression to change operator precedence order. For example, parenthesis are unnecessary in the expression (a +b+ c). Instead use a+b+c. Parenthesis are necessary in the expression (a+b+c)/3. - DO NOT use the break and continue statements in your solution. - Your program must be readable including indenting, spaces, and avoid lines that are too long. Use the the sample programs in the lecture notes as a guide. - Comment your program. Read the document at the "Lecture" link on Carmen under Modules->Commenting Your Program-> Commenting your program. DO NOT comment every line. - Only use C++ statements presented in the course. I.e. statements and notation presented in the lecture notes and assigned readings. Besides program behavior (compiles and passes tests), effective commenting, tabbing, code quality, and choice of statements (e.g., use of while loop vs for loop) will affect your grade. Your program should have the file name, your name, creation dates and a brief description of the program at the top of the program (see TASK 2 below). In addition, read the document on "Commenting" found under Modules Carmen. To receive full credit, only use C++ statements presented in the lecture notes and assigned readings with the exception that you do NOT use the break and continue statements. Your solution will be graded based on passing test cases, formatting, good choice of variable and function names, defining functions properly, and the quality of your solution including proper use of const, proper use of pass-by-value vs pass-by-reference, choosing for vs while loops appropriately, avoiding repetitive code where a loop should be used, proper use of the if and if-else statements or avoiding them when unnecessary. Write your solution in the provided code template. DO NOT delete nor change the code already given to you in the code template unless instructed to do so at particular locations. You will add your code to this template to formulate your solution. Important!: Write your code incrementally. This means that when you implement a task you should compile, run, and test your current solution before moving to the next task. Use your own test cases and the provided test cases to help you arrive at your final solution. Write a program that prompts the user for polar coordinates (radius and angle) and converts this representation to cartesian coordinates ( x, y) TASK 1: Study the lecture notes (Powerpoint slides and pre-recorded lectures) and assigned readings before you start. TASK 2: Replace "??" with your name, creation date, and a description of the program (synopsis). TASK 3: Follow the instructions given in the comments found in the main function and the instructions below. Add functions and function prototypes as specified below. When completed, the program reads in the polar coordinates of a point and computes and outputs the Cartesian coordinates. The main( function of the program is already provided in the template. DO NOT MODIFY ANY OF THE CODE in procedure main(). Your task is to add two functions, degrees2radians() and compute_coord(), so that the program produces the desired results. 1. DO NOT MODIFY ANY OF THE CODE in procedure main(). 2. All functions should be written AFTER the main procedure. 3. A function prototype should be written for each function and placed BEFORE the main procedure. 4. Each function should have a comment explaining what it does. 5. Each function parameter should have a comment explaining the parameter. 6. Note that polarcoord.cpp will NOT compile since the function prototypes and function definitions are missing. 7. Program polarcoord.cpp: a. Write a function degrees2radians 0 which converts degrees to radians. The function has one parameter: an angle in degrees of type double. The function returns a value of type double which is the angle in radians. The formula to convert degrees to radians is: R=D/180 where D is degrees and R is radians. b. Write a function compute_coord 0 which computes the Cartesian (x,y) coordinates of a point from its polar coordinates (radius, angle) where angle is measured in radians. The function has four parameters listed in the following order: i. the polar radius of the point, ii. the polar angle in radians of the point, iii. the x-coordinate of the point, iv. the y-coordinate of the point. All parameters should have type double. The first two parameters should be passed by value and the last two parameters should be passed by reference. The function does not return any value, but it modifies the last two parameters. The formula to compute the x and y-coordinates from the polar coordinates is: x= radius cos(angle),y= radius xsin(angle), where radius is the polar radius, angle is the angle measured in radians, x is the x-coordinate and y is the y-coordinate of the point. 446534.3081260.932947 polarcoord.cpp Load default template... Load default template

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

Students also viewed these Databases questions