Geometric calculations

Assignment Help C/C++ Programming
Reference no: EM13835330

Geometric Calculations

In this homework assignment, you will be writing an area calculator to understand console input/output, some basic data types, and basic arithmetic in C++.

This assignment has you

• translating equations into C++ expressions,
• using math constants,
• using math functions,
• precisely formatting output

Part I: Calculating Areas

1. In Visual C++, create a new project (called, for example, homework2 or HW2 or ...), for this assignment. Never use spaces in filenames or project names. Follow the same process as you did in the first assignment to create the project and Add ! New Item to the Source Files folder, calling it hw2.cpp or somethingsimilar. If you need a refresher, please refer back to Homework 1. You should copy all of the Hello World code as a starting point. Look at the last assignment if you need to.

2. We're going to need to include an additional header file for this assignment, one for some math functions we'll be using. So, include cmath and this #define before the other #include at the very top of your program file:

#define _USE_MATH_DEFINES // for C++
#include <cmath>

And use the constant M_PI for π in your equations.

4. You're going to write a small program that prompts the user to enter the radius of a circle, followed by the length and the width of a rectangle, all in meters. Then, the program computes the area of the circle, the area of the rectangle, and the total areas of the circle and the rectangle.

5. We're going to need variables to store values that the user is going to type in. Inside main(), declare three variables of type double for radius, width, and length. If you aren't sure how to declare the variables, please refer to the textbook.

6. Remember how we used cout to write text output to the screen? When reading input, you usually prompt the user with some text using cout. Then, you read the data that the user responds with using cin. For example, here is what you do for radius:

cout << "Please enter the radius of a circle: "; cin >> radius;

Notice that there is a space after the colon and no endl at the end of the prompt line. This means that when you run the program and are asked to enter a number, it will go on the same line as the prompt. The Enter shown below in the output is from the user hitting
Enter! Also note the direction of the << and >> for cout and cin!

7. Run the program to make sure you don't have any errors at this point. Adding a few lines and running it to make sure there are not errors is called incremental development.

8. Now repeat this "prompt and read" process for the width and then for the length of the rectangle.

9. Next, declare three more variables at the top of the main() of type double to hold the values your program needs to calculate for circle area, rectangle area, and the total area of the two combined.

10. The mathematical formulas to calculate the circle area and rectangle area are:

The area of a circle → π * radius2

The area of a rectangle → length * width

Your output should look like this: (Please copy and paste the text from these prompts into your code! You are graded on this on Web-CAT.)

Please enter the radius of a circle: 10
Please enter the width of a rectangle: 20
Please enter the length of a rectangle: 30
The area of the circle is 314.159.
The area of the rectangle is 600.
The combined area is 914.159.

Run your code with several different inputs and hand check the values to make sure your code is doing the calculations right.

Part II: Adding Circumference and Diagonal Length

Now we will further incrementally add more code to do more!

1. Next, modify the program to calculate the circumference of the circle, the diagonal length of the rectangle, and the difference of the two lengths.

2. Add three new variable declarations of type double to represent these 3 values.

3. Now, add the code to calculate the circumference of a circle, the diagonal length of rectangle, and the difference of the two lengths. The mathematical formulas to calculate the circumference of a circle and the diagonal length of a rectangle are:

circle circumference → 2 π * radius

rectangle diagonal length  → sqrt ( length2 + width2 )

Sample Output: Your program will be tested with several input sets, including the one shown here in RED. Your program must exactly match the words and format in this example. The numbers vary, of course, based on the input numbers.

Please enter the radius of a circle: 10
Please enter the width of a rectangle: 20
Please enter the length of a rectangle: 30
The area of the circle is 314.159.
The area of the rectangle is 600.
The combined area is 914.159.
The circumference of the circle is 62.8319.
The diagonal length of the rectangle is 36.0555.
The difference between the two is 26.7763.

Run your code with several different inputs and hand check the values to make sure your code is doing the calculations right.

Reference no: EM13835330

Questions Cloud

Compare two operating system : Find a friend, relative, or co-worker with a computer that uses an operating system that you don't usually use (Windows, Mac OS, or Linux). Try out the operating system, and observe how it works compared with the operating system that you normally..
How would you distinguish quality management from qi : How would you distinguish quality management from QI in healthcare? Please provide some examples.
Discuss the ways in which meetings can be more productive : Two of the most frequently reported problems were -Getting off the subject- and -No goals or agenda.- Discuss the ways in which meetings can be more productive.
Elements of reasoning and intellectual standards : Elements of Reasoning and Intellectual Standards Option A Using the 8 elements of reasoning that were outlined in week 2 (Purpose, problem, information, concepts, assumptions, inferences, points of view, implications or consequences) choose a news ar..
Geometric calculations : In this homework assignment, you will be writing an area calculator to understand console input/output, some basic data types, and basic arithmetic in C++.
Write a program to estimate the minimum of the function : Write a program to estimate the minimum of the function using the steepest descent method. Use the starting point [10 , 1]
Creating a database which inventories collateral consequence : By creating a database which inventories collateral consequences, professionals within the court will have a resource that will give them convenient access to this data. The data base can be used to study trends and patterns, examine restrictions ..
The decision making process : What Impact do you think technology can play in the decision making process? In which steps could technology be usef
Why do you think it is hard to find trustworthy information : Why do you think it is hard to find trustworthy information? What about the worldwide web and Libraries? (200 words) cite your sources

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Consider implementing subnetting to support three department

Consider implementing subnetting to support three departments within an organization. The three departments P, Q and R need support for 30, 40 and 60 hosts.

  Computer graphicsdevelop a simple interactive

computer graphicsdevelop a simple interactive two-dimensional spaceship deck plan editor using opengl and glut. your

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  Program that takes a number between

Write a program that takes a number between -121 and 121 and output that number in the format of power of 3 (1,3,9,27)example:13 = 9+3+1

  Develop a program that displays random numbers

Using a timer to generate a random number, develop a program that displays random numbers between 1 and 47 for your state's lottery.

  The reverse of each word, and a palindrome checker

give us the first letter of each word, the first half of each word, the reverse of each word, and a palindrome checker to see if the word is a palindrome.

  Two-dimensional array of double to hold the sales

Suppose you have a two-dimensional array of double to hold the sales amounts for all your salespeople three years. Assume you employ 50 salespeople and this array already holds valid data.

  Give students practice in writing and calling their function

To give students practice in writing and calling their own functions. To give students practice in implementing and planning complex programs.

  Write a program to make the ssds function

Write a program to make the SSDs function as a MM:SS real-time clock. Hint: You must not use a single delay routine for the one second delay because that will not allow for persistence of vision. The displays need to be constantly refreshed during ev..

  C program to mips program

Convert the following C program to MIPS program. Assuming that i, j, k, f, are stored in registers $s0, $s1, $s2, $s3 already. The base address of arrays A and B are in registers $s4 and $s5, respectively. (30

  Write a program that reads in a list of integer numbers and

Write a program that reads in a list of integer numbers and print out the sum of all numbers, the average, the lowest and the highest value entered. The first input number indicates how many numbers the program is attempting to read. For example, if ..

  Write a function that accepts an integer parameter

Write a function that accepts an integer parameter and returns its integer square root. The function should throw an exception if it is passed an integer that is not a perfect square. Demonstrate the function with a suitable driver program

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd