Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- #include <math.h>
- class Program
- {
- static void Main(string[] args)
- {
- Punkt p1 = new Punkt (10, 20);
- Punkt p2 = new Punkt (20, 40);
- System.Console.WriteLine("Punkt 1: " + p1.getX() + ", " + p1.getY());
- System.Console.WriteLine("Punkt 2: " + p2.getX() + ", " + p2.getY());
- Strecke S = new Strecke (p1, p2);
- System.Console.WriteLine("Length: " + S.getLength());
- System.Console.WriteLine("Slope: " + S.getSlope());
- System.Console.ReadKey();
- }
- }
- class Punkt
- {
- double x;
- double y;
- public Punkt (double x, double y)
- {
- this.x = x;
- this.y = y;
- }
- double getX()
- {
- return x;
- }
- double getY()
- {
- return y;
- }
- }
- class Strecke
- {
- Punkt p1;
- Punkt p2;
- public Strecke (Punkt p1, Punkt p2)
- {
- this.p1 = p1;
- this.p2 = p2;
- }
- //calculate the distance between 2 points
- double getLength ()
- return sqrt(pow(p2.getX()-p1.getX(),2)
- + pow(p2.getY()-p1.getY(),2));
- }
- //calculate the slope between 2 points
- double getSlope (){
- return (p2.getY()-p1.getY())/(p2.getX()-p1.getX());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement