ECF 1.5
main.cpp
1#include<fstream>
2#include<iostream>
3#include<string>
4#include<sstream>
5using namespace std;
6
7typedef unsigned int uint;
8
9
10//
11// ispis Tree u infix formatu
12//
13void showTree(string& output, stringstream& ss)
14{
15 string token;
16
17 ss >> token;
18
19 if(token == "+" || token == "-" || token == "*" || token == "/") {
20 output += "(";
21 showTree(output, ss);
22 output += token;
23 showTree(output, ss);
24 output += ")";
25 }
26 else if(token == "sqrt" || token == "log" || token == "sin" || token == "cos") {
27 output += token + "(";
28 showTree(output, ss);
29 output += ")";
30 }
31 else
32 output += token;
33
34 return;
35}
36
37
38
39int main(int argc, char **argv)
40{
41 string ind;
42
43 if(argc > 1) {
44 ifstream infile(argv[1]);
45 if(!infile) {
46 cout << "nema fajla!" << endl;
47 return 1;
48 }
49 getline(infile, ind);
50 }
51 else {
52 cout << "daj: ";
53 getline(cin, ind);
54 }
55
56 string output;
57 stringstream ss;
58 ss << ind;
59 showTree(output, ss);
60 std::cout << output << endl;
61
62 if(argc > 2) {
63 ofstream outfile(argv[2]);
64 outfile << output << endl;
65 outfile.close();
66 }
67
68 return 0;
69}