Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8.  
  9. namespace ConsoleApplication2
  10. {
  11.     #include <math.h>
  12.  
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             Punkt p1 = new Punkt (10, 20);
  18.             Punkt p2 = new Punkt (20, 40);
  19.             System.Console.WriteLine("Punkt 1: " + p1.getX() + ", " + p1.getY());
  20.             System.Console.WriteLine("Punkt 2: " + p2.getX() + ", " + p2.getY());
  21.  
  22.             Strecke S = new Strecke (p1, p2);
  23.  
  24.             System.Console.WriteLine("Length: " + S.getLength());
  25.             System.Console.WriteLine("Slope: " + S.getSlope());
  26.  
  27.             System.Console.ReadKey();
  28.         }
  29.     }
  30.    
  31.     class Punkt
  32.     {
  33.         double x;
  34.         double y;
  35.  
  36.         public Punkt (double x, double y)
  37.         {
  38.             this.x = x;
  39.             this.y = y;
  40.         }
  41.        
  42.         double getX()
  43.         {
  44.             return x;
  45.         }
  46.        
  47.         double getY()
  48.         {
  49.             return y;
  50.         }
  51.     }
  52.  
  53.     class Strecke
  54.     {
  55.         Punkt p1;
  56.         Punkt p2;
  57.        
  58.         public Strecke (Punkt p1, Punkt p2)
  59.         {
  60.             this.p1 = p1;
  61.             this.p2 = p2;
  62.         }
  63.        
  64.         //calculate the distance between 2 points
  65.         double getLength ()
  66.             return sqrt(pow(p2.getX()-p1.getX(),2)
  67.                 + pow(p2.getY()-p1.getY(),2));
  68.         }
  69.        
  70.         //calculate the slope between 2 points
  71.         double getSlope (){
  72.             return (p2.getY()-p1.getY())/(p2.getX()-p1.getX());
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement