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
|
#include <iostream.h>
#include <math.h>
int LD (void);
int SOL(int, int, int, int);
void main()
{
double slope;
float x1, y1, x2, y2;
char ans;
ans='y';
while (ans=='y' || ans=='Y')
{
cout << "\nEnter X1: ";
cin >> x1;
cout << "\nEnter Y1: ";
cin >> y1;
cout << "\nEnter X2: ";
cin >> x2;
cout << "\nEnter Y2: ";
cin >> y2;
SOL (x1, x2, y1, y2);
LD (x1, x2, slope);
cout<<"\nDo you wish to continue? (y/n): ";
cin>>ans;
}
}
int SOL (int x1, int x2, int y1, int y2)
{
if (x1-x2 != 0)
{
cout<<"Slope is: "<<(y1-y2)/(x1-x2)<<endl;
return (y1-y2)/(x1-x2);
}
else
{
cout<<"Slope is undefined.";
return 0;
}
}
void LD (int x1, int x2, int slope)
{
if (x1-x2 != 0)
{
if (slope > 0){
cout<<"The line is: Rising";
}
else if (slope < 0){
cout<<"The line is: Falling";
}
else if (slope == 0){
cout<<"The line is: Horizontal";
}
else {
cout<<"The line is: Vertical";
}
}
}
|