?
Solved

I need help with this Project

Posted on 1998-12-05
7
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 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

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

765 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