Advertisement
Guest User

cycki

a guest
Feb 11th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <string>
  6. #include <ctime>
  7. #include <vector>
  8.  
  9. #include <thread>
  10.  
  11. using namespace std;
  12.  
  13.  
  14. vector <char> litery;
  15.  
  16. int b;
  17.  
  18.  
  19. void print() {
  20.     for(int i = 0; i < b; i++) {
  21.         cout << litery[i] << flush;
  22.     }
  23. }
  24.  
  25. void losuj() {
  26.     litery.clear();
  27.  
  28.     for(int i = 0; i < b; i++) {
  29.         litery.push_back(( char )(rand() % 24) + 65);
  30.  
  31.         int j =(rand() % 2);
  32.         if(j) {
  33.             litery[i] += 97 - 65 ;
  34.         }
  35.     }
  36. }
  37.  
  38. void ustalWartosc() {
  39.     cout << "Jak dlugi ma to byc wyraz??" << endl;
  40.     cin >> b;
  41. }
  42.  
  43. void losujWyraz() {
  44.     losuj();
  45.     print();
  46.     cout << endl;
  47. }
  48.  
  49. void zapiszWyraz() {
  50.     string nazwaPlikuWejsciowego;
  51.     string nazwaPlikuWyjsciowego;
  52.  
  53.     fstream plikWejsciowy;
  54.     fstream plikWyjsciowy;
  55.  
  56.     cout << "Podaj nazwe pliku, do ktorego mam zapisac dane: " << endl;
  57.     cin >> nazwaPlikuWyjsciowego;
  58.  
  59.     plikWyjsciowy.open(nazwaPlikuWyjsciowego.c_str(), ios::out, ios::app );
  60.  
  61.     for(int i = 0; i < litery.size(); i++) {
  62.         plikWyjsciowy << litery[i] << flush;
  63.     }
  64.  
  65.     plikWyjsciowy.close();
  66.  
  67. }
  68.  
  69. void wyswietlPlik() {
  70.     print();
  71.     this_thread::sleep_for(3s);
  72. }
  73.  
  74. void koniec() {
  75.     cin.get();
  76. }
  77.  
  78. void error() {
  79.     cout << "error" << flush;
  80.     cin.get();
  81. }
  82.  
  83.  
  84. void menu() {
  85.     int menu = 0;
  86.  
  87.     while(menu != 5) {
  88.         system("clear"); //dla windowsa cls
  89.  
  90.         cout << "Menu" << endl;
  91.         cout << "1-Ustal dlugosc" << endl;
  92.         cout << "2-Losuj wyraz" << endl;
  93.         cout << "3-Zapisz Wyraz" << endl;
  94.         cout << "4-Wyswietl plik" << endl;
  95.         cout << "5-Koniec" << endl;
  96.  
  97.  
  98.         cin >> menu;
  99.  
  100.         switch(menu) {
  101.             case 1:  ustalWartosc();   break;
  102.             case 2:  losujWyraz();     break;
  103.             case 3:  zapiszWyraz();    break;
  104.             case 4:  wyswietlPlik();   break;
  105.             case 5:  koniec();         break;
  106.             default: error();          break;
  107.         }
  108.     }
  109. }
  110.  
  111.  
  112. int main() {
  113.     srand( time( NULL ) );
  114.  
  115.     char tablicaCharow[100][100];
  116.  
  117.     menu();
  118.  
  119.     cin.get();
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement