代写C代码 代做C程序 C辅导 C家教

远程写代码 Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

代写C++程序,可以远程写,也可以离线写,一对一手把手教学
In-Class 2 - Area, Volume, etc Calculations
In this assignment, you are writing an area calculator to practice
performing console input & output,
using some basic data types,
formatting output, and
performing some basic arithmetic in C++ and
using integer math, which discards the fractional part of results.
Description
1. In CodeBlocks, create a new project (call it, for example, inclass2 or ic2), for this
assignment. Never use spaces in filenames or project names. Follow the same process as
you did in the first in-class assignment to create the project and edit main.cpp. Refer back to
the InClass1 exercise, if necessary.
2. We need to #include an additional header file for this assignment in order to use some math
functions. So, #include cmath and this #define before the other #include statements (at the
very top of your program file):
#define _USE_MATH_DEFINES // for C++
#include <cmath>
This allows you to use the named constant M_PI declared in the cmath library for π in
your expressions in your program.
4. You are to write a program that prompts the user to enter the radius of a circle, all in meters.
Then, your program calculates the diameter, circumference, and area of a circle with the
entered radius, and the surface area and volume of a sphere using the same radius.
5. You need variables to store value(s) that the user enters. To do this, at the top of the main()
function after its beginning brace { declare three variables of type double for radius,
width, and length. e.g.
int main()
{
double radius;
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 using cin, you read the data that
the user responds with. For example, here is what you do for radius:
cout << "Enter the radius of a circle: ";
cin >> radius;7. 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! The user must hit Enter (carriage return) in order for the program to read the
numbers.
Also note the direction of the "arrows" << and >> for cout and cin! The arrows point
towards where the data is going -- towards the output, or into a variable. e.g.
cout << "printed words… \n\n";
cin >> variable1;
And multiple items can be output or input in one statement:
cout << "printed words…" << var1 << "more text\n";
cin >> variable1 >> variable1 >> variable1;
8. Run the program to make sure you don't have any errors at this point. Adding a few lines of
code and running it (to make sure there are not errors) is called incremental development.
9. Next, declare more variables at the top of the main() function of type double to hold the
values your program needs to calculate for diameter, circumference, and area of a circle,
and the surface area and volume of a sphere. Variables must be declared before you can
use them in expressions.
10. Mathematical formulas to calculate the circle area, sphere volume are:
The area of a circle is π radius2
The area of a sphere is 4/3 π radius3
Additional formulas can be found at
http://www.austincc.edu/pintutor/pin_mh/_source/Handouts/Geometry_Formulas/
Geometry_Formulas_2D_3D_Perimeter_Area_Volume.pdf
You use these formulas to assign values to the variables declared in step #9.
circArea = M_PI * radius * radius;
And you need to declare circArea "above" this line of code in which you use it.
11. Finally, output the text and variable values as shown below.
You need to format your output using fixed and setprecision() as covered in class and shown
below.Your output should look exactly like this: (Please copy and paste the text from the prompts and
output text into your code! You are graded on this on Web-CAT.)
Enter the radius of a circle: 19.5555
The diameter of the circle is 39.11.
The circumference of the circle is 122.87.
The area of the circle is 1201.40.
The surface area of the sphere is 4805.60.
The volume of the sphere is 31325.31.
Run your code with several different inputs and hand check the
values to make sure your code is doing the calculations right.
The reason output of programs uses this font (Courier) is that
each character is the same width. You can line up characters and spacing. For
example, the 39 in the first line of output lines up with the 19 in the input; the period in the 3rd
line lines up with the s in ‘is’ in the line above it; etc. This text is NOT courier and does not line
up.
Programming Style
An important part of programming is using proper programming style, formatting, and comments. At this
point, the most important items are:
Use descriptive variable names
Vertical (proper use of blank line mostly) and horizontal spacing (putting spaces around operators,
indentation, etc.)
o Indent properly, as shown in class and in the text
o Skip a line between each small section of your program, so that each section is
separated by a blank line,
Have a beginning comment that describes what the program is doing (just “Homework 1” is not
good enough). See the main Canvas page for what every program header needs to contain.
Each section (i.e. logicl chunk of code) begins with a comment describing what that section does,
so that the comments alone would provide an outline of the program (It’s NOT good to follow
every line of code with a comment.)
Continue typing your code on the next line if it is too long. Too long is over 80 characters. In
Code::Blocks, there is a column indicator at the bottom-middle-ish of the screen that tells you
which column the cursor is at.
Submit Your WorkTo submit your work to Web-CAT to be graded.

相关推荐