FilipKinderman

Zadania_Operacje

Apr 19th, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. Zadanie 1
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8. int main() //
  9. {
  10.     ofstream zapis_do_pliku("plik.txt");
  11.     srand( time ( NULL ) );
  12.     int i;
  13.     for (int i = 1; i<=10; i++)
  14.     {
  15.         zapis_do_pliku<<rand() % 30 + 1;
  16.     }
  17.  
  18.     return 0;
  19. }
  20. Zadanie 2
  21. #include <iostream>
  22. #include <fstream>
  23. using namespace std;
  24.  
  25.  string imie;
  26.  string miejscowosc;
  27.  int numer_telefonu;
  28.  int main()
  29.  {
  30.      ofstream operacje("operacje.txt", ios::app);
  31.  
  32.      cout <<"Wpisz imie"<<endl;
  33.      cin>> imie;
  34.      cout<< "Wpisz miejscowosc"<<endl;
  35.      cin>> miejscowosc;
  36.      cout<< "Wpisz numer telefonu"<<endl;
  37.      cin>> numer_telefonu;
  38.  
  39.      operacje<<imie<<endl;
  40.      operacje<<miejscowosc<<endl;
  41.      operacje<<numer_telefonu<<endl;
  42.  
  43.     return 0;
  44. }
  45. 3.)
  46.  
  47. #include <iostream>
  48. #include <fstream>
  49. #include <iomanip>
  50.  
  51. using namespace std;
  52.  
  53. int main() {
  54.  
  55.     ofstream zapis_do_pliku("dane.txt");
  56.     int tab[10][10];
  57.  
  58.     for (int i = 0; i < 10; i++) {
  59.  
  60.         for (int x = 0; x < 10; x++) {
  61.             tab[i][x] = (i + 1) * (x + 1);
  62.             zapis_do_pliku << setw(4) << tab[i][x] << " ";
  63.         }
  64.         zapis_do_pliku << endl;
  65.  
  66.  
  67.     }
  68.     return 0;
  69.  
  70. }
  71. Zadanie 5
  72. #include <iostream>
  73. #include <fstream>
  74.  
  75. using namespace std;
  76.  
  77. int main()
  78. {
  79.     int a =0;
  80.     string x;
  81.     ifstream wiersz ("wiersz.txt");
  82.     while(getline(wiersz,x))
  83.     {
  84.         if(a%2==0)
  85.         {
  86.             cout<<x<<endl;
  87.         }
  88.         a++;
  89.     }
  90.     return 0;
  91. }
  92.  
  93. Zadanie 6
  94. #include <iostream>
  95. #include <fstream>
  96.  
  97. using namespace std;
  98.  
  99. int main()
  100. {
  101.     int a =0;
  102.     string x;
  103.     ifstream wiersz ("wiersz.txt");
  104.     while(getline(wiersz,x))
  105.     {
  106.         if(a%3==0)
  107.         {
  108.             cout<<x<<endl;
  109.         }
  110.         a++;
  111.     }
  112.     return 0;
  113. }
  114.  
  115. Zad 7
  116. #include <iostream>
  117. #include <fstream>
  118. using namespace std;
  119. string x;
  120. int main()
  121. {
  122.     ofstream nazwa ("dane.txt");
  123.     if (!nazwa.is_open())
  124.     {
  125.         cout<<"Brak dostepu do pliku";
  126.     }
  127.     nazwa<<"Filip"<<endl;
  128.     nazwa<<"Kinderman"<<endl;
  129.     nazwa<<18<<endl;
  130.     ifstream nazwa1 ("dane.txt");
  131.     nazwa1.seekg(7,ios::beg);
  132.     while(getline(nazwa1,x))
  133.     {
  134.         cout<<x<<endl;
  135.     }
  136.  
  137.  
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment