Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JIIP KOLOSY.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
- //
- #include <iostream>
- #include<map>
- #include<string>
- #include<cmath>
- using namespace std;
- class M {
- protected:
- int rows, cols;
- double** a;
- public:
- M(int x, int y)
- {
- cols = x;
- rows = y;
- a = new double* [y];
- for (int i = 0; i < y; i++)
- {
- a[i] = new double[x];
- }
- }
- void Show() {
- for (int i = 0; i < cols; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- double* operator() (const M&,int x,int y) const
- {
- if (x > cols || y > rows) throw std::out_of_range(" X lub Y poza zakresem");
- else
- {
- return &a[x][y];
- }
- }
- ~M() {
- cout << "Destroyed like yo mama" << endl;
- };
- };
- class NamedM : public M
- {
- //protected:
- public:
- string name;
- NamedM(int x, int y, string xname) :name(xname), M(x, y) {};
- void namedShow()
- {
- cout << name << endl;
- Show();
- }
- };
- int main()
- {
- M janusz(4, 4);
- janusz.Show();
- try {
- cout << janusz(janusz, 3, 3) << endl;
- }
- catch (exception & e)
- {
- cout << "Wyjebalo bleda" << e.what() << endl;
- }
- NamedM janina(3, 3, "SZLAUF");
- janina.namedShow();
- //TO NIE DZIALA PRZE PANA
- /*
- M* z(4,3);
- if (NamedM* y = dynamic_cast<NamedM*>(z))
- {
- z->Show();
- }
- else {
- z->namedShow();
- }*/
- }
- /* MAPY
- map<int, string> name_map;
- name_map[1] = "Plusz";
- name_map[2] = "Lubi";
- name_map[3] = "Susz";
- name_map[4] = "kappa"
- name_map[4] = "Penis ?";
- cout << name_map[4] << endl;
- for (map<int, string>::iterator it = name_map.begin(); it != name_map.end(); it++)
- {
- cout << it->first << " => " << it->second << endl;
- }
- name_map.clear();
- name_map.insert(pair<int, string>(1, "KUPA"));
- cout << name_map[1] << endl;
- cout << name_map.size() << endl;
- name_map.insert(pair<int, string>(2, "KAL"));
- cout << name_map[2] << endl;
- cout << name_map.empty() << endl;
- name_map.clear();
- cout << name_map.empty() << endl;
- map<float, string> mapka;
- mapka[1.3]=("shiettt");
- cout << mapka[1.3] << endl;
- */
- /* TEMPLATES
- template<typename T>
- void Print(T value)
- {
- cout << value << endl;
- }
- Print(4);
- Print("HELLO");
- Print("kappa");
- Print<string>("KAPUCZINO");
- template<typename T, int N>
- class Array
- {
- private:
- T m_Array[N];
- public:
- int GetSize() const { return N; }
- };
- Array<int,5> array;
- cout << array.GetSize() << endl;
- */
- /* OPERATORS
- struct Vector2
- {
- float x, y;
- Vector2(float x, float y)
- : x(x), y(y) {}
- Vector2 Add(const Vector2& other) const
- {
- return Vector2(x + other.x, y + other.y);
- }
- Vector2 Multiply(const Vector2& other) const
- {
- return Vector2(x * other.x, y * other.y);
- }
- Vector2 operator+(const Vector2& other) const
- {
- return (Add(other));
- }
- Vector2 operator*(const Vector2& other) const
- {
- return (Multiply(other));
- }
- };
- ostream& operator <<(ostream& stream, const Vector2& other)
- {
- stream << other.x << ", " << other.y;
- return stream;
- }
- Vector2 position(3.0f, 2.0f);
- Vector2 speed(0.5f, 0.5f);
- Vector2 powerup(1.1f, 1.1f);
- Vector2 result1 = position.Add(speed.Multiply(powerup));
- Vector2 result = position + speed * powerup;
- cout << result.x << " " << result.y << endl;
- cout << result1.x << " " << result1.y << endl;
- cout << result << endl;
- cout << result1 << endl;
- */
- /* LAMBDA
- double x = 3;
- double y= [] (double x) {
- if (sin(x) > cos(x)) return sin(x);
- else return cos(x);
- }(x);
- cout << y << endl;
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement