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
ADVERTISEMENT
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
View Related
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
Dec 10, 2014
Below is what i have so far. My main issue is outputting the area and perimeter of the given coordinates as i need the final coordinate to connect up to the first coordinate. I've tried doing that using numberOfcorners but it says "the expression must have integral or enum type"
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
float ArrayX[10];
float ArrayY[10];
float numberOfcorners;
[Code] .....
View 3 Replies
View Related
Oct 18, 2014
What I'm trying to do is create a dividend calculator that loops through each quarter printing the quarter # as done, then what I want it to do is loop through the calculations at the end.
"quarterlydividend = (sharesobtainable*dividend)/4;"
Basically to continuously calculate how many shares would be held each quarter. Eventually calculating them for years at a time.
I've tired over and over several different types of loops but have been unsuccessful.
#include <stdio.h>
#include <stdlib.h>
#define DIVIDEND = dividendprice/4*sharesobtainable
#define ENDOFQUARTERSHARES2
#define FOURQUARTERS 4
char symbol[5];
float dividendprince;
[Code] ....
View 1 Replies
View Related
Apr 13, 2013
double compute_taxes(double gpay) {
double gross;
double td; // to hold the tax deduction
if (gross <= 1000)
td = gross * 0.5;
else if(gross < 1500)
td= gross * 0.6;
[Code] ....
Write the function double compute_npay(double gpay) that receives an employee's gross pay using the value parameter gpay, computes the net pay and returns it. the net pay is the gross pay - the tax deduction. To compute the net pay, it first calls compute_taxes() to compute the tax deduction.
View 4 Replies
View Related
Feb 10, 2014
What is wrong with this code cause im not getting the correct ratio of total people to cumulative length?
Code:
#include<stdio.h>
#include<stdlib.h>
//define constant variables
#define FIRST_CAR_LENGTH 10
#define NORMAL_CAR_LENGTH 8
#define CAR_CAPACITY 4
int main(void){
//Set up some variable with values that come from input or calculations
[Code].....
View 7 Replies
View Related
Jul 23, 2014
#include <stdio.h>
#include <stdlib.h>
int b_diff (int, int);
[Code].....
I am trying to take two arrays H[], and V[] and call each element to compute the bit difference(Hamming distance) and return that back to the main function to be used in calculating pixel_phase and pixel_smoothing. I'm getting an error that bit_diff cannot be used as a function and I've tried renaming it but nothing seems to work.
[ int b_diff (int a, int ] is how it should actually look.int b_diff (int a, int is how it should actually look).
View 14 Replies
View Related
Sep 23, 2013
This code is not computing the averages.. I am trying to add up all the values in the array and divide them by the number of addresses in the array
Here is the snippet of what I have do far :
//Run through all possible train combinations
Code] :
for(tl=10; tl<=max_tl; tl+=8) {
n_cars++;
num_trains=(.25*max_track)/tl;
num_people=n_cars*num_trains*4;
[Code] ....
View 10 Replies
View Related
Sep 30, 2013
I'm suppose to provide an inner loop that computes the zeta function and the other loop is just press y for to continue, anything else exit.so far i got this:
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main() {
double x, n,zeta;
[code]....
I can't seem to get the formula right.
View 2 Replies
View Related
May 11, 2014
How to do recursive function for the following?
RecursiveComputeRouteDistance(p1index,p2index,locations,latitudes,longitudes): recursively computes the total distance between all waypoints (route) using computeDistance function to compute the distance between two adjacent points. You need to recursively compute the distance for the base case(s) and the general case(s).
This is my computeDistance function
int computeDistance(double a1,double b1,double a2,double b2) {
const int R=6378136;
const float Pi =3.14159;
float Dist=0;
Dist= ((Pi*R)/180)* acos((cos(a1)* cos(b1)* cos(a2)* cos(b2)) + (cos(a1) *sin(b1)* cos(a2)*sin(b2)) + (sin(a1)*sin(a2)));
return Dist;
}
View 2 Replies
View Related
May 5, 2014
I made a simple program to compute the lengths of a triangles sides, but when I enter 30 for angle and 10 for hypotenuse I get the opposite side is -9.880316 and the adjacent is 1.542514.
#include <stdio.h>
#include <math.h>
main() {
float angle;
float hypotenuse;
float adjacent;
float opposite;
[Code] ....
View 2 Replies
View Related
Jun 9, 2013
i am looking for a verified code in simple c, for generating fft of an input image (.jpg). the output can be a text file including fft coefficients.can you recommend me any source except open-cv?
View 6 Replies
View Related
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
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
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
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
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
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
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
Jul 5, 2013
Write a program using turbo c to draw a rectangle inside a circle..........
View 2 Replies
View Related
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
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
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
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
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