├── .gitattributes ├── .gitignore ├── Chapter01 └── Chapter01 │ ├── Auto-deduction for class templates │ └── main.cpp │ ├── Braced initializer list │ └── main.cpp │ ├── Features │ └── main.cpp │ ├── Inline variables │ └── main.cpp │ ├── Simplified static_assert │ └── staticassert.cpp │ ├── local scoped variables │ └── main.cpp │ ├── stdinvoke method │ └── main.cpp │ └── structured binding │ └── main.cpp ├── Chapter02 └── STL │ ├── Array │ └── main.cpp │ ├── AssociativeContainers │ ├── Queue │ │ └── main.cpp │ ├── map │ │ └── main.cpp │ ├── multiset │ │ └── main.cpp │ ├── priorityqueue │ │ ├── .main.cpp.swp │ │ └── main.cpp │ ├── set │ │ └── main.cpp │ └── stack │ │ └── main.cpp │ ├── Deque │ └── main.cpp │ ├── Functors │ └── main.cpp │ ├── List │ └── main.cpp │ ├── SequentialContainers │ ├── array │ │ └── main.cpp │ ├── deque │ │ └── main.cpp │ └── forwardlist │ │ └── main.cpp │ ├── Vector │ ├── main.cpp │ └── main1.cpp │ ├── map │ └── main.cpp │ ├── multimap │ └── main.cpp │ ├── multiset │ └── main.cpp │ ├── priorityqueue │ └── main.cpp │ ├── queue │ └── main.cpp │ └── stack │ └── main.cpp ├── Chapter03 └── Templates │ ├── classtemplate │ ├── .main.cpp.swp │ ├── main.cpp │ └── myalgorithm.h │ ├── functiontemplate │ └── main.cpp │ ├── overloading │ └── main.cpp │ ├── partial_specialization │ ├── main.cpp │ └── partiallyspecialized.h │ └── specialization │ ├── dynamicarray.h │ ├── dynamicarrayforbool.h │ └── main.cpp ├── Chapter04 └── SmartPointers │ ├── autoptr │ └── main.cpp │ ├── rawpointer │ └── main.cpp │ ├── sharedptr │ ├── main.cpp │ ├── problem.cpp │ └── solution.cpp │ └── unique_ptr │ └── main.cpp ├── Chapter05 ├── Ex1 │ ├── .qmake.stash │ ├── Ex1.pro │ ├── Makefile │ └── main.cpp ├── Ex10 │ ├── .qmake.stash │ ├── Ex10.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp ├── Ex2 │ ├── .qmake.stash │ ├── Ex2.pro │ ├── Makefile │ └── main.cpp ├── Ex3 │ ├── .qmake.stash │ ├── Ex3.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp ├── Ex4 │ ├── .qmake.stash │ ├── Ex4.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp ├── Ex5 │ ├── .qmake.stash │ ├── Ex5.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp ├── Ex6 │ ├── .qmake.stash │ ├── Ex6.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp ├── Ex7 │ ├── .qmake.stash │ ├── Ex7.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp ├── Ex8 │ ├── .qmake.stash │ ├── Ex8.pro │ ├── Makefile │ ├── MyDlg.cpp │ ├── MyDlg.h │ └── main.cpp └── Ex9 │ ├── .qmake.stash │ ├── BoxDlg.cpp │ ├── BoxDlg.h │ ├── Ex9.pro │ ├── GridDlg.cpp │ ├── GridDlg.h │ ├── HBoxDlg.cpp │ ├── HBoxDlg.h │ ├── MainDlg.cpp │ ├── MainDlg.h │ ├── Makefile │ ├── VBoxDlg.cpp │ ├── VBoxDlg.h │ └── main.cpp ├── Chapter06 └── Multithreading │ ├── Ex1 │ └── main.cpp │ ├── Ex10 │ └── main.cpp │ ├── Ex11 │ └── main.cpp │ ├── Ex12 │ └── main.cpp │ ├── Ex13 │ └── main.cpp │ ├── Ex2 │ └── main.cpp │ ├── Ex3 │ ├── Thread.cpp │ ├── Thread.h │ └── main.cpp │ ├── Ex4 │ ├── Account.cpp │ ├── Account.h │ └── main.cpp │ ├── Ex5 │ ├── Account.cpp │ ├── Account.h │ └── main.cpp │ ├── Ex6 │ ├── Account.cpp │ ├── Account.h │ ├── Thread.cpp │ ├── Thread.h │ └── main.cpp │ ├── Ex7 │ ├── Thread.cpp │ ├── Thread.h │ └── main.cpp │ ├── Ex8 │ ├── Thread.cpp │ ├── Thread.h │ └── main.cpp │ └── Ex9 │ └── main.cpp ├── Chapter07 ├── Ex1.zip ├── Ex2.zip └── Ex3.zip ├── Chapter08 └── cucumber-cpp.zip ├── Chapter09 └── Chapter09 │ ├── Debugging application │ └── main.cpp │ ├── Detecting memory access outside the boundary of an array │ └── arrayboundsoverrun.cpp │ ├── Mismatched use of new and free or malloc and delete │ └── mismatchingnewandfree.cpp │ ├── already released memory locations │ └── main.cpp │ ├── memory leaks │ ├── list.cpp │ ├── list.h │ └── main.cpp │ └── uninitialized memory access │ └── main.cpp ├── Chapter10 └── OCP │ ├── .Item.h.swp │ ├── GSTVisitor.cpp │ ├── GSTVisitor.h │ ├── GSTVisitor.o │ ├── Item.cpp │ ├── Item.h │ ├── Item.o │ ├── Makefile │ ├── Visitable.h │ ├── Visitable.h.gch │ ├── Visitor.h │ ├── Visitor.h.gch │ ├── gst.exe │ ├── main.cpp │ └── main.o ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /Chapter01/Chapter01/Auto-deduction for class templates/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class MyClass { 6 | private: 7 | T1 t1; 8 | T2 t2; 9 | public: 10 | MyClass( T1 t1 = T1(), T2 t2 = T2() ) { } 11 | 12 | void printSizeOfDataTypes() { 13 | cout << "\nSize of t1 is " << sizeof ( t1 ) << " bytes." << endl; 14 | cout << "\nSize of t2 is " << sizeof ( t2 ) << " bytes." << endl; 15 | } 16 | }; 17 | 18 | int main ( ) { 19 | 20 | //Until C++14 21 | MyClass obj1; 22 | obj1.printSizeOfDataTypes( ); 23 | 24 | //New syntax in C++17 25 | MyClass obj2( 1, 10.56 ); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Chapter01/Chapter01/Braced initializer list/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | 9 | //Equivalent to std::initializer_list 10 | auto intInitializerValues = { 1, 2, 3, 4, 5 }; 11 | 12 | //Equivalent to std::initializer_list 13 | auto doubleInitializerValues = { 1.5, 2.5, 3.5 }; 14 | 15 | //Will not compile as it will be deduced to conflicting data types 16 | //while all data types should be same, in this case it is double, int and float 17 | //which will be deduced as double and int by the compiler, hence it won't compile 18 | //auto t = { 1.0, 1, 2.0f }; 19 | 20 | vector vectorOfIntegers = intInitializerValues; 21 | vector vectorOfDoubles = doubleInitializerValues; 22 | 23 | cout << "\nValues in integer vectors are ..." << endl; 24 | copy ( vectorOfIntegers.begin(), vectorOfIntegers.end(), ostream_iterator ( cout, "\t" ) ); 25 | cout << endl; 26 | 27 | cout << "\nValues in double vectors are ..." << endl; 28 | copy ( vectorOfDoubles.begin(), vectorOfDoubles.end(), ostream_iterator ( cout, "\t" ) ); 29 | cout << endl; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Chapter01/Chapter01/Features/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | namespace org { 5 | namespace tektutor { 6 | namespace application { 7 | namespace internals { 8 | int x; 9 | } 10 | } 11 | } 12 | } 13 | 14 | int main ( ) { 15 | org::tektutor::application::internals::x = 100; 16 | cout << "\nValue of x is " << org::tektutor::application::internals::x << endl; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Chapter01/Chapter01/Inline variables/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class MyClass { 5 | private: 6 | static inline int count = 0; 7 | public: 8 | MyClass() { 9 | ++count; 10 | } 11 | 12 | public: 13 | void printCount( ) { 14 | cout << "\nCount value is " << count << endl; 15 | } 16 | }; 17 | 18 | int main ( ) { 19 | 20 | MyClass obj; 21 | 22 | obj.printCount( ) ; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter01/Chapter01/Simplified static_assert/staticassert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main ( ) { 6 | 7 | const int x = 5, y = 5; 8 | 9 | static_assert ( 1 == 0, "Assertion failed" ); 10 | static_assert ( 1 == 0 ); 11 | static_assert ( x == y ); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Chapter01/Chapter01/local scoped variables/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isGoodToProceed( ) { 5 | return true; 6 | } 7 | 8 | bool isGood( ) { 9 | return true; 10 | } 11 | 12 | void functionWithSwitchStatement( ) { 13 | 14 | switch ( auto status = isGood( ) ) { 15 | case true: 16 | cout << "\nAll good!" << endl; 17 | break; 18 | 19 | case false: 20 | cout << "\nSomething gone bad" << endl; 21 | break; 22 | } 23 | 24 | } 25 | 26 | int main ( ) { 27 | 28 | if ( auto flag = isGoodToProceed( ) ) { 29 | cout << "flag is a local variable and it loses its scope outside the if block" << endl; 30 | } 31 | 32 | functionWithSwitchStatement(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Chapter01/Chapter01/stdinvoke method/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void globalFunction( ) { 6 | cout << "globalFunction ..." << endl; 7 | } 8 | 9 | class MyClass { 10 | public: 11 | void memberFunction ( int data ) { 12 | std::cout << "\nMyClass memberFunction ..." << std::endl; 13 | } 14 | 15 | static void staticFunction ( int data ) { 16 | std::cout << "MyClass staticFunction ..." << std::endl; 17 | } 18 | }; 19 | 20 | int main ( ) { 21 | 22 | MyClass obj; 23 | 24 | std::invoke ( &MyClass::memberFunction, obj, 100 ); 25 | std::invoke ( &MyClass::staticFunction, 200 ); 26 | std::invoke ( globalFunction ); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter01/Chapter01/structured binding/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main ( ) { 6 | 7 | tuple student("Sriram", 10); 8 | auto [name, age] = student; 9 | 10 | cout << "\nName of the student is " << name << endl; 11 | cout << "Age of the student is " << age << endl; 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Chapter02/STL/Array/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | int main () { 9 | array a = { 1, 5, 2, 4, 3 }; 10 | 11 | cout << "\nSize of array is " << a.size() << endl; 12 | 13 | auto pos = a.begin(); 14 | 15 | cout << endl; 16 | while ( pos != a.end() ) 17 | cout << *pos++ << "\t"; 18 | cout << endl; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/Queue/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | 9 | queue q; 10 | 11 | q.push ( 100 ); 12 | q.push ( 200 ); 13 | q.push ( 300 ); 14 | 15 | cout << "\nValues in Queue are ..." << endl; 16 | while ( ! q.empty() ) { 17 | cout << q.front() << endl; 18 | q.pop(); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/map/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | 9 | map contacts; 10 | 11 | contacts["Jegan"] = 123456789; 12 | contacts["Meena"] = 523456289; 13 | contacts["Nitesh"] = 623856729; 14 | contacts["Sriram"] = 993456789; 15 | 16 | auto pos = contacts.find( "Sriram" ); 17 | 18 | if ( pos != contacts.end() ) 19 | cout << pos->second << endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/multiset/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main( ) { 9 | 10 | multimap< string, long > contacts = { 11 | 12 | { "Jegan", 2232342343 }, 13 | { "Meena", 3243435343 }, 14 | { "Nitesh",6234324343 }, 15 | { "Sriram",8932443241 }, 16 | { "Nitesh",5534327346 } 17 | 18 | }; 19 | 20 | auto pos = contacts.find ( "Nitesh" ); 21 | int count = contacts.count( "Nitesh" ); 22 | int index = 0; 23 | 24 | while ( pos != contacts.end() ) { 25 | cout << "\nMobile number of " << pos->first << " is " << pos->second << endl; 26 | ++index; 27 | if ( index == count ) 28 | break; 29 | } 30 | 31 | cout << "--------------------------------------------------------------" << endl; 32 | 33 | pos = contacts.begin(); 34 | 35 | while ( pos != contacts.end() ) { 36 | cout << "\nMobile number of " << pos->first << " is " << pos->second << endl; 37 | ++pos; 38 | } 39 | 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/priorityqueue/.main.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter02/STL/AssociativeContainers/priorityqueue/.main.cpp.swp -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/priorityqueue/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | 9 | priority_queue q; 10 | 11 | q.push( 100 ); 12 | q.push( 50 ); 13 | q.push( 1000 ); 14 | q.push( 800 ); 15 | q.push( 300 ); 16 | 17 | cout << "Priority queue values are ..." << endl; 18 | while ( ! q.empty() ) { 19 | cout << q.top() << "\t"; 20 | q.pop(); 21 | } 22 | cout << endl; 23 | 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/set/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main( ) { 9 | set s1 = { 1, 3, 5, 7, 9 }; 10 | set s2 = { 2, 3, 7, 8, 10 }; 11 | 12 | vector v( s1.size() + s2.size() ); 13 | 14 | cout << "\nFirst set values are ..." << endl; 15 | copy ( s1.begin(), s1.end(), ostream_iterator ( cout, "\t" ) ); 16 | cout << endl; 17 | 18 | cout << "\nSecond set values are ..." << endl; 19 | copy ( s2.begin(), s2.end(), ostream_iterator ( cout, "\t" ) ); 20 | cout << endl; 21 | 22 | auto pos = set_difference ( s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin() ); 23 | v.resize ( pos - v.begin() ); 24 | 25 | cout << "\nValues present in set one but not in set two are ..." << endl; 26 | copy ( v.begin(), v.end(), ostream_iterator ( cout, "\t" ) ); 27 | cout << endl; 28 | 29 | v.clear(); 30 | 31 | v.resize ( s1.size() + s2.size() ); 32 | 33 | pos = set_union ( s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin() ); 34 | 35 | v.resize ( pos - v.begin() ); 36 | 37 | cout << "\nMerged set values in vector are ..." << endl; 38 | copy ( v.begin(), v.end(), ostream_iterator ( cout, "\t" ) ); 39 | cout << endl; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Chapter02/STL/AssociativeContainers/stack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | 9 | stack spoken_languages; 10 | 11 | spoken_languages.push ( "French" ); 12 | spoken_languages.push ( "German" ); 13 | spoken_languages.push ( "English" ); 14 | spoken_languages.push ( "Hindi" ); 15 | spoken_languages.push ( "Sanskrit" ); 16 | spoken_languages.push ( "Tamil" ); 17 | 18 | cout << "\nValues in Stack are ..." << endl; 19 | while ( ! spoken_languages.empty() ) { 20 | cout << spoken_languages.top() << endl; 21 | spoken_languages.pop(); 22 | } 23 | cout << endl; 24 | 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter02/STL/Deque/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | deque d = { 10, 20, 30, 40, 50 }; 9 | 10 | cout << "\nInitial size of deque is " << d.size() << endl; 11 | 12 | d.push_back( 60 ); 13 | d.push_front( 5 ); 14 | 15 | cout << "\nSize of deque after push back and front is " << d.size() << endl; 16 | 17 | copy ( d.begin(), d.end(), ostream_iterator( cout, "\t" ) ); 18 | d.clear(); 19 | 20 | cout << "\nSize of deque after clearing all values is " << d.size() << 21 | endl; 22 | 23 | cout << "\nIs the deque empty after clearing values ? " << ( d.empty() 24 | ? "true" : "false" ) << endl; 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Chapter02/STL/Functors/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Printer { 9 | public: 10 | void operator() ( const T& element ) { 11 | cout << element << "\t"; 12 | } 13 | }; 14 | 15 | int main () { 16 | vector v = { 10, 20, 30, 40, 50 }; 17 | 18 | cout << "\nPrint the vector entries using Functor" << endl; 19 | 20 | for_each ( v.begin(), v.end(), Printer() ); 21 | 22 | cout << endl; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter02/STL/List/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | 9 | list l; 10 | 11 | for (int count=0; count<5; ++count) 12 | l.push_back( (count+1) * 100 ); 13 | 14 | auto pos = l.begin(); 15 | 16 | cout << "\nPrint the list ..." << endl; 17 | while ( pos != l.end() ) 18 | cout << *pos++ << "-->"; 19 | cout << " X" << endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Chapter02/STL/SequentialContainers/array/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main ( ) { 9 | list l = { 100, 20, 5, 80, 50 }; 10 | 11 | cout << "\nPrint the list before sorting ..." << endl; 12 | copy ( l.begin(), l.end(), ostream_iterator(cout, "-->") ); 13 | cout << "X" << endl; 14 | 15 | l.sort(); 16 | 17 | cout << "\nPrint the list after sorting ..." << endl; 18 | copy ( l.begin(), l.end(), ostream_iterator(cout, "-->") ); 19 | cout << "X" << endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Chapter02/STL/SequentialContainers/deque/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | deque d = { 10, 20, 30, 40, 50 }; 9 | 10 | cout << "\nSize of deque is " << d.size() << endl; 11 | cout << "\nCapacity of deque is " << d.max_size() << endl; 12 | 13 | d.push_back( 60 ); 14 | cout << "\nSize of deque is " << d.size() << endl; 15 | cout << "\nCapacity of deque is " << d.max_size() << endl; 16 | 17 | d.push_front( 5 ); 18 | cout << "\nSize of deque is " << d.size() << endl; 19 | cout << "\nCapacity of deque is " << d.max_size() << endl; 20 | 21 | cout << "\nPrint the deque ..." << endl; 22 | copy ( d.begin(), d.end(), ostream_iterator( cout, "\t" ) ); 23 | cout << endl; 24 | 25 | d.clear(); 26 | cout << "\nIs the deque emtpty ? " << (d.empty() ? "true" : "false") << endl; 27 | cout << "\nSize of deque after clearing all values is " << d.size() << endl; 28 | 29 | cout << "\nPrint the deque ..." << endl; 30 | copy ( d.begin(), d.end(), ostream_iterator( cout, "\t" ) ); 31 | cout << endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter02/STL/SequentialContainers/forwardlist/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main ( ) { 8 | 9 | forward_list l = { 10, 10, 20, 30, 45, 45, 50 }; 10 | 11 | cout << "\nlist with all values ..." << endl; 12 | copy ( l.begin(), l.end(), ostream_iterator(cout, "\t") ); 13 | 14 | cout << "\nSize of list with duplicates is " << distance( l.begin(), l.end() ) << endl; 15 | 16 | l.unique(); 17 | 18 | cout << "\nSize of list without duplicates is " << distance( l.begin(), l.end() ) << endl; 19 | 20 | l.resize( distance( l.begin(), l.end() ) ); 21 | 22 | cout << "\nlist after removing duplicates ..." << endl; 23 | copy ( l.begin(), l.end(), ostream_iterator(cout, "\t") ); 24 | cout << endl; 25 | 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Chapter02/STL/Vector/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main () { 7 | vector v = { 1, 5, 2, 4, 3 }; 8 | 9 | cout << "\nSize of vector is " << v.size() << endl; 10 | 11 | auto pos = v.begin(); 12 | 13 | cout << "\nPrint vector elements before sorting" << endl; 14 | while ( pos != v.end() ) 15 | cout << *pos++ << "\t"; 16 | cout << endl; 17 | 18 | sort( v.begin(), v.end() ); 19 | 20 | pos = v.begin(); 21 | 22 | cout << "\nPrint vector elements after sorting" << endl; 23 | 24 | while ( pos != v.end() ) 25 | cout << *pos++ << "\t"; 26 | cout << endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter02/STL/Vector/main1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | vector v; 9 | cout << "\nType empty string to end the input once you are done feeding the vector" << endl; 10 | cout << "\nEnter some numbers to feed the vector ..." << endl; 11 | istream_iterator start_input(cin); 12 | istream_iterator end_input; 13 | 14 | copy ( start_input, end_input, back_inserter( v ) ); 15 | 16 | cout << "\nPrint the vector ..." << endl; 17 | copy ( v.begin(), v.end(), ostream_iterator(cout, "\t") ); 18 | cout << endl; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter02/STL/map/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | map< string, long > contacts; 9 | 10 | contacts[ "Jegan" ] = 1234567890; 11 | contacts[ "Meena" ] = 5784433221; 12 | contacts[ "Nitesh" ] = 4567891234; 13 | contacts[ "Sriram" ] = 8901122334; 14 | 15 | auto pos = contacts.find( "Sriram" ); 16 | 17 | if ( pos != contacts.end() ) 18 | cout << "\nMobile number of " << pos->first << " is " << 19 | pos->second << endl; 20 | else 21 | cout << "\nContact not found." << endl; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter02/STL/multimap/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() { 9 | multimap< string, long > contacts = { 10 | { "Jegan", 2232342343 }, 11 | { "Meena", 3243435343 }, 12 | { "Nitesh", 6234324343 }, 13 | { "Sriram", 8932443241 }, 14 | { "Nitesh", 5534327346 } 15 | }; 16 | 17 | auto pos = contacts.find ( "Nitesh" ); 18 | int count = contacts.count( "Nitesh" ); 19 | int index = 0; 20 | 21 | while ( pos != contacts.end() ) { 22 | cout << "\nMobile number of " << pos->first << " is " << 23 | pos->second << endl; 24 | ++index; 25 | if ( index == count ) 26 | break; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter02/STL/multiset/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | multiset s = { 10, 30, 10, 50, 70, 90 }; 9 | 10 | cout << "\nMultiset values are ..." << endl; 11 | 12 | copy ( s.begin(), s.end(), ostream_iterator ( cout, "\t" ) ); 13 | cout << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/STL/priorityqueue/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | priority_queue q; 9 | 10 | q.push( 100 ); 11 | q.push( 50 ); 12 | q.push( 1000 ); 13 | q.push( 800 ); 14 | q.push( 300 ); 15 | 16 | cout << "\nSequence in which value are inserted are ..." << endl; 17 | cout << "100\t50\t1000\t800\t300" << endl; 18 | cout << "Priority queue values are ..." << endl; 19 | 20 | while ( ! q.empty() ) { 21 | cout << q.top() << "\t"; 22 | q.pop(); 23 | } 24 | cout << endl; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter02/STL/queue/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | queue q; 9 | 10 | q.push ( 100 ); 11 | q.push ( 200 ); 12 | q.push ( 300 ); 13 | 14 | cout << "\nValues in Queue are ..." << endl; 15 | while ( ! q.empty() ) { 16 | cout << q.front() << endl; 17 | q.pop(); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter02/STL/stack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | stack spoken_languages; 9 | 10 | spoken_languages.push ( "French" ); 11 | spoken_languages.push ( "German" ); 12 | spoken_languages.push ( "English" ); 13 | spoken_languages.push ( "Hindi" ); 14 | spoken_languages.push ( "Sanskrit" ); 15 | spoken_languages.push ( "Telugu" ); 16 | spoken_languages.push ( "Kannada" ); 17 | spoken_languages.push ( "Tamil" ); 18 | 19 | cout << "\nValues in Stack are ..." << endl; 20 | while ( ! spoken_languages.empty() ) { 21 | cout << spoken_languages.top() << endl; 22 | spoken_languages.pop(); 23 | } 24 | cout << endl; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter03/Templates/classtemplate/.main.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter03/Templates/classtemplate/.main.cpp.swp -------------------------------------------------------------------------------- /Chapter03/Templates/classtemplate/main.cpp: -------------------------------------------------------------------------------- 1 | #include "myalgorithm.h" 2 | 3 | int main() { 4 | 5 | MyAlgorithm algorithm1; 6 | 7 | array a = { 10, 5, 15, 20, 25, 18, 1, 100, 90, 18 }; 8 | 9 | cout << "\nArray values before sorting ..." << endl; 10 | copy ( a.begin(), a.end(), ostream_iterator(cout, "\t") ); 11 | cout << endl; 12 | 13 | algorithm1.sort ( a ); 14 | 15 | cout << "\nArray values after sorting ..." << endl; 16 | copy ( a.begin(), a.end(), ostream_iterator(cout, "\t") ); 17 | cout << endl; 18 | 19 | MyAlgorithm algorithm2; 20 | double d[] = { 100.0, 20.5, 200.5, 300.8, 186.78, 1.1 }; 21 | 22 | cout << "\nArray values before sorting ..." << endl; 23 | copy ( d, d+6, ostream_iterator(cout, "\t") ); 24 | 25 | cout << endl; 26 | 27 | algorithm2.sort ( d ); 28 | 29 | cout << "\nArray values after sorting ..." << endl; 30 | copy ( d, d+6, ostream_iterator(cout, "\t") ); 31 | cout << endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter03/Templates/classtemplate/myalgorithm.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class MyAlgorithm { 9 | public: 10 | MyAlgorithm() { } 11 | ~MyAlgorithm() { } 12 | 13 | void sort( array &data ) { 14 | 15 | for ( int i=0; i 31 | inline void MyAlgorithm::sort ( T data[size] ) { 32 | 33 | for ( int i=0; i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | template 7 | void sort ( T input[] ) { 8 | 9 | for ( int i=0; i( cout, "\t" ) ); 24 | cout << endl; 25 | 26 | ::sort( a ); 27 | 28 | cout << "\nValues in the int array after sorting ..." << endl; 29 | copy ( a, a+10, ostream_iterator( cout, "\t" ) ); 30 | cout << endl; 31 | 32 | double b[5] = { 85.6d, 76.13d, 0.012d, 1.57d, 2.56d }; 33 | 34 | cout << "\nValues in the double array before sorting ..." << endl; 35 | copy ( b, b+5, ostream_iterator( cout, "\t" ) ); 36 | cout << endl; 37 | 38 | ::sort( b ); 39 | 40 | cout << "\nValues in the double array after sorting ..." << endl; 41 | copy ( b, b+5, ostream_iterator( cout, "\t" ) ); 42 | cout << endl; 43 | 44 | string names[6] = { 45 | "Rishi Kumar Sahay", 46 | "Arun KR", 47 | "Arun CR", 48 | "Ninad", 49 | "Pankaj", 50 | "Nikita" 51 | }; 52 | 53 | cout << "\nNames before sorting ..." << endl; 54 | copy ( names, names+6, ostream_iterator( cout, "\n" ) ); 55 | cout << endl; 56 | 57 | ::sort( names ); 58 | 59 | cout << "\nNames after sorting ..." << endl; 60 | copy ( names, names+6, ostream_iterator( cout, "\n" ) ); 61 | cout << endl; 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /Chapter03/Templates/overloading/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void sort ( array data ) { 6 | 7 | cout << "Non-template sort function invoked ..." << endl; 8 | 9 | int size = data.size(); 10 | 11 | for ( int i=0; i 22 | void sort ( array data ) { 23 | 24 | cout << "Template sort function invoked with one argument..." << endl; 25 | 26 | cout << "\nSize is " << size << endl; 27 | 28 | for ( int i=0; i 38 | void sort ( T data[], int size ) { 39 | 40 | cout << "Template sort function invoked with two argument..." << endl; 41 | 42 | for ( int i=0; i a = { 10, 50, 40, 30, 60, 20 }; 55 | ::sort ( a ); 56 | 57 | array b = { 10.6f, 57.9f, 80.7f, 35.1f, 69.3f, 20.0f }; 58 | ::sort( b ); 59 | 60 | array c = { 10.6d, 57.9d, 80.7d, 35.1d, 69.3d, 20.0d }; 61 | ::sort ( c ); 62 | 63 | double d[] = { 10.5d, 12.1d, 5.56d, 1.31d, 81.5d, 12.86d }; 64 | ::sort ( d, 6 ); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /Chapter03/Templates/partial_specialization/main.cpp: -------------------------------------------------------------------------------- 1 | #include "partiallyspecialized.h" 2 | 3 | int main ( ) { 4 | 5 | int x = 10; 6 | int *y = &x; 7 | int *z = &x; 8 | 9 | MyTemplateClass obj; 10 | 11 | obj.F1(x, y, z); 12 | obj.F2(x, x); 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Chapter03/Templates/partial_specialization/partiallyspecialized.h: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class MyTemplateClass { 6 | public: 7 | void F1( T1 t1, T2 t2, T3 t3 ) { 8 | cout << "\nPrimary Template Class - Function F1 invoked ..." << endl; 9 | 10 | cout << "Value of t1 is " << t1 << endl; 11 | cout << "Value of t2 is " << t2 << endl; 12 | cout << "Value of t3 is " << t3 << endl; 13 | } 14 | 15 | void F2(T1 t1, T2 t2) { 16 | cout << "\nPrimary Tempalte Class - Function F2 invoked ..." << endl; 17 | 18 | cout << "Value of t1 is " << t1 << endl; 19 | cout << "Value of t2 is " << 2 * t2 << endl; 20 | } 21 | }; 22 | 23 | template 24 | class MyTemplateClass< T1, T2*, T3*> : public MyTemplateClass { 25 | public: 26 | void F1( T1 t1, T2* t2, T3* t3 ) { 27 | cout << "\nPartially Specialized Template Classs - Function F1 invoked ..." << endl; 28 | cout << "Value of t1 is " << t1 << endl; 29 | cout << "Value of t2 is " << *t2 << endl; 30 | cout << "Value of t3 is " << *t3 << endl; 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /Chapter03/Templates/specialization/dynamicarray.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | template < class T > 8 | class DynamicArray { 9 | private: 10 | deque< T > dynamicArray; 11 | typename deque< T >::iterator pos; 12 | public: 13 | DynamicArray( ) { initialize(); } 14 | ~DynamicArray( ) { } 15 | 16 | void initialize( ) { 17 | pos = dynamicArray.begin(); 18 | } 19 | 20 | void appendValue( T element ) { 21 | dynamicArray.push_back ( element ); 22 | } 23 | 24 | bool hasNextValue( ) { 25 | return ( pos != dynamicArray.end() ); 26 | } 27 | 28 | T getValue( ) { 29 | return *pos++; 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter03/Templates/specialization/dynamicarrayforbool.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | template <> 8 | class DynamicArray { 9 | private: 10 | deque< bitset<8> *> dynamicArray; 11 | bitset<8> oneByte; 12 | typename deque * >::iterator pos; 13 | int bitSetIndex; 14 | 15 | int getDequeIndex ( ) { 16 | return (bitSetIndex) ? (bitSetIndex/8) : 0; 17 | } 18 | public: 19 | DynamicArray( ) { 20 | bitSetIndex = 0; 21 | initialize(); 22 | } 23 | ~DynamicArray( ) { } 24 | 25 | void initialize( ) { 26 | pos = dynamicArray.begin(); 27 | bitSetIndex = 0; 28 | } 29 | 30 | 31 | void appendValue( bool value) { 32 | 33 | int dequeIndex = getDequeIndex( ); 34 | 35 | bitset<8> *pBit = NULL; 36 | 37 | if ( ( dynamicArray.size() == 0 ) || ( dequeIndex >= ( dynamicArray.size()) ) ) { 38 | pBit = new bitset<8>(); 39 | pBit->reset(); 40 | dynamicArray.push_back ( pBit ); 41 | } 42 | 43 | if ( !dynamicArray.empty() ) 44 | pBit = dynamicArray.at( dequeIndex ); 45 | 46 | pBit->set( bitSetIndex % 8, value ); 47 | ++bitSetIndex; 48 | 49 | } 50 | 51 | bool hasNextValue( ) { 52 | return (bitSetIndex < (( dynamicArray.size() * 8 ) )); 53 | } 54 | 55 | bool getValue( ) { 56 | 57 | int dequeIndex = getDequeIndex(); 58 | bitset<8> *pBit = dynamicArray.at(dequeIndex); 59 | 60 | int index = bitSetIndex % 8; 61 | ++bitSetIndex; 62 | 63 | return (*pBit)[index] ? true : false; 64 | 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /Chapter03/Templates/specialization/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dynamicarray.h" 2 | #include "dynamicarrayforbool.h" 3 | 4 | int main ( ) { 5 | 6 | DynamicArray intArray; 7 | 8 | intArray.appendValue( 100 ); 9 | intArray.appendValue( 200 ); 10 | intArray.appendValue( 300 ); 11 | intArray.appendValue( 400 ); 12 | 13 | intArray.initialize(); 14 | 15 | cout << "\nInt DynamicArray values are ..." << endl; 16 | while ( intArray.hasNextValue() ) 17 | cout << intArray.getValue() << "\t"; 18 | cout << endl; 19 | 20 | DynamicArray charArray; 21 | 22 | charArray.appendValue( 'H' ); 23 | charArray.appendValue( 'e' ); 24 | charArray.appendValue( 'l' ); 25 | charArray.appendValue( 'l' ); 26 | charArray.appendValue( 'o' ); 27 | 28 | charArray.initialize(); 29 | 30 | cout << "\nChar DynamicArray values are ..." << endl; 31 | while ( charArray.hasNextValue() ) 32 | cout << charArray.getValue() << "\t"; 33 | cout << endl; 34 | 35 | DynamicArray boolArray; 36 | 37 | 38 | boolArray.appendValue ( true ); 39 | boolArray.appendValue ( false ); 40 | boolArray.appendValue ( true ); 41 | boolArray.appendValue ( false ); 42 | 43 | boolArray.appendValue ( true ); 44 | boolArray.appendValue ( false ); 45 | boolArray.appendValue ( true ); 46 | boolArray.appendValue ( false ); 47 | 48 | boolArray.appendValue ( true ); 49 | boolArray.appendValue ( true); 50 | boolArray.appendValue ( false); 51 | boolArray.appendValue ( false ); 52 | 53 | boolArray.appendValue ( true ); 54 | boolArray.appendValue ( true); 55 | boolArray.appendValue ( false); 56 | boolArray.appendValue ( false ); 57 | 58 | boolArray.initialize(); 59 | cout << "\nBool DynamicArray values are ..." << endl; 60 | while ( boolArray.hasNextValue() ) 61 | cout << boolArray.getValue() ; 62 | cout << endl; 63 | 64 | return 0; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Chapter04/SmartPointers/autoptr/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class MyClass { 8 | private: 9 | static int count; 10 | string name; 11 | public: 12 | MyClass() { 13 | ostringstream stringStream(ostringstream::ate); 14 | stringStream << "Object"; 15 | stringStream << ++count; 16 | 17 | name = stringStream.str(); 18 | 19 | cout << "\nMyClass Default constructor - " << name << endl; 20 | } 21 | 22 | ~MyClass() { 23 | cout << "\nMyClass destructor - " << name << endl; 24 | } 25 | 26 | MyClass ( const MyClass &objectBeingCopied ) { 27 | cout << "\nMyClass copy constructor" << endl; 28 | } 29 | 30 | MyClass& operator = ( const MyClass &objectBeingAssigned ) { 31 | cout << "\nMyClass assignment operator" << endl; 32 | } 33 | 34 | void sayHello() { 35 | cout << "Hello from MyClass " << name << endl; 36 | } 37 | 38 | }; 39 | 40 | int MyClass::count = 0; 41 | 42 | int main ( ) { 43 | 44 | auto_ptr ptr1( new MyClass() ); 45 | auto_ptr ptr2( new MyClass() ); 46 | 47 | ptr1->sayHello(); 48 | ptr2->sayHello(); 49 | 50 | //At this point the below stuffs happen 51 | //1. ptr2 smart pointer has given up ownership of MyClass Object 2 52 | //2. MyClass Object 2 will be destructed as ptr2 has given up its ownership on Object 2 53 | //3. Ownership of Object 1 will be transferred to ptr2 54 | ptr2 = ptr1; 55 | 56 | //The line below if uncommented will result in core dump as ptr1 has given up its ownership 57 | //on Object 1 and the ownership of Object 1 is transferred to ptr2. 58 | // ptr1->sayHello(); 59 | 60 | ptr2->sayHello(); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Chapter04/SmartPointers/rawpointer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class MyClass { 5 | public: 6 | void someMethod() { 7 | 8 | int *ptr = new int(); 9 | 10 | *ptr = 100; 11 | 12 | int result = *ptr / 0; 13 | 14 | delete ptr; 15 | 16 | } 17 | 18 | }; 19 | 20 | int main ( ) { 21 | 22 | MyClass objMyClass; 23 | 24 | objMyClass.someMethod(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/SmartPointers/sharedptr/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class MyClass { 8 | private: 9 | static int count; 10 | string name; 11 | public: 12 | MyClass() { 13 | ostringstream stringStream(ostringstream::ate); 14 | stringStream << "Object"; 15 | stringStream << ++count; 16 | 17 | name = stringStream.str(); 18 | 19 | cout << "\nMyClass Default constructor - " << name << endl; 20 | } 21 | 22 | ~MyClass() { 23 | cout << "\nMyClass destructor - " << name << endl; 24 | } 25 | 26 | MyClass ( const MyClass &objectBeingCopied ) { 27 | cout << "\nMyClass copy constructor" << endl; 28 | } 29 | 30 | MyClass& operator = ( const MyClass &objectBeingAssigned ) { 31 | cout << "\nMyClass assignment operator" << endl; 32 | } 33 | 34 | void sayHello() { 35 | cout << "Hello from MyClass " << name << endl; 36 | } 37 | 38 | }; 39 | 40 | int MyClass::count = 0; 41 | 42 | int main ( ) { 43 | 44 | shared_ptr ptr1( new MyClass() ); 45 | ptr1->sayHello(); 46 | cout << "\nUse count is " << ptr1.use_count() << endl; 47 | 48 | { 49 | shared_ptr ptr2( ptr1 ); 50 | ptr2->sayHello(); 51 | cout << "\nUse count is " << ptr2.use_count() << endl; 52 | } 53 | 54 | shared_ptr ptr3 = ptr1; 55 | ptr3->sayHello(); 56 | cout << "\nUse count is " << ptr3.use_count() << endl; 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Chapter04/SmartPointers/sharedptr/problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class C; 8 | 9 | class A { 10 | private: 11 | shared_ptr ptr; 12 | public: 13 | A() { 14 | cout << "\nA constructor" << endl; 15 | } 16 | 17 | ~A() { 18 | cout << "\nA destructor" << endl; 19 | } 20 | 21 | void setObject ( shared_ptr ptr ) { 22 | this->ptr = ptr; 23 | } 24 | }; 25 | 26 | class B { 27 | private: 28 | shared_ptr ptr; 29 | public: 30 | B() { 31 | cout << "\nB constructor" << endl; 32 | } 33 | 34 | ~B() { 35 | cout << "\nB destructor" << endl; 36 | } 37 | 38 | void setObject ( shared_ptr ptr ) { 39 | this->ptr = ptr; 40 | } 41 | }; 42 | 43 | class C { 44 | private: 45 | shared_ptr ptr1; 46 | shared_ptr ptr2; 47 | public: 48 | C(shared_ptr ptr1, shared_ptr ptr2) { 49 | cout << "\nC constructor" << endl; 50 | this->ptr1 = ptr1; 51 | this->ptr2 = ptr2; 52 | } 53 | 54 | ~C() { 55 | cout << "\nC destructor" << endl; 56 | } 57 | }; 58 | 59 | int main ( ) { 60 | 61 | shared_ptr a( new A() ); 62 | shared_ptr b( new B() ); 63 | shared_ptr c( new C( a, b ) ); 64 | 65 | a->setObject ( shared_ptr( c ) ); 66 | b->setObject ( shared_ptr( c ) ); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /Chapter04/SmartPointers/sharedptr/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class C; 8 | 9 | class A { 10 | private: 11 | weak_ptr ptr; 12 | public: 13 | A() { 14 | cout << "\nA constructor" << endl; 15 | } 16 | 17 | ~A() { 18 | cout << "\nA destructor" << endl; 19 | } 20 | 21 | void setObject ( weak_ptr ptr ) { 22 | this->ptr = ptr; 23 | } 24 | }; 25 | 26 | class B { 27 | private: 28 | weak_ptr ptr; 29 | public: 30 | B() { 31 | cout << "\nB constructor" << endl; 32 | } 33 | 34 | ~B() { 35 | cout << "\nB destructor" << endl; 36 | } 37 | 38 | void setObject ( weak_ptr ptr ) { 39 | this->ptr = ptr; 40 | } 41 | }; 42 | 43 | class C { 44 | private: 45 | shared_ptr ptr1; 46 | shared_ptr ptr2; 47 | public: 48 | C(shared_ptr ptr1, shared_ptr ptr2) { 49 | cout << "\nC constructor" << endl; 50 | this->ptr1 = ptr1; 51 | this->ptr2 = ptr2; 52 | } 53 | 54 | ~C() { 55 | cout << "\nC destructor" << endl; 56 | } 57 | }; 58 | 59 | int main ( ) { 60 | 61 | shared_ptr a( new A() ); 62 | shared_ptr b( new B() ); 63 | shared_ptr c( new C( a, b ) ); 64 | 65 | a->setObject ( weak_ptr( c ) ); 66 | b->setObject ( weak_ptr( c ) ); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /Chapter04/SmartPointers/unique_ptr/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class MyClass { 8 | private: 9 | static int count; 10 | string name; 11 | public: 12 | MyClass() { 13 | ostringstream stringStream(ostringstream::ate); 14 | stringStream << "Object"; 15 | stringStream << ++count; 16 | 17 | name = stringStream.str(); 18 | 19 | cout << "\nMyClass Default constructor - " << name << endl; 20 | } 21 | 22 | ~MyClass() { 23 | cout << "\nMyClass destructor - " << name << endl; 24 | } 25 | 26 | MyClass ( const MyClass &objectBeingCopied ) { 27 | cout << "\nMyClass copy constructor" << endl; 28 | } 29 | 30 | MyClass& operator = ( const MyClass &objectBeingAssigned ) { 31 | cout << "\nMyClass assignment operator" << endl; 32 | } 33 | 34 | void sayHello() { 35 | cout << "Hello from MyClass " << name << endl; 36 | } 37 | 38 | }; 39 | 40 | int MyClass::count = 0; 41 | 42 | int main ( ) { 43 | 44 | unique_ptr ptr1( new MyClass() ); 45 | unique_ptr ptr2( new MyClass() ); 46 | 47 | ptr1->sayHello(); 48 | ptr2->sayHello(); 49 | 50 | //At this point the below stuffs happen 51 | //1. ptr2 smart pointer has given up ownership of MyClass Object 2 52 | //2. MyClass Object 2 will be destructed as ptr2 has given up its ownership on Object 2 53 | //3. Ownership of Object 1 will be transferred to ptr2 54 | ptr2 = move(ptr1); 55 | 56 | //The line below if uncommented will result in core dump as ptr1 has given up its ownership 57 | //on Object 1 and the ownership of Object 1 is transferred to ptr2. 58 | ptr1->sayHello(); 59 | 60 | ptr2->sayHello(); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Chapter05/Ex1/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex1/Ex1.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Thu Oct 27 16:29:56 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex1 7 | INCLUDEPATH += . 8 | 9 | # Input 10 | SOURCES += main.cpp 11 | -------------------------------------------------------------------------------- /Chapter05/Ex1/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Makefile for building: Ex1 3 | # Generated by qmake (3.0) (Qt 5.7.0) 4 | # Project: Ex1.pro 5 | # Template: app 6 | # Command: /usr/bin/qmake -o Makefile Ex1.pro 7 | ############################################################################# 8 | 9 | MAKEFILE = Makefile 10 | 11 | ####### Compiler, tools and options 12 | 13 | CC = gcc 14 | CXX = g++ 15 | DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB 16 | CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES) 17 | CXXFLAGS = -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC $(DEFINES) 18 | INCPATH = -I. -I. -I../../../Qt5.7.0/5.7/gcc_64/include -I../../../Qt5.7.0/5.7/gcc_64/include/QtGui -I../../../Qt5.7.0/5.7/gcc_64/include/QtCore -I. -I../../../Qt5.7.0/5.7/gcc_64/mkspecs/linux-g++ 19 | QMAKE = /usr/bin/qmake 20 | DEL_FILE = rm -f 21 | CHK_DIR_EXISTS= test -d 22 | MKDIR = mkdir -p 23 | COPY = cp -f 24 | COPY_FILE = cp -f 25 | COPY_DIR = cp -f -R 26 | INSTALL_FILE = install -m 644 -p 27 | INSTALL_PROGRAM = install -m 755 -p 28 | INSTALL_DIR = cp -f -R 29 | DEL_FILE = rm -f 30 | SYMLINK = ln -f -s 31 | DEL_DIR = rmdir 32 | MOVE = mv -f 33 | TAR = tar -cf 34 | COMPRESS = gzip -9f 35 | DISTNAME = Ex11.0.0 36 | DISTDIR = /home/jegan/MasteringC++/Chapter5/Ex1/.tmp/Ex11.0.0 37 | LINK = g++ 38 | LFLAGS = -Wl,-O1 -Wl,-rpath,/home/jegan/Qt5.7.0/5.7/gcc_64/lib 39 | LIBS = $(SUBLIBS) -L/home/jegan/Qt5.7.0/5.7/gcc_64/lib -lQt5Gui -L/usr/lib64 -lQt5Core -lGL -lpthread 40 | AR = ar cqs 41 | RANLIB = 42 | SED = sed 43 | STRIP = strip 44 | 45 | ####### Output directory 46 | 47 | OBJECTS_DIR = ./ 48 | 49 | ####### Files 50 | 51 | SOURCES = main.cpp 52 | OBJECTS = main.o 53 | DIST = ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/spec_pre.prf \ 54 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/unix.conf \ 55 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/linux.conf \ 56 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/sanitize.conf \ 57 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/gcc-base.conf \ 58 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/gcc-base-unix.conf \ 59 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/g++-base.conf \ 60 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/g++-unix.conf \ 61 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/qconfig.pri \ 62 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dcore.pri \ 63 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dcore_private.pri \ 64 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dextras.pri \ 65 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dextras_private.pri \ 66 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dinput.pri \ 67 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dinput_private.pri \ 68 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dlogic.pri \ 69 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dlogic_private.pri \ 70 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquick.pri \ 71 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquick_private.pri \ 72 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickextras.pri \ 73 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickextras_private.pri \ 74 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickinput.pri \ 75 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickinput_private.pri \ 76 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickrender.pri \ 77 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickrender_private.pri \ 78 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3drender.pri \ 79 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3drender_private.pri \ 80 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bluetooth.pri \ 81 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bluetooth_private.pri \ 82 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bootstrap_private.pri \ 83 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_clucene_private.pri \ 84 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_concurrent.pri \ 85 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_concurrent_private.pri \ 86 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_core.pri \ 87 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_core_private.pri \ 88 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_dbus.pri \ 89 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_dbus_private.pri \ 90 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designer.pri \ 91 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designer_private.pri \ 92 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designercomponents_private.pri \ 93 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_eglfs_device_lib_private.pri \ 94 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gamepad.pri \ 95 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gamepad_private.pri \ 96 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gui.pri \ 97 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gui_private.pri \ 98 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_help.pri \ 99 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_help_private.pri \ 100 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_location.pri \ 101 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_location_private.pri \ 102 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimedia.pri \ 103 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimedia_private.pri \ 104 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimediawidgets.pri \ 105 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimediawidgets_private.pri \ 106 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_network.pri \ 107 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_network_private.pri \ 108 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_nfc.pri \ 109 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_nfc_private.pri \ 110 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_opengl.pri \ 111 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_opengl_private.pri \ 112 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_openglextensions.pri \ 113 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_openglextensions_private.pri \ 114 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_packetprotocol_private.pri \ 115 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_platformsupport_private.pri \ 116 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_positioning.pri \ 117 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_positioning_private.pri \ 118 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_printsupport.pri \ 119 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_printsupport_private.pri \ 120 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qml.pri \ 121 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qml_private.pri \ 122 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmldebug_private.pri \ 123 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmldevtools_private.pri \ 124 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmltest.pri \ 125 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmltest_private.pri \ 126 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qtmultimediaquicktools_private.pri \ 127 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quick.pri \ 128 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quick_private.pri \ 129 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickcontrols2.pri \ 130 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickcontrols2_private.pri \ 131 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickparticles_private.pri \ 132 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quicktemplates2_private.pri \ 133 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickwidgets.pri \ 134 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickwidgets_private.pri \ 135 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_script.pri \ 136 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_script_private.pri \ 137 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scripttools.pri \ 138 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scripttools_private.pri \ 139 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scxml.pri \ 140 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scxml_private.pri \ 141 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sensors.pri \ 142 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sensors_private.pri \ 143 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialbus.pri \ 144 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialbus_private.pri \ 145 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialport.pri \ 146 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialport_private.pri \ 147 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sql.pri \ 148 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sql_private.pri \ 149 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_svg.pri \ 150 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_svg_private.pri \ 151 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_testlib.pri \ 152 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_testlib_private.pri \ 153 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uiplugin.pri \ 154 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uitools.pri \ 155 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uitools_private.pri \ 156 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webchannel.pri \ 157 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webchannel_private.pri \ 158 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webengine.pri \ 159 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webengine_private.pri \ 160 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecore.pri \ 161 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecore_private.pri \ 162 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecoreheaders_private.pri \ 163 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginewidgets.pri \ 164 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginewidgets_private.pri \ 165 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_websockets.pri \ 166 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_websockets_private.pri \ 167 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webview.pri \ 168 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webview_private.pri \ 169 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_widgets.pri \ 170 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_widgets_private.pri \ 171 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_x11extras.pri \ 172 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_x11extras_private.pri \ 173 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xcb_qpa_lib_private.pri \ 174 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xml.pri \ 175 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xml_private.pri \ 176 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xmlpatterns.pri \ 177 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xmlpatterns_private.pri \ 178 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt_functions.prf \ 179 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt_config.prf \ 180 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/linux-g++/qmake.conf \ 181 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/spec_post.prf \ 182 | .qmake.stash \ 183 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/exclusive_builds.prf \ 184 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/default_pre.prf \ 185 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/resolve_config.prf \ 186 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/default_post.prf \ 187 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/warn_on.prf \ 188 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt.prf \ 189 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/resources.prf \ 190 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/moc.prf \ 191 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/unix/opengl.prf \ 192 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/unix/thread.prf \ 193 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/file_copies.prf \ 194 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/testcase_targets.prf \ 195 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/exceptions.prf \ 196 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/yacc.prf \ 197 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/lex.prf \ 198 | Ex1.pro main.cpp 199 | QMAKE_TARGET = Ex1 200 | DESTDIR = 201 | TARGET = Ex1 202 | 203 | 204 | first: all 205 | ####### Build rules 206 | 207 | $(TARGET): $(OBJECTS) 208 | $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) 209 | 210 | Makefile: Ex1.pro ../../../Qt5.7.0/5.7/gcc_64/mkspecs/linux-g++/qmake.conf ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/spec_pre.prf \ 211 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/unix.conf \ 212 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/linux.conf \ 213 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/sanitize.conf \ 214 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/gcc-base.conf \ 215 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/gcc-base-unix.conf \ 216 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/g++-base.conf \ 217 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/g++-unix.conf \ 218 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/qconfig.pri \ 219 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dcore.pri \ 220 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dcore_private.pri \ 221 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dextras.pri \ 222 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dextras_private.pri \ 223 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dinput.pri \ 224 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dinput_private.pri \ 225 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dlogic.pri \ 226 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dlogic_private.pri \ 227 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquick.pri \ 228 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquick_private.pri \ 229 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickextras.pri \ 230 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickextras_private.pri \ 231 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickinput.pri \ 232 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickinput_private.pri \ 233 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickrender.pri \ 234 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickrender_private.pri \ 235 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3drender.pri \ 236 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3drender_private.pri \ 237 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bluetooth.pri \ 238 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bluetooth_private.pri \ 239 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bootstrap_private.pri \ 240 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_clucene_private.pri \ 241 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_concurrent.pri \ 242 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_concurrent_private.pri \ 243 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_core.pri \ 244 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_core_private.pri \ 245 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_dbus.pri \ 246 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_dbus_private.pri \ 247 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designer.pri \ 248 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designer_private.pri \ 249 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designercomponents_private.pri \ 250 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_eglfs_device_lib_private.pri \ 251 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gamepad.pri \ 252 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gamepad_private.pri \ 253 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gui.pri \ 254 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gui_private.pri \ 255 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_help.pri \ 256 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_help_private.pri \ 257 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_location.pri \ 258 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_location_private.pri \ 259 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimedia.pri \ 260 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimedia_private.pri \ 261 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimediawidgets.pri \ 262 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimediawidgets_private.pri \ 263 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_network.pri \ 264 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_network_private.pri \ 265 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_nfc.pri \ 266 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_nfc_private.pri \ 267 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_opengl.pri \ 268 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_opengl_private.pri \ 269 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_openglextensions.pri \ 270 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_openglextensions_private.pri \ 271 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_packetprotocol_private.pri \ 272 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_platformsupport_private.pri \ 273 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_positioning.pri \ 274 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_positioning_private.pri \ 275 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_printsupport.pri \ 276 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_printsupport_private.pri \ 277 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qml.pri \ 278 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qml_private.pri \ 279 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmldebug_private.pri \ 280 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmldevtools_private.pri \ 281 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmltest.pri \ 282 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmltest_private.pri \ 283 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qtmultimediaquicktools_private.pri \ 284 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quick.pri \ 285 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quick_private.pri \ 286 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickcontrols2.pri \ 287 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickcontrols2_private.pri \ 288 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickparticles_private.pri \ 289 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quicktemplates2_private.pri \ 290 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickwidgets.pri \ 291 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickwidgets_private.pri \ 292 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_script.pri \ 293 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_script_private.pri \ 294 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scripttools.pri \ 295 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scripttools_private.pri \ 296 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scxml.pri \ 297 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scxml_private.pri \ 298 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sensors.pri \ 299 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sensors_private.pri \ 300 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialbus.pri \ 301 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialbus_private.pri \ 302 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialport.pri \ 303 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialport_private.pri \ 304 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sql.pri \ 305 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sql_private.pri \ 306 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_svg.pri \ 307 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_svg_private.pri \ 308 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_testlib.pri \ 309 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_testlib_private.pri \ 310 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uiplugin.pri \ 311 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uitools.pri \ 312 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uitools_private.pri \ 313 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webchannel.pri \ 314 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webchannel_private.pri \ 315 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webengine.pri \ 316 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webengine_private.pri \ 317 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecore.pri \ 318 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecore_private.pri \ 319 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecoreheaders_private.pri \ 320 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginewidgets.pri \ 321 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginewidgets_private.pri \ 322 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_websockets.pri \ 323 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_websockets_private.pri \ 324 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webview.pri \ 325 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webview_private.pri \ 326 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_widgets.pri \ 327 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_widgets_private.pri \ 328 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_x11extras.pri \ 329 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_x11extras_private.pri \ 330 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xcb_qpa_lib_private.pri \ 331 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xml.pri \ 332 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xml_private.pri \ 333 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xmlpatterns.pri \ 334 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xmlpatterns_private.pri \ 335 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt_functions.prf \ 336 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt_config.prf \ 337 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/linux-g++/qmake.conf \ 338 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/spec_post.prf \ 339 | .qmake.stash \ 340 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/exclusive_builds.prf \ 341 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/default_pre.prf \ 342 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/resolve_config.prf \ 343 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/default_post.prf \ 344 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/warn_on.prf \ 345 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt.prf \ 346 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/resources.prf \ 347 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/moc.prf \ 348 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/unix/opengl.prf \ 349 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/unix/thread.prf \ 350 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/file_copies.prf \ 351 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/testcase_targets.prf \ 352 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/exceptions.prf \ 353 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/yacc.prf \ 354 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/lex.prf \ 355 | Ex1.pro \ 356 | ../../../Qt5.7.0/5.7/gcc_64/lib/libQt5Gui.prl \ 357 | ../../../Qt5.7.0/5.7/gcc_64/lib/libQt5Core.prl 358 | $(QMAKE) -o Makefile Ex1.pro 359 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/spec_pre.prf: 360 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/unix.conf: 361 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/linux.conf: 362 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/sanitize.conf: 363 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/gcc-base.conf: 364 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/gcc-base-unix.conf: 365 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/g++-base.conf: 366 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/common/g++-unix.conf: 367 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/qconfig.pri: 368 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dcore.pri: 369 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dcore_private.pri: 370 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dextras.pri: 371 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dextras_private.pri: 372 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dinput.pri: 373 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dinput_private.pri: 374 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dlogic.pri: 375 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dlogic_private.pri: 376 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquick.pri: 377 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquick_private.pri: 378 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickextras.pri: 379 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickextras_private.pri: 380 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickinput.pri: 381 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickinput_private.pri: 382 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickrender.pri: 383 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3dquickrender_private.pri: 384 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3drender.pri: 385 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_3drender_private.pri: 386 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bluetooth.pri: 387 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bluetooth_private.pri: 388 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_bootstrap_private.pri: 389 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_clucene_private.pri: 390 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_concurrent.pri: 391 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_concurrent_private.pri: 392 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_core.pri: 393 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_core_private.pri: 394 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_dbus.pri: 395 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_dbus_private.pri: 396 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designer.pri: 397 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designer_private.pri: 398 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_designercomponents_private.pri: 399 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_eglfs_device_lib_private.pri: 400 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gamepad.pri: 401 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gamepad_private.pri: 402 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gui.pri: 403 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_gui_private.pri: 404 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_help.pri: 405 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_help_private.pri: 406 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_location.pri: 407 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_location_private.pri: 408 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimedia.pri: 409 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimedia_private.pri: 410 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimediawidgets.pri: 411 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_multimediawidgets_private.pri: 412 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_network.pri: 413 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_network_private.pri: 414 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_nfc.pri: 415 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_nfc_private.pri: 416 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_opengl.pri: 417 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_opengl_private.pri: 418 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_openglextensions.pri: 419 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_openglextensions_private.pri: 420 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_packetprotocol_private.pri: 421 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_platformsupport_private.pri: 422 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_positioning.pri: 423 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_positioning_private.pri: 424 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_printsupport.pri: 425 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_printsupport_private.pri: 426 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qml.pri: 427 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qml_private.pri: 428 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmldebug_private.pri: 429 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmldevtools_private.pri: 430 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmltest.pri: 431 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qmltest_private.pri: 432 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_qtmultimediaquicktools_private.pri: 433 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quick.pri: 434 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quick_private.pri: 435 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickcontrols2.pri: 436 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickcontrols2_private.pri: 437 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickparticles_private.pri: 438 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quicktemplates2_private.pri: 439 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickwidgets.pri: 440 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_quickwidgets_private.pri: 441 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_script.pri: 442 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_script_private.pri: 443 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scripttools.pri: 444 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scripttools_private.pri: 445 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scxml.pri: 446 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_scxml_private.pri: 447 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sensors.pri: 448 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sensors_private.pri: 449 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialbus.pri: 450 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialbus_private.pri: 451 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialport.pri: 452 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_serialport_private.pri: 453 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sql.pri: 454 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_sql_private.pri: 455 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_svg.pri: 456 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_svg_private.pri: 457 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_testlib.pri: 458 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_testlib_private.pri: 459 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uiplugin.pri: 460 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uitools.pri: 461 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_uitools_private.pri: 462 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webchannel.pri: 463 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webchannel_private.pri: 464 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webengine.pri: 465 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webengine_private.pri: 466 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecore.pri: 467 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecore_private.pri: 468 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginecoreheaders_private.pri: 469 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginewidgets.pri: 470 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webenginewidgets_private.pri: 471 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_websockets.pri: 472 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_websockets_private.pri: 473 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webview.pri: 474 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_webview_private.pri: 475 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_widgets.pri: 476 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_widgets_private.pri: 477 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_x11extras.pri: 478 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_x11extras_private.pri: 479 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xcb_qpa_lib_private.pri: 480 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xml.pri: 481 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xml_private.pri: 482 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xmlpatterns.pri: 483 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/modules/qt_lib_xmlpatterns_private.pri: 484 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt_functions.prf: 485 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt_config.prf: 486 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/linux-g++/qmake.conf: 487 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/spec_post.prf: 488 | .qmake.stash: 489 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/exclusive_builds.prf: 490 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/default_pre.prf: 491 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/resolve_config.prf: 492 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/default_post.prf: 493 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/warn_on.prf: 494 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/qt.prf: 495 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/resources.prf: 496 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/moc.prf: 497 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/unix/opengl.prf: 498 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/unix/thread.prf: 499 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/file_copies.prf: 500 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/testcase_targets.prf: 501 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/exceptions.prf: 502 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/yacc.prf: 503 | ../../../Qt5.7.0/5.7/gcc_64/mkspecs/features/lex.prf: 504 | Ex1.pro: 505 | ../../../Qt5.7.0/5.7/gcc_64/lib/libQt5Gui.prl: 506 | ../../../Qt5.7.0/5.7/gcc_64/lib/libQt5Core.prl: 507 | qmake: FORCE 508 | @$(QMAKE) -o Makefile Ex1.pro 509 | 510 | qmake_all: FORCE 511 | 512 | 513 | all: Makefile $(TARGET) 514 | 515 | dist: distdir FORCE 516 | (cd `dirname $(DISTDIR)` && $(TAR) $(DISTNAME).tar $(DISTNAME) && $(COMPRESS) $(DISTNAME).tar) && $(MOVE) `dirname $(DISTDIR)`/$(DISTNAME).tar.gz . && $(DEL_FILE) -r $(DISTDIR) 517 | 518 | distdir: FORCE 519 | @test -d $(DISTDIR) || mkdir -p $(DISTDIR) 520 | $(COPY_FILE) --parents $(DIST) $(DISTDIR)/ 521 | $(COPY_FILE) --parents main.cpp $(DISTDIR)/ 522 | 523 | 524 | clean: compiler_clean 525 | -$(DEL_FILE) $(OBJECTS) 526 | -$(DEL_FILE) *~ core *.core 527 | 528 | 529 | distclean: clean 530 | -$(DEL_FILE) $(TARGET) 531 | -$(DEL_FILE) .qmake.stash 532 | -$(DEL_FILE) Makefile 533 | 534 | 535 | ####### Sub-libraries 536 | 537 | mocclean: compiler_moc_header_clean compiler_moc_source_clean 538 | 539 | mocables: compiler_moc_header_make_all compiler_moc_source_make_all 540 | 541 | check: first 542 | 543 | benchmark: first 544 | 545 | compiler_rcc_make_all: 546 | compiler_rcc_clean: 547 | compiler_moc_header_make_all: 548 | compiler_moc_header_clean: 549 | compiler_moc_source_make_all: 550 | compiler_moc_source_clean: 551 | compiler_yacc_decl_make_all: 552 | compiler_yacc_decl_clean: 553 | compiler_yacc_impl_make_all: 554 | compiler_yacc_impl_clean: 555 | compiler_lex_make_all: 556 | compiler_lex_clean: 557 | compiler_clean: 558 | 559 | ####### Compile 560 | 561 | main.o: main.cpp ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/QDebug \ 562 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qdebug.h \ 563 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qalgorithms.h \ 564 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qglobal.h \ 565 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qconfig.h \ 566 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qfeatures.h \ 567 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qsystemdetection.h \ 568 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qprocessordetection.h \ 569 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qcompilerdetection.h \ 570 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qtypeinfo.h \ 571 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qtypetraits.h \ 572 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qisenum.h \ 573 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qsysinfo.h \ 574 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qlogging.h \ 575 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qflags.h \ 576 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qatomic.h \ 577 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qbasicatomic.h \ 578 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qatomic_bootstrap.h \ 579 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qgenericatomic.h \ 580 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qatomic_cxx11.h \ 581 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qatomic_msvc.h \ 582 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qglobalstatic.h \ 583 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qmutex.h \ 584 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qnumeric.h \ 585 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qversiontagging.h \ 586 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qhash.h \ 587 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qchar.h \ 588 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qiterator.h \ 589 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qlist.h \ 590 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qrefcount.h \ 591 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qarraydata.h \ 592 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qhashfunctions.h \ 593 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qpair.h \ 594 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qbytearraylist.h \ 595 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qbytearray.h \ 596 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qnamespace.h \ 597 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qstring.h \ 598 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qstringbuilder.h \ 599 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qstringlist.h \ 600 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qregexp.h \ 601 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qstringmatcher.h \ 602 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qmap.h \ 603 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qtextstream.h \ 604 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qiodevice.h \ 605 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qobject.h \ 606 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qobjectdefs.h \ 607 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qobjectdefs_impl.h \ 608 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qcoreevent.h \ 609 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qscopedpointer.h \ 610 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qmetatype.h \ 611 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qvarlengtharray.h \ 612 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qcontainerfwd.h \ 613 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qobject_impl.h \ 614 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qlocale.h \ 615 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qvariant.h \ 616 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qshareddata.h \ 617 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qvector.h \ 618 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qpoint.h \ 619 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qset.h \ 620 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qcontiguouscache.h \ 621 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qsharedpointer.h \ 622 | ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qsharedpointer_impl.h 623 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp 624 | 625 | ####### Install 626 | 627 | install: FORCE 628 | 629 | uninstall: FORCE 630 | 631 | FORCE: 632 | 633 | -------------------------------------------------------------------------------- /Chapter05/Ex1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main ( ) { 4 | 5 | qDebug() << "Hello Qt from CLI app" << endl; 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/Ex10/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex10/Ex10.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Fri Oct 21 21:43:32 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex10 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | HEADERS += MyDlg.h 13 | SOURCES += main.cpp MyDlg.cpp 14 | -------------------------------------------------------------------------------- /Chapter05/Ex10/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: This dialog will demonstrate the use of QFormLayout and the way 7 | * to combine multiple layouts in the same dialog. 8 | * It will also given an idea on how to make use of QLabel, QLineEdit 9 | * and QPushButton and Signals and Slots. 10 | * 11 | * Version: 1.0 12 | * Created: 10/22/2016 13 | * Revision: none 14 | * Compiler: gcc 15 | * 16 | * Author: Jeganathan Swaminathan 17 | * Organization: TekTutor 18 | * 19 | * ===================================================================================== 20 | */ 21 | #include "MyDlg.h" 22 | 23 | MyDlg::MyDlg() { 24 | pAddButton = new QPushButton("Add"); 25 | pSubtractButton = new QPushButton("Subtract"); 26 | pMultiplyButton = new QPushButton("Multiply"); 27 | pDivideButton = new QPushButton("Divide"); 28 | 29 | pButtonLayout = new QBoxLayout(QBoxLayout::RightToLeft); 30 | 31 | pButtonLayout->addWidget ( pDivideButton ); 32 | pButtonLayout->addWidget ( pMultiplyButton ); 33 | pButtonLayout->addWidget ( pSubtractButton ); 34 | pButtonLayout->addWidget ( pAddButton ); 35 | pButtonLayout->addStretch ( ); 36 | 37 | pFormLayout = new QFormLayout(); 38 | 39 | pFirstEdit = new QLineEdit(); 40 | pSecondEdit = new QLineEdit(); 41 | pResultEdit = new QLineEdit(); 42 | 43 | pFormLayout->addRow("First number",pFirstEdit); 44 | pFormLayout->addRow("Second number",pSecondEdit); 45 | pFormLayout->addRow("Result",pResultEdit); 46 | 47 | pMainLayout = new QVBoxLayout(this); 48 | 49 | pMainLayout->addLayout ( pFormLayout ); 50 | pMainLayout->addLayout ( pButtonLayout ); 51 | 52 | setLayout ( pMainLayout ); 53 | 54 | connect ( 55 | pAddButton, 56 | SIGNAL ( clicked() ), 57 | this, 58 | SLOT ( onAddButtonClicked() ) 59 | ); 60 | connect ( 61 | pSubtractButton, 62 | SIGNAL ( clicked() ), 63 | this, 64 | SLOT ( onSubtractButtonClicked() ) 65 | ); 66 | connect ( 67 | pMultiplyButton, 68 | SIGNAL ( clicked() ), 69 | this, 70 | SLOT ( onMultiplyButtonClicked() ) 71 | ); 72 | connect ( 73 | pDivideButton, 74 | SIGNAL ( clicked() ), 75 | this, 76 | SLOT ( onDivideButtonClicked() ) 77 | ); 78 | } 79 | 80 | void MyDlg::onAddButtonClicked() { 81 | qDebug() << "Add button clicked ..." << endl; 82 | int firstNumber = pFirstEdit->text().toInt(); 83 | int secondNumber = pSecondEdit->text().toInt(); 84 | int result = firstNumber + secondNumber; 85 | QString strResult; 86 | strResult.setNum( result ); 87 | 88 | pResultEdit->setText( strResult ); 89 | } 90 | 91 | void MyDlg::onSubtractButtonClicked() { 92 | qDebug() << "Subtract button clicked ..." << endl; 93 | } 94 | 95 | void MyDlg::onMultiplyButtonClicked() { 96 | qDebug() << "Multiply button clicked ..." << endl; 97 | } 98 | 99 | void MyDlg::onDivideButtonClicked() { 100 | qDebug() << "Divide button clicked ..." << endl; 101 | } 102 | -------------------------------------------------------------------------------- /Chapter05/Ex10/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: This dialog will demonstrate the use of QFormLayout and the way 7 | * to combine multiple layouts in the same dialog. 8 | * It will also given an idea on how to make use of QLabel, QLineEdit 9 | * and QPushButton and Signals and Slots. 10 | * 11 | * Version: 1.0 12 | * Created: 10/22/2016 13 | * Revision: none 14 | * Compiler: gcc 15 | * 16 | * Author: Jeganathan Swaminathan 17 | * Organization: TekTutor 18 | * 19 | * ===================================================================================== 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | class MyDlg : public QDialog { 32 | Q_OBJECT 33 | private: 34 | QVBoxLayout *pMainLayout; 35 | QBoxLayout *pButtonLayout; 36 | QFormLayout *pFormLayout; 37 | 38 | QLineEdit *pFirstEdit, *pSecondEdit, *pResultEdit; 39 | QLabel *pFirstLabel, *pSecondLabel, *pResultLabel; 40 | QPushButton *pAddButton, *pSubtractButton, *pMultiplyButton, *pDivideButton; 41 | public: 42 | MyDlg(); 43 | private slots: 44 | void onAddButtonClicked(); 45 | void onSubtractButtonClicked(); 46 | void onMultiplyButtonClicked(); 47 | void onDivideButtonClicked(); 48 | }; 49 | -------------------------------------------------------------------------------- /Chapter05/Ex10/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This exercise will demonstrate the use of QFormLayout 7 | * QLabel and QLineEdit. 8 | * 9 | * Version: 1.0 10 | * Created: 10/22/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include "MyDlg.h" 21 | 22 | int main (int argc, char **argv) { 23 | QApplication theApp(argc,argv); 24 | 25 | MyDlg dlg; 26 | dlg.show(); 27 | 28 | return theApp.exec(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/Ex2/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex2/Ex2.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Thu Oct 27 17:05:22 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex2 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | SOURCES += main.cpp 13 | -------------------------------------------------------------------------------- /Chapter05/Ex2/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This is a simple Hello Wold GUI app in Qt. 7 | * 8 | * Version: 1.0 9 | * Created: 10/15/2016 11:41:39 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include 20 | 21 | int main ( int argc, char **argv ) { 22 | 23 | QApplication theApp (argc,argv); 24 | 25 | QWidget myWindow; 26 | //myWindow.setWindowTitle ( "Hello Qt, my first GUI application"); 27 | myWindow.show(); 28 | 29 | return theApp.exec(); 30 | } 31 | -------------------------------------------------------------------------------- /Chapter05/Ex3/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex3/Ex3.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Sun Oct 16 18:24:15 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex3 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | HEADERS += MyDlg.h 13 | SOURCES += main.cpp MyDlg.cpp 14 | -------------------------------------------------------------------------------- /Chapter05/Ex3/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QHBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:11:17 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "MyDlg.h" 19 | 20 | MyDlg::MyDlg() { 21 | pLayout = new QHBoxLayout(this); 22 | 23 | pBttn1 = new QPushButton ("Button 1"); 24 | pBttn2 = new QPushButton ("Button 2"); 25 | pBttn3 = new QPushButton ("Button 3"); 26 | 27 | pBttn1->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 28 | pBttn2->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 29 | pBttn3->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 30 | 31 | pLayout->addWidget ( pBttn1 ); 32 | pLayout->addWidget ( pBttn2 ); 33 | pLayout->addWidget ( pBttn3 ); 34 | 35 | setLayout ( pLayout ); 36 | 37 | setWindowTitle ("Horizontal Box Layout"); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Chapter05/Ex3/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QHBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:08:21 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | class MyDlg : public QDialog { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3; 26 | QHBoxLayout *pLayout; 27 | public: 28 | MyDlg(); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /Chapter05/Ex3/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QHBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:18:27 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include "MyDlg.h" 20 | 21 | int main ( int argc, char **argv ) { 22 | QApplication::setColorSpec(QApplication::ManyColor); 23 | QApplication theApp ( argc, argv ); 24 | 25 | MyDlg dlg; 26 | dlg.show(); 27 | 28 | return theApp.exec(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Chapter05/Ex4/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex4/Ex4.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Wed Nov 2 23:00:03 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex4 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | HEADERS += MyDlg.h 13 | SOURCES += main.cpp MyDlg.cpp 14 | -------------------------------------------------------------------------------- /Chapter05/Ex4/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QVBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:11:17 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "MyDlg.h" 19 | 20 | MyDlg::MyDlg() { 21 | pLayout = new QVBoxLayout(this); 22 | 23 | pBttn1 = new QPushButton ("Button 1"); 24 | pBttn2 = new QPushButton ("Button 2"); 25 | pBttn3 = new QPushButton ("Button 3"); 26 | 27 | pBttn1->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 28 | pBttn2->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 29 | pBttn3->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 30 | 31 | pLayout->addWidget ( pBttn1 ); 32 | pLayout->addWidget ( pBttn2 ); 33 | pLayout->addWidget ( pBttn3 ); 34 | 35 | setLayout ( pLayout ); 36 | 37 | setWindowTitle ("Vertical Box Layout"); 38 | } 39 | 40 | void MyDlg::someFunction() { 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Chapter05/Ex4/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QVBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:08:21 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | class MyDlg : public QDialog { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3; 26 | QVBoxLayout *pLayout; 27 | public: 28 | MyDlg(); 29 | void someFunction(); 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /Chapter05/Ex4/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QHBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:18:27 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include "MyDlg.h" 20 | 21 | int main ( int argc, char **argv ) { 22 | QApplication::setColorSpec(QApplication::ManyColor); 23 | QApplication theApp ( argc, argv ); 24 | 25 | MyDlg dlg; 26 | dlg.show(); 27 | 28 | return theApp.exec(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Chapter05/Ex5/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex5/Ex5.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Mon Oct 17 05:20:58 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex5 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | HEADERS += MyDlg.h 13 | SOURCES += main.cpp MyDlg.cpp 14 | -------------------------------------------------------------------------------- /Chapter05/Ex5/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:11:17 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "MyDlg.h" 19 | 20 | MyDlg::MyDlg() { 21 | pLayout = new QBoxLayout(QBoxLayout::BottomToTop, this); 22 | 23 | pBttn1 = new QPushButton ("Button 1"); 24 | pBttn2 = new QPushButton ("Button 2"); 25 | pBttn3 = new QPushButton ("Button 3"); 26 | pBttn4 = new QPushButton ("Button 4"); 27 | pBttn5 = new QPushButton ("Button 5"); 28 | 29 | pBttn1->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 30 | pBttn2->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 31 | pBttn3->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 32 | pBttn4->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 33 | pBttn5->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 34 | 35 | pLayout->addWidget ( pBttn1 ); 36 | pLayout->addWidget ( pBttn2 ); 37 | pLayout->addWidget ( pBttn3 ); 38 | pLayout->addWidget ( pBttn4 ); 39 | pLayout->addWidget ( pBttn5 ); 40 | 41 | setLayout ( pLayout ); 42 | 43 | setWindowTitle ("Box Layout"); 44 | } 45 | -------------------------------------------------------------------------------- /Chapter05/Ex5/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:08:21 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | class MyDlg : public QDialog { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4, *pBttn5; 26 | QBoxLayout *pLayout; 27 | public: 28 | MyDlg(); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /Chapter05/Ex5/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:18:27 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include "MyDlg.h" 20 | 21 | int main ( int argc, char **argv ) { 22 | QApplication theApp ( argc, argv ); 23 | 24 | MyDlg dlg; 25 | dlg.show(); 26 | 27 | return theApp.exec(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Chapter05/Ex6/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex6/Ex6.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Mon Oct 17 06:08:36 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex6 7 | INCLUDEPATH += . 8 | QT += widgets 9 | 10 | # Input 11 | HEADERS += MyDlg.h 12 | SOURCES += main.cpp MyDlg.cpp 13 | -------------------------------------------------------------------------------- /Chapter05/Ex6/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:11:17 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "MyDlg.h" 19 | 20 | MyDlg::MyDlg() { 21 | pLayout = new QGridLayout(this); 22 | 23 | pBttn1 = new QPushButton ("Button 1"); 24 | pBttn2 = new QPushButton ("Button 2"); 25 | pBttn3 = new QPushButton ("Button 3"); 26 | pBttn4 = new QPushButton ("Button 4"); 27 | pBttn5 = new QPushButton ("Button 5"); 28 | 29 | pBttn6 = new QPushButton ("Button 6"); 30 | pBttn7 = new QPushButton ("Button 7"); 31 | pBttn8 = new QPushButton ("Button 8"); 32 | pBttn9 = new QPushButton ("Button 9"); 33 | pBttn10 = new QPushButton ("Button 10"); 34 | 35 | pLayout->addWidget ( pBttn1, 0, 0 ); //First row, first column 36 | pLayout->addWidget ( pBttn2, 0, 1 ); //First row, second column 37 | pLayout->addWidget ( pBttn3, 0, 2 ); //First row, third column 38 | pLayout->addWidget ( pBttn4, 0, 3 ); //First row, fourth column 39 | pLayout->addWidget ( pBttn5, 0, 4 ); //First row, fifth column 40 | 41 | pLayout->addWidget ( pBttn6, 1, 0 ); //Second row, first column 42 | pLayout->addWidget ( pBttn7, 1, 1 ); //Second row, second column 43 | pLayout->addWidget ( pBttn8, 1, 2 ); //Second row, third column 44 | pLayout->addWidget ( pBttn9, 1, 3 ); //Second row, fourth column 45 | pLayout->addWidget ( pBttn10, 1, 4 ); //Second row, fifth column 46 | 47 | setLayout ( pLayout ); 48 | 49 | setWindowTitle ("Grid Layout"); 50 | } 51 | -------------------------------------------------------------------------------- /Chapter05/Ex6/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QGridLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:08:21 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | class MyDlg : public QDialog { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4, *pBttn5; 26 | QPushButton *pBttn6, *pBttn7, *pBttn8, *pBttn9, *pBttn10; 27 | QGridLayout *pLayout; 28 | public: 29 | MyDlg(); 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /Chapter05/Ex6/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:18:27 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include "MyDlg.h" 20 | 21 | int main ( int argc, char **argv ) { 22 | QApplication theApp ( argc, argv ); 23 | 24 | MyDlg dlg; 25 | dlg.show(); 26 | 27 | return theApp.exec(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Chapter05/Ex7/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex7/Ex7.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Mon Oct 17 06:33:44 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex7 7 | INCLUDEPATH += . 8 | QT += widgets 9 | 10 | # Input 11 | HEADERS += MyDlg.h 12 | SOURCES += main.cpp MyDlg.cpp 13 | -------------------------------------------------------------------------------- /Chapter05/Ex7/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QGridLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/17/2016 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include "MyDlg.h" 19 | 20 | MyDlg::MyDlg() { 21 | pLayout = new QGridLayout(this); 22 | 23 | pBttn1 = new QPushButton ("Button 1"); 24 | pBttn2 = new QPushButton ("Button 2"); 25 | pBttn3 = new QPushButton ("Button 3"); 26 | pBttn4 = new QPushButton ("Button 4"); 27 | 28 | pBttn5 = new QPushButton ("Button 5"); 29 | pBttn6 = new QPushButton ("Button 6"); 30 | pBttn7 = new QPushButton ("Button 7"); 31 | pBttn8 = new QPushButton ("Button 8"); 32 | 33 | pBttn3->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ); 34 | 35 | pLayout->addWidget ( pBttn1, 0, 0, 1, 1 ); //First row, first column - Takes one row and one column 36 | pLayout->addWidget ( pBttn2, 0, 1, 1, 2 ); //First row, second column - Takes one row and two columns 37 | pLayout->addWidget ( pBttn3, 0, 3, 2, 1 ); //First row, third column - Takes two rows and one column 38 | 39 | pLayout->addWidget ( pBttn4, 1, 0, 1, 3 ); //Second row, fourth column - Takes one row and three columns 40 | 41 | pLayout->addWidget ( pBttn5, 2, 0 ); //Third row, first column - Takes one row and one column 42 | pLayout->addWidget ( pBttn6, 2, 1 ); //Third row, second column - Takes one row and two columns 43 | pLayout->addWidget ( pBttn7, 2, 2 ); //Third row, third column - Takes two rows and one column 44 | pLayout->addWidget ( pBttn8, 2, 3 ); //Third row, fourth column - Takes one row and three columns 45 | 46 | setLayout ( pLayout ); 47 | 48 | setWindowTitle ("Grid Layout"); 49 | } 50 | -------------------------------------------------------------------------------- /Chapter05/Ex7/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QGridLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/17/2016 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | class MyDlg : public QDialog { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4; 26 | QPushButton *pBttn5, *pBttn6, *pBttn7, *pBttn8; 27 | QGridLayout *pLayout; 28 | public: 29 | MyDlg(); 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /Chapter05/Ex7/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: Simple Qt application with QDialog, QPushButton and QBoxLayout 7 | * 8 | * Version: 1.0 9 | * Created: 10/16/2016 05:18:27 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: TekTutor 15 | * 16 | * ===================================================================================== 17 | */ 18 | #include 19 | #include "MyDlg.h" 20 | 21 | int main ( int argc, char **argv ) { 22 | QApplication theApp ( argc, argv ); 23 | 24 | MyDlg dlg; 25 | dlg.show(); 26 | 27 | return theApp.exec(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Chapter05/Ex8/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex8/Ex8.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Mon Oct 17 19:35:51 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex8 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | HEADERS += MyDlg.h 13 | SOURCES += main.cpp MyDlg.cpp 14 | -------------------------------------------------------------------------------- /Chapter05/Ex8/MyDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.cpp 5 | * 6 | * Description: Simple Qt application with QDialog & QPushButton that demonstrates 7 | * Signals and Slots 8 | * 9 | * Version: 1.0 10 | * Created: 10/19/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "MyDlg.h" 20 | 21 | MyDlg::MyDlg() { 22 | pLayout = new QHBoxLayout(this); 23 | 24 | pBttn = new QPushButton ("Click Me"); 25 | 26 | pLayout->addWidget ( pBttn ); 27 | 28 | setLayout ( pLayout ); 29 | 30 | setWindowTitle ("Signals and Slots"); 31 | 32 | connect ( 33 | pBttn, 34 | SIGNAL ( clicked() ), 35 | this, 36 | SLOT ( onButtonClicked() ) 37 | ); 38 | } 39 | 40 | void MyDlg::onButtonClicked() { 41 | qDebug() << "Button clicked ..."; 42 | } 43 | -------------------------------------------------------------------------------- /Chapter05/Ex8/MyDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MyDlg.h 5 | * 6 | * Description: Simple Qt application with QPushButton that demonstrates 7 | * Signals and Slots 8 | * 9 | * Version: 1.0 10 | * Created: 10/19/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class MyDlg : public QDialog { 26 | Q_OBJECT 27 | private: 28 | QPushButton *pBttn; 29 | QHBoxLayout *pLayout; 30 | 31 | public: 32 | MyDlg(); 33 | 34 | private slots: 35 | void onButtonClicked(); 36 | 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /Chapter05/Ex8/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: Simple Qt application with QDialog & QPushButton that demonstrates 7 | * Signals and Slots 8 | * 9 | * Version: 1.0 10 | * Created: 10/18/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include "MyDlg.h" 21 | 22 | int main ( int argc, char **argv ) { 23 | QApplication theApp ( argc, argv ); 24 | 25 | MyDlg dlg; 26 | dlg.show(); 27 | 28 | return theApp.exec(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Chapter05/Ex9/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_DEFAULT_INCDIRS = \ 2 | /usr/include/c++/5 \ 3 | /usr/include/x86_64-linux-gnu/c++/5 \ 4 | /usr/include/c++/5/backward \ 5 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 6 | /usr/local/include \ 7 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 8 | /usr/include/x86_64-linux-gnu \ 9 | /usr/include 10 | QMAKE_DEFAULT_LIBDIRS = \ 11 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 12 | /usr/lib/x86_64-linux-gnu \ 13 | /usr/lib \ 14 | /lib/x86_64-linux-gnu \ 15 | /lib 16 | -------------------------------------------------------------------------------- /Chapter05/Ex9/BoxDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: BoxDlg.cpp 5 | * 6 | * Description: This dialog will demonstrate Box layout with 5 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "BoxDlg.h" 20 | 21 | BoxDlg::BoxDlg() { 22 | 23 | pBttn1 = new QPushButton("Button 1"); 24 | pBttn2 = new QPushButton("Button 2"); 25 | pBttn3 = new QPushButton("Button 3"); 26 | pBttn4 = new QPushButton("Button 4"); 27 | pBttn5 = new QPushButton("Button 5"); 28 | 29 | pLayout = new QBoxLayout(QBoxLayout::BottomToTop, this); 30 | 31 | pLayout->addWidget ( pBttn1 ); 32 | pLayout->addWidget ( pBttn2 ); 33 | pLayout->addWidget ( pBttn3 ); 34 | pLayout->addWidget ( pBttn4 ); 35 | pLayout->addWidget ( pBttn5 ); 36 | 37 | setLayout ( pLayout ); 38 | } 39 | -------------------------------------------------------------------------------- /Chapter05/Ex9/BoxDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: BoxDlg.h 5 | * 6 | * Description: This dialog will demonstrate Box layout with 5 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | class BoxDlg : public QWidget { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4, *pBttn5; 26 | QBoxLayout *pLayout; 27 | public: 28 | BoxDlg(); 29 | }; 30 | -------------------------------------------------------------------------------- /Chapter05/Ex9/Ex9.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Wed Oct 19 20:06:49 2016 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = Ex9 7 | INCLUDEPATH += . 8 | 9 | QT += widgets 10 | 11 | # Input 12 | HEADERS += BoxDlg.h GridDlg.h HBoxDlg.h MainDlg.h VBoxDlg.h 13 | SOURCES += BoxDlg.cpp GridDlg.cpp HBoxDlg.cpp main.cpp MainDlg.cpp VBoxDlg.cpp 14 | -------------------------------------------------------------------------------- /Chapter05/Ex9/GridDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: GridDlg.cpp 5 | * 6 | * Description: This dialog will demonstrate Grid layout with 10 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "GridDlg.h" 20 | 21 | GridDlg::GridDlg() { 22 | 23 | pBttn1 = new QPushButton("Button 1"); 24 | pBttn2 = new QPushButton("Button 2"); 25 | pBttn3 = new QPushButton("Button 3"); 26 | pBttn4 = new QPushButton("Button 4"); 27 | pBttn5 = new QPushButton("Button 5"); 28 | 29 | pBttn6 = new QPushButton("Button 6"); 30 | pBttn7 = new QPushButton("Button 7"); 31 | pBttn8 = new QPushButton("Button 8"); 32 | pBttn9 = new QPushButton("Button 9"); 33 | pBttn10 = new QPushButton("Button 10"); 34 | 35 | pLayout = new QGridLayout(this); 36 | 37 | pLayout->addWidget ( pBttn1, 0, 0 ); //First row, First Column 38 | pLayout->addWidget ( pBttn2, 0, 1 ); //First row, Second Column 39 | pLayout->addWidget ( pBttn3, 0, 2 ); //First row, Third Column 40 | pLayout->addWidget ( pBttn4, 0, 3 ); //First row, Fourth Column 41 | pLayout->addWidget ( pBttn5, 0, 4 ); //First row, Fifth Column 42 | 43 | pLayout->addWidget ( pBttn6, 1, 0 ); //Second row, First Column 44 | pLayout->addWidget ( pBttn7, 1, 1 ); //Second row, Second Column 45 | pLayout->addWidget ( pBttn8, 1, 2 ); //Second row, Third Column 46 | pLayout->addWidget ( pBttn9, 1, 3 ); //Second row, Fourth Column 47 | pLayout->addWidget ( pBttn10,1, 4 ); //Second row, Fifth Column 48 | 49 | setLayout ( pLayout ); 50 | } 51 | -------------------------------------------------------------------------------- /Chapter05/Ex9/GridDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: GridDlg.h 5 | * 6 | * Description: This dialog will demonstrate Grid layout with 10 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | class GridDlg : public QWidget { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4, *pBttn5; 26 | QPushButton *pBttn6, *pBttn7, *pBttn8, *pBttn9, *pBttn10; 27 | QGridLayout *pLayout; 28 | public: 29 | GridDlg(); 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter05/Ex9/HBoxDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: HBoxDlg.cpp 5 | * 6 | * Description: This dialog will demonstrate Horizontal box layout with 5 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "HBoxDlg.h" 20 | 21 | HBoxDlg::HBoxDlg() { 22 | 23 | pBttn1 = new QPushButton("Button 1"); 24 | pBttn2 = new QPushButton("Button 2"); 25 | pBttn3 = new QPushButton("Button 3"); 26 | pBttn4 = new QPushButton("Button 4"); 27 | pBttn5 = new QPushButton("Button 5"); 28 | 29 | pLayout = new QHBoxLayout(this); 30 | 31 | pLayout->addWidget ( pBttn1 ); 32 | pLayout->addWidget ( pBttn2 ); 33 | pLayout->addWidget ( pBttn3 ); 34 | pLayout->addWidget ( pBttn4 ); 35 | pLayout->addWidget ( pBttn5 ); 36 | 37 | setLayout ( pLayout ); 38 | } 39 | -------------------------------------------------------------------------------- /Chapter05/Ex9/HBoxDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: HBoxDlg.h 5 | * 6 | * Description: This dialog will demonstrate Horizontal box layout with 5 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | class HBoxDlg : public QWidget { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4, *pBttn5; 26 | QHBoxLayout *pLayout; 27 | public: 28 | HBoxDlg(); 29 | }; 30 | -------------------------------------------------------------------------------- /Chapter05/Ex9/MainDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MainDlg.cpp 5 | * 6 | * Description: This class is going to be the main dialog of this application. 7 | * Stacked layout will be used to stack up all the four pages in this dialog. 8 | * 9 | * Version: 1.0 10 | * Created: 10/19/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | 20 | #include "MainDlg.h" 21 | 22 | MainDlg::MainDlg() { 23 | pHBoxDlg = new HBoxDlg(this); 24 | pVBoxDlg = new VBoxDlg(this); 25 | pBoxDlg = new BoxDlg(this); 26 | pGridDlg = new GridDlg(this); 27 | 28 | pStackedLayout = new QStackedLayout(); 29 | 30 | pStackedLayout->addWidget ( pHBoxDlg ); 31 | pStackedLayout->addWidget ( pVBoxDlg ); 32 | pStackedLayout->addWidget ( pBoxDlg ); 33 | pStackedLayout->addWidget ( pGridDlg ); 34 | 35 | pNavigationLayout = new QBoxLayout(QBoxLayout::RightToLeft); 36 | 37 | pPrevBttn = new QPushButton ("Prev Page"); 38 | pNextBttn = new QPushButton ("Next Page"); 39 | pExitBttn = new QPushButton ("Exit App"); 40 | 41 | pNavigationLayout->addWidget ( pExitBttn ); 42 | pNavigationLayout->addWidget ( pNextBttn ); 43 | pNavigationLayout->addWidget ( pPrevBttn ); 44 | pNavigationLayout->addStretch( ); 45 | 46 | pMainLayout = new QVBoxLayout(this); 47 | 48 | pMainLayout->addLayout ( pStackedLayout ); 49 | pMainLayout->addLayout ( pNavigationLayout ); 50 | 51 | setLayout ( pMainLayout ); 52 | 53 | connect ( 54 | pPrevBttn, 55 | SIGNAL ( clicked() ), 56 | this, 57 | SLOT ( onPrevPage() ) 58 | ); 59 | 60 | connect ( 61 | pNextBttn, 62 | SIGNAL ( clicked() ), 63 | this, 64 | SLOT ( onNextPage() ) 65 | ); 66 | 67 | connect ( 68 | pExitBttn, 69 | SIGNAL ( clicked() ), 70 | this, 71 | SLOT ( onExitApp() ) 72 | ); 73 | } 74 | 75 | void MainDlg::onPrevPage() { 76 | int currentPageIndex = pStackedLayout->currentIndex(); 77 | 78 | if ( currentPageIndex > 0 ) 79 | pStackedLayout->setCurrentIndex ( currentPageIndex - 1 ); 80 | } 81 | 82 | void MainDlg::onNextPage() { 83 | int currentPageIndex = pStackedLayout->currentIndex(); 84 | 85 | if ( currentPageIndex < 3 ) 86 | pStackedLayout->setCurrentIndex ( currentPageIndex + 1 ); 87 | } 88 | 89 | void MainDlg::onExitApp() { 90 | close(); 91 | } 92 | -------------------------------------------------------------------------------- /Chapter05/Ex9/MainDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: MainDlg.h 5 | * 6 | * Description: This class is going to be the main dialog of this application. 7 | * Stacked layout will be used to stack up all the four pages in this dialog. 8 | * 9 | * Version: 1.0 10 | * Created: 10/19/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | 20 | //Built-in Qt headers goes here 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | //Custom headers goes here 29 | #include "HBoxDlg.h" 30 | #include "VBoxDlg.h" 31 | #include "BoxDlg.h" 32 | #include "GridDlg.h" 33 | 34 | class MainDlg : public QDialog { 35 | Q_OBJECT 36 | private: 37 | QStackedLayout *pStackedLayout; 38 | QBoxLayout *pNavigationLayout; 39 | QVBoxLayout *pMainLayout; 40 | QPushButton *pPrevBttn, *pNextBttn, *pExitBttn; 41 | 42 | HBoxDlg *pHBoxDlg; 43 | VBoxDlg *pVBoxDlg; 44 | BoxDlg *pBoxDlg; 45 | GridDlg *pGridDlg; 46 | public: 47 | MainDlg(); 48 | private slots: 49 | void onPrevPage(); 50 | void onNextPage(); 51 | void onExitApp(); 52 | }; 53 | -------------------------------------------------------------------------------- /Chapter05/Ex9/VBoxDlg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: VBoxDlg.cpp 5 | * 6 | * Description: This dialog will demonstrate vertical box layout with 5 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "VBoxDlg.h" 20 | 21 | VBoxDlg::VBoxDlg() { 22 | 23 | pBttn1 = new QPushButton("Button 1"); 24 | pBttn2 = new QPushButton("Button 2"); 25 | pBttn3 = new QPushButton("Button 3"); 26 | pBttn4 = new QPushButton("Button 4"); 27 | pBttn5 = new QPushButton("Button 5"); 28 | 29 | pLayout = new QVBoxLayout(this); 30 | 31 | pLayout->addWidget ( pBttn1 ); 32 | pLayout->addWidget ( pBttn2 ); 33 | pLayout->addWidget ( pBttn3 ); 34 | pLayout->addWidget ( pBttn4 ); 35 | pLayout->addWidget ( pBttn5 ); 36 | 37 | setLayout ( pLayout ); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Chapter05/Ex9/VBoxDlg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: VBoxDlg.h 5 | * 6 | * Description: This dialog will demonstrate Vertical box layout with 5 buttons. 7 | * 8 | * 9 | * Version: 1.0 10 | * Created: 10/20/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | class VBoxDlg : public QWidget { 24 | private: 25 | QPushButton *pBttn1, *pBttn2, *pBttn3, *pBttn4, *pBttn5; 26 | QVBoxLayout *pLayout; 27 | public: 28 | VBoxDlg(); 29 | }; 30 | -------------------------------------------------------------------------------- /Chapter05/Ex9/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This has the main entry-point function. The main function will 7 | * launch the main dialog that has the stacked layout. 8 | * 9 | * Version: 1.0 10 | * Created: 10/19/2016 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: TekTutor 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include "MainDlg.h" 21 | 22 | int main ( int argc, char **argv ) { 23 | QApplication theApp ( argc, argv ); 24 | 25 | MainDlg dlg; 26 | dlg.show(); 27 | 28 | return theApp.exec(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void* threadProc ( void *param ) { 7 | for (int count=0; count<3; ++count) 8 | cout << "Message " << count << " from " << pthread_self() 9 | << endl; 10 | pthread_exit(0); 11 | } 12 | 13 | int main() { 14 | pthread_t thread1, thread2, thread3; 15 | 16 | pthread_create ( &thread1, NULL, threadProc, NULL ); 17 | pthread_create ( &thread2, NULL, threadProc, NULL ); 18 | pthread_create ( &thread3, NULL, threadProc, NULL ); 19 | 20 | pthread_join( thread1, NULL ); 21 | pthread_join( thread2, NULL ); 22 | 23 | pthread_join( thread3, NULL ); 24 | 25 | return 0; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex10/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void sayHello( promise promise_ ) { 6 | promise_.set_value ( "Hello Concurrency support library!" ); 7 | } 8 | 9 | int main ( ) { 10 | promise promiseObj; 11 | 12 | future futureObj = promiseObj.get_future( ); 13 | async ( launch::async, sayHello, move( promiseObj ) ); 14 | cout << futureObj.get( ) << endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex11/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int add ( int firstInput, int secondInput ) { 8 | return firstInput + secondInput; 9 | } 10 | 11 | int main ( ) { 12 | packaged_task addTask( add); 13 | 14 | future output = addTask.get_future( ); 15 | 16 | thread addThread ( move(addTask), 15, 10 ); 17 | 18 | addThread.join( ); 19 | 20 | cout << "The sum of 15 + 10 is " << output.get() << endl; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex12/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int add ( int firstInput, int secondInput ) { 7 | return firstInput + secondInput; 8 | } 9 | 10 | int main ( ) { 11 | 12 | packaged_task addTask( add ); 13 | 14 | future output = addTask.get_future(); 15 | 16 | thread addThread ( move(addTask), 15, 10); 17 | 18 | addThread.join(); 19 | 20 | cout << "The sum of 15 + 10 is " << output.get() << endl; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex13/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void add ( int firstInput, int secondInput, promise output ) { 8 | 9 | try { 10 | if ( ( INT_MAX == firstInput ) || ( INT_MAX == secondInput ) ) 11 | output.set_exception( current_exception() ) ; 12 | } 13 | catch(...) {} 14 | 15 | output.set_value( firstInput + secondInput ) ; 16 | 17 | } 18 | 19 | int main ( ) { 20 | 21 | 22 | try { 23 | promise promise_; 24 | future output = promise_.get_future(); 25 | async ( launch::deferred, add, INT_MAX, INT_MAX, move(promise_) ); 26 | cout << "The sum of INT_MAX + INT_MAX is " << output.get ( ) << endl; 27 | } 28 | catch( exception e ) { 29 | cerr << "Exception occured" << endl; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void threadProc() { 6 | for( int count=0; count<3; ++count ) { 7 | cout << "Message => " 8 | << count 9 | << " from " 10 | << this_thread::get_id() 11 | << endl; 12 | } 13 | } 14 | 15 | int main() { 16 | thread thread1 ( threadProc ); 17 | thread thread2 ( threadProc ); 18 | thread thread3 ( threadProc ); 19 | 20 | thread1.join(); 21 | thread2.join(); 22 | thread3.join(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex3/Thread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Thread.cpp 5 | * 6 | * Description: This is a thread class that abstracts the C++ Thread 7 | * Support Library. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 04:12:35 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | 20 | #include "Thread.h" 21 | 22 | Thread::Thread() { 23 | pThread = NULL; 24 | stopped = false; 25 | } 26 | 27 | Thread::~Thread() { 28 | delete pThread; 29 | pThread = NULL; 30 | } 31 | 32 | void Thread::run() { 33 | while ( ! stopped ) { 34 | cout << this_thread::get_id() << endl; 35 | this_thread::sleep_for ( 1s ); 36 | } 37 | cout << "\nThread " << this_thread::get_id() 38 | << " stopped as requested." << endl; 39 | return; 40 | } 41 | 42 | void Thread::stop() { 43 | stopped = true; 44 | } 45 | 46 | void Thread::start() { 47 | pThread = new thread( &Thread::run, this ); 48 | } 49 | 50 | 51 | void Thread::join() { 52 | pThread->join(); 53 | } 54 | 55 | void Thread::detach() { 56 | pThread->detach(); 57 | } 58 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex3/Thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Thread.h 5 | * 6 | * Description: This is a thread class that abstracts the C++ Thread 7 | * Support Library. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 04:12:35 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include 20 | #include 21 | using namespace std; 22 | 23 | class Thread { 24 | private: 25 | thread *pThread; 26 | bool stopped; 27 | void run(); 28 | public: 29 | Thread(); 30 | ~Thread(); 31 | 32 | void start(); 33 | void stop(); 34 | void join(); 35 | void detach(); 36 | }; 37 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex3/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This exercise will demonstrate using mutex as a locking mechnaism. 7 | * 8 | * Version: 1.0 9 | * Created: 04/09/2017 10:24:44 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include "Thread.h" 21 | using namespace std; 22 | 23 | 24 | int main() { 25 | Thread thread1, thread2, thread3; 26 | thread1.start(); 27 | thread2.start(); 28 | thread3.start(); 29 | 30 | thread1.detach(); 31 | thread2.detach(); 32 | thread3.detach(); 33 | 34 | this_thread::sleep_for ( 3s ); 35 | 36 | thread1.stop(); 37 | thread2.stop(); 38 | thread3.stop(); 39 | 40 | this_thread::sleep_for ( 3s ); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex4/Account.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.cpp 5 | * 6 | * Description: Demonstrates use of mutex to synchronize multiple threads 7 | * that share a common resource within same process. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 10:31:56 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Account.h" 20 | 21 | Account::Account(double balance) { 22 | this->balance = balance; 23 | } 24 | 25 | double Account::getBalance() { 26 | return balance; 27 | } 28 | 29 | void Account::withdraw(double amount) { 30 | if ( balance < amount ) { 31 | cout << "Insufficient balance, withdraw denied." << endl; 32 | return; 33 | } 34 | 35 | balance = balance - amount; 36 | } 37 | 38 | void Account::deposit(double amount) { 39 | balance = balance + amount; 40 | } 41 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex4/Account.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.h 5 | * 6 | * Description: Demonstrates use of mutex. 7 | * 8 | * Version: 1.0 9 | * Created: 04/09/2017 10:28:48 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | using namespace std; 21 | 22 | class Account { 23 | private: 24 | double balance; 25 | public: 26 | Account( double ); 27 | double getBalance( ); 28 | void deposit ( double amount ); 29 | void withdraw ( double amount ) ; 30 | }; 31 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex4/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This exercise will demonstrate using mutex as a locking mechnaism. 7 | * 8 | * Version: 1.0 9 | * Created: 04/09/2017 10:24:44 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include "Account.h" 21 | using namespace std; 22 | 23 | enum ThreadType { 24 | DEPOSITOR, 25 | WITHDRAWER 26 | }; 27 | 28 | Account account(5000.00); 29 | 30 | void threadProc ( ThreadType typeOfThread ) { 31 | 32 | while ( 1 ) { 33 | switch ( typeOfThread ) { 34 | case DEPOSITOR: { 35 | cout << "Account balance before the deposit is " 36 | << account.getBalance() << endl; 37 | 38 | account.deposit( 2000.00 ); 39 | 40 | cout << "Account balance after deposit is " 41 | << account.getBalance() << endl; 42 | this_thread::sleep_for( 1s ); 43 | } 44 | break; 45 | 46 | case WITHDRAWER: { 47 | cout << "Account balance before withdrawing is " 48 | << account.getBalance() << endl; 49 | 50 | account.deposit( 1000.00 ); 51 | cout << "Account balance after withdrawing is " 52 | << account.getBalance() << endl; 53 | this_thread::sleep_for( 1s ); 54 | } 55 | break; 56 | } 57 | } 58 | } 59 | 60 | int main( ) { 61 | thread depositor ( threadProc, ThreadType::DEPOSITOR ); 62 | thread withdrawer ( threadProc, ThreadType::WITHDRAWER ); 63 | 64 | depositor.join(); 65 | withdrawer.join(); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex5/Account.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.cpp 5 | * 6 | * Description: Demonstrates use of mutex to synchronize multiple threads 7 | * that share a common resource within same process. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 10:31:56 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Account.h" 20 | 21 | Account::Account(double balance) { 22 | this->balance = balance; 23 | } 24 | 25 | double Account::getBalance() { 26 | return balance; 27 | } 28 | 29 | void Account::withdraw(double amount) { 30 | if ( balance < amount ) { 31 | cout << "Insufficient balance, withdraw denied." << endl; 32 | return; 33 | } 34 | 35 | balance = balance - amount; 36 | } 37 | 38 | void Account::deposit(double amount) { 39 | balance = balance + amount; 40 | } 41 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex5/Account.h: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Account { 5 | private: 6 | double balance; 7 | public: 8 | Account( double balance ); 9 | double getBalance(); 10 | void deposit(double amount); 11 | void withdraw(double amount); 12 | }; 13 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex5/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This exercise will demonstrate using mutex as a locking mechnaism. 7 | * 8 | * Version: 1.0 9 | * Created: 04/09/2017 10:24:44 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "Account.h" 23 | using namespace std; 24 | 25 | enum ThreadType { 26 | DEPOSITOR, 27 | WITHDRAWER 28 | }; 29 | 30 | mutex locker; 31 | 32 | Account account(5000.00); 33 | 34 | void threadProc ( ThreadType typeOfThread ) { 35 | 36 | while ( 1 ) { 37 | switch ( typeOfThread ) { 38 | case DEPOSITOR: { 39 | 40 | locker.lock(); 41 | 42 | cout << "Account balance before the deposit is " 43 | << account.getBalance() << endl; 44 | 45 | account.deposit( 2000.00 ); 46 | 47 | cout << "Account balance after deposit is " 48 | << account.getBalance() << endl; 49 | 50 | locker.unlock(); 51 | this_thread::sleep_for( 1s ); 52 | } 53 | break; 54 | 55 | case WITHDRAWER: { 56 | 57 | locker.lock(); 58 | 59 | cout << "Account balance before withdrawing is " 60 | << account.getBalance() << endl; 61 | 62 | account.deposit( 1000.00 ); 63 | cout << "Account balance after withdrawing is " 64 | << account.getBalance() << endl; 65 | 66 | locker.unlock(); 67 | this_thread::sleep_for( 1s ); 68 | } 69 | break; 70 | } 71 | } 72 | } 73 | 74 | int main( ) { 75 | thread depositor ( threadProc, ThreadType::DEPOSITOR ); 76 | thread withdrawer ( threadProc, ThreadType::WITHDRAWER ); 77 | 78 | depositor.join(); 79 | withdrawer.join(); 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex6/Account.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Account.cpp 5 | * 6 | * Description: Demonstrates use of mutex to synchronize multiple threads 7 | * that share a common resource within same process. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 10:31:56 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | #include "Account.h" 20 | 21 | Account::Account(double balance) { 22 | this->balance = balance; 23 | } 24 | 25 | double Account::getBalance() { 26 | return balance; 27 | } 28 | 29 | void Account::withdraw(double amount) { 30 | if ( balance < amount ) { 31 | cout << "Insufficient balance, withdraw denied." << endl; 32 | return; 33 | } 34 | 35 | balance = balance - amount; 36 | } 37 | 38 | void Account::deposit(double amount) { 39 | balance = balance + amount; 40 | } 41 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex6/Account.h: -------------------------------------------------------------------------------- 1 | #ifndef __ACCOUNT_H 2 | #define __ACCOUNT_H 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Account { 8 | private: 9 | double balance; 10 | public: 11 | Account( double balance ); 12 | double getBalance(); 13 | void deposit(double amount); 14 | void withdraw(double amount); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex6/Thread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Thread.cpp 5 | * 6 | * Description: This is a thread class that abstracts the C++ Thread 7 | * Support Library. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 04:12:35 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | 20 | #include "Thread.h" 21 | 22 | mutex Thread::locker; 23 | 24 | Thread::Thread(Account *pAccount, ThreadType typeOfThread) { 25 | this->pAccount = pAccount; 26 | pThread = NULL; 27 | stopped = false; 28 | threadType = typeOfThread; 29 | } 30 | 31 | Thread::~Thread() { 32 | delete pThread; 33 | pThread = NULL; 34 | } 35 | 36 | void Thread::run() { 37 | while(1) { 38 | switch ( threadType ) { 39 | case DEPOSITOR: 40 | locker.lock(); 41 | 42 | cout << "Depositor: current balance is " << pAccount->getBalance() << endl; 43 | pAccount->deposit(2000.00); 44 | cout << "Depositor: post deposit balance is " << pAccount->getBalance() << endl; 45 | 46 | locker.unlock(); 47 | 48 | this_thread::sleep_for(1s); 49 | break; 50 | 51 | case WITHDRAWER: 52 | locker.lock(); 53 | 54 | cout << "Withdrawer: current balance is " << pAccount->getBalance() << endl; 55 | pAccount->withdraw(1000.00); 56 | cout << "Withdrawer: post withraw balance is " << pAccount->getBalance() << endl; 57 | 58 | locker.unlock(); 59 | 60 | this_thread::sleep_for(1s); 61 | break; 62 | } 63 | } 64 | } 65 | 66 | void Thread::start() { 67 | pThread = new thread( &Thread::run, this ); 68 | } 69 | 70 | void Thread::stop() { 71 | stopped = true; 72 | } 73 | 74 | void Thread::join() { 75 | pThread->join(); 76 | } 77 | 78 | void Thread::detach() { 79 | pThread->detach(); 80 | } 81 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex6/Thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: Thread.h 5 | * 6 | * Description: This is a thread class that abstracts the C++ Thread 7 | * Support Library. 8 | * 9 | * Version: 1.0 10 | * Created: 04/09/2017 04:12:35 PM 11 | * Revision: none 12 | * Compiler: gcc 13 | * 14 | * Author: Jeganathan Swaminathan 15 | * Organization: 16 | * 17 | * ===================================================================================== 18 | */ 19 | #ifndef __THREAD_H 20 | #define __THREAD_H 21 | 22 | #include 23 | #include 24 | #include 25 | using namespace std; 26 | #include "Account.h" 27 | 28 | enum ThreadType { 29 | DEPOSITOR, 30 | WITHDRAWER 31 | }; 32 | 33 | class Thread { 34 | private: 35 | thread *pThread; 36 | Account *pAccount; 37 | static mutex locker; 38 | ThreadType threadType; 39 | bool stopped; 40 | void run(); 41 | public: 42 | Thread(Account *pAccount, ThreadType typeOfThread); 43 | ~Thread(); 44 | void start(); 45 | void stop(); 46 | void join(); 47 | void detach(); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex6/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This exercise will demonstrate using mutex as a locking mechnaism. 7 | * 8 | * Version: 1.0 9 | * Created: 04/09/2017 10:24:44 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include "Account.h" 20 | #include "Thread.h" 21 | 22 | int main( ) { 23 | 24 | Account account(5000.00); 25 | 26 | Thread depositor ( &account, ThreadType::DEPOSITOR ); 27 | Thread withdrawer ( &account, ThreadType::WITHDRAWER ); 28 | 29 | depositor.start(); 30 | withdrawer.start(); 31 | 32 | depositor.join(); 33 | withdrawer.join(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex7/Thread.cpp: -------------------------------------------------------------------------------- 1 | #include "Thread.h" 2 | 3 | mutex Thread::commonLock; 4 | 5 | int Thread::count = 0; 6 | 7 | Thread::Thread( ThreadType typeOfThread ) { 8 | pThread = NULL; 9 | stopped = false; 10 | threadType = typeOfThread; 11 | (threadType == READER) ? name = "READER" : name = "WRITER"; 12 | } 13 | 14 | Thread::~Thread() { 15 | delete pThread; 16 | pThread = NULL; 17 | } 18 | 19 | int Thread::getCount( ) { 20 | cout << name << " is waiting for lock in getCount() method ..." << 21 | endl; 22 | lock_guard locker(commonLock); 23 | return count; 24 | } 25 | 26 | int Thread::updateCount( ) { 27 | cout << name << " is waiting for lock in updateCount() method ..." << endl; 28 | lock_guard locker(commonLock); 29 | int value = getCount(); 30 | count = ++value; 31 | return count; 32 | } 33 | 34 | void Thread::run( ) { 35 | while ( 1 ) { 36 | switch ( threadType ) { 37 | case READER: 38 | cout << name<< " => value of count from getCount() method is " << getCount() << endl; 39 | this_thread::sleep_for ( 500ms ); 40 | break; 41 | 42 | case WRITER: 43 | cout << name << " => value of count from updateCount() method is" << updateCount() << endl; 44 | this_thread::sleep_for ( 500ms ); 45 | break; 46 | } 47 | } 48 | } 49 | 50 | void Thread::start( ) { 51 | pThread = new thread ( &Thread::run, this ); 52 | } 53 | 54 | void Thread::stop( ) { 55 | stopped = true; 56 | } 57 | 58 | void Thread::join( ) { 59 | pThread->join(); 60 | } 61 | 62 | void Thread::detach( ) { 63 | pThread->detach( ); 64 | } 65 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex7/Thread.h: -------------------------------------------------------------------------------- 1 | #ifndef __THREAD_H 2 | #define __THREAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | enum ThreadType { 12 | READER, 13 | WRITER 14 | }; 15 | 16 | class Thread { 17 | private: 18 | string name; 19 | thread *pThread; 20 | ThreadType threadType; 21 | static mutex commonLock; 22 | static int count; 23 | bool stopped; 24 | void run( ); 25 | public: 26 | Thread ( ThreadType typeOfThread ); 27 | ~Thread( ); 28 | void start( ); 29 | void stop( ); 30 | void join( ); 31 | void detach ( ); 32 | int getCount( ); 33 | int updateCount( ); 34 | }; 35 | #endif 36 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex7/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: main.cpp 5 | * 6 | * Description: This exercise will demonstrate using mutex as a locking mechnaism. 7 | * 8 | * Version: 1.0 9 | * Created: 04/09/2017 10:24:44 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Jeganathan Swaminathan 14 | * Organization: 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #include 20 | using namespace std; 21 | 22 | #include "Thread.h" 23 | 24 | int main ( ) { 25 | Thread reader( READER ); 26 | Thread writer( WRITER ); 27 | 28 | reader.start( ); 29 | writer.start( ); 30 | 31 | reader.join( ); 32 | writer.join( ); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex8/Thread.cpp: -------------------------------------------------------------------------------- 1 | #include "Thread.h" 2 | 3 | mutex Thread::locker; 4 | condition_variable Thread::untilReady; 5 | bool Thread::ready = false; 6 | queue Thread::appQueue; 7 | 8 | Thread::Thread( ThreadType typeOfThread ) { 9 | pThread = NULL; 10 | stopped = false; 11 | threadType = typeOfThread; 12 | (CONSUMER == typeOfThread) ? name = "CONSUMER" : name = "PRODUCER"; 13 | } 14 | 15 | Thread::~Thread( ) { 16 | delete pThread; 17 | pThread = NULL; 18 | } 19 | 20 | void Thread::run() { 21 | int count = 0; 22 | int data = 0; 23 | while ( 1 ) { 24 | switch ( threadType ) { 25 | case CONSUMER: 26 | { 27 | 28 | cout << name << " waiting to acquire mutex ..." << endl; 29 | 30 | unique_lock uniqueLocker( locker ); 31 | 32 | cout << name << " acquired mutex ..." << endl; 33 | cout << name << " waiting for conditional variable signal..." << endl; 34 | 35 | untilReady.wait ( uniqueLocker, [] { return ready; } ); 36 | 37 | cout << name << " received conditional variable signal ..." << endl; 38 | 39 | data = appQueue.front( ) ; 40 | 41 | cout << name << " received data " << data << endl; 42 | 43 | appQueue.pop( ); 44 | ready = false; 45 | } 46 | cout << name << " released mutex ..." << endl; 47 | break; 48 | 49 | case PRODUCER: 50 | { 51 | cout << name << " waiting to acquire mutex ..." << endl; 52 | unique_lock uniqueLocker( locker ); 53 | cout << name << " acquired mutex ..." << endl; 54 | if ( 32000 == count ) count = 0; 55 | appQueue.push ( ++ count ); 56 | ready = true; 57 | uniqueLocker.unlock(); 58 | cout << name << " released mutex ..." << endl; 59 | untilReady.notify_one(); 60 | cout << name << " notified conditional signal ..." << endl; 61 | } 62 | break; 63 | } 64 | } 65 | } 66 | 67 | void Thread::start( ) { 68 | pThread = new thread ( &Thread::run, this ); 69 | } 70 | 71 | void Thread::stop( ) { 72 | stopped = true; 73 | } 74 | 75 | void Thread::join( ) { 76 | pThread->join( ); 77 | } 78 | 79 | void Thread::detach( ) { 80 | pThread->detach( ); 81 | } 82 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex8/Thread.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | enum ThreadType { 11 | PRODUCER, 12 | CONSUMER 13 | }; 14 | 15 | class Thread { 16 | private: 17 | static mutex locker; 18 | static condition_variable untilReady; 19 | static bool ready; 20 | static queue appQueue; 21 | thread *pThread; 22 | ThreadType threadType; 23 | bool stopped; 24 | string name; 25 | 26 | void run(); 27 | public: 28 | Thread(ThreadType typeOfThread); 29 | ~Thread(); 30 | void start(); 31 | void stop(); 32 | void join(); 33 | void detach(); 34 | }; 35 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex8/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Thread.h" 2 | 3 | int main ( ) { 4 | 5 | Thread producer( ThreadType::PRODUCER ); 6 | Thread consumer( ThreadType::CONSUMER ); 7 | 8 | producer.start(); 9 | consumer.start(); 10 | 11 | producer.join(); 12 | consumer.join(); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/Multithreading/Ex9/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void sayHello( ) { 6 | cout << endl << "Hello Concurrency support library!" << endl; 7 | } 8 | 9 | int main ( ) { 10 | future futureObj = async ( launch::async, sayHello ); 11 | futureObj.wait( ); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Chapter07/Ex1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter07/Ex1.zip -------------------------------------------------------------------------------- /Chapter07/Ex2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter07/Ex2.zip -------------------------------------------------------------------------------- /Chapter07/Ex3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter07/Ex3.zip -------------------------------------------------------------------------------- /Chapter08/cucumber-cpp.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter08/cucumber-cpp.zip -------------------------------------------------------------------------------- /Chapter09/Chapter09/Debugging application/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; //Use this judiciously - this is applicable throughout the book 6 | 7 | class MyInteger { 8 | private: 9 | int number; 10 | 11 | public: 12 | MyInteger( int value ) { 13 | this->number = value; 14 | } 15 | 16 | MyInteger(const MyInteger & rhsObject ) { 17 | this->number = rhsObject.number; 18 | } 19 | 20 | MyInteger& operator = (const MyInteger & rhsObject ) { 21 | 22 | if ( this != &rhsObject ) 23 | this->number = rhsObject.number; 24 | 25 | return *this; 26 | } 27 | 28 | bool operator < (const MyInteger &rhsObject) { 29 | return this->number > rhsObject.number; 30 | } 31 | 32 | bool operator > (const MyInteger &rhsObject) { 33 | return this->number > rhsObject.number; 34 | } 35 | 36 | friend ostream & operator << ( ostream &output, const MyInteger &object ); 37 | }; 38 | 39 | ostream & operator << (ostream &o, const MyInteger& object) { 40 | o << object.number; 41 | } 42 | 43 | int main ( ) { 44 | 45 | vector v = { 10, 100, 40, 20, 80, 70, 50, 30, 60, 90 }; 46 | 47 | cout << "\nVectors entries before sorting are ..." << endl; 48 | copy ( v.begin(), v.end() , ostream_iterator( cout, "\t" ) ); 49 | cout << endl; 50 | 51 | sort ( v.begin(), v.end() ); 52 | 53 | cout << "\nVectors entries after sorting are ..." << endl; 54 | copy ( v.begin(), v.end() , ostream_iterator( cout, "\t" ) ); 55 | cout << endl; 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /Chapter09/Chapter09/Detecting memory access outside the boundary of an array/arrayboundsoverrun.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main ( ) { 5 | int a[10]; 6 | 7 | a[10] = 100; 8 | cout << a[10] << endl; 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /Chapter09/Chapter09/Mismatched use of new and free or malloc and delete/mismatchingnewandfree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main ( ) { 4 | 5 | int *ptr = new int(); 6 | 7 | free (ptr); // The correct approach is delete ptr 8 | 9 | char *c = (char*)malloc ( sizeof(char) ); 10 | 11 | delete c; // The correct approach is free ( c ) 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Chapter09/Chapter09/already released memory locations/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main( ) { 5 | 6 | int *ptr = new int(); 7 | 8 | *ptr = 100; 9 | 10 | cout << "\nValue stored at pointer location is " << *ptr << endl; 11 | 12 | delete ptr; 13 | 14 | *ptr = 200; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Chapter09/Chapter09/memory leaks/list.cpp: -------------------------------------------------------------------------------- 1 | #include "list.h" 2 | 3 | List::List( ) { 4 | pNewNode = NULL; 5 | pHead = NULL; 6 | pTail = NULL; 7 | __size = 0; 8 | } 9 | 10 | List::~List() {} 11 | 12 | void List::createNewNode( int data ) { 13 | pNewNode = new Node(); 14 | pNewNode->next = NULL; 15 | pNewNode->data = data; 16 | } 17 | 18 | void List::append( int data ) { 19 | createNewNode( data ); 20 | if ( pHead == NULL ) { 21 | pHead = pNewNode; 22 | pTail = pNewNode; 23 | __size = 1; 24 | } 25 | else { 26 | Node *pCurrentNode = pHead; 27 | while ( pCurrentNode != NULL ) { 28 | if ( pCurrentNode->next == NULL ) break; 29 | pCurrentNode = pCurrentNode->next; 30 | } 31 | 32 | pCurrentNode->next = pNewNode; 33 | ++__size; 34 | } 35 | } 36 | 37 | void List::print( ) { 38 | cout << "\nList entries are ..." << endl; 39 | Node *pCurrentNode = pHead; 40 | while ( pCurrentNode != NULL ) { 41 | cout << pCurrentNode->data << "\t"; 42 | pCurrentNode = pCurrentNode->next; 43 | } 44 | cout << endl; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Chapter09/Chapter09/memory leaks/list.h: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Node { 5 | int data; 6 | Node *next; 7 | }; 8 | 9 | class List { 10 | private: 11 | Node *pNewNode; 12 | Node *pHead; 13 | Node *pTail; 14 | int __size; 15 | void createNewNode( int ); 16 | public: 17 | List(); 18 | ~List(); 19 | int size(); 20 | void append ( int data ); 21 | void print( ); 22 | }; 23 | -------------------------------------------------------------------------------- /Chapter09/Chapter09/memory leaks/main.cpp: -------------------------------------------------------------------------------- 1 | #include "list.h" 2 | 3 | int main ( ) { 4 | List l; 5 | 6 | for (int count = 0; count < 5; ++count ) 7 | l.append ( (count+1) * 10 ); 8 | l.print(); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter09/Chapter09/uninitialized memory access/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class MyClass { 5 | private: 6 | int x; 7 | public: 8 | MyClass( ); 9 | void print( ); 10 | }; 11 | 12 | MyClass::MyClass() { 13 | cout << "\nMyClass constructor ..." << endl; 14 | } 15 | 16 | void MyClass::print( ) { 17 | cout << "\nValue of x is " << x << endl; 18 | } 19 | 20 | int main ( ) { 21 | 22 | MyClass obj; 23 | obj.print(); 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Chapter10/OCP/.Item.h.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/.Item.h.swp -------------------------------------------------------------------------------- /Chapter10/OCP/GSTVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include "GSTVisitor.h" 2 | 3 | void GSTVisitor::visit ( Visitable *pItem ) { 4 | price = pItem->getPrice() + (0.18 * pItem->getPrice()); 5 | } 6 | 7 | double GSTVisitor::getPrice() { 8 | return price; 9 | } 10 | -------------------------------------------------------------------------------- /Chapter10/OCP/GSTVisitor.h: -------------------------------------------------------------------------------- 1 | #include "Visitor.h" 2 | #include "Visitable.h" 3 | 4 | class GSTVisitor : public Visitor { 5 | public: 6 | void visit ( Visitable * ); 7 | double getPrice(); 8 | }; 9 | -------------------------------------------------------------------------------- /Chapter10/OCP/GSTVisitor.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/GSTVisitor.o -------------------------------------------------------------------------------- /Chapter10/OCP/Item.cpp: -------------------------------------------------------------------------------- 1 | #include "Item.h" 2 | 3 | Item::Item ( string name, double quantity, double unitPrice ) { 4 | this->name = name; 5 | this->quantity = quantity; 6 | this->unitPrice = unitPrice; 7 | } 8 | 9 | string Item::getDescription() { 10 | return name; 11 | } 12 | 13 | double Item::getQuantity() { 14 | return quantity; 15 | } 16 | 17 | double Item::getPrice() { 18 | return quantity * unitPrice; 19 | } 20 | 21 | void Item::accept ( Visitor *pVisitor ) { 22 | pVisitor->visit ( this ); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter10/OCP/Item.h: -------------------------------------------------------------------------------- 1 | #ifndef __ITEM_H 2 | #define __ITEM_H 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #include "Visitable.h" 9 | #include "Visitor.h" 10 | 11 | class Item : public Visitable { 12 | private: 13 | string name; 14 | double quantity; 15 | double unitPrice; 16 | public: 17 | Item ( string name, double quantity, double unitPrice ); 18 | string getDescription(); 19 | double getQuantity(); 20 | double getPrice(); 21 | void accept ( Visitor *pVisitor ); 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Chapter10/OCP/Item.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/Item.o -------------------------------------------------------------------------------- /Chapter10/OCP/Makefile: -------------------------------------------------------------------------------- 1 | all: GSTVisitor.o Item.o main.o 2 | g++ -o gst.exe GSTVisitor.o Item.o main.o 3 | 4 | GSTVisitor.o: GSTVisitor.cpp Visitable.h Visitor.h 5 | g++ -c GSTVisitor.cpp 6 | 7 | Item.o: Item.cpp 8 | g++ -c Item.cpp 9 | 10 | main.o: main.cpp 11 | g++ -c main.cpp 12 | -------------------------------------------------------------------------------- /Chapter10/OCP/Visitable.h: -------------------------------------------------------------------------------- 1 | #ifndef __VISITABLE_H 2 | #define __VISITABLE_H 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Visitor; 8 | 9 | class Visitable { 10 | public: 11 | virtual void accept ( Visitor * ) = 0; 12 | virtual double getPrice() = 0; 13 | virtual string getDescription() = 0; 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Chapter10/OCP/Visitable.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/Visitable.h.gch -------------------------------------------------------------------------------- /Chapter10/OCP/Visitor.h: -------------------------------------------------------------------------------- 1 | class Visitable; 2 | 3 | #ifndef __VISITOR_H 4 | #define __VISITOR_H 5 | 6 | 7 | class Visitor { 8 | protected: 9 | double price; 10 | 11 | public: 12 | virtual void visit ( Visitable * ) = 0; 13 | virtual double getPrice() = 0; 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Chapter10/OCP/Visitor.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/Visitor.h.gch -------------------------------------------------------------------------------- /Chapter10/OCP/gst.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/gst.exe -------------------------------------------------------------------------------- /Chapter10/OCP/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Item.h" 2 | #include "GSTVisitor.h" 3 | 4 | int main ( ) { 5 | 6 | Item pen("Reynolds Microtib Pen", 2, 10.0); 7 | Item schoolBag("School Bag", 1, 100.0); 8 | Item shoes("Formal Shoe", 2, 500.0); 9 | 10 | GSTVisitor gstVisitor; 11 | 12 | cout << "-----------------------------------------" << endl; 13 | cout << " Bill " << endl; 14 | cout << "-----------------------------------------" << endl; 15 | 16 | pen.accept ( &gstVisitor ); 17 | double totalPurchaseAmount = gstVisitor.getPrice(); 18 | cout << pen.getDescription() << "\t\t is Rs." << gstVisitor.getPrice() << endl; 19 | 20 | schoolBag.accept ( &gstVisitor ); 21 | totalPurchaseAmount = totalPurchaseAmount + gstVisitor.getPrice(); 22 | cout << schoolBag.getDescription() << "\t\t\t is Rs." << gstVisitor.getPrice() << endl; 23 | 24 | shoes.accept ( &gstVisitor ); 25 | totalPurchaseAmount = totalPurchaseAmount + gstVisitor.getPrice(); 26 | cout << shoes.getDescription() << "\t\t\t is Rs." << gstVisitor.getPrice() << endl; 27 | 28 | cout << "-----------------------------------------" << endl; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Chapter10/OCP/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Mastering-Cpp-Programming/7d2c3b533d1e0b7a9ff41df6fe380db89c7e44d2/Chapter10/OCP/main.o -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Mastering C++ Programming 5 | This is the code repository for [Mastering C++ Programming](https://www.packtpub.com/application-development/mastering-c-programming?utm_source=github&utm_medium=repository&utm_campaign=9781786461629), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the book from start to finish. 6 | ## About the Book 7 | C++ has come a long way and has now been adopted in several contexts. Its key strengths are its software infrastructure and resource-constrained applications. The C++ 17 release will change the way developers write code, and this book will help you master your developing skills with C++. With real-world, practical examples explaining each concept, the book will begin by introducing you to the latest features in C++ 17. It encourages clean code practices in C++ in general, and demonstrates the GUI app-development options in C++. You’ll get tips on avoiding memory leaks using smart-pointers. Next, you’ll see how multi-threaded programming can help you achieve concurrency in your applications. Moving on, you’ll get an in-depth understanding of the C++ Standard Template Library. We show you the concepts of implementing TDD and BDD in your C++ programs, and explore template-based generic programming, giving you the expertise to build powerful applications. Finally, we’ll round up with debugging techniques and best practices.By the end of the book, you’ll have an in-depth understanding of the language and its various facets. 8 | ## Instructions and Navigation 9 | All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02. 10 | 11 | 12 | 13 | The code will look like the following: 14 | ``` 15 | #include 16 | #include 17 | #include 18 | #include "Account.h" 19 | using namespace std; 20 | enum ThreadType { 21 | DEPOSITOR, 22 | WITHDRAWER 23 | }; 24 | mutex locker; 25 | ``` 26 | 27 | You will need to be equipped with the following tools before you get started with the book: 28 | g++ compiler of version 5.4.0 20160609 or above 29 | GDB 7.11.1 30 | Valgrind 3.11.0 31 | Cucumber-cpp Git 2.7.4 32 | Google test framework (gtest 1.6 or later) 33 | CMake 3.5.1 34 | Ruby 2.5.1 35 | Qt 5.7.0 36 | Bundler v 1.14.6 37 | The OS required is Ubuntu 16.04 64-bit or later. The hardware configuration should at least be of 1 GB RAM and 20 GB disk space. A virtual machine with this configuration should also suffice. 38 | 39 | ## Related Products 40 | * [Mastering C++ Multithreading](https://www.packtpub.com/application-development/mastering-c-multithreading?utm_source=github&utm_medium=repository&utm_campaign=9781787121706) 41 | 42 | * [Mastering C# and .NET Framework](https://www.packtpub.com/application-development/mastering-c-and-net-framework?utm_source=github&utm_medium=repository&utm_campaign=9781785884375) 43 | 44 | * [Mastering Cassandra [Video]](https://www.packtpub.com/big-data-and-business-intelligence/mastering-cassandra-video?utm_source=github&utm_medium=repository&utm_campaign=9781784396381) 45 | 46 | ### Download a free PDF 47 | 48 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
49 |
--------------------------------------------------------------------------------

https://packt.link/free-ebook/9781786461629