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++ 5.32 KB | None | 0 0
  1. zad 1.
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     string linia;
  12.     fstream plik;
  13.     fstream plik2;
  14.  
  15.     plik.open( "plik.txt", ios::in );
  16.     plik2.open( "plik2.txt", ios::out | ios::trunc );
  17.     string a;
  18.     string b;
  19.     cout << "Podaj szukany tekst: ";
  20.     cin >> a;
  21.     cout << "Zamien na: ";
  22.     cin >> b;
  23.     int n;
  24.     if( plik.good() == true and plik2.good() == true )
  25.     {
  26.         while( !plik.eof() )
  27.         {
  28.             getline( plik, linia );
  29.  
  30.             do{
  31.                 n = linia.find( a, 0 );
  32.                 if( n != - 1 )
  33.                 {
  34.                     linia.replace( n, a.size(), b );
  35.                 }
  36.  
  37.             }while (n!=-1);
  38.         plik2 << linia << endl;
  39.             cout << linia << endl;
  40.         }
  41.     }
  42.  
  43.     plik.close();
  44.     plik2.close();
  45.  
  46.     return 0;
  47. }
  48.  
  49. /----------------------------------------------------------------------------------/
  50.  
  51. zadanie 2.
  52.  
  53. #include <iostream>
  54. #include <fstream>
  55. #include <string>
  56.  
  57. using namespace std;
  58.  
  59. int main()
  60. {
  61.    
  62. string lancuch;
  63. int znaki[123];
  64.  
  65. for(int i = 0;i<123;i++ )
  66.     {
  67.         znaki[i]=0;
  68.     }
  69.  
  70. fstream plik;
  71.     plik.open("D:\\nazwa.txt", ios::in);
  72.  
  73.        
  74. while (!plik.eof())
  75.     {
  76.         getline(plik, lancuch);
  77.  
  78.         for(int i = 0; i < lancuch.length()+1;i++)
  79.         {  
  80.            
  81.             if((int)lancuch[i]>64 || (int)lancuch[i]<91)
  82.                 {
  83.                     ++znaki[(int)lancuch[i]];
  84.                 }
  85.            
  86.             else if((int)lancuch[i]>96 || (int)lancuch[i]<123)
  87.                 {
  88.                     ++znaki[(int)lancuch[i]];
  89.                 }
  90.            
  91.         }
  92.     }
  93.    
  94. plik.close();
  95.  
  96. cout<<"Male litery: "<<endl;
  97.  
  98. for(int i=96;i<123;i++)
  99.                 if(znaki[i]>0)
  100.                         cout<<(char)i<<" - "<<znaki[i]<<endl;
  101.  
  102. cout<<"Duze litery: "<<endl;
  103.  
  104. for(int i=65;i<91;i++)
  105.                 if(znaki[i]>0)
  106.                         cout<<(char)i<<" - "<<znaki[i]<<endl;
  107.  
  108. int suma=0;
  109. for(int i=65;i<123;i++)
  110. {
  111.     suma+=znaki[i];
  112. }
  113.  
  114. cout<<"\nSuma znakow: "<<suma<<endl;
  115.  
  116. //czestosc wystepowania danego znaku
  117.  
  118. cout<<"Male litery: "<<endl;
  119.  
  120. for(int i=96;i<123;i++)
  121.                 if(znaki[i]>0)
  122.                         cout<<(char)i<<" - "<<(double)(((double)znaki[i]*100)/(double)suma)<<"%"<<endl;
  123.  
  124. cout<<"Duze litery: "<<endl;
  125.  
  126. for(int i=65;i<91;i++)
  127.                 if(znaki[i]>0)
  128.                         cout<<(char)i<<" - "<<(double)(((double)znaki[i]*100)/(double)suma)<<"%"<<endl;
  129.  
  130. return 0;
  131. }
  132.  
  133. /-----------------------------------------------------------------------------------------------------------/
  134.  
  135. zadanie .3.
  136.  
  137. #include <iostream>
  138. #include <cstdlib>
  139.  
  140. using namespace std;
  141.  
  142. void policz(char tab[], int rozmiar)
  143. {
  144.     char tablica[rozmiar];
  145.     char uwaga[5]={'U','W','A','G','A'};
  146.     int ilosc=0;
  147.    
  148.     //liczenie znakow
  149.     for(int q=0;q<rozmiar-1;q++)
  150.     {
  151.         if(tab[q]!=NULL) ilosc++;  
  152.     }
  153.    
  154.     cout<<"Ilosc znakow: "<<ilosc<<endl;
  155.    
  156.    
  157.     //kopiowanie tablicy i dopisanie napisu "uwaga"
  158.     for(int i=0;i<rozmiar-1;i++)
  159.     {
  160.         tablica[i]=tab[i];
  161.         tab[i]=uwaga[i];   
  162.     }
  163.    
  164.    
  165.    
  166.     //przeniesienie znakow za napis "uwaga"
  167.     for(int i=0;i<rozmiar-1;i++)
  168.     {
  169.         tab[i+5]=tablica[i];
  170.        
  171.         if(ilosc+5>rozmiar)
  172.         {
  173.             for(int v = rozmiar-1 ; v>rozmiar-5 ; --v)
  174.             {
  175.                 tab[v]='.';
  176.             }
  177.            
  178.         }  
  179.     }
  180. }
  181.  
  182.  
  183. void display(char tab[], int rozmiar)
  184. {
  185.     //cout<<"Wyswietl tablice znakow: ";
  186.         for(int i=0;i<rozmiar-1;i++)
  187.         {
  188.             cout<<tab[i];
  189.         }
  190. cout<<endl;
  191. }
  192.  
  193. int main(int argc, char** argv) {
  194.    
  195.     int x = 6;
  196.        
  197.     char tab[x];
  198.     for(int i = 0; i < x-1 ; i++)
  199.     {
  200.             tab[i]=NULL;
  201.     }  
  202.     tab[0]='w';
  203.     tab[1]='i';
  204.     tab[2]='t';
  205.     tab[3]='a';
  206.     tab[4]='m';
  207.     tab[5]='y';
  208.    
  209.     cout<<"Tablica znakow na wejsciu"<<endl;
  210.     display(tab, x);
  211.     policz(tab, x);
  212.     cout<<"Tablica znakow na wyjsciu"<<endl;
  213.     display(tab, x);
  214.    
  215.     return 0;
  216. }
  217.  
  218. //-------------------------------------------------------------------------
  219.  
  220. Zadanie 4.
  221.  
  222. #include "stdio.h"
  223. #include <iostream>
  224.  
  225. using namespace std;
  226.  
  227. /* Pobierz wartosc A z tabeli lat */
  228. int tabA(int rok)
  229. {
  230. if (rok <= 1582)
  231. {
  232. return 15;
  233. }
  234. if (rok <= 1699)
  235. {
  236. return 22;
  237. }
  238. if (rok <= 1899)
  239. {
  240. return 23;
  241. }
  242. if (rok <= 2199)
  243. {
  244. return 24;
  245. }
  246. if (rok <= 2299)
  247. {
  248. return 25;
  249. }
  250. if (rok <= 2399)
  251. {
  252. return 26;
  253. }
  254. if (rok <= 2499)
  255. {
  256. return 25;
  257. }
  258. return 0; /* poza zakresem */
  259. }
  260.  
  261. /* Pobierz wartosc B z tabeli lat */
  262. int tabB(int rok)
  263. {
  264. if (rok <= 1582)
  265. {
  266. return 6;
  267. }
  268. if (rok <= 1699)
  269. {
  270. return 2;
  271. }
  272. if (rok <= 1799)
  273. {
  274. return 3;
  275. }
  276. if (rok <= 1899)
  277. {
  278. return 4;
  279. }
  280. if (rok <= 2099)
  281. {
  282. return 5;
  283. }
  284. if (rok <= 2199)
  285. {
  286. return 6;
  287. }
  288. if (rok <= 2299)
  289. {
  290. return 0;
  291. }
  292. if (rok <= 2499)
  293. {
  294. return 1;
  295. }
  296. return 0; /* poza zakresem */
  297. }
  298.  
  299. /* oblicz ile dni po 22 marca przypada wielkanoc */
  300. int wielkanoc(int rok)
  301. {
  302. int a, b, c, d, e;
  303.  
  304. a = rok % 19;
  305. b = rok % 4;
  306. c = rok % 7;
  307. d = (a*19 + tabA(rok)) % 30;
  308. e = (2*b + 4*c + 6*d + tabB(rok)) % 7;
  309. if ((d == 29 && e == 6) ||
  310. (d == 28 && e == 6))
  311. {
  312. d-=7;
  313. }
  314. return d+e;
  315. }
  316.  
  317. /* pobierz dane od uzytkownika */
  318. int main()
  319. {
  320. int rok, data;
  321.  
  322. cout<<"Podaj rok (33-2499)\n";
  323. cin>>rok;
  324.  
  325. if ((rok < 33) || (rok > 2499))
  326. {
  327. cout<<"Podany rok nie jest w zakresie 33-2499.\n";
  328. return 0;
  329. }
  330.  
  331. data = 22 + wielkanoc(rok);
  332. if (data > 31)
  333. {
  334. cout<<"Wielkanoc przypada "<< data%31 <<" kwietnia\n"<<endl;
  335. }
  336. else
  337. {
  338. cout<<"Wielkanoc przypada "<<data<<" marca\n"<<endl;
  339. }
  340.  
  341. return 0;
  342. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement