Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <cstdio>
- #include <string>
- #include <ctime>
- #include <vector>
- #include <thread>
- using namespace std;
- vector <char> litery;
- int b;
- void print() {
- for(int i = 0; i < b; i++) {
- cout << litery[i] << flush;
- }
- }
- void losuj() {
- litery.clear();
- for(int i = 0; i < b; i++) {
- litery.push_back(( char )(rand() % 24) + 65);
- int j =(rand() % 2);
- if(j) {
- litery[i] += 97 - 65 ;
- }
- }
- }
- void ustalWartosc() {
- cout << "Jak dlugi ma to byc wyraz??" << endl;
- cin >> b;
- }
- void losujWyraz() {
- losuj();
- print();
- cout << endl;
- }
- void zapiszWyraz() {
- string nazwaPlikuWejsciowego;
- string nazwaPlikuWyjsciowego;
- fstream plikWejsciowy;
- fstream plikWyjsciowy;
- cout << "Podaj nazwe pliku, do ktorego mam zapisac dane: " << endl;
- cin >> nazwaPlikuWyjsciowego;
- plikWyjsciowy.open(nazwaPlikuWyjsciowego.c_str(), ios::out, ios::app );
- for(int i = 0; i < litery.size(); i++) {
- plikWyjsciowy << litery[i] << flush;
- }
- plikWyjsciowy.close();
- }
- void wyswietlPlik() {
- print();
- this_thread::sleep_for(3s);
- }
- void koniec() {
- cin.get();
- }
- void error() {
- cout << "error" << flush;
- cin.get();
- }
- void menu() {
- int menu = 0;
- while(menu != 5) {
- system("clear"); //dla windowsa cls
- cout << "Menu" << endl;
- cout << "1-Ustal dlugosc" << endl;
- cout << "2-Losuj wyraz" << endl;
- cout << "3-Zapisz Wyraz" << endl;
- cout << "4-Wyswietl plik" << endl;
- cout << "5-Koniec" << endl;
- cin >> menu;
- switch(menu) {
- case 1: ustalWartosc(); break;
- case 2: losujWyraz(); break;
- case 3: zapiszWyraz(); break;
- case 4: wyswietlPlik(); break;
- case 5: koniec(); break;
- default: error(); break;
- }
- }
- }
- int main() {
- srand( time( NULL ) );
- char tablicaCharow[100][100];
- menu();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement