Advertisement
Guest User

Kolokwium 2

a guest
Jan 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. #define M 5
  9. #define N 5
  10. void wspak (char znaki[], int rozmiar)
  11. {
  12. cout << znaki[rozmiar-1];
  13. if (rozmiar>0) wspak(znaki, --rozmiar);
  14. }
  15.  
  16. void wypelnij (int A[M][N]) //W tej funkcji bóldupi o to, że M i N są ustalone
  17. { //mimo, że dokłądnie o to prosił
  18. int a, b;
  19. cout << "Podaj lewa granice - a: ";
  20. cin >> a;
  21. cout << "Podaj prawa granice - b: ";
  22. cin >> b;
  23.  
  24. for(int i = 0; i < M; i++)
  25. {
  26. for(int j = 0; j < N; j++)
  27. {
  28. A[i][j] = rand()%(b-a+1) + a;
  29. }
  30. }
  31. }
  32.  
  33.  
  34. void wyswietl(int A[M][N])
  35. {
  36. for(int i = 0; i < M; i++)
  37. {
  38. for(int j = 0; j < N; j++)
  39. {
  40. cout.width(7);
  41. cout << A[j][i] << " ";
  42. }
  43. cout << endl;
  44. }
  45. }
  46.  
  47.  
  48. struct Student
  49. {
  50. char nazwisko[20];
  51. int numer_indeksu;
  52. char kierunek[20];
  53. };
  54.  
  55.  
  56. void wczytaj(Student* student)
  57. {
  58. cout << "podaj nazwisko" << endl;
  59. cin >> student->nazwisko;
  60. cout << "podaj nr indeksu" << endl;
  61. cin >> student->numer_indeksu;
  62. char kierunek1[20];
  63. cout << "podaj kierunek" << endl;
  64. string s;
  65. cin.ignore();
  66. cin.getline(student->kierunek, 20);
  67. }
  68.  
  69. void wyswietlzapisz (Student studenci[4])
  70. {
  71. fstream plik;
  72. plik.open("/Users/Michal/Desktop/Michal Rytych/Praca2/Praca2/dane.txt", ios_base::out | ios_base::in | ios_base::app);
  73. for (int i = 0; i < 4; i++)
  74. {
  75. cout << "student: " << studenci[i].nazwisko << ", nr indeksu: " << studenci[i].numer_indeksu << " studiuje na kierunku: " << studenci[i].kierunek << endl;
  76. plik << "student: " << studenci[i].nazwisko << ", nr indeksu: " << studenci[i].numer_indeksu << " studiuje na kierunku: " << studenci[i].kierunek << endl;
  77. }
  78. plik.close();
  79. }
  80.  
  81.  
  82.  
  83. int main()
  84. {
  85. srand(0);
  86. cout << "Wyraz 'witam' wspak: "; //Tu ma problem z tym, że nie może sobie podać dowolnego wyrazu
  87. wspak("witam", 5); //mimo, że nie prosił o to wcale...
  88.  
  89. cout << endl;
  90. int A[M][N];
  91.  
  92. wypelnij(A);
  93. wyswietl(A);
  94.  
  95. Student studenci[4];
  96.  
  97. cout << endl;
  98.  
  99. wczytaj(&studenci[0]);
  100. wczytaj(&studenci[1]);
  101. wczytaj(&studenci[2]);
  102. wczytaj(&studenci[3]);
  103. wyswietlzapisz(studenci);
  104.  
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement