Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91405164
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in C/C++

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As