mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-10-28 11:10:38 +01:00
bla bla
This commit is contained in:
48
uczelnia/2_semestr/programowanie/laby/lab9/zad2.cpp
Normal file
48
uczelnia/2_semestr/programowanie/laby/lab9/zad2.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
struct Student {
|
||||
std::string imie;
|
||||
std::string numerIndexu;
|
||||
Student(std::string imie, std::string numerIndexu)
|
||||
: imie(imie), numerIndexu(numerIndexu) {}
|
||||
Student() {}
|
||||
};
|
||||
|
||||
class Kurs {
|
||||
const int max_student = 30;
|
||||
int current_student = 0;
|
||||
Student *studenci;
|
||||
|
||||
public:
|
||||
Kurs() : studenci(new Student[max_student]) {}
|
||||
void zapiszStudenta(Student student) {
|
||||
if (current_student >= max_student) {
|
||||
throw std::range_error("You can't add more students!");
|
||||
}
|
||||
studenci[current_student++] = student;
|
||||
}
|
||||
|
||||
void wypiszStudentów() {
|
||||
for (int i = 0; i < current_student; i++) {
|
||||
std::cout << "=== Student ===\n";
|
||||
std::cout << "- Imię : " << studenci[i].imie << '\n';
|
||||
std::cout << "- Numer indeksu : " << studenci[i].numerIndexu << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Student bogdan = Student("Bogdan", "23894");
|
||||
Student stanislaw = Student("Stanisław", "238947");
|
||||
Kurs matematyka = Kurs();
|
||||
Kurs programowanie = Kurs();
|
||||
matematyka.zapiszStudenta(bogdan);
|
||||
matematyka.zapiszStudenta(stanislaw);
|
||||
programowanie.zapiszStudenta(bogdan);
|
||||
std::cout << "\nKurs matematyki:\n" << std::endl;
|
||||
matematyka.wypiszStudentów();
|
||||
std::cout << "\nKurs programowania:\n" << std::endl;
|
||||
programowanie.wypiszStudentów();
|
||||
}
|
||||
Reference in New Issue
Block a user