What data would you put together into a struct so that it would make that program easier to manage and make the data on it easier to manage. C++

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What data would you put together into a struct so that it would make that program easier to manage and make the data on it easier to manage. C++ 

#include<iostream>

#include<cmath>

#include<limits>

//Define constants Pi

#define PI 3.14

using namespace std;

//Define a function to calculate the radius

double calculateRadius(int x1,int y1,int x2,int y2)

{

//Compute radius

double radius = sqrt(pow(x2-x1, 2) + pow((y2-y1), 2));

//Return radius to calling function

return radius;

}

//Define a function to calculate Area

double calculateArea(double radius)

{

//Return area to calling function

return PI * radius * radius;

}

//Define a function to calculate perimeter

double calculatePeriemeter(double radius)

{

//Return perimeter to calling function

return 2*PI*radius;

}

int main()

{

//Variables declaration

int x1, y1, x2, y2;

double radius, area, perimeter;

cout<<"\nPlease enter the center point in the form x y: ";

cin>>x1>>y1;

while(1)

{

if(cin.fail())

{

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

cout<<"You entered something that is not a number. Please try again"<<endl;

cout<<"\nPlease enter the center point in the form x y: ";

cin>>x1>>y1;

}

if(!cin.fail())

break;

}

//Prompt the user to enter the point on the circle in the form x y

cout<<"Please enter the point on the circle in the form x y: ";

cin>>x2>>y2;

while(1)

{

if(cin.fail())

{

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

cout<<"You entered something that is not a number. Please try again"<<endl;

cout<<"\nPlease enter the point on the circle in the form x y: ";

cin>>x2>>y2;

}

if(!cin.fail())

break;

}

//call to functions and store the return values to variables

radius = calculateRadius(x1, y1, x2, y2);

area = calculateArea(radius);

perimeter = calculatePeriemeter(radius);

//display the outputs

cout<<"Here is the information for the circle formed from ("<<x1<<","<<y1<<") and ("<<x2<<","<<y2<<")"<<endl;

cout<<"Radius: "<<radius<<endl;

cout<<"Area: "<<area<<endl;

cout<<"Perimeter: "<<perimeter<<endl;

return 0;

}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Coding
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education