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
|
// Find the midpoint of 2 points
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;
int main()
{
char ME;
double X1, Y1, X2, Y2, MX, MY, EX, EY;
cout << "Find the Midpoint or Endpoint of 2 points.\n\n"
"Are you trying to find the Midpoint or Endpoint?\n"
"[M/E] ";
cin >> ME;
if (tolower(ME) == 'M')
{
cout << "Enter the the first coordinate:\n";
get_coord( x1, y1 );
cout << "\nEnter the second coordinate:\n";
get_coord( x2, y2 );
MX = (X1 + X2) / 2;
MY = (Y1 + Y2) / 2;
cout << "Midpoint is: " << "(" << MX << "," << MY << ")";
std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
std::cin.get();
return 0;
}
if (tolower(ME) == 'E')
{
cout << "Enter the the first coordinate:\n";
get_coord( X1, Y1 );
cout << "\nEnter the midpoint:\n";
get_coord( MX, MY );
EX = (((-X1 / 2) + MX) * 2);
EY = (((-Y1 / 2) + MY) * 2);
cout << "Endpoint is: " << "(" << EX << "," << EY << ")";
std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
std::cin.get();
return 0;
}
else
{
cout << "You didn't enter M or E!";
|