Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Labs - val / Lab_oop_1

.cpp
Скачиваний:
5
Добавлен:
15.06.2014
Размер:
1.26 Кб
Скачать
#include <stdio.h>

class Complex
{
    protected:
        float realPart;
        float imaginaryPart;
    public:
        Complex(float a, float b)
        {
            realPart = a;
            imaginaryPart = b;
        }
        static Complex addition(Complex a, Complex b)
        {
            Complex c(0,0);
            c.realPart = a.realPart + b.realPart;
            c.imaginaryPart = a.imaginaryPart + b.imaginaryPart;
            return c;
        }
        static Complex subtraction(Complex a, Complex b)
        {
            Complex c(0,0);
            c.realPart = a.realPart - b.realPart;
            c.imaginaryPart = a.imaginaryPart - b.imaginaryPart;
            return c;
        }
        static void printComplex(Complex a, char *additionalText)
        {
            printf("%s: (%f , %f)\n", additionalText, a.realPart, a.imaginaryPart);
        }
};

int main()
{
    Complex x(2,2);
    Complex y(3,3);
    Complex z(0,0);

    Complex::printComplex(x,"First number");
    Complex::printComplex(y,"Second number");
    Complex::printComplex(Complex::addition(x,y),"Addition");
    Complex::printComplex(Complex::subtraction(x,y),"Subctraction");

    getchar(); getchar();
}




Соседние файлы в папке Labs - val
  • #
    15.06.2014504 б5Lab5_2.cpp
  • #
    15.06.2014131.14 Кб5Lab5_2.obj
  • #
    15.06.2014504 б6Lab5_2.~cpp
  • #
    15.06.201445 б5Lab6.cpp
  • #
    15.06.20144.24 Кб5Lab6.obj
  • #
    15.06.20141.26 Кб5Lab_oop_1.cpp
  • #
    15.06.20145.61 Кб5Lab_oop_1.obj
  • #
    15.06.20141.26 Кб5Lab_oop_1.~cpp
  • #
    15.06.2014126 б5Lab_oop_2.cpp
  • #
    15.06.20142.78 Кб5Lab_oop_2.obj
  • #
    15.06.2014126 б5Lab_oop_2.~cpp