Complex numbers problem

How to call moduo in my class ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <cmath>
#define Pi 3.1415
#include <iomanip>

using namespace std;

class Kompleks
{
public:

	Kompleks (double r=0, double i=0) : _Re(r),_Im(i)
	{}

	double Re() const
	{ return _Re; }

	double Im() const
	{ return _Im; }

	double Ro() const
	{return this->Moduo();}

	double Fi() const
	{
	if (Re())  return atan(Im()/Re());
	else return Im()<0 ? -Pi/2 : Pi/2;
	}

	double Moduo () const
	{
	return sqrt(Re()*Re()+Im()*Im());
	}

	Kompleks operator +(const Kompleks& c) const
	{
	return Kompleks(Re() + c.Re(), Im() + c.Im());
	}

	Kompleks operator -(const Kompleks& c) const
	{
	return Kompleks( Re() - c.Re(), Im() - c.Im() );
	}

	Kompleks operator *(const Kompleks& c) const
	{
	return Kompleks( Re() * c.Re() - Im() * c.Im(), Re() * c.Im() + Im() * c.Re());
	}

	Kompleks operator * (const double d) const
	{
	return Kompleks (Re()*d,Im()*d);
	}

	Kompleks operator /(const Kompleks& c) const
	{
	return Kompleks( (Re() * c.Re() + Im() * c.Im())/(c.Re() * c.Re() + c.Im() * c.Im())
	,(Im() * c.Re() - Re() * c.Im())/(c.Re() * c.Re() + c.Im() * c.Im()));
	}

	Kompleks operator ~() const
	{
	return Kompleks(Re() , -Im());
	}

	istream& Citaj (istream &ul)
	{
	char c, i;
	ul >> _Re >> c >> _Im >> i;
	if (c=='-')
		_Im=-_Im;
	return ul;
	}

	ostream& Pisi (ostream &izl) const
	{
	char c = Im()<0 ? '-' : '+';
	return izl <<Re() << c << abs(Im()) << 'i';
	}

private:
	double _Re;
	double _Im;

};

istream& operator >> (istream& str, Kompleks& c)
{ return c.Citaj(str);}

ostream& operator << (ostream& str, const Kompleks& c)
{ return c.Pisi(str); }
int main(){
    double Rs;
    double Ls;
    double Lm;
    double Lr;
    double Rr;
    double f;

    double Vnt1;
    double ut1;
    double Snt1;

    double Vnt2;
    double ut2;
    double Snt2;

    double Lvoda;
    double rd;
    double xd;
    double r0;
    double x0;

    FILE *generator, *transformator1, *vod, *transformator2, *rezultati;
    generator = fopen("Generator.txt", "r");
    transformator1 = fopen("Transformator1.txt", "r");
    transformator2 = fopen("Transformator2.txt", "r");
    vod = fopen("Vod.txt", "r");
    rezultati = fopen("Rezultati.txt", "w");

    fscanf(generator, "%lf", &Rs);
    fscanf(generator, "%lf", &Ls);
    fscanf(generator, "%lf", &Lm);
    fscanf(generator, "%lf", &Rr);
    fscanf(generator, "%lf", &Lr);
    fscanf(generator, "%lf", &f);

    fscanf(transformator1, "%lf", &Vnt1);
    fscanf(transformator1, "%lf", &ut1);
    fscanf(transformator1, "%lf", &Snt1);

    fscanf(transformator2, "%lf", &Vnt2);
    fscanf(transformator2, "%lf", &ut2);
    fscanf(transformator2, "%lf", &Snt2);

    fscanf(vod, "%lf", &rd);
    fscanf(vod, "%lf", &xd);
    fscanf(vod, "%lf", &r0);
    fscanf(vod, "%lf", &x0);
    fscanf(vod, "%lf", &Lvoda);

    //Generator
    double Xs = 2*Pi*f*Ls;
    Kompleks Zs = (Rs,Xs);
    cout <<Zs;
    return 0;

}
Last edited on
How to call moduo in my class ?

moduo is a class method, how do you normally call non-static, non-ctor class methods ? hint: you've already called class methods line 41, 46, 51, 61 for example
Topic archived. No new replies allowed.