?
Solved

I need help with this Project

Posted on 1998-12-05
7
Medium Priority
?
196 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 85

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 85

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

840 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