1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main (void){
char choice;
bool loop = true;
double point1x, point1y;
double point2x, point2y;
double a, b, c;
double distance;
double midpointx, midpointy;
char commaDelimiter1, commaDelimiter2;
char parenthesis1, parenthesis2, parenthesis3, parenthesis4;
cout << "\n\t\tWelcome to the Point Menu Program!!!\n\n";
while(loop != false){
cout << "\t1) calculate Distance between two points\n";
cout << "\t2) calculate Midpoint of two points\n";
cout << "\t3) Quit\n\n";
cout << "\tChoice: ";
cin >> choice;
cin.ignore(INT_MAX, '\n');
if(choice == '1' || choice == 'D' || choice == 'd'){
cout << "\n\nWhere is your first point? ";
cin >> parenthesis1;
cin >> point1x;
cin >> commaDelimiter1;
cin >> point1y;
cin >> parenthesis2;
cout << "Where is your second point? ";
cin >> parenthesis3;
cin >> point2x;
cin >> commaDelimiter2;
cin >> point2y;
cin >> parenthesis4;
a = pow(point2x - point1x, 2);
b = pow(point2y - point1y, 2);
c = a + b;
distance = sqrt(c);
cout << "\n(" << point1x << ", " << point1y << ") is " << distance << " units away from (" << point2x << ", " << point2y << ").\n\n\n";
}
else if(choice == '2' || choice == 'M' || choice == 'm'){
cout << "\n\nWhere is your first point? ";
cin >> parenthesis1;
cin >> point1x;
cin >> commaDelimiter1;
cin >> point1y;
cin >> parenthesis2;
cout << "Where is your second point? ";
cin >> parenthesis3;
cin >> point2x;
cin >> commaDelimiter2;
cin >> point2y;
cin >> parenthesis4;
midpointx = (point1x + point2x) / 2;
midpointy = (point1y + point2y) / 2;
cout << "\nThe midpoint of the line segment from (" << point1x << ", " << point1y << ") to\n";
cout << "(" << point2x << ", " << point2y << ") is (" << midpointx << ", " << midpointy << ").\n\n\n";
}
else if(choice == '3' || choice == 'Q' || choice == 'q')
{
loop = false;
cout << "\nThank you for using the PMP!!\n\n";
cout << "Endeavor to have a transcendental day!\n\n";
}
else if(choice > '3' || choice < '1')
{
cout << "\nI'm sorry, that choice is invalid!\n\n";
cout << "Please try to read/type more carefully next time...\n\n";
}
else
{
cout << "\nI'm sorry, that choice is invalid!\n\n";
cout << "Please try to read/type more carefully next time...\n\n";
}
}
return 0;
}
|