Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- internal class Program {
- static void Main(string[] args) {
- Bod bod = new Bod();
- Console.WriteLine("Zadej souřadnice bodu");
- bod.nacti_souradnici();
- Bod posun = new Bod();
- Console.WriteLine("Zadej posunutí");
- posun.nacti_souradnici();
- bod.posunuti(posun);
- bod.vypis_souradnice();
- Console.WriteLine(bod.vypocitej_vzdalenost(0, 0));
- }
- }
- class Bod {
- public int x {get; set;}
- public int y {get; set;}
- public Bod() {
- x = 0;
- y = 0;
- }
- public Bod(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public void posunuti(Bod bod) {
- this.x += bod.x;
- this.y += bod.y;
- }
- public void vypis_souradnice() {
- Console.WriteLine($"[{x}, {y}]");
- }
- public double vypocitej_vzdalenost(int x, int y) {
- int dx = this.x - x;
- int dy = this.y - y;
- return Math.Sqrt(dx*dx + dy*dy);
- }
- public void nacti_souradnici() {
- Console.Write("x: ");
- x = Convert.ToInt32(Console.ReadLine());
- Console.Write("y: ");
- y = Convert.ToInt32(Console.ReadLine());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement