Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lab2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <stdlib.h>
- class complex {
- float re,im;
- public:
- complex(): re(0), im(0){}
- complex(float r, float i): re(r), im(i){}
- float get_real() {
- return re;
- }
- float get_imaginar() {
- return im;
- }
- complex add(complex x){
- complex ret;
- ret.re = re + x.re;
- ret.im = im + x.im;
- return ret;
- }
- complex add1(complex x) {
- return complex(re + x.re, im + x.im);
- }
- complex inmultire(complex x){
- complex ret;
- ret.re = re * x.re - im * x.im;
- ret.im = re * x.im + im * x.re;
- return ret;
- }
- void print(){
- std::cout << re << "+i" << im << std::endl;
- }
- };
- class vector {
- float info[3];
- public:
- vector () {
- for(int i = 0; i < 3; i++)
- info[i] = 0.0f;
- }
- vector add(vector a){
- vector b;
- for(int i = 0; i < 3; i++)
- b.info[i] = a.info[i] + info[i];
- return b;
- }
- vector add(int a){
- vector b;
- for(int i = 0; i < 3; i++)
- b.info[i] = a + info[i];
- return b;
- }
- vector add(float a){
- vector b;
- for(int i = 0; i < 3; i++)
- b.info[i] = a + info[i];
- return b;
- }
- void print(){
- for(int i = 0; i < 3; i++)
- std::cout << info[i] << " ";
- std::cout << std::endl;
- }
- };
- float add(float a, float b){
- return a + b;
- }
- complex add(complex a, complex b){
- return a.add1(b);
- }
- complex add(complex a, float b) {
- return complex(a.get_real() + b, a.get_imaginar());
- }
- int _tmain(int argc, _TCHAR* argv[]) {
- vector b, c;
- b = c.add(1);
- c = c.add(3.2f);
- b.print();
- c.print();
- c = b.add(c);
- c.print();
- std::cout << "=========================================" << std::endl;
- complex x(3.4f, 1.1f);
- complex y(2.6f, 7.9f);
- complex z;
- int f = 4, g = 7;
- double k = 4.5, l = 7.8;
- float m = 4.5f, n = 3.6f, p;
- z = add(x, y);
- z.print();
- z = add(x, m);
- z.print();
- z = add(m, x);
- z.print();
- p = add(m, n);
- std::cout << p << std::endl;
- f = add(f, g);
- std::cout << f << std::endl;
- k = add(k, l);
- std::cout << k << std::endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment