Solved

I need help with this Project

Posted on 1998-12-05
7
191 Views
Last Modified: 2010-04-02
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
Comment
Question by:rm11
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

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

Author Comment

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

Author Comment

by:rm11
ID: 1179349
A freind of mine ask me to help him with his geometry class
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 84

Expert Comment

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

Accepted Solution

by:
dvest earned 200 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

by:nietod
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

by:dvest
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question