
Re-write Sample Program 11.2 so that it works for an array of structures. Write the program so that it compares 6 circles. You will need to come up with a new way of determining which circle’s center is closest to the origin.
Sample code 11.2
#include <iostream>
#include <cmath> // necessary for pow function
#include <iomanip>
using namespace std;
struct circle // declares the structure circle
{ // This structure has 6 members
float centerX; // x coordinate of center
float centerY; // y coordinate of center
float radius;
float area;
float circumference;
float distance_from_origin;
};
const float PI = 3.14159;
int main()
{
circle circ1, circ2; // defines 2 circle structure variables
cout << "Please enter the radius of the first circle: ";
cin >> circ1.radius;
cout << endl
<< "Please enter the x-coordinate of the center: ";
cin >> circ1.centerX;
cout << endl
<< "Please enter the y-coordinate of the center: ";
cin >> circ1.centerY;
circ1.area = PI * pow(circ1.radius, 2.0);
circ1.circumference = 2 * PI * circ1.radius;
circ1.distance_from_origin = sqrt(pow(circ1.centerX,2.0)
+ pow(circ1.centerY,2.0));
cout << endl << endl;
cout << "Please enter the radius of the second circle: ";
cin >> circ2.radius;
cout << endl
<< "Please enter the x-coordinate of the center: ";
cin >> circ2.centerX;
cout << endl
<< "Please enter the y-coordinate of the center: ";
cin >> circ2.centerY;
circ2.area = PI * pow(circ2.radius, 2.0);
circ2.circumference = 2 * PI * circ2.radius;
circ2.distance_from_origin = sqrt(pow(circ2.centerX,2.0)
+ pow(circ2.centerY,2.0));
cout << endl << endl;
// This next section determines which circle's center is
// closer to the origin
if (circ1.distance_from_origin > circ2.distance_from_origin)
{
cout << "The first circle is further from the origin"
<< endl << endl;
}
else if (circ1.distance_from_origin < circ2.distance_from_origin)
{
cout << "The first circle is closer to the origin"
<< endl << endl;
}
else
cout << "The two circles are equidistant from the origin";
cout << endl << endl;
cout << setprecision(2) << fixed << showpoint;
cout << "The area of the first circle is : ";
cout << circ1.area << endl;
cout << "The circumference of the first circle is: ";
cout << circ1.circumference << endl << endl;
cout << "The area of the second circle is : ";
cout << circ2.area << endl;
cout << "The circumference of the second circle is: ";
cout << circ2.circumference << endl << endl;
return 0;
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Questions: There needs to be a dynamic array of Child that opposes with SCALE and is assigned to "familyTree". The createFamilyTree() function needs to be defined. Please see the C++ code.arrow_forwardWrite in C++ 1. Define a struct for a soccer player that stores their name, jersey number, and total points scored. 2.Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the average number of points scored by the players. 3.Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the index of the player who scored the most points. 4.Using the struct in #1, write a function that sorts an array of soccer players by name. 5.Using the struct in #1, write a function that takes an (unsorted) array of soccer players and its size and a number as arguments, and returns the name of the soccer player with that number. It should not do any extra unnecessary work. 6.Define a function to find a given target value in an array, but use pointer notation rather than array notation whenever possible. 7.Write a swap function, that swaps the values of two variables in main, but use…arrow_forwardConsider the following structure definition. Write a C/C++ function that takes an array of struct student with its size and applies a curve system like if the student scored below 50, 1dd 10 points, if it is above 50, add 2 points. The lowest possible mark is 0 and the highest possible mark is 10. struct student{ int ID; int score; void applycurve (struct student a[ ], int size)arrow_forward
- In C++ Assume that a 5 element array of type string named boroughs has been declared and initialized. Write the code necessary to switch (exchange) the values of the first and last elements of the array.arrow_forwardtypedef char string[50]; struct a Tag { int a; }; // 1. indicate the data type returned by function Exam() Exam(struct a Tag *ptr) { float b; double C[ 10 ]; string s; } // Access the members of the structure variable indirectly via ptr // You are REQUIRED to use the structure pointer operator; see comments numbered 2 to 5. // 2. input the value of member a scanf("%d", ); // 3. assign 3.1416 as the value of member b = 3.1416; // 4. print the value of the last element of array C. printf("%lf\n", |); // 5. copy "Hello" into string s strcpy( return ptr; , "Hello");arrow_forwardC programming fill in the following code #include "graph.h" #include <stdio.h>#include <stdlib.h> /* initialise an empty graph *//* return pointer to initialised graph */Graph *init_graph(void){} /* release memory for graph */void free_graph(Graph *graph){} /* initialise a vertex *//* return pointer to initialised vertex */Vertex *init_vertex(int id){} /* release memory for initialised vertex */void free_vertex(Vertex *vertex){} /* initialise an edge. *//* return pointer to initialised edge. */Edge *init_edge(void){} /* release memory for initialised edge. */void free_edge(Edge *edge){} /* remove all edges from vertex with id from to vertex with id to from graph. */void remove_edge(Graph *graph, int from, int to){} /* remove all edges from vertex with specified id. */void remove_edges(Graph *graph, int id){} /* output all vertices and edges in graph. *//* each vertex in the graphs should be printed on a new line *//* each vertex should be printed in the following format:…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





