⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http:^^www.cs.wisc.edu^~rmanning^cs110^program1.html

📁 This data set contains WWW-pages collected from computer science departments of various universities
💻 HTML
字号:
Date: Mon, 11 Nov 1996 17:23:53 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Wed, 06 Nov 1996 04:29:43 GMTContent-length: 4494<HTML> <HEAD> <TITLE>CS110, Program 1</TITLE> </HEAD><body><H1> Program 1 -- Polygons on the March </H1><H3> Due Date: Wednesday, November 13 </H3><H2> Some Background </H2>A <EM>polygon</EM> is a flat shape with 3 or more sides, all of whichare straight (e.g. a triangle is a 3-sided polygon).  When all thesides of a polygon have the same length, the polygon is called<em>regular</em>.  Equilateral triangles and squares are regularpolygons with 3 and 4 sides respectively. <P>All regular polygons can be fit perfectly within a circle (such that thecircle touches all the corners of the polygon).  This circle is calledthe <em>circumscribed circle</em>. <H2> The Problem </H2><P>You are to write a program that will perform a few calculations onregular polygons.  Your program will ask the user (1) how many sidesthe polygon has, and (2) what the length of each side is.  Remember,all sides have the same length so part (2) is just one question!  Thenumber of sides should be stored in an integer variable, and all othervariables should be of type <strong>double</strong>. <P>As output, your program will display (1) the area of the polygon,and (2) the radius of the circumscribed circle.  Just use the formulasgiven below; you don't need to understand them at all! <P>In addition to the requirements above, print a welcoming message when theprogram starts and an exiting message when the program ends (seesample printout; use any messages you like!). <P>Finally, put a comment at the beginning of your program brieflydescribing the purpose of the program (use 1 or 2 sentences).  Ofcourse, put your name and login name in comments at the beginning ofthe program just like in assignment 0. <H2> The Formulas </H2>In the following equations, <em>sides</em> is the number of sides,<em>edge</em> is the length of each side, <em>radius</em> is theradius of the circumscribed circle, and <em>area</em> is the area ofthe polygon.  Note that <em>sides</em> and <em>edge</em> are what theuser enters, and <em>radius</em> and <em>area</em> are what theprogram outputs.  Also note that <em>edge</em> is squared in the formula for <em>area</em>.<P><P><IMG ALIGN=MID SRC="prog1.equation.jpg" ALT="The formula is too complicatedto view in text form; you need to see the picture"><H2> A Sample Run </H2><pre>Step inside the amazing polygonator... Number of sides? 4Length of each side? 7.82Area of polygon: 61.1524Radius of circumscribed circle: 5.529575That's all, folks!</pre><H2> Hints </H2><li> Don't write the whole program at once!  For example, start bywriting a program which only displays some messages.  When that isworking, create some variables and add the input commands.  Test yourinput statements by redisplaying what the user has typed in.  Finally,add the math commands to finish the program. <li> Use <strong>pow(x,y)</strong> for calculating the square root.For example, pow(7, 0.5) calculates the square root of 7. <li> Remember to use <strong>#include&lt;math.h&gt;</strong>, sinceyou will need cos(), sin(), and pow().  Of course, you also need<strong>#include&lt;iostream.h&gt;</strong> in order to use<strong>cout</strong> and <strong>cin</strong>. <li> Use meaningful variable names.  Avoid one-letter names unlessthey make your program more understandable. <li> Create some variables to store intermediate calculations. <li> Test your program on several cases for which you already know the correctanswers.  For instance, see the sample run given above for a square.Here's another case: when the number of sides is 3 and the length of each side is2.1, the area is 1.909586 and the radius is 1.2124356. <H2>What to turn in</H2>Turn in the following two pages, <B>stapled together:</B><li> (page 1) <em>Printed listing of the source file.</em> This is tobe done just like in program 0. <li> (page 2) <em>Printed copy of your program's output when run on asample test case.</em>  This can be done easily as follows: Afterrunning your program, pull down the little tab button on the upperleft hand corner of the output window (the window with INACTIVE at thetop), and select the Print option . This will send all outputgenerated by your program  in this window to the printer. <P> In addition, as with all assignments, <EM>you must electronically turn in acopy of your program's source code</EM>.  Use the filename "<STRONG>program1.cpp</strong>".</BODY> </HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -