Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <stdio.h>
  8. #include <conio.h>
  9. #include <algorithm>
  10. #include <sstream>
  11.  
  12. using namespace std;
  13.  
  14. // LICZBA POMIARÓW: 1095; PIERWSZA LICZBA: GODZINY; DRUGA LICZBA: TEMPERATURA.
  15.  
  16. void zadanie_2_compare(string stacja_1, string stacja_2, string stacja_3)
  17. {
  18.     int liczba_nieprawidlowych_wskazan_we_wszystkich_3_stacjach = 0;
  19.    
  20.     ofstream plik_out;
  21.    
  22.     plik_out.open("wyniki_systemy.txt", ios::app);
  23.    
  24.     for (int i=0; i<1095; i++)
  25.     {
  26.         if ((stacja_1[i] == '0')&&(stacja_2[i] == '0')&&(stacja_3[i] == '0')) liczba_nieprawidlowych_wskazan_we_wszystkich_3_stacjach++;
  27.     }
  28.    
  29.     plik_out << endl << endl << "Zadanie 58.2:" << endl << "Ilosc blednych wskazan we wszystkich trzech stacjach naraz: " << liczba_nieprawidlowych_wskazan_we_wszystkich_3_stacjach;
  30.    
  31.     plik_out.close();
  32. }
  33.  
  34. string to_base(int base, int decimal)
  35. {
  36.  char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
  37.  string result = "";
  38.  while (decimal != 0)
  39.  {
  40.   result += digits[decimal % base];
  41.   decimal /= base;
  42.  }
  43.  reverse(result.begin(), result.end());
  44.  return result;
  45. }
  46.  
  47. string zadanie_2(int nr_stacji)
  48. {
  49.     ifstream plik_in;
  50.    
  51.     string zegar, godz, wzorowe_wskazanie_zegara_string;
  52.     int wzorowe_wskazanie_zegara = 12, podst, temp;
  53.    
  54.     switch (nr_stacji)
  55.     {
  56.         case 1:
  57.         plik_in.open("dane_systemy1.txt");
  58.         podst = 2;
  59.         break;
  60.        
  61.         case 2:
  62.         plik_in.open("dane_systemy2.txt");
  63.         podst = 4;
  64.         break;
  65.        
  66.         case 3:
  67.         plik_in.open("dane_systemy3.txt");
  68.         podst = 8;
  69.         break;
  70.        
  71.         default:
  72.         cout << "ERROR";
  73.         exit(0);
  74.     }
  75.    
  76.     while (!plik_in.eof())
  77.     {
  78.         godz = "";
  79.        
  80.         plik_in >> godz >> temp;
  81.        
  82.         wzorowe_wskazanie_zegara_string = to_base(podst, wzorowe_wskazanie_zegara);
  83.        
  84.         if (wzorowe_wskazanie_zegara_string == godz) zegar += "1";
  85.         else zegar += "0";
  86.        
  87.         wzorowe_wskazanie_zegara += 24;
  88.     }
  89.    
  90.     plik_in.close();
  91.    
  92.     return zegar;
  93. }
  94.  
  95. void clear()
  96. {
  97.     ofstream plik_out;
  98.     plik_out.open("wyniki_systemy.txt");
  99.     plik_out.clear();
  100.     plik_out.close();
  101. }
  102.  
  103. void zadanie_1(int nr_stacji)
  104. {    
  105.     int licznik = 1, podst;
  106.     long double godz_int, temp_int, temp_int_min;
  107.    
  108.     ifstream plik_in;
  109.     ofstream plik_out;
  110.    
  111.     switch (nr_stacji)
  112.     {
  113.         case 1:
  114.         plik_in.open("dane_systemy1.txt");
  115.         podst = 2;
  116.         break;
  117.        
  118.         case 2:
  119.         plik_in.open("dane_systemy2.txt");
  120.         podst = 4;
  121.         break;
  122.        
  123.         case 3:
  124.         plik_in.open("dane_systemy3.txt");
  125.         podst = 8;
  126.         break;
  127.        
  128.         default:
  129.         cout << "ERROR";
  130.         exit(0);
  131.     }
  132.    
  133.     plik_out.open("wyniki_systemy.txt", ios::app);
  134.    
  135.     while (!plik_in.eof())
  136.     {
  137.         plik_in >> godz_int >> temp_int;
  138.        
  139.         if (licznik == 1) temp_int_min = temp_int;
  140.         else
  141.         {
  142.             if (temp_int < temp_int_min) temp_int_min = temp_int;
  143.         }
  144.        
  145.         licznik++;
  146.     }
  147.    
  148.     if (podst == 2)
  149.     {
  150.         plik_out << "Zadanie 58.1:" << endl << "Stacja nr 1: " << temp_int_min;
  151.     }
  152.     if (podst == 4)
  153.     {
  154.         int dlugosc;
  155.        
  156.         string temp_string_min, temp_min_bin;
  157.        
  158.         ostringstream ss;
  159.        
  160.         ss << temp_int_min;
  161.        
  162.         temp_string_min = ss.str();
  163.        
  164.         dlugosc = temp_string_min.length();
  165.        
  166.         for (int i=0; i<dlugosc; i++)
  167.         {
  168.             switch (temp_string_min[i])
  169.             {
  170.                 case '-':
  171.                 temp_min_bin += "-";
  172.                 break;
  173.                
  174.                 case '0':
  175.                 temp_min_bin += "00";
  176.                 break;
  177.                
  178.                 case '1':
  179.                 temp_min_bin += "01";
  180.                 break;
  181.                
  182.                 case '2':
  183.                 temp_min_bin += "10";
  184.                 break;
  185.                
  186.                 case '3':
  187.                 temp_min_bin += "11";
  188.                 break;
  189.             }
  190.         }
  191.        
  192.         while (temp_min_bin[1] == '0')
  193.         {
  194.             temp_min_bin.erase(1, 1);
  195.         }
  196.        
  197.         plik_out << endl << "Stacja nr 2: " << temp_min_bin;
  198.     }
  199.     if (podst == 8)
  200.     {
  201.         int dlugosc;
  202.        
  203.         string temp_string_min, temp_min_bin;
  204.        
  205.         ostringstream ss;
  206.        
  207.         ss << temp_int_min;
  208.        
  209.         temp_string_min = ss.str();
  210.        
  211.         dlugosc = temp_string_min.length();
  212.        
  213.         for (int i=0; i<dlugosc; i++)
  214.         {
  215.             switch (temp_string_min[i])
  216.             {
  217.                 case '-':
  218.                 temp_min_bin += "-";
  219.                 break;
  220.                
  221.                 case '0':
  222.                 temp_min_bin += "000";
  223.                 break;
  224.                
  225.                 case '1':
  226.                 temp_min_bin += "001";
  227.                 break;
  228.                
  229.                 case '2':
  230.                 temp_min_bin += "010";
  231.                 break;
  232.                
  233.                 case '3':
  234.                 temp_min_bin += "011";
  235.                 break;
  236.                
  237.                 case '4':
  238.                 temp_min_bin += "100";
  239.                 break;
  240.                
  241.                 case '5':
  242.                 temp_min_bin += "101";
  243.                 break;
  244.                
  245.                 case '6':
  246.                 temp_min_bin += "110";
  247.                 break;
  248.                
  249.                 case '7':
  250.                 temp_min_bin += "111";
  251.                 break;    
  252.             }
  253.         }
  254.        
  255.         while (temp_min_bin[1] == '0')
  256.         {
  257.             temp_min_bin.erase(1, 1);
  258.         }
  259.        
  260.         plik_out << endl << "Stacja nr 3: " << temp_min_bin;
  261.     }
  262.    
  263.     plik_in.close();
  264.     plik_out.close();
  265. }
  266.  
  267. int main()
  268. {
  269.     clear();
  270.    
  271.     zadanie_1(1);
  272.     zadanie_1(2);
  273.     zadanie_1(3);
  274.    
  275.     string stacja_1, stacja_2, stacja_3;
  276.    
  277.     stacja_1 = zadanie_2(1);
  278.     stacja_2 = zadanie_2(2);
  279.     stacja_3 = zadanie_2(3);
  280.    
  281.     zadanie_2_compare(stacja_1, stacja_2, stacja_3);
  282.    
  283.     return 0;
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement