Új hozzászólás Aktív témák
-
sko
csendes tag
KREE, a C++-ban (OOP-ban) való programozás egyik alaptulajdonsága, hogy nem jó a később majd megszépítjük módszer, már az alapokat is jól kell lerakni. A te feladatod központi problémája két pont távolságának kiszámítása. Először ezt kell C++-ban leprogramozni. Íme itt egy lehetséges implementáció. Remélem minden tiszta benne, ha nem kérdezz nyugodtan! Ha tiszta, akkor innen kell továbblépni a pontok konténerekbe tárolásával és távolságuk kiszámításával.
#include <iostream>
#include <cmath>
using namespace std;
class Point
//If you need to calculate the distances of points, always start with creating a point object type.
{
int x = 0;
int y = 0;
public:
Point(): x(0), y(0) {}
Point(int X, int Y): x(X), y(Y) {}
float operator - (const Point&);
//Overloaded minus operator to calculate the distance of two points.
//This will enormously simplify your work later.
};
float Point::operator - (const Point& other)
{
int X = x - other.x;
int Y = y - other.y;
//No abs() necessary, because we will square the coordinates anyway.
float distance = sqrt(X*X + Y*Y);
//Could be double, long double, whatever you like.
return distance;
//There is no real need for this variable, you could return the result of sqrt() directly. Whatever you like.
}
int main()
{
Point middlepoint(8,-6);
Point endpoint(-5,10);
float dist = middlepoint - endpoint;
//Calculate the distance of these points. It's just that simple.
cout << dist << endl;
return 0;
}
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Lenovo Thinkpad T14 G3 Golyóálló Üzleti Érintős Laptop 14" -50% i5-1250P 12Mag 16GB/512GB FHD+
- Samsung Odyssey G9 49" Oled 240Hz G-Sync VRR Gamer monitor Eladó
- Eladó LG OLED G4 55'' (OLED55G48LW) 3 ÉV GARANCIA
- ÚJ Samsung 65" Neo QLED 4K QN90F Vision AI Smart TV (2025) QN70F QN80F QN85F 3év Gar
- Szép! Lenovo Thinkpad T14 G3 "Golyóálló" Üzleti Laptop 14" -60% i5-1250P 12Mag 32/512 FHD+
- Samsung Galaxy A53 5G 128GB, Kártyafüggetlen, 1 Év Garanciával
- iKing.Hu - Honor 400 Pro Black Stílusos csúcsteló, nagy tárhely 12/512 GB,3 hónap gari!
- Intel Core i5 3470 confidential Ivy bridge Quad Core
- Windows, Office licencek kedvező áron, egyenesen a Microsoft-tól - Automata kézbesítés utalással is!
- CTO Bontott 0perces TÜZES EZÜST MacBook Air 13.6" M4 10C/1G 16GB 512GB Gar.: 1 év APPLE világgar
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

