C++ :: Calculate Area Of Circle Without Pi

Mar 22, 2013

I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.

Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()

[Code] .....

View 7 Replies


ADVERTISEMENT

C :: Program That Calculates The Area And Circumference Of A Circle

Sep 27, 2014

I trying to write a program that calculates the area and circumference of a circle.

This is what I wrote so far.

Code:

#include <stdio.h>
void main()
{
int r;
int pi=3.14159265;
float cir,area;
printf("
enter the radius of the circle ");

[Code]...

the Problem is when I input the radius the answer I get is zero regardless of the the radius. Am I missing something?

View 4 Replies View Related

C++ :: Finding Pi Through Computing Area Of A Quarter Circle?

May 4, 2015

question: Finding pi through computing area of a quarter circle

my code

PHP Code:

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
    int sum=0;            
    double PI,h,x;            
 
[Code] .....

View 14 Replies View Related

C++ :: Calculate Dimensions Of A Circle?

Jul 3, 2013

Code:

#ifndef CIRCLE_H
#define CIRCLE_H
class Circle {
public:
//constructors
Circle();
Circle(double r);

[code]....

The function isBigger() returns true (or false) if the radius of the Circle instance on which the function is invoked is bigger (or smaller) than the radius of the Circle instance passed to the function.: How to implement this function?

View 5 Replies View Related

C++ :: Calculate Area And Volume Of Cylinder?

Apr 27, 2013

I would like to calculate area and volume of cylinder but radious and height should be integer, float and double. How can i do?

View 9 Replies View Related

C++ :: Calculate Area Using Rectangle / Trapezoid Or Both

Feb 17, 2014

#include <iostream>
#include <cmath>
using namespace std;

//prototypes for all separate functions
int chooseFunc(int);
int chooseMethod(int);
int numRect(int);

[Code] .....

It seems that my program will ask the user for the number of rectangles and trapezoids but will fail to compute the area under the curve from the user input. Therefore, I believe I have a logical error somewhere or I'm forgetting to call something somewhere.

View 1 Replies View Related

C++ :: Calculate Area And Perimeter Of A Rectangle

Jan 28, 2013

Write a program that prompts the user to input the length of a rectangle and the width of a rectangle and then displays the rectangle's area and perimeter. The program should be broken down in 3 parts:

1. Input the length and the width (two input statements)

2. Calculate the area & perimeter (results should be saved in variables

3. print results.

Format the output so the user can easily read the results. Use the tab escape so its easy to read.
---------------------------------------------------------------
So here's what I have so far. I have been stuck for two days

#include iostream
using namespace std;
int main () {
int double length;
int width;
int area;
int perimeter;

[Code] ....

I dont want to get a zero for not turning this in...

View 14 Replies View Related

C :: Calculate Area Of Rectangle - Variable R Is Being Used Without Being Initialized

Mar 15, 2014

I am writing a program to calculate a rectangle's area.

Eg.
Enter top left point: 1 1 (User input)
Enter bottom right point: 2 -1 (User input)
Top Left x = 1.000000 y: 1.000000
Bottom Right x = 2.000000 y: -1.000000
Area = 2.000000 (Program output)

It keeps on prompting me my variable r is being used without being initialized, when I think I already did so.

Code:
typedef struct {
double x;
double y;
} Point;

[Code] ....

View 8 Replies View Related

C :: How To Calculate Surface Area And Volume For Rectangular Prism

Jan 24, 2015

So for my assignment, I have to write code to calculate the surface area and volume for a rectangular prism that involves the use of functions. I made the program without functions and it works perfectly but as I'm putting in the required functions, it conversely made it non-functional, ironically. How to call functions correctly and the online book we're using now is confusing me even more.

Code:

#include <stdio.h>
#include <math.h>
int main(void) {
double x1, x2, x3, x4, x5, x6, x7, x8 = 0;
double y1, y2, y3, y4, y5, y6, y7, y8 = 0;
double z1, z2, z3, z4, z5, z6, z7, z8 = 0;
double length, width, height=0;

[Code]....

And here is the version I'm using to test it (without the need to input the individual coordinates).

Code:

#include <stdio.h>
#include <math.h>
int main(void) {
double x1, x2, x3, x4, x5, x6, x7, x8 = 0;
double y1, y2, y3, y4, y5, y6, y7, y8 = 0;
double z1, z2, z3, z4, z5, z6, z7, z8 = 0;
double volumePrism, surfaceArea =0;

[Code]...

View 3 Replies View Related

C++ :: Calculate Surface Area Of Various Shapes - Symbolic Constant For The Value Of PI

Mar 2, 2013

This error keeps coming.

******************************************************************
CSCI 240 Program 5 Part 2 Spring 2013

Programmer:
Section: 1
Date Due: 3/1/13

Purpose: This program uses functions to calculate the surface area of various shapes. It is an exercise in learning to write functions.
******************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.14
//Symbolic constant for the value of PI

int Menu();
int getValue( string prompt, int lowerBound, int upperBound );

[Code] .....

View 10 Replies View Related

C++ :: Calculate Area For 500 Different Measurements For Playground Company In Region

Feb 13, 2014

You are writing a program to calculate the area for 500 different measurements for a playground company in the region. The company must calculate square footage of each prospective playground, as well as the total cost to mulch each area. The cost of mulch changes frequently, so the company would like to be able to input the current cost per square foot of mulch each time they run the program. Since the quantity of data is large, the input should come from a file called “measurements.txt”. You can assume the file includes the length of each prospective playground, followed by the width. The file will be in the following format.

450300
120210
.
.
.

Ask the user the name of the file they would like to write to, as well as the current price of mulch per square foot. Output the area of each playground, along with the total price of mulch to the file that the user specifies. The playground company would like each column of output to be 20 characters in width. Each column should have an appropriate heading in the output file. You should format your output data appropriately. For example, for the input data displayed above, along with a $2.00 per square foot mulch price, the output would be:

Area Total Mulch Price
135000 $270000.00
25200 $50400.00

View 3 Replies View Related

C/C++ :: Application To Calculate Area And Perimeter Of Geometric Shapes

Oct 18, 2013

How would this look like in C? Develop an application to calculate the area and perimeter of geometric shapes. First the user is asked to enter a letter representing the shape. We use C for circle, R for rectangle and S for square. After the user chooses the shape, the program prompts for the appropriate dimensions of the shape accordingly.

For instance, if the user has chosen a square, the program will ask for a side. If it's a circle, the program will ask for radius. If it's a rectangle, it will ask for length and width. Upon receiving the appropriate dimensions, the program will calculate the area and the perimeter of the requested shape and print it on the screen. And again, the code will ask for another letter. If the user enters 'Q' the program terminates.

Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >S
Please enter the side of the square > 8
The area is 64 and the perimeter is 32
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >R
Please enter the width of the rectangle > 5
Please enter the length of the rectangle > 7
The area is 35 and the perimeter is 24
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >Q

View 1 Replies View Related

C++ :: Moving In A Circle

Apr 15, 2014

I'm making this program to mess with people and make them think its a virus.

#define _WIN32_WINNT 0x0500 //For hiding your console
#include <cstdlib>
#include <iostream>
#include <Windows.h>
#include <WinBase.h>

[Code]....

At line 42 and 43 I want to make the cursor move around in a circle over and over again but I'm not sure how.

View 4 Replies View Related

C++ :: How To Find Each Pixel In The Circle

Jul 26, 2014

How can I find each and every pixel in a circle so that I can do some operations on it.

View 6 Replies View Related

C :: Printing A Circle In PPM Image

Oct 30, 2013

I'm supposed to print a small rectangle inside concentric circles that are inscribed in a rectangle.I'm not really sure where to start with printing a circle in a ppm file.

View 13 Replies View Related

C++ :: MFC Drawing Circle Instead Of Square

Mar 11, 2014

Found a good beginner's tutorial to learn Visual C++: [URL] ....

How to change the drawing so that instead of squares, the game draws circles. Can figure out that using Ellipse in the code results in circle outlines, but the fill remains as square color shapes.

The drawing code from the tutorial is below. How to substitute filled circles for filled squares.

Code:

// CSameGameView drawing
void CSameGameView::OnDraw(CDC* pDC){
// First get a pointer to the document
CSameGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)

[Code] ....

View 6 Replies View Related

C++ :: Creating Array Of Eight Circle Objects

Nov 4, 2013

Im supposed to create an to array of eight Circle objects initialized with the following radii: 2.5, 4.0, 1.0, 3.0, 6.0, 5.5, 3.5, 2.0. Then use a bubble sort to arrange the objects in ascending order of radius size before displaying the area of each object.

The error I get is "Cannot open include file: 'Circle.h': No such file or directory". Do I have to create a separate file for it?

#include <iostream>
#include <iomanip>
#include "Circle.h"
using namespace std;
class Circle {
public:
Circle()

[Code] ...

View 1 Replies View Related

C++ :: Circle Fill Color In - FLTK

Aug 28, 2014

I installed FLTK 1.3.X (from here [URL] ...) on my visual studio 2012 compiler and use PPP book for programming (this: [URL] ..... ). My problem is about filling a Shape in. For example , this code:

#include <Simple_window.h>
using namespace Graph_lib;
int main() {
Simple_window win(Point(100,100), 1000, 600, "Binary_tree");
Graph_lib::Circle c(Point(200,200),50);
c.set_color(Color::red);

[Code] ....

When I run the program, All three Shapes are drawn but only the Rectangle is filled in! Why?

set_color works for the three and apparently the set_fill_color is defined for all Shapes and it too should work but why it doesn't work for Circle and Ellipse?

This is the .CPP and .h files [URL] ....

View 3 Replies View Related

C/C++ :: How To Draw Rectangle Inside A Circle

Jul 5, 2013

Write a program using turbo c to draw a rectangle inside a circle..........

View 2 Replies View Related

Visual C++ :: Radius And Centre Of Circle

Jan 22, 2014

I am drawing a circle using ellipse because there is no explicit command for this.

Code:
pDC->Ellipse(CRect(70, 170, 300, 400));

What is the centre of circle and what is radius in the above command?

View 2 Replies View Related

C :: Creating PPM Image - Black Rectangle With A Circle

Mar 12, 2013

I'm trying to create a PPM image for a class assignment. A black rectangle with a circle at the point 225, 175 with a radius of 75. I have to use certain specific methods, so I can't use like Bresenham's really famous method for creating a circle.

The problem is that it compiles fine, and transfers to an image fine, but always says that I have a negative or zero image size.

Code:

#include "shapes.h"
int main () {
int i, j, x, y;

fprintf(stdout,"P6 width height 255
");

[Code] ....

And my header is:

Code:
#include <stdio.h>#include <math.h>
#define height 480
#define width 640
#define cy 175
#define cx 225
#define radius 75

The circle has to be filled in. I made it white. Also, i and j are unsused so far, so just ignore them.

View 1 Replies View Related

C/C++ :: Plotting Points On A Circle With One Fixed Axis

Oct 31, 2014

I am working on a computer program where I need to generate points on a circle. I am familiar with this kind of algorithm:

for(d=0; d<=2*pi; d+=0.01)
{
x = cos(d)*radius;
y = sin(d)*radius;
}

However, due to the specifics of the program I am writing, I need to iterate through a fixed number of points one at a time, like so:

for ( int x = 0; x < blockSize; x++ )
{
y = ???
}

This essentially "fixes" one axis of the circle, since I can't do: x=rx+sin(d)*r.

I have tried simply: "y = sin(d)*radius;" and I get a curved shape, but it's not a circle.

My question then is, how do I get the value of y in this situation, where the x axis is incrementing by 1 through a range of values? Is it mathematically possible?

View 6 Replies View Related

C/C++ :: Circle Paper Of Radius R - Max Cone Volume

Jan 23, 2014

My problem is the following : We have a circle paper of radius R. We will cut off a sector of this circle (with length rem_sec), and the remaining (bigger part) will create a cone. Radius of cone base is r.

I need to create a code that prompts the user to enter circle's radius R and the program will calculate the length of removed sector (rem_sec) so that the created cone has the Max Volume.

I wrote the following code, but it doesn't work. It displays both rem_sec and MaxV = 0.

#include <iostream>
#include <cmath>
#include <iomanip>
#include <conio.h>
using namespace std;
const double PI = 3.1415;
int main() {
double rem_sec;

[Code] ...

View 5 Replies View Related

C# :: How To Make A Planet That Moves In A Circle Motion

Dec 7, 2014

i would like to make a planet that moves in a circle motion. I dont know how to start and how i can move a "planet" in a circle motion?

View 2 Replies View Related

C/C++ :: Find Angle And Radius Of Given Point Of A Circle

Oct 7, 2013

Let (x,y) be the center of the circle. (x,y) will not be (0,0). I have radius of the circle. Now i want to find the angle and radius of the given point inside the circle.

View 2 Replies View Related

C++ :: Create Array Of Eight Circle Objects Initialized With Radii

Nov 6, 2013

Im supposed to create an array of eight Circle objects initialized with the radii which is in the program. Also I must use bubble sort to arrange the objects is ascending order.

ERRORS:
'initializing' : cannot convert from 'double' to 'Circle'
'setRadius' : is not a member of 'Circle'
see declaration of 'Circle'
'findArea' : is not a member of 'Circle'
see declaration of 'Circle

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
class Circle {

[Code] ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved