Solved

# I need help with this Project

Posted on 1998-12-05
Medium Priority
197 Views
I need help with this Project
Write a programm that accepts two points as input.
Have the programm calculate a third point that, with the other points in a plane,
If the two points given:
form a vertical line--------->create a right triangle where the slope of the
hypotenuse is -3. create the third point to the right
of the point with the lower "y" value.
form a horizontal line----->create a right triangle where the slope of the
hypotenuse is 3.create the third point above the point
with the higher "x" value.
form a diagonal line------->create a right triangle by placing the third point
above the point with the lower "y" value.

It doesn't need to be graphical!
0
Question by:rm11
• 2
• 2
• 2
• +1

LVL 85

Expert Comment

ID: 1179347
Is this a homework assignment for school?
What problem are you having with it?
0

LVL 1

Author Comment

ID: 1179348
A freind of mine ask me to help him with his geometry class
0

LVL 1

Author Comment

ID: 1179349
A freind of mine ask me to help him with his geometry class
0

LVL 85

Expert Comment

ID: 1179350
So, what help is needed?  How far have you gotten?  Where are you having difficulty?
0

LVL 1

Accepted Solution

dvest earned 800 total points
ID: 1179351
Hi rm11,
It was unclear if you needed help with the algorithm or the  coding.  Here is the code to
(hopefully) do what you need.  In the case of a horizontal or vertical line, it creates the 3rd point
along the desired axis a distance away that is a ratio of the length of the first segment.  This
gets the slope to 3 (-3).  In the 3rd case for the most part we flip the slope of the segment we start with.  Sorry its not very commented, but is relatively straight-forward.  It should work fine in the 1st quadrant.  Some translation might be required if entry needs to be any possible point.
Please let me know if anything else needs clarified.

#include<iostream.h>
#include<iomanip.h>
#include<math.h>
int main()
{
class point
{
public:
float x;
float y;
};
point pt1;
point pt2;
point pt3;
cout<<"The first point should be the one with the lowest"
<<endl<<"x-value"<<endl;
cout<<"Enter the first point's x-value:";
cin>>pt1.x;
cout<<"\nEnter the first point's y-value:";
cin>>pt1.y;
cout<<"\nEnter the second point's x-value:";
cin>>pt2.x;
cout<<"\nEnter the second point's y-value:";
cin>>pt2.y;
cout<<endl;

/*
If the two points given:
form a vertical line--------->create a right triangle where the slope of the
hypotenuse is -3. create the third point to the right
of the point with the lower "y" value.
*/
if(pt1.x==pt2.x)//the line is vertical-hyp slope -3
{
cout<<"\nThe line is vertical.\n"
if(pt1.y>pt2.y)
{
point temp=pt1;
pt1=pt2;
pt2=temp;
}

float length = fabs(pt2.y-pt1.y);
float length2= fabs(length*.3333333333);
pt3.x=pt1.x+length2;
pt3.y=pt1.y;
}
//      form a horizontal line----->create a right triangle where the slope of the
//   hypotenuse is 3.create the third point above the point
//   with the higher "x" value.
else if(pt1.y==pt2.y)//the line is horizontal
{
cout<<"\nThe line is horizontal.\n";
if (pt1.x>pt2.x)
{
point temp=pt1;
pt1=pt2;
pt2=temp;
}

float length=fabs(pt2.x-pt1.x);
float length2=fabs(length*3.0);
pt3.x=pt2.x;
pt3.y=pt2.y+length2;
}
//form a diagonal line------->create a right triangle by placing
//the third point above the point with the lower "y" value.*/

else
{
cout<<"\nThe line is diagonal.\n"
float xlength=fabs(pt2.x-pt1.x);
float ylength=fabs(pt2.y-pt1.y);
if(pt1.y<pt2.y)
{
pt3.y=pt1.y+xlength;
pt3.x=pt1.x-ylength;
}
else
{
pt3.y=pt2.y+xlength;
pt3.x=pt2.x+ylength;
}
}
cout<<setw(8)<<"Point 3's x is:"<<pt3.x<<" and y is:"<<pt3.y;
cout<<endl;

return 0;
}//end main()

0

LVL 22

Expert Comment

ID: 1179352
Dvest, rm11, unethical behavior is grounds for removal from experts exchange.  Experts can provide limited assistance in school assignments, like answering highly specific questions (like a teacher would answer) and by reviewing a student's work and offering limited suggestions and criticisms (like a teacher would do).  Anything more than that is probably unethical.
0

LVL 1

Expert Comment

ID: 1179353
Dear nietod,
Thank you for your comment.  I took rm11's comment that it was for a friend's geometry class to mean that the coding was not for any grade, just to create a tool for another to use.  Regardless, I'll endeavor to narrow down questions (and answers) to more specific issues instead of complete programs.
This is my first week in EE and it has been wonderful.  Please accept my apologies for any possible improrpriety.

Thanks for the clarification,
David
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.