Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // labkiostatnie.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
- //
- #include <iostream>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <iomanip>
- #include <map>
- using namespace std;
- class Person {
- private:
- int pesel;
- string imie;
- string nazwisko;
- public:
- Person(int pesell = 0, string imiee = "null", string nazwiskoo = "null") : pesel(pesell), imie(imiee), nazwisko(nazwiskoo) {
- cout << "Test1";
- }
- virtual string tostring()
- {
- return (imie + " " + nazwisko + " Pesel:" + to_string(pesel) + "\n");
- }
- int get_pesel()
- {
- return pesel;
- }
- string get_imie()
- {
- return imie;
- }
- string get_nazwisko()
- {
- return nazwisko;
- }
- };
- class Student : public Person {
- private:
- int nr;
- string kierunek;
- public:
- Student(int pesell = 0, string imiee = "null", string nazwiskoo = "null", int nrr = 0, string kierunekk = "null") : Person(pesell, imiee, nazwiskoo), nr(nrr), kierunek(kierunekk){
- cout << "Test2";
- }
- string tostring()
- {
- return (get_imie() + " " + get_nazwisko() + " Pesel:" + to_string(get_pesel()) + " Nr indeksu:" + to_string(nr) + " Kierunek:" + kierunek + "\n");
- }
- };
- class InvalidValue {
- public:
- const char* what() {
- return "Value error";
- }
- };
- class InvalidIndex {
- public:
- const char* what() {
- return "Index error";
- }
- };
- class StaticArray {
- private:
- vector <int> values;
- public:
- StaticArray(vector <int> _values) : values(_values) {
- try {
- for (int i = 0; i < values.size(); i++)
- if(values[i] < 0)
- throw InvalidValue();
- }
- catch(InvalidValue &ex){
- cerr << ex.what() << endl;
- }
- };
- int at(int index)
- {
- try {
- if (index >= 16)
- {
- throw InvalidIndex();
- }
- return values[index];
- }
- catch (InvalidIndex &ex)
- {
- cerr << ex.what() << endl;
- }
- return 0;
- }
- };
- int main()
- {
- cout << "Hello World!\n";
- Person osoba1(1010, "Pawel", "Janecki");
- cout << "EMD";
- //cout << osoba1.tostring();
- Student osoba2(100, "Ania", "Kowalska", 300, "Informatyka");
- cout << "END2";
- //cout << osoba2.tostring();
- vector <Person*> dane;
- dane.push_back(&osoba1);
- dane.push_back(&osoba2);
- Student* osoba3 = new Student(1001, "Ania2", "Kowalsk2a", 300, "Informaty2ka");
- for (int i = 0; i < dane.size(); i++)
- {
- cout << 1;
- cout << dane[i]->tostring();
- }
- try {
- cout << "Throwing an integer exception...\n";
- throw 42;
- }
- catch (int i) {
- cout << " the integer exception was caught, with value: " << i << '\n';
- }
- try {
- cout << "Creating a vector of size 5... \n";
- vector<int> v(5);
- cout << "Accessing the 11th element of the vector...\n";
- cout << v.at(10); // vector::at() throws out_of_range
- }
- catch (const std::exception & e) { // caught by reference to base
- cout << " a standard exception was caught, with message '"
- << e.what() << "'\n";
- }
- double a, b, c;
- cout << "Podaj po spacji a b c " << endl;
- cin >> a >> b >> c;
- double delta = pow(b, 2) - 4 * a * c;
- try {
- if (delta < 0)
- {
- throw "Negative value, error";
- }
- double deltasqrt = sqrt(delta);
- double x1 = (-b - deltasqrt) / (2 * a);
- double x2 = (-b + deltasqrt) / (2 * a);
- cout << "x1 to " << x1 << " x2 to " << x2 << endl;
- }
- catch (const char *ex)
- {
- cout << ex << endl;
- }
- std::stringstream sstream;
- int d;
- cin >> d;
- sstream << std::hex << d;
- std::string result = sstream.str();
- cout << result;
- vector <int> Test1;
- for (int i = 0; i < 16; i++)
- {
- Test1.push_back(i - 100);
- }
- cout << "Test111" << endl;
- StaticArray Array1(Test1);
- cout << "Test222" << endl;
- cout << Array1.at(14)<< endl;
- string teststring = "asdd";
- map<char, int> test2;
- for (int i = 0; i < teststring.size(); i++)
- {
- test2[teststring[i]]++;
- }
- for (map<char, int>::iterator x = test2.begin(); x != test2.end(); ++x)
- {
- cout << x->first << " " << x->second << endl;
- }
- }
- // Uruchomienie programu: Ctrl + F5 lub menu Debugowanie > Uruchom bez debugowania
- // Debugowanie programu: F5 lub menu Debugowanie > Rozpocznij debugowanie
- // Porady dotyczące rozpoczynania pracy:
- // 1. Użyj okna Eksploratora rozwiązań, aby dodać pliki i zarządzać nimi
- // 2. Użyj okna programu Team Explorer, aby nawiązać połączenie z kontrolą źródła
- // 3. Użyj okna Dane wyjściowe, aby sprawdzić dane wyjściowe kompilacji i inne komunikaty
- // 4. Użyj okna Lista błędów, aby zobaczyć błędy
- // 5. Wybierz pozycję Projekt > Dodaj nowy element, aby utworzyć nowe pliki kodu, lub wybierz pozycję Projekt > Dodaj istniejący element, aby dodać istniejące pliku kodu do projektu
- // 6. Aby w przyszłości ponownie otworzyć ten projekt, przejdź do pozycji Plik > Otwórz > Projekt i wybierz plik sln
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement