diff --git a/Advanced-Cpp-Programming.vcxproj b/Advanced-Cpp-Programming.vcxproj index 76fb0dd..88a4c9d 100644 --- a/Advanced-Cpp-Programming.vcxproj +++ b/Advanced-Cpp-Programming.vcxproj @@ -128,13 +128,19 @@ + + + + + + - + diff --git a/Advanced-Cpp-Programming.vcxproj.filters b/Advanced-Cpp-Programming.vcxproj.filters index 4a5df29..6dfcd69 100644 --- a/Advanced-Cpp-Programming.vcxproj.filters +++ b/Advanced-Cpp-Programming.vcxproj.filters @@ -27,12 +27,30 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + Source Files - + Source Files diff --git a/Cpp'11 New features/Constructor-and-memoriy.cpp b/Cpp'11 New features/Constructor-and-memoriy.cpp new file mode 100644 index 0000000..8596309 --- /dev/null +++ b/Cpp'11 New features/Constructor-and-memoriy.cpp @@ -0,0 +1,83 @@ +// Learn Advance C++ Programming +// Constructors and Memory + +#include +#include +#include + +using namespace std; + +class Test { +private: + static const int SIZE = 100; + int* _pBuffer; + +public: + Test() { + cout << "Constructor" << endl; + _pBuffer = new int[SIZE] {}; // Setting all the bytes to 0 in the memory block + //memset(_pBuffer, 0, sizeof(int) * SIZE); // Setting all the bytes to 0 in the memory block using memset + + } + + Test(int i) { + cout << "Parameterized Constructor" << endl; + _pBuffer = new int[SIZE] {}; + + for (int i = 0; i < SIZE; i++) { + _pBuffer[i] = 7 * i; + } + + } + + Test(const Test& other) { + cout << "Copy Constructor" << endl; + + _pBuffer = new int[SIZE] {}; + + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + + } + + Test& operator=(const Test& other) { + cout << "Assignment" << endl; + + _pBuffer = new int[SIZE] {}; + + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + + return *this; + } + + ~Test() { + cout << "Destructor" << endl; + + delete [] _pBuffer; + + } + + friend ostream& operator<<(ostream& out, const Test& test); + +}; + +ostream& operator<<(ostream& out, const Test& test) { + out << "Hello from test" << endl; + return out; +} + +Test getTest() { + + return Test(); +} + +int main() { + + Test test1 = getTest(); + cout << test1 << endl; + + vector vec; + vec.push_back(Test()); + + return 0; +} + diff --git a/Cpp'11 New features/Dynamic-casts.cpp b/Cpp'11 New features/Dynamic-casts.cpp new file mode 100644 index 0000000..b002de4 --- /dev/null +++ b/Cpp'11 New features/Dynamic-casts.cpp @@ -0,0 +1,41 @@ +// Learn Advanced C++ Programming +// Dynamic Casts + +#include + +using namespace std; + +class Parent { + virtual void speak() { + cout << "parent!" << endl; + } +}; + +class Brother : public Parent { + +}; + +class Sister : public Parent { + +}; + + + +int main() { + + Parent parent; + Brother brother; + + Parent* pPBrother = &brother; + + Brother* pBBrother = dynamic_cast(pPBrother); + + if (pBBrother == nullptr) { + cout << "Invalid Cast" << endl; + } + else { + cout << pBBrother << endl; + } + return 0; +} + diff --git a/Cpp'11 New features/Elision-optimization.cpp b/Cpp'11 New features/Elision-optimization.cpp new file mode 100644 index 0000000..80458d2 --- /dev/null +++ b/Cpp'11 New features/Elision-optimization.cpp @@ -0,0 +1,55 @@ +// Learn Advance C++ programming +// Elision and Optimization + +#include +#include + +using namespace std; +class Test { +public: + Test() { + cout << "Constructor" << endl; + } + + Test(int i) { + cout << "Parameterized Constructor" << endl; + } + + Test(const Test& other) { + cout << "Copy constructor" << endl; + } + + Test& operator=(const Test& other) { + cout << "Assignment" << endl; + return *this; + } + + ~Test() { + cout << "destructor" << endl; + } + + friend ostream& operator<<(ostream& out, const Test& test); + +}; + + +ostream& operator<<(ostream& out, const Test& test) { + + out << "Hello" << endl; + return out; +} + +Test getTest() { + return Test(); +} + +int main() { + + Test test1 = getTest(); + + cout << test1 << endl; + + return 0; +} + + diff --git a/Cpp'11 New features/Move-assignment-operator.cpp b/Cpp'11 New features/Move-assignment-operator.cpp new file mode 100644 index 0000000..e9b8a29 --- /dev/null +++ b/Cpp'11 New features/Move-assignment-operator.cpp @@ -0,0 +1,83 @@ +// Learn Advanced C++ Programming +// Move Assignment Operator + +#include +#include + +using namespace std; + +class Test { +private: + static const int SIZE = 100; + int* _pBuffer{ nullptr }; + +public: + Test() { + _pBuffer = new int[SIZE] {}; + } + + Test(int i) { + _pBuffer = new int[SIZE] {}; + for (int i = 0; i < SIZE; i++) { + _pBuffer[i] = 7 * i; + } + } + + Test(const Test& other) { + _pBuffer = new int[SIZE] {}; + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + } + + + // Move Constructor + Test(Test&& other) { + cout << "Move Constructor" << endl; + _pBuffer = other._pBuffer; + other._pBuffer = nullptr; + } + + Test& operator=(const Test& other) { + _pBuffer = new int[SIZE] {}; + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + return *this; + } + + Test& operator=(Test&& other) { + cout << "Move Assignment operator" << endl; + delete[] _pBuffer; + _pBuffer = other._pBuffer; + other._pBuffer = nullptr; + + return *this; + } + + ~Test() { + delete[] _pBuffer; + } + + friend ostream& operator<<(ostream& out, const Test& test); +}; + +ostream& operator<<(ostream& out, const Test& test) { + out << "Hello from test"; + return out; +} + +Test getTest() { + return Test(); +} + +int main() { + vector vec; + vec.push_back(Test()); + + Test test; + + test = getTest(); + + + return 0; +} + + + diff --git a/Cpp'11 New features/Move-constructors.cpp b/Cpp'11 New features/Move-constructors.cpp new file mode 100644 index 0000000..f254910 --- /dev/null +++ b/Cpp'11 New features/Move-constructors.cpp @@ -0,0 +1,71 @@ +// Learn Advanced C++ Programming +// Move Constructors + +#include +#include + +using namespace std; + +class Test { +private: + static const int SIZE = 100; + int* _pBuffer{nullptr}; + +public: + Test() { + _pBuffer = new int[SIZE] {}; + } + + Test(int i) { + _pBuffer = new int[SIZE] {}; + for (int i = 0; i < SIZE; i++) { + _pBuffer[i] = 7 * i; + } + } + + Test(const Test& other) { + _pBuffer = new int[SIZE] {}; + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + } + + + // Move Constructor + Test(Test&& other) { + cout << "Move Constructor" << endl; + _pBuffer = other._pBuffer; + other._pBuffer = nullptr; + } + + Test& operator=(const Test& other) { + _pBuffer = new int[SIZE] {}; + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + return *this; + } + + ~Test() { + delete[] _pBuffer; + } + + friend ostream& operator<<(ostream& out, const Test& test); +}; + +ostream& operator<<(ostream& out, const Test& test) { + out << "Hello from test"; + return out; +} + +Test getTest() { + return Test(); +} + +int main() { + vector vec; + vec.push_back(Test()); + + + + return 0; +} + + + diff --git a/Cpp'11 New features/Reinterpret-cast.cpp b/Cpp'11 New features/Reinterpret-cast.cpp new file mode 100644 index 0000000..7cd0edc --- /dev/null +++ b/Cpp'11 New features/Reinterpret-cast.cpp @@ -0,0 +1,41 @@ +// Learn Advanced C++ Programming +// Reinterpret Casts + +#include + +using namespace std; + +class Parent { + virtual void speak() { + cout << "parent!" << endl; + } +}; + +class Brother : public Parent { + +}; + +class Sister : public Parent { + +}; + + + +int main() { + + Parent parent; + Brother brother; + Sister sister; + + Parent* pPBrother = &brother; + + Sister* pBBrother = reinterpret_cast(pPBrother); + + if (pBBrother == nullptr) { + cout << "Invalid Cast" << endl; + } + else { + cout << pBBrother << endl; + } + return 0; +} \ No newline at end of file diff --git a/Cpp'11 New features/Rvalues-Lvalues.cpp b/Cpp'11 New features/Rvalues-Lvalues.cpp new file mode 100644 index 0000000..6db1317 --- /dev/null +++ b/Cpp'11 New features/Rvalues-Lvalues.cpp @@ -0,0 +1,99 @@ +// Learn Advance C++ Programming +// Rvalues and Lvalues + +#include +#include +#include + +using namespace std; + +class Test { +private: + static const int SIZE = 100; + int* _pBuffer; + +public: + Test() { + cout << "Constructor" << endl; + _pBuffer = new int[SIZE] {}; // Setting all the bytes to 0 in the memory block + //memset(_pBuffer, 0, sizeof(int) * SIZE); // Setting all the bytes to 0 in the memory block using memset + + } + + Test(int i) { + cout << "Parameterized Constructor" << endl; + _pBuffer = new int[SIZE] {}; + + for (int i = 0; i < SIZE; i++) { + _pBuffer[i] = 7 * i; + } + + } + + Test(const Test& other) { + cout << "Copy Constructor" << endl; + + _pBuffer = new int[SIZE] {}; + + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + + } + + Test& operator=(const Test& other) { + cout << "Assignment" << endl; + + _pBuffer = new int[SIZE] {}; + + memcpy(_pBuffer, other._pBuffer, SIZE * sizeof(int)); + + return *this; + } + + ~Test() { + cout << "Destructor" << endl; + + delete[] _pBuffer; + + } + + friend ostream& operator<<(ostream& out, const Test& test); + +}; + +ostream& operator<<(ostream& out, const Test& test) { + out << "Hello from test" << endl; + return out; +} + +Test getTest() { + + return Test(); +} + +void check(const Test &value) { + cout << "lValue function" << endl; +} + +void check(Test&& value) { + cout << "rValue function" << endl; +} + +int main() { + + Test test1 = getTest(); + cout << test1 << endl; + + vector vec; + vec.push_back(Test()); + + Test& ltest1 = test1; + + Test&& rtest1 = getTest(); + + check(test1); + check(getTest()); + + + return 0; +} + diff --git a/Cpp'11 New features/Shared-pointers.cpp b/Cpp'11 New features/Shared-pointers.cpp new file mode 100644 index 0000000..12c2e72 --- /dev/null +++ b/Cpp'11 New features/Shared-pointers.cpp @@ -0,0 +1,38 @@ +// Learn Advanced C++ programming +// Shared Pointers + +#include +using namespace std; + + +class Test { +public: + Test() { + cout << "created" << endl; + } + + void greet() { + cout << "hello" << endl; + } + + ~Test() { + cout << "destroyed" << endl; + } + +}; + + +int main() { + + shared_ptr pTest2(nullptr); + + { + shared_ptr pTest1 = make_shared(); + pTest2 = pTest1; + } + + + cout << "Finished" << endl; + return 0; +} + diff --git a/Cpp'11 New features/Static-casts.cpp b/Cpp'11 New features/Static-casts.cpp new file mode 100644 index 0000000..dfd6c76 --- /dev/null +++ b/Cpp'11 New features/Static-casts.cpp @@ -0,0 +1,47 @@ +// Learn Advanced C++ Programming +// Static Casts + +#include + +using namespace std; + +class Parent { + +}; + +class Brother : public Parent { + +}; + +class Sister : public Parent { + +}; + + + +int main() { + + Parent parent; + Brother brother; + + Parent* pParent = &brother; // Works + + //Brother* pBrother = &parent // Does not work + + // How to make it work? + // Unsafe btw + Brother* pBrother = static_cast(&parent); + + Parent* pPBrother = &brother; + + Brother* pBBrother = static_cast(pPBrother); + + cout << pPBrother << endl; + + cout << pBrother << endl; + + Parent&& p = static_cast(parent); + + return 0; +} + diff --git a/Cpp'11 New features/bind.cpp b/Cpp'11 New features/bind.cpp new file mode 100644 index 0000000..6292e31 --- /dev/null +++ b/Cpp'11 New features/bind.cpp @@ -0,0 +1,30 @@ +// Learn Advanced C++ Programming +// Bind + +#include +#include + +using namespace std; +using namespace placeholders; + +int add(int a, int b, int c) { + cout << a << "," << b << "," << c << endl; + return a + b + c; +} + +void run(function func) { + func(7, 3); +} + +int main() { + + auto calci = bind(add, _2, 100, _1); + + cout << calci(10, 30) << endl; + + run(calci); + + return 0; +} + + diff --git a/Cpp'11 New features/perfect-forwarding.cpp b/Cpp'11 New features/perfect-forwarding.cpp new file mode 100644 index 0000000..7b3e850 --- /dev/null +++ b/Cpp'11 New features/perfect-forwarding.cpp @@ -0,0 +1,34 @@ +// Learn Advanced C++ Programming +// Perfect Forwarding + +#include + +using namespace std; + +class Test { + +}; + +template +void call(T&& arg) { + check(forward(arg)); +} + +void check(Test& test) { + cout << "lvalue" << endl; +} + +void check(Test&& test) { + cout << "rvalue" << endl; +} + + +int main() { + + Test test; + + check(test); + + return 0; +} + diff --git a/Cpp'11 New features/unique-pointers.cpp b/Cpp'11 New features/unique-pointers.cpp new file mode 100644 index 0000000..858232c --- /dev/null +++ b/Cpp'11 New features/unique-pointers.cpp @@ -0,0 +1,35 @@ +// Learn Advancec C++ programming +// Unique Pointers + +#include +#include +using namespace std; + +class Test { +public: + Test() { + cout << "created" << endl; + } + + void greet() { + cout << "Hello" << endl; + } + + ~Test() { + cout << "destroyed" << endl; + } + +}; + + +int main() { + + unique_ptr pTest(new Test); + + pTest->greet(); + + cout << "Finished" << endl; + + return 0; +} + diff --git a/Fractal Images/Bitmap.cpp b/Fractal Images/Bitmap.cpp new file mode 100644 index 0000000..b561ce0 --- /dev/null +++ b/Fractal Images/Bitmap.cpp @@ -0,0 +1,61 @@ +#include +#include "Bitmap.h" +#include "BitmapFileHeader.h" +#include "BitmapInfoHeader.h" + +using namespace fractal; +using namespace std; + +namespace fractal { + + Bitmap::Bitmap(int width, int height) : m_width(width), m_height(height), m_pPixels(new uint8_t[width * height * 3]{}) { + + } + + bool Bitmap::write(string filename) { + BitmapFileHeader fileheader; + BitmapInfoHeader infoheader; + + fileheader.fileSize = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + (m_width * m_height * 3); + fileheader.dataOffset = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader); + + infoheader.width = m_width; + infoheader.height = m_height; + + ofstream file; + + file.open(filename, ios::out | ios::binary); + + if (!file) { + return false; + } + + file.write((char*)&fileheader, sizeof(fileheader)); + file.write((char*)&infoheader, sizeof(infoheader)); + file.write((char*)m_pPixels.get(), m_width * m_height * 3); + + file.close(); + + if (!file) { + return false; + } + + return true; + } + void Bitmap::setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue) { + uint8_t* pPixel = m_pPixels.get(); + + pPixel += (y*3)*m_width+(x*3); + + pPixel[0] = blue; + pPixel[1] = green; + pPixel[2] = red; + + + } + + Bitmap:: ~Bitmap() { + + } + +} diff --git a/Fractal Images/Bitmap.h b/Fractal Images/Bitmap.h new file mode 100644 index 0000000..14b5138 --- /dev/null +++ b/Fractal Images/Bitmap.h @@ -0,0 +1,29 @@ +#pragma once + +#ifndef BITMAP_H_ +#define BITMAP_H_ + +#include +#include +#include + +using namespace std; + +namespace fractal { + + class Bitmap{ + private: + int m_width{0}; + int m_height{0}; + unique_ptr m_pPixels{nullptr}; + public: + Bitmap(int width, int height); + + bool write(string filename); + void setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue); + + virtual ~Bitmap(); + }; + +} +#endif /* BITMAP_H_ */ \ No newline at end of file diff --git a/Fractal Images/BitmapFileHeader.h b/Fractal Images/BitmapFileHeader.h new file mode 100644 index 0000000..2927ccf --- /dev/null +++ b/Fractal Images/BitmapFileHeader.h @@ -0,0 +1,20 @@ +#ifndef BITMAPFILEHEADER_H_ +#define BITMAPFILEHEADER_H_ + +#include + +using namespace std; + +#pragma pack(2) + +namespace fractal { + + struct BitmapFileHeader { + char header[2]{ 'B','M' }; + int32_t fileSize; + int32_t reserved{ 0 }; + int32_t dataOffset; + }; + +} +#endif /* BITMAPFILEHEADER_H_ */ diff --git a/Fractal Images/BitmapInfoHeader.h b/Fractal Images/BitmapInfoHeader.h new file mode 100644 index 0000000..1c0a0e2 --- /dev/null +++ b/Fractal Images/BitmapInfoHeader.h @@ -0,0 +1,27 @@ +#ifndef BITMAPINFOHEADER_H_ +#define BITMAPINFOHEADER_H_ + +#include + +using namespace std; + +#pragma pack(2) + +namespace fractal { + + struct BitmapInfoHeader { + int32_t headerSize{ 40 }; + int32_t width; + int32_t height; + int16_t planes{ 1 }; + int16_t bitsPerPixel{ 24 }; + int32_t compression{ 0 }; + int32_t dataSize{ 0 }; + int32_t horizontalResolution{ 2400 }; + int32_t vertialResolution{ 2400 }; + int32_t colors{ 0 }; + int32_t importantColors{ 0 }; + }; + +} +#endif /* BITMAPINFOHEADER_H_ */ \ No newline at end of file diff --git a/Fractal Images/Mandelbrot.cpp b/Fractal Images/Mandelbrot.cpp new file mode 100644 index 0000000..5833044 --- /dev/null +++ b/Fractal Images/Mandelbrot.cpp @@ -0,0 +1,40 @@ +#include +#include"Mandelbrot.h" + +using namespace std; + +namespace fractal{ + + Mandelbrot::Mandelbrot() { + + } + + Mandelbrot::~Mandelbrot() { + + } + + + int Mandelbrot::getIteration(double x, double y) { + + complex z = 0; + complex c(x, y); + + int iterations = 0; + + while (iterations < MAX_ITERATIONS) { + z = z * z + c; + + if (abs(z) > 2) { + break; + } + + iterations++; + + } + + return iterations; + } + +} + + diff --git a/Fractal Images/Mandelbrot.h b/Fractal Images/Mandelbrot.h new file mode 100644 index 0000000..60cc2e1 --- /dev/null +++ b/Fractal Images/Mandelbrot.h @@ -0,0 +1,21 @@ +#pragma once +#ifndef MANDELBROT_H_ +#define MANDELBROT_H_ + +namespace fractal { + + class Mandelbrot{ + public: + static const int MAX_ITERATIONS = 1000; + + public: + Mandelbrot(); + virtual ~Mandelbrot(); + + static int getIteration(double x, double y); + + }; + +} + +#endif /* MANDELBROT_H_ */ \ No newline at end of file diff --git a/Fractal Images/Zoom.h b/Fractal Images/Zoom.h new file mode 100644 index 0000000..a997eb9 --- /dev/null +++ b/Fractal Images/Zoom.h @@ -0,0 +1,18 @@ +#ifndef ZOOM_H_ +#define ZOOM_H_ + +namespace fractal { + + struct Zoom{ + int x{ 0 }; + int y{ 0 }; + double scale{ 0.0 }; + + Zoom(int x, int y, double scale) : x(x), y(y), scale(scale) {}; + + + }; + +} + +#endif /* ZOOM_H_ */ diff --git a/Fractal Images/ZoomList.cpp b/Fractal Images/ZoomList.cpp new file mode 100644 index 0000000..8681ca2 --- /dev/null +++ b/Fractal Images/ZoomList.cpp @@ -0,0 +1,33 @@ +#include +#include "ZoomList.h" + +using namespace std; + +namespace fractal { + + ZoomList::ZoomList(int width, int height) : m_width(width), m_height(height) { + + } + + void ZoomList::add(const Zoom& zoom) { + zooms.push_back(zoom); + + + m_xCenter += (zoom.x - m_width / 2) * m_scale; + m_yCenter += (zoom.y - m_height / 2) * m_scale; + + m_scale *= zoom.scale; + + cout << m_xCenter << ", " << m_yCenter << ", " << m_scale << endl; + } + + pair ZoomList::doZoom(int x, int y) { + + double xFractal = (x - m_width / 2) * m_scale + m_xCenter; + double yFractal = (y = m_height / 2) * m_scale + m_yCenter; + + return pair(xFractal, yFractal); + } + +} + diff --git a/Fractal Images/ZoomList.h b/Fractal Images/ZoomList.h new file mode 100644 index 0000000..11f4c94 --- /dev/null +++ b/Fractal Images/ZoomList.h @@ -0,0 +1,32 @@ +#pragma once + +#ifndef ZOOMLIST_H_ +#define ZOOMLIST_H_ + +#include +#include +#include"Zoom.h" + +using namespace std; + +namespace fractal { + + class ZoomList{ + private: + double m_xCenter{0}; + double m_yCenter{0}; + double m_scale{1.0}; + int m_width{0}; + int m_height{0}; + vector zooms; + + public: + ZoomList(int width, int height); + void add(const Zoom& zoom); + pair doZoom(int x, int y); + + }; + +} + +#endif \ No newline at end of file diff --git a/Fractal Images/main.cpp b/Fractal Images/main.cpp new file mode 100644 index 0000000..3fd7655 --- /dev/null +++ b/Fractal Images/main.cpp @@ -0,0 +1,94 @@ +// Learn Advanced C++ Programming +// Main + +#include +#include +#include +#include + +#include"Bitmap.h" +#include"Mandelbrot.h" +#include"Zoom.h" +#include "ZoomList.h" + +using namespace std; +using namespace fractal; + + + +int main() { + + int const WIDTH = 800; + int const HEIGHT = 600; + + Bitmap bitmap(WIDTH, HEIGHT); + + double min = 99999; + double max = -99999; + + ZoomList zoomList(WIDTH, HEIGHT); + + zoomList.add(Zoom(WIDTH/2, HEIGHT/2, 0.1/WIDTH)); + + unique_ptr histogram(new int[Mandelbrot::MAX_ITERATIONS]{0}); + unique_ptr fractal(new int[WIDTH * HEIGHT] {0}); + + + for (int y = 0; y < HEIGHT; y++) { + for (int x = 0; x < WIDTH; x++) { + pair coords = zoomList.doZoom(x, y); + + int iterations = Mandelbrot::getIteration(coords.first, coords.second); + + fractal[y * WIDTH + x] = iterations; + + if (iterations != Mandelbrot::MAX_ITERATIONS) { + + histogram[iterations]++; + } + + } + } + + int total = 0; + for (int i = 0; i < Mandelbrot::MAX_ITERATIONS; i++) { + total += histogram[i]; + } + + for (int y = 0; y < HEIGHT; y++) { + for (int x = 0; x < WIDTH; x++) { + + uint8_t red = 0; + uint8_t green = 0; + uint8_t blue = 0; + + int iterations = fractal[y * WIDTH + x]; + + if (iterations != Mandelbrot::MAX_ITERATIONS) { + + + + double hue = 0.0; + for (int i = 0; i <= iterations; i++) { + hue += ((double)histogram[i]) / total; + } + + green = pow(255, hue); + + } + + bitmap.setPixel(x, y, red, green, blue); + + + } + } + + + bitmap.write("test.bmp"); + + cout << "Finished" << endl; + + return 0; +} + + diff --git a/README.md b/README.md index 9e2dad4..97ce31d 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# Advanced-Cpp-Programming \ No newline at end of file +# Advanced-Cpp-Programming +![UC-81ec06fe-847b-4063-9d49-0e8469486514-Advanced-CPP-Programming](https://user-images.githubusercontent.com/106025754/207595955-8e01549f-6fa3-4014-8b6d-64acaba04cdc.jpg) diff --git a/Standard Template Library/MultiMaps.cpp b/Standard Template Library/MultiMaps.cpp index 460fc30..7144ddc 100644 --- a/Standard Template Library/MultiMaps.cpp +++ b/Standard Template Library/MultiMaps.cpp @@ -15,8 +15,7 @@ int main() { lookup.insert(make_pair(30, "Raj")); lookup.insert(make_pair(20, "Bob")); - // multimap stores values with the same key unlike normal map - // not storing same key values and over writing the string + // multimap stores values with the same key unlike normal map not storing same key values and over writing the string for (multimap::iterator it = lookup.begin(); it != lookup.end(); it++) { diff --git a/Standard Template Library/Stacks-and-queues.cpp b/Standard Template Library/Stacks-and-queues.cpp index 9de2d15..bdaeaaa 100644 --- a/Standard Template Library/Stacks-and-queues.cpp +++ b/Standard Template Library/Stacks-and-queues.cpp @@ -40,7 +40,7 @@ int main() { Test &test1 = testStack.top(); testStack.pop(); test1.print(); - Reference refers to destroy objects + Reference refers to destroyed objects */ while (testStack.size() > 0) { diff --git a/multiple-inheritance.cpp b/multiple-inheritance.cpp new file mode 100644 index 0000000..72d4cfc --- /dev/null +++ b/multiple-inheritance.cpp @@ -0,0 +1,39 @@ +// Learn Advanced C++ Programming +// Multiple Inheritance + +#include + +using namespace std; + + +class MusicalInstrument { +public: + virtual void play() { cout << "Playing instrument" << endl; } + virtual void reset() { cout << "Resetting the instrument" << endl; } + virtual ~MusicalInstrument() {}; +}; + +class Machine { +public: + virtual void start() { cout << "Starting the machine" << endl; } + virtual void reset() { cout << "Resetting the machine" << endl; } + virtual ~Machine() {}; +}; + +class Synthesizer : public Machine, public MusicalInstrument { +public: + virtual ~Synthesizer() {}; +}; + + +int main() { + Synthesizer* pSynth = new Synthesizer(); + + pSynth->play(); + pSynth->start(); + pSynth->MusicalInstrument::reset(); + + delete pSynth; + + return 0; +} \ No newline at end of file diff --git a/test.bmp b/test.bmp new file mode 100644 index 0000000..9e97e08 Binary files /dev/null and b/test.bmp differ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy