Forum grupy T2 I Roku EiT

  • Nie jesteś zalogowany.
  • Polecamy: Gry

#1 2008-03-08 14:28:04

Paweł Ewert

UÂżytkownik

3042810
Zarejestrowany: 2007-12-09
Posty: 10
Punktów :   
WWW

Informatyka 4 marca

Program 1:

Spoiler:

#include <iostream>
#include <conio.h>

using namespace std;

class cTenaciousD {
      private:
             double x;
             int y;
      public:
             void vIn(double newX, int newY);
             void vOut();
             cTenaciousD cSum(cTenaciousD &newTenac);
             cTenaciousD() {};
             cTenaciousD(double newX, int newY = 0):
                                x(newX), y(newY) {};
             ~cTenaciousD() {};
};

void cTenaciousD :: vIn(double newX, int newY)
{
     x = newX;
     y = newY;
}

void cTenaciousD :: vOut()
{
     cout << endl << ".x = " << x << endl << ".y = " << y << endl;
}

cTenaciousD cTenaciousD :: cSum (cTenaciousD &newTenac)
{
           x += newTenac.x;
           y += newTenac.y;
}

int main()
{
    double newX;
    int newY;
    cout << "Podaj x pierwszego obiektu : ";
    cin >> newX;
    cout << "Podaj y pierwszego obiektu : ";
    cin >> newY;
    cTenaciousD JB(newX,newY);
    JB.vOut();
   
    cout << "Podaj x drugiego obiektu : ";
    cin >> newX;
    cout << "Podaj y drugiego obiektu : ";
    cin >> newY;
    cTenaciousD KG(newX,newY);
    KG.vOut();
   
    cout << endl <<"Suma : " << endl;
   
    KG.cSum(JB);
    KG.vOut();
   
    getch();
    return 0;
}

Program 2:

Spoiler:

#include <iostream>
#include <conio.h>
#include <cmath>

using namespace std;

class cPoint {
      private:
              double x, y;
      public:
             cPoint() {};
             cPoint(double newX, double newY = 0.0):
                        x(newX),y(newY) {};
             void vChangeXY(double newX, double newY);
             void vAdd(cPoint &newPoint);
             void vSubstract(cPoint &newPoint);
             double dDistance(cPoint &newPoint);
};

void cPoint :: vChangeXY(double newX, double newY)
{
     x = newX;
     y = newY;
}

void cPoint :: vAdd(cPoint &newPoint)
{
     x += newPoint.x;
     y += newPoint.y;
}

void cPoint :: vSubstract(cPoint &newPoint)
{
     x -= newPoint.x;
     y -= newPoint.y;
}

double cPoint :: dDistance(cPoint &newPoint)
{
       return sqrt(pow(x - newPoint.x,2) + pow(y - newPoint.y,2));
}

int main()
{
    cPoint Punkt1(0,0);
    cPoint Punkt2(2,2);
    cout << Punkt1.dDistance(Punkt2);
    getch();
    return 0;
}

Te programy są Mateusza B. więc jeśli jakieś pytania to od niego

Offline

 

Stopka forum

RSS
Powered by PunBB 1.2.23
© Copyright 2002–2008 PunBB
Polityka cookies - Wersja Lo-Fi


Darmowe Forum | Ciekawe Fora | Darmowe Fora
GotLink.plwodomierze wrocław biuro rachunkowe www.otokot.pl