Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <iostream>
  3. #include<fstream>
  4. #include <string>
  5. #include <vector>
  6. using namespace std;
  7. //float tabela[];
  8. int vel = 0;
  9. vector<string> strings;
  10. vector< vector<float> > podatki((100), vector<float>(100));
  11. void preberi(){
  12.     ifstream input("test.csv");
  13.     if (input.is_open()) {
  14.  
  15.         while (!input.eof()) {
  16.             string ena;
  17.             string s;
  18.            
  19.             int dolz = 0;
  20.             //getline(input, ena); //read number
  21.             //data = atoi(ena.c_str()); //convert to integer
  22.             int vrsta = 0;
  23.             while (getline(input, s, ';')) {
  24.                 //cout << s << endl;
  25.                 dolz++;
  26.                 strings.push_back(s);
  27.                 string sst = "";
  28.                
  29.                 float fst = 0;
  30.                 int stolp = 0;
  31.                 //cout << s.length() << endl;
  32.                 cout << s[4] << endl;
  33.                 for (int i = 0; i < s.length(); i++) {
  34.                     if (s[i] == ','|| i== s.length() ) {
  35.                         fst = strtof(sst.c_str(), NULL);
  36.                         sst.clear();
  37.                         podatki[vrsta][stolp] = fst;
  38.                         cout << fst << "::" << podatki[vrsta][stolp] << " ";
  39.                         stolp++;
  40.                     }
  41.                    
  42.                     else {
  43.                        
  44.                         sst += s[i];
  45.                        
  46.                     }
  47.  
  48.  
  49.                 }
  50.                 fst = strtof(sst.c_str(), NULL);
  51.                 sst.clear();
  52.                 podatki[vrsta][stolp] = fst;
  53.                 cout << fst << "::" << podatki[vrsta][stolp] << " ";
  54.                 vrsta++;
  55.                 cout << endl;
  56.             }
  57.             cout << endl;
  58.             vel = dolz/2+1;
  59.             dolz = 0;
  60.             //cout << strings[0][0] << endl;
  61.  
  62.            
  63.  
  64.         }
  65.  
  66.     }
  67. }
  68. void sestej() {
  69.     vector< vector<float> > resitev((vel), vector<float>(vel));
  70.    
  71.     for (int i = 0; i < vel ; i++) {
  72.         for (int j = 0; j < vel ; j++) {
  73.             if(j%2!=1){
  74.             resitev[i][j] = atof(&(const char)strings[i][j]) +atof(&(const char)strings[i + vel ][j]);
  75.             cout << atof(&(const char)strings[i][j]) << "+" << atof(&(const char)strings[i + vel][j]) << "=";
  76.             cout << atof(&(const char)strings[i][j]) + atof(&(const char)strings[i + vel][j]) << " ";
  77.             }
  78.         }
  79.         cout << endl;
  80.     }
  81.     cout << endl; cout << endl;
  82.     for (int i = 0; i < vel; i++) {
  83.         for (int j = 0; j < vel; j++) {
  84.             cout << (resitev[i][j ]) <<" ";
  85.         }
  86.         cout << endl;
  87.     }
  88. }
  89. int main( int argc, char** argv) {
  90.     if (argc == 3) {
  91.         if (string(argv[1]) == "i") {
  92.             printf("Int\n");
  93.             preberi();
  94.  
  95.             sestej();
  96.         }
  97.         else if (string(argv[1]) == "f") {
  98.             printf("Float\n");
  99.         }
  100.         else {
  101.             printf("error\n");
  102.         }
  103.         for (int i = 0; i < argc; ++i) {
  104.             std::cout <<i<<" "<< argv[i] << std::endl;
  105.         }
  106.     }
  107.     else {
  108.         printf("Premalo/Prevec parametrov....Pravilna uporab...\n");
  109.  
  110.     }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement