Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void provjeri(char* znakImag, double& y) {
- if (znakImag[0] == '+') {
- if (znakImag[1] != 'i') {
- y = double(int(znakImag[1] - 48));
- }
- else {
- y = 1.0;
- }
- }
- else {
- if (znakImag[1] != 'i') {
- y = double(int(znakImag[1] - 48)) * (-1.0);
- }
- else {
- y = -1.0;
- }
- }
- }
- void izvrsi(complex& z1,complex& z2,char* operacija,complex& rezultat) {
- if (operacija[0] == 'a') {
- cout << operacija << " " << z1 + z2 << endl;
- rezultat = z1 + z2;
- }
- else if (operacija[0] == 's') {
- cout << operacija << " " << z1 - z2 << endl;
- rezultat = z1 - z2;
- }
- else if (operacija[0] == 'm') {
- cout << operacija << " " << z1 * z2 << endl;
- rezultat= z1 * z2;
- }
- else if (operacija[0] == 'd') {
- cout << operacija << " " << z1 / z2 << endl;
- rezultat= z1 / z2;
- }
- else {
- cout << "Pogresna operacija";
- }
- }
- int main() {
- ifstream file;
- char putanja[13] = ".\\podaci.txt";
- ofstream fileOut;
- char putanja1[16] = ".\\rezultati.txt";
- file.open(putanja);
- if (!file.is_open()) {
- cout << "File nije otvoren";
- }
- char operacija[5];
- char znak = 'f'; // bzvz inicijalizacija prom...
- double x = 0;
- double y = 0;
- char znakImag[5];
- while (file.good()) {
- file >> x >> znakImag;
- if (file.eof()) {
- break;
- }
- provjeri(znakImag, y);
- file >> operacija;
- complex z1 = complex(x, y);
- file >> x >> znakImag;
- provjeri(znakImag, y);
- complex z2 = complex(x, y);
- complex z3;
- izvrsi(z1,z2,operacija,z3);
- fileOut.open(putanja1, ios::app);
- fileOut << "(" << z1 << ")" << " " << operacija << " " << "(" << z2 << ")" << " = " << z3 << endl;
- fileOut.close();
- }
- file.close();
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement