Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <fstream>
- using namespace std;
- #define M 5
- #define N 5
- void wspak (char znaki[], int rozmiar)
- {
- cout << znaki[rozmiar-1];
- if (rozmiar>0) wspak(znaki, --rozmiar);
- }
- void wypelnij (int A[M][N]) //W tej funkcji bóldupi o to, że M i N są ustalone
- { //mimo, że dokłądnie o to prosił
- int a, b;
- cout << "Podaj lewa granice - a: ";
- cin >> a;
- cout << "Podaj prawa granice - b: ";
- cin >> b;
- for(int i = 0; i < M; i++)
- {
- for(int j = 0; j < N; j++)
- {
- A[i][j] = rand()%(b-a+1) + a;
- }
- }
- }
- void wyswietl(int A[M][N])
- {
- for(int i = 0; i < M; i++)
- {
- for(int j = 0; j < N; j++)
- {
- cout.width(7);
- cout << A[j][i] << " ";
- }
- cout << endl;
- }
- }
- struct Student
- {
- char nazwisko[20];
- int numer_indeksu;
- char kierunek[20];
- };
- void wczytaj(Student* student)
- {
- cout << "podaj nazwisko" << endl;
- cin >> student->nazwisko;
- cout << "podaj nr indeksu" << endl;
- cin >> student->numer_indeksu;
- char kierunek1[20];
- cout << "podaj kierunek" << endl;
- string s;
- cin.ignore();
- cin.getline(student->kierunek, 20);
- }
- void wyswietlzapisz (Student studenci[4])
- {
- fstream plik;
- plik.open("/Users/Michal/Desktop/Michal Rytych/Praca2/Praca2/dane.txt", ios_base::out | ios_base::in | ios_base::app);
- for (int i = 0; i < 4; i++)
- {
- cout << "student: " << studenci[i].nazwisko << ", nr indeksu: " << studenci[i].numer_indeksu << " studiuje na kierunku: " << studenci[i].kierunek << endl;
- plik << "student: " << studenci[i].nazwisko << ", nr indeksu: " << studenci[i].numer_indeksu << " studiuje na kierunku: " << studenci[i].kierunek << endl;
- }
- plik.close();
- }
- int main()
- {
- srand(0);
- cout << "Wyraz 'witam' wspak: "; //Tu ma problem z tym, że nie może sobie podać dowolnego wyrazu
- wspak("witam", 5); //mimo, że nie prosił o to wcale...
- cout << endl;
- int A[M][N];
- wypelnij(A);
- wyswietl(A);
- Student studenci[4];
- cout << endl;
- wczytaj(&studenci[0]);
- wczytaj(&studenci[1]);
- wczytaj(&studenci[2]);
- wczytaj(&studenci[3]);
- wyswietlzapisz(studenci);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement