Advertisement
KitSaels

Bod.cs

Apr 30th, 2024
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. internal class Program {
  5.  
  6.     static void Main(string[] args) {
  7.         Bod bod = new Bod();
  8.         Console.WriteLine("Zadej souřadnice bodu");
  9.         bod.nacti_souradnici();
  10.         Bod posun = new Bod();
  11.         Console.WriteLine("Zadej posunutí");
  12.         posun.nacti_souradnici();
  13.         bod.posunuti(posun);
  14.         bod.vypis_souradnice();
  15.         Console.WriteLine(bod.vypocitej_vzdalenost(0, 0));
  16.     }
  17. }
  18.  
  19. class Bod {
  20.     public int x {get; set;}
  21.     public int  y {get; set;}
  22.  
  23.     public Bod() {
  24.         x = 0;
  25.         y = 0;
  26.     }
  27.  
  28.     public Bod(int x, int y) {
  29.         this.x = x;
  30.         this.y = y;
  31.     }
  32.  
  33.     public void posunuti(Bod bod) {
  34.         this.x += bod.x;
  35.         this.y += bod.y;
  36.     }
  37.  
  38.     public void vypis_souradnice() {
  39.         Console.WriteLine($"[{x}, {y}]");
  40.     }
  41.  
  42.     public double vypocitej_vzdalenost(int x, int y) {
  43.         int dx = this.x - x;
  44.         int dy = this.y - y;
  45.         return Math.Sqrt(dx*dx + dy*dy);
  46.     }
  47.  
  48.     public void nacti_souradnici() {
  49.         Console.Write("x: ");
  50.         x = Convert.ToInt32(Console.ReadLine());
  51.         Console.Write("y: ");
  52.         y = Convert.ToInt32(Console.ReadLine());
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement