I\'m not getting the right output for this program here is the code and data fil
ID: 3623015 • Letter: I
Question
I'm not getting the right output for this program here is the code and data file
data0= 30 30 10 5 9
1. 10 20 12 -3 -9
2. 50 20 40 -50 -20
3. 30 10 4 80 10
4. 99 99 40 -40 -60
5. 1 1 1 1 1
/* 2170_2_4.cc
Problem description:
Write a program to move and caluclate the area and circumference of a circle.
The program should read from the screen the information of a circle, which contains:
1. the location of a circle indicated by three integers, i.e.
x- and y-coordinates of the center, and radius.
2. an integer indicating the moving distance in the horizontal direction.
Positive number means moving right, otherwise moving left.
3. an integer indicating the moving distance in the vertical direction.
Positive number means moving down, otherwise moving up.
For example, suppose we read the following 5 intergers from the screen:
20 10 40 9 -7
So the location of the center is (20, 10), and radius is 40. The circle should be moved 9 units
to the right and 7 units up.
You are required to declare and define the following "void" functions,
1. moveCircle function, which passes coordinates of the center by reference, and the
moving distances on horizontal and vertical directions by value.
2. calculate function, which passes the radius by value, and get back the area
(PI*radius*radius) and circumference (2*PI*radius) of the circle through reference
parameters. Assume PI = 3.14 within this function.
*/
#include
#include
#include
using namespace std;
// Function prototypes
void movecircle(int&,int&,int,int);
void calculate(int,double&,double&);
moveCircle function: a void function that passes coordinates of the center by reference, and the moving distances on horizontal and vertical directions by value. calculate function: a void function that passes the radius by value, and get back the area (PI*radius*radius) and circumference (2*PI*radius) of the circle through reference parameters. Assume PI = 3.14 within this function.
int main( )
{
int x; //x-coordinate of the center
int y; //y-coordinate of the center
int radius; // the radius of the center
int hdist; // moving distance on horizontal direction
int vdist; // moving distance on vertical direction
double area; // area of the circle
double circumference; // circumference of the circle
cin >> x >> y >> radius >> hdist >> vdist; //Read the circle information
calculate(radius,area,circumference);
// Calculate the new x,y cordinates by calling the moveCircle function
// Calculate the area and the circumference of the circle by calling the calculate function
Calculate the new x,y cordinates by calling the moveCircle function Calculate the area and the circumference of the circle by calling the calculate function
cout << " Center = (" < << " Area = " << area << " Circumference=" << circumference << endl;
return 0;
}
// moveCircle function: a void function that passes coordinates of the center by reference,
// and the moving distances on horizontal and vertical directions by value.
moveCircle function: a void function that passes coordinates of the center by reference, and the moving distances on horizontal and vertical directions by value.
void movecircle(int& x,int& y,int hdist,int vdist)
{x+=hdist;
y+=vdist;
}
// calculate function: a void function that passes the radius by value, and get back the area
// (PI*radius*radius) and circumference (2*PI*radius) of the circle through reference
// parameters. Assume PI = 3.14 within this function.
calculate function: a void function that passes the radius by value, and get back the area (PI*radius*radius) and circumference (2*PI*radius) of the circle through reference parameters. Assume PI = 3.14 within this function.
void calculate(int r,double& a,double& c)
{double pi=3.14;
a=pi*r*r;
c=2*pi*r;
}
Explanation / Answer
please rate - thanks
try this
#include <iostream>
#include <math.h>
using namespace std;
// Function prototypes
void movecircle(int&,int&,int,int);
void calculate(int,double&,double&);
//moveCircle function: a void function that passes coordinates of the center by reference, and the moving distances on horizontal and vertical directions by value. calculate function: a void function that passes the radius by value, and get back the area (PI*radius*radius) and circumference (2*PI*radius) of the circle through reference parameters. Assume PI = 3.14 within this function.
int main( )
{
int x; //x-coordinate of the center
int y; //y-coordinate of the center
int radius; // the radius of the center
int hdist; // moving distance on horizontal direction
int vdist; // moving distance on vertical direction
double area; // area of the circle
double circumference; // circumference of the circle
cin >> x >> y >> radius >> hdist >> vdist; //Read the circle information
calculate(radius,area,circumference);
// Calculate the new x,y cordinates by calling the moveCircle function
// Calculate the area and the circumference of the circle by calling the calculate function
//Calculate the new x,y cordinates by calling the moveCircle function Calculate the area and the circumference of the circle by calling the calculate function
movecircle(x,y,hdist,vdist);
cout << " Center = ("<<x<<","<<y<<") Area = " << area << " Circumference=" << circumference << endl;
system("pause");
return 0;
}
// moveCircle function: a void function that passes coordinates of the center by reference,
// and the moving distances on horizontal and vertical directions by value.
//moveCircle function: a void function that passes coordinates of the center by reference, and the moving distances on horizontal and vertical directions by value.
void movecircle(int& x,int& y,int hdist,int vdist)
{x+=hdist;
y+=(vdist*-1);
}
// calculate function: a void function that passes the radius by value, and get back the area
// (PI*radius*radius) and circumference (2*PI*radius) of the circle through reference
// parameters. Assume PI = 3.14 within this function.
//calculate function: a void function that passes the radius by value, and get back the area (PI*radius*radius) and circumference (2*PI*radius) of the circle through reference parameters. Assume PI = 3.14 within this function.
void calculate(int r,double& a,double& c)
{double pi=3.14;
a=pi*r*r;
c=2*pi*r;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.