/* * Name: * Class: CS140-001 * Assignment: Programming Assignment 2 * Date: 01/
ID: 3878401 • Letter: #
Question
/*
* Name:
* Class: CS140-001
* Assignment: Programming Assignment 2
* Date: 01/26/2018
*/
#include <iostream>
using namespace std;
const double PI = 3.14159;
int main()
{
double x;
double y;
double radius;
double center;
double area;
double circumference;
cout.setf(ios::fixed);
cout.precision(2);
cout << "Programmed by Taylor Heimann" << endl << endl;
cout << "Enter the x and y coordinates of the center of the circle: ";
cin >> x;
cout << " ";
cin >> y;
cout << "Enter the radius of the circle: ";
cin >> radius;
cout << "****************************" << endl;
cout << "Circle Information" << endl;
cout << "Radius: " << radius << endl;
cout << "Center: (" << x << ", " << y << ")" << endl;
area = PI * radius * radius;
circumference = 2 * PI * radius;
cout << "Area: " << area << endl;
cout << "Circumference: " << circumference << endl;
if (!(x == 0) && !(y == 0))
{
cout << "Circle is completely in Quadrant ";
if (x > 0)
{
if (y > 0) cout << "I";
else cout << "IV";
}
else if (x < 0)
{
if (y > 0) cout << "II";
else cout << "III";
}
}
if ((x == 0) && (y == 0))
{
cout << "Circle center is at the orgin";
}
if ((x == 0) && !(y = 0))
{
cout << "Circle center is on ";
{
if (x == 0) cout << "y";
else cout << "";
}
cout << " - axis";
}
if (!(x == 0) && (y == 0))
{
cout << "Circle center is on ";
{
if (y == 0) cout << "x";
else cout << "";
}
cout << " - axis";
}
if ((x != 0) && (y != 0))
{
cout << "Circle crosses at least one of the axes and the center is not on an axis";
}
cout << endl;
cout << "****************************" << endl;
system("pause");
}
OUTPUTS
Programmed by Lori Tetzner
Enter the x and y coordinates of the center of the circle: 6.5 -3.7
Enter the radius of the circle: 4.2
****************************
Circle Information Radius: 4.2
Center: (6.5, -3.7)
Area: 55.42 Circumference: 26.39
Circle crosses at least one of the axes and the center is not on an axis
****************************
Programmed by Lori Tetzner
Enter the x and y coordinates of the center of the circle: -5.1 0
Enter the radius of the circle: 10
****************************
Circle Information Radius: 10
Center: (-5.1, 0)
Area: 314.16
Circumference: 62.83
Circle center is on x - axis
****************************
I am trying to write a program that looks EXACTLY like these out puts using "if else" statements.
I am having troble with the decimal places on some numbers.
also cant figure out the if else statement for the last line, first output..
Explanation / Answer
#include <iostream>
using namespace std;
const double PI = 3.14159;
int main()
{
double x;
double y;
double radius;
double center;
double area;
double circumference;
cout.setf(ios::fixed);
cout.precision(2);
cout << "Programmed by Taylor Heimann" << endl << endl;
cout << "Enter the x and y coordinates of the center of the circle: ";
cin >> x;
cout << " ";
cin >> y;
cout << "Enter the radius of the circle: ";
cin >> radius;
cout << "****************************" << endl;
cout << "Circle Information" << endl;
cout << "Radius: " << radius << endl;
cout << "Center: (" << x << ", " << y << ")" << endl;
area = PI * radius * radius;
circumference = 2 * PI * radius;
cout << "Area: " << area << endl;
cout << "Circumference: " << circumference << endl;
bool flag = false;
if (!(x == 0) && !(y == 0))
{
//check if the circle is in 1 st quadrant
if (x > 0 && y > 0 && ( (y - radius) > 0 && ( x - radius ) > 0 ))
{
cout << "Circle is completely in Quadrant I";
flag = true;
}
//check if the circle is in 4 th quadrant
else if(x > 0 && y < 0 && ( (y + radius) < 0 && ( x - radius ) > 0 ))
{
cout << "Circle is completely in Quadrant IV";
flag = true;
}
//check if the circle is in 2 nd quadrant
else if (x < 0 && y > 0 && ( (y - radius) > 0 && ( x + radius ) < 0 ))
{
cout << "Circle is completely in Quadrant II";
flag = true;
}
//check if the circle is in 3 rd quadrant
else if (x < 0 && y < 0 && ( (y < radius) > 0 && ( x + radius ) < 0 ))
{
cout << "Circle is completely in Quadrant III";
flag = true;
}
}
if(!flag)
{
if ((x == 0) && (y == 0))
{
cout << "Circle center is at the orgin";
}
else if ((x == 0) && !(y == 0))
{
cout << "Circle center is on ";
{
if (x == 0) cout << "y";
else cout << "";
}
cout << " - axis";
}
else if (!(x == 0) && (y == 0))
{
cout << "Circle center is on ";
{
if (y == 0) cout << "x";
else cout << "";
}
cout << " - axis";
}
else if ((x != 0) && (y != 0))
{
cout << "Circle crosses at least one of the axes and the center is not on an axis";
}
}
cout << endl;
cout << "****************************" << endl;
system("pause");
}
Sample Output 1:
Programmed by Lori Tetzner
Enter the x and y coordinates of the center of the circle: 6.5 -3.7
Enter the radius of the circle: 4.2
****************************
Circle Information Radius: 4.2
Center: (6.5, -3.7)
Area: 55.42 Circumference: 26.39
Circle crosses at least one of the axes and the center is not on an axis
****************************
Sample Output 2:
Programmed by Lori Tetzner
Enter the x and y coordinates of the center of the circle: -5.1 0
Enter the radius of the circle: 10
****************************
Circle Information Radius: 10
Center: (-5.1, 0)
Area: 314.16
Circumference: 62.83
Circle center is on x - axis
****************************
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.