Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.67 KB | None | 0 0
  1. Zadanie 1.
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.         fstream plik;
  11.         string lancuch;
  12.         plik.open("D:\\nazwa.txt", ios::out); // otwarcie pliku do zapisu
  13.  
  14.         do{
  15.                 cin >> lancuch; //odczyt znakow z klawiatury
  16.                 if(lancuch=="0") break;
  17.                 plik << lancuch <<" ";
  18.         }while(lancuch!="0");
  19.  
  20.         plik.close();
  21.         return 0;
  22. }
  23.  
  24.  
  25.  
  26. /------------------------------------------------------------
  27. Zadanie 2.
  28. #include <iostream>
  29. #include <fstream>
  30.  
  31. using namespace std;
  32.  
  33. struct TData{
  34.   int a;
  35. };
  36.  
  37. int main()
  38. {
  39. TData a;
  40. TData *b = &a;
  41.  
  42. cin>>(*b).a;
  43. cout<<a.a;
  44.     return 0;
  45. }
  46.  
  47. /------------------------------------------------------------
  48. Zadanie 3.
  49. #include <iostream>
  50.  
  51. using namespace std;
  52.  
  53. bool palindrom(string text)
  54. {
  55.  
  56.     for(int i=0;i<text.length();i++)
  57.     {
  58.         text[i]=tolower(text[i]);
  59.     }
  60.  
  61.     for(int i=0;i<text.length();i++)
  62.     {
  63.         if(text[i]!=text[text.length()-(i+1)])
  64.         {
  65.             return false;
  66.         }
  67.     }
  68.     return true;
  69. }
  70.  
  71.  
  72. int main()
  73. {
  74.     string lancuch;
  75.     cin>>lancuch;
  76.     if(palindrom(lancuch)) cout<<"Jest palindromem";
  77.     else cout<<"Nie jest palindromem";
  78.         return 0;
  79. }
  80. /------------------------------------------------------------
  81. Zadanie 4.
  82. #include <iostream>
  83. #include <fstream>
  84. #include <cstdlib>
  85.  
  86. using namespace std;
  87.  
  88. int main()
  89. {
  90.  
  91. fstream plik;
  92.  
  93.     string lancuch, tmp="", multi="";
  94.     plik.open("D:\\nazwa.txt", ios::in);
  95.  
  96. double suma=0, liczba=0;
  97. int z=0;
  98.  
  99. while (!plik.eof())
  100.     {
  101.         liczba=0;
  102.         tmp="";
  103.         getline(plik, lancuch);
  104.        
  105.         if((int)lancuch[0]>47 && (int)lancuch[0]<58)
  106.         {
  107.                 multi="";
  108.                 cout<<endl<<lancuch[0]<<" x ";
  109.                 multi=lancuch[0];
  110.                 liczba=atof(multi.c_str());
  111.         }
  112.        
  113.         for(int i=lancuch.length();i>0;i--)
  114.         {
  115.             if(lancuch[i]==' ')
  116.             {
  117.                 z=i;
  118.                 break;
  119.             }
  120.         }
  121.         for(int i=z+1;i<lancuch.length();i++)
  122.         {
  123.             tmp+=lancuch[i];
  124.         }
  125.        
  126.         if(liczba==0) suma+=atof(tmp.c_str());
  127.         else suma+=(atof(tmp.c_str())*liczba);
  128.        
  129.         cout<<tmp<<endl;
  130.     }
  131.  
  132. cout<<"Rachunek: "<< suma;
  133. plik.close();
  134. return 0;
  135. }
  136.  
  137. /------------------------------------------------------------
  138. Zadanie 5.
  139.  
  140. #include <iostream>
  141. #include <string>
  142. #include <fstream>
  143. #include <cstdio>
  144.  
  145. using namespace std;
  146.  
  147. int main()
  148. {
  149.     string linia;
  150.     fstream plik;
  151.     fstream plik2;
  152.  
  153.     plik.open( "D:\\nazwa.txt", ios::in );
  154.     plik2.open( "D:\\nazwa1.txt", ios::out | std::ios::out | ios::trunc );
  155.     string a;
  156.     string b;
  157.     cout << "Podaj szukany tekst: ";
  158.     cin >> a;
  159.     cout << "Zamien na: ";
  160.     cin >> b;
  161.     int n;
  162.     if( plik.good() == true and plik2.good() == true )
  163.     {
  164.         while( !plik.eof() )
  165.         {
  166.             getline( plik, linia );
  167.  
  168.             do{
  169.                 n = linia.find( a, 0 );
  170.                 if( n != - 1 )
  171.                 {
  172.                     linia.replace( n, a.size(), b );
  173.                 }
  174.  
  175.             }while (n!=-1);
  176.         plik2 << linia << endl;
  177.             cout << linia << endl;
  178.         }
  179.     }
  180.  
  181.    
  182.    
  183.    
  184.    
  185.    
  186.     plik.open( "D:\\nazwa.txt", ios::out );
  187.     while( !plik2.eof() )
  188.         {
  189.             getline( plik2, linia );
  190.  
  191.         plik << linia << endl;
  192.             cout << linia << endl;
  193.         }
  194.        
  195.     plik.close();
  196.     plik2.close();
  197.  
  198. system("del D:\\nazwa.txt");
  199. rename ("D:\\nazwa1.txt", "D:\\nazwa.txt");
  200.  
  201.     return 0;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement