Solved

I need help with this Project

Posted on 1998-12-05
7
187 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
Comment Utility
Is this a homework assignment for school?
What problem are you having with it?
0
 
LVL 1

Author Comment

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

Author Comment

by:rm11
Comment Utility
A freind of mine ask me to help him with his geometry class
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now