├── .gitignore ├── CCppBookCode ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ ├── FxFor.h │ ├── PointFor.h │ ├── RevertEndianness.h │ ├── main_declarations.h │ └── range.h └── src │ ├── CRC.cpp │ ├── Calendar_struct.cpp │ ├── ClassRelations.cpp │ ├── Dec2Roman.cpp │ ├── EventSystems.cpp │ ├── FileSystem.cpp │ ├── FixedPtArithm.cpp │ ├── FloatingPoint.cpp │ ├── Functions.cpp │ ├── Functions_Lambdas.cpp │ ├── InnerProduct.cpp │ ├── Miscellany.cpp │ ├── NewtonZero.cpp │ ├── OperatorReview.cpp │ ├── Pointers.cpp │ ├── References.cpp │ ├── STLExamples.cpp │ ├── SmartPointers.cpp │ ├── StatementReview.cpp │ ├── Time.cpp │ ├── TinyCube.cpp │ ├── VarConstArray.cpp │ ├── Variables.cpp │ ├── VectorsStringsArrays.cpp │ ├── VirtualMechanisms.cpp │ ├── letter_histogram.cpp │ ├── main.cpp │ ├── range_test.cpp │ └── tuple_vs_struct.cpp ├── CPro ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt └── src │ ├── main.c │ ├── string_test.c │ ├── struct_test.c │ └── union_test.c ├── CompInterest ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt └── src │ └── main.cpp ├── Complex ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ └── Complex.h └── src │ ├── Complex.cpp │ ├── ComplexTest.cpp │ └── main.cpp ├── ComplexQuadEq ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ └── ComplexQuadEq.h └── src │ ├── ComplexQuadEq.cpp │ ├── ComplexQuadEqTest.cpp │ └── main.cpp ├── CurrencyCalc ├── CMakeLists.txt ├── CurrencyCalc_Lib │ ├── CMakeLists.txt │ ├── ReadMe.txt │ ├── build_linux │ │ └── Info.txt │ ├── build_mac │ │ └── Info.txt │ ├── build_win │ │ └── Info.txt │ ├── include │ │ ├── Currency.h │ │ ├── CurrencyCalcPlayGround.h │ │ ├── CurrencyExchanger.h │ │ ├── HTTP_File.h │ │ └── XML_CurrencyExchanger.h │ ├── lib │ │ └── CurrencyCalc_Lib.lib │ └── src │ │ ├── Currency.cpp │ │ ├── CurrencyCalcPlayGround.cpp │ │ ├── CurrencyExchanger.cpp │ │ ├── HTTP_File.cpp │ │ └── XML_CurrencyExchanger.cpp ├── CurrencyCalc_Terminal │ ├── CMakeLists.txt │ ├── ReadMe.txt │ ├── build_linux │ │ └── Info.txt │ ├── build_mac │ │ └── Info.txt │ ├── build_win │ │ └── Info.txt │ └── src │ │ └── main.cpp ├── CurrencyCalc_WindowGUI │ ├── CMakeLists.txt │ ├── ReadMe.txt │ ├── build_linux │ │ └── Info.txt │ ├── build_mac │ │ └── Info.txt │ ├── build_win │ │ └── Info.txt │ ├── include │ │ ├── CloseWindow.h │ │ ├── CurCalc_GUI.h │ │ └── StringConverters.h │ └── src │ │ ├── CloseWindow.cpp │ │ ├── CurCalc_GUI.cpp │ │ └── main.cpp └── ReadMe.txt ├── EasyMatrix ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ ├── EMUtility.h │ ├── EMatrix.h │ └── MarsXorShift.h └── src │ ├── EMTest.cpp │ ├── EMUtility.cpp │ ├── EMatrix.cpp │ └── main.cpp ├── EmptyPro ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ ├── Info.txt │ └── MacReadMe.txt ├── build_win │ └── Info.txt ├── include │ └── empty.h └── src │ ├── empty.cpp │ └── main.cpp ├── FLTK └── FLTK_ReadMe.txt ├── FixBinCalc ├── EnterNewValueDialog.cpp ├── EnterNewValueDialog.h ├── FixBinCalc.cpp ├── FixBinCalc.dsp ├── FixBinCalc.dsw ├── FixBinCalc.h ├── FixBinCalc.rc ├── FixBinCalc.sln ├── FixBinCalc.vcxproj ├── FixBinCalc.vcxproj.filters ├── FixBinCalc.vcxproj.user ├── FixBinCalcDlg.cpp ├── FixBinCalcDlg.h ├── ReadMe.txt ├── Release │ └── FixBinCalc.exe ├── StdAfx.cpp ├── StdAfx.h ├── res │ ├── BoxySoft.bmp │ ├── FixBinCalc.ico │ └── FixBinCalc.rc2 └── resource.h ├── Grades ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt └── src │ └── main.cpp ├── LongNumber ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ ├── Derived_PESEL.h │ ├── Embedded_PESEL.h │ └── LongNumberFor.h └── src │ ├── Derived_PESEL_Test.cpp │ ├── Embedded_PESEL_Test.cpp │ ├── LongNumber_Test.cpp │ └── main.cpp ├── ParallelCores ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ ├── EMUtility.h │ ├── EMatrix.h │ ├── MarsXorShift.h │ └── range.h └── src │ ├── EMTest_ParAlg.cpp │ ├── EMUtility_ParAlg.cpp │ ├── EMatrix.cpp │ ├── InnerProduct_ParAlg.cpp │ ├── OpenMPExamples.cpp │ └── main.cpp ├── Parser ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ ├── ExpressionTreeBuilderInterpreter.h │ ├── Nodes.h │ ├── SimpleExpressionInterpreter.h │ ├── TheStack.h │ ├── Visitors.h │ └── range.h └── src │ ├── ExpressionParser_Test.cpp │ ├── NodeStackConverters.cpp │ ├── Nodes.cpp │ ├── Visitors.cpp │ └── main.cpp ├── QuadEq ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ └── QuadEq.h └── src │ ├── QuadEq.cpp │ └── main.cpp ├── README.md ├── RomanAppSuite ├── RomanApp │ ├── CMakeLists.txt │ ├── ReadMe.txt │ ├── build_linux │ │ └── Info.txt │ ├── build_mac │ │ └── Info.txt │ ├── build_win │ │ └── Info.txt │ ├── include │ │ └── Dec2Roman.h │ └── src │ │ ├── Dec2Roman.cpp │ │ └── main.cpp └── RomanApp_GTest │ ├── CMakeLists.txt │ ├── ReadMe.txt │ ├── build_linux │ └── Info.txt │ ├── build_mac │ ├── Info.txt │ └── MacReadMe.txt │ ├── build_win │ └── Info.txt │ ├── include │ └── pch.h │ ├── packages │ └── Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1 │ │ ├── ThirdPartyNotices.txt │ │ ├── build │ │ └── native │ │ │ ├── Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.propertiesui.xml │ │ │ ├── Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets │ │ │ └── include │ │ │ └── gtest │ │ │ ├── gtest-death-test.h │ │ │ ├── gtest-message.h │ │ │ ├── gtest-param-test.h │ │ │ ├── gtest-param-test.h.pump │ │ │ ├── gtest-printers.h │ │ │ ├── gtest-spi.h │ │ │ ├── gtest-test-part.h │ │ │ ├── gtest-typed-test.h │ │ │ ├── gtest.h │ │ │ ├── gtest_pred_impl.h │ │ │ ├── gtest_prod.h │ │ │ └── internal │ │ │ ├── custom │ │ │ ├── README.md │ │ │ ├── gtest-port.h │ │ │ ├── gtest-printers.h │ │ │ └── gtest.h │ │ │ ├── gtest-death-test-internal.h │ │ │ ├── gtest-filepath.h │ │ │ ├── gtest-internal.h │ │ │ ├── gtest-linked_ptr.h │ │ │ ├── gtest-param-util-generated.h │ │ │ ├── gtest-param-util-generated.h.pump │ │ │ ├── gtest-param-util.h │ │ │ ├── gtest-port-arch.h │ │ │ ├── gtest-port.h │ │ │ ├── gtest-string.h │ │ │ ├── gtest-tuple.h │ │ │ ├── gtest-tuple.h.pump │ │ │ ├── gtest-type-util.h │ │ │ └── gtest-type-util.h.pump │ │ ├── lib │ │ └── native │ │ │ └── v140 │ │ │ └── windesktop │ │ │ └── msvcstl │ │ │ └── static │ │ │ └── rt-dyn │ │ │ ├── x64 │ │ │ ├── Debug │ │ │ │ ├── gtest_maind.lib │ │ │ │ └── gtestd.lib │ │ │ └── Release │ │ │ │ ├── gtest.lib │ │ │ │ └── gtest_main.lib │ │ │ └── x86 │ │ │ ├── Debug │ │ │ ├── gtest_maind.lib │ │ │ └── gtestd.lib │ │ │ └── Release │ │ │ ├── gtest.lib │ │ │ └── gtest_main.lib │ │ └── license (MIT).txt │ └── src │ ├── pch.cpp │ └── test.cpp ├── TheCube ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux │ └── Info.txt ├── build_mac │ └── Info.txt ├── build_win │ └── Info.txt ├── include │ └── TheCube.h └── src │ ├── TheCube.cpp │ ├── TheCubeTest.cpp │ └── main.cpp └── TheStack ├── CMakeLists.txt ├── ReadMe.txt ├── build_linux └── Info.txt ├── build_mac └── Info.txt ├── build_win └── Info.txt ├── include ├── TheStack.h └── range.h └── src ├── TheStackTest.cpp └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Defines the files and directories to be ignored by Git 2 | # 3 | # Defined by Boguslaw Cyganek to the repository of the book: 4 | # Introduction to Programming with C++ for Engineers 5 | # by Wiley 2020 6 | 7 | # This works as follows: 8 | # Blank lines or the ones starting with hash # are ignored 9 | # The standard regular expressions, such as *.obj work 10 | # Start a pattern with a forward slash / to avoid recursivity 11 | # End a pattern with a forward slash / to specify a directory 12 | # Start a pattern with an exclamation point ! to negate a pattern 13 | 14 | 15 | # Exclude these directories: 16 | 17 | build_linux/ 18 | build_win/ 19 | build_mac/ 20 | 21 | FLTK/ 22 | 23 | -------------------------------------------------------------------------------- /CCppBookCode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CppBookCode ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /CCppBookCode/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CCppBookCode/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CCppBookCode/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CCppBookCode/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CCppBookCode/include/PointFor.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | // Template members within a template class example 15 | template < typename T > 16 | class TPointFor 17 | { 18 | 19 | private: 20 | 21 | T fx {}, fy {}; // Two coordinates of T type 22 | 23 | 24 | public: 25 | 26 | void Set_x( T x ) { fx = x; } 27 | void Set_y( T y ) { fy = y; } 28 | 29 | auto Get_x( void ) const { return fx; } 30 | auto Get_y( void ) const { return fy; } 31 | 32 | public: 33 | 34 | 35 | // A template member copy constructor to initialize 36 | // from a point with different coordinate types. 37 | // To be general must call Get_x and Get_y 38 | // Direct access possible only if T == U 39 | template < typename U > 40 | TPointFor< T >( const TPointFor< U > & pt ) : fx( pt.Get_x() ), fy( pt.Get_y() ) {} 41 | 42 | // A template member assignment operator to to initialize 43 | // from a point with different coordinate types. 44 | template < typename U > 45 | TPointFor< T > & operator = ( const TPointFor< U > & pt ) 46 | { 47 | //fx = pt.fx; these two work only 48 | //fy = pt.fy; if T == U 49 | fx = pt.Get_x(); // allow conversion 50 | fy = pt.Get_y(); 51 | return * this; 52 | } 53 | 54 | 55 | // A default constructor needs to be explicitly coded 56 | // since the copy constructor and the assignment were added 57 | // (otherwise could be skipped). 58 | //TPointFor( void ) : fx( T() ), fy( T() ) {} 59 | TPointFor( void ) = default; 60 | }; 61 | 62 | 63 | 64 | inline void PointTest( void ) 65 | { 66 | 67 | using RealPoint = TPointFor< double >; 68 | 69 | using IntPoint = TPointFor< int >; 70 | 71 | 72 | RealPoint rp1, rp2; // Calls default constructor 73 | 74 | IntPoint ip1, ip2; // Calls default constructor 75 | 76 | 77 | rp1 = rp2; // Assignment within the same clas 78 | // - no special template assignment needed 79 | 80 | rp1 = ip2; // Assignment across different classes 81 | // - special template assignment necessary 82 | 83 | RealPoint rp3( ip1 ); // Also copy construction across the different classes 84 | } 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /CCppBookCode/include/RevertEndianness.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include 15 | #include // for is_unsigned_v 16 | 17 | 18 | 19 | /////////////////////////////////////////////////////////// 20 | // Template function to change endianness of integer types 21 | // i.e. it reverts order of bytes in the input arg. 22 | // Example: 0x78ABCDEF will be changed to 0xEFCDAB78 23 | /////////////////////////////////////////////////////////// 24 | // 25 | // INPUT: 26 | // in - integer like type 27 | // OUTPUT: 28 | // byte reversed version of in 29 | // 30 | // REMARKS: 31 | // 32 | // 33 | template < typename T > 34 | constexpr auto RevertEndianness( T in ) 35 | { 36 | //static_assert( std::is_unsigned< T >::value ); 37 | static_assert( std::is_unsigned_v< T > ); 38 | 39 | T out { 0 }; 40 | for( auto i { 0 }; i < sizeof( in ); ++ i ) // rotate bytes 41 | { 42 | out <<= 8; 43 | out |= in & 0xFF; 44 | in >>= 8; 45 | } 46 | return out; 47 | } 48 | 49 | 50 | 51 | inline void RevertEndianness_Test( void ) 52 | { 53 | // RevertEndianness can be computed in the compilation time 54 | // Notice 'u' in 0xABCDu - this makes 0xABCD an unsigned constant 55 | std::cout << std::hex << std::uppercase << "ABCD" << "\t <-> " 56 | << RevertEndianness( 0xABCDu ) << std::endl; 57 | 58 | // Compilation time since argument is constexpr 59 | constexpr unsigned int ui { 0xABCDu }; 60 | std::cout << std::hex << std::uppercase << ui << "\t <-> " 61 | << RevertEndianness( ui ) << std::endl; 62 | 63 | long l { 0x01234567 }; 64 | // This will not compile since l is not an 'unsigned' type 65 | //std::cout << std::hex << l << "\t <-> " 66 | // << RevertEndianness( l ) << std::endl; 67 | 68 | unsigned long ul { 0x01234567ul }; 69 | std::cout << std::hex << std::uppercase << ul << "\t <-> " 70 | << RevertEndianness( ul ) << std::endl; 71 | 72 | unsigned long long ull { 0x0123456789ABCDEFull }; 73 | std::cout << std::hex << std::uppercase << ull << "\t <-> " 74 | << RevertEndianness( ull ) << std::endl; 75 | } 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /CCppBookCode/src/CRC.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include 15 | #include 16 | 17 | 18 | 19 | ///////////////////////////////////////////////////////////////// 20 | // Returns a remainder of the CRC sum. 21 | ///////////////////////////////////////////////////////////////// 22 | // 23 | // INPUT: crc - previously computed crc value 24 | // byte - new value to be reflected by the new crc 25 | // 26 | // OUTPUT: new crc value 27 | // 28 | // REMARKS: 29 | // At the beginning the crc parameter should be set to 0. 30 | // The function counts 8-bit CRC for transmission of bytes 31 | // 32 | unsigned char CalcCRC( unsigned char crc, unsigned char byte ) 33 | { 34 | // A representation of the polynomial with bits reversed and omitted MSBit==1 35 | const unsigned short kPoly = 0xE0; 36 | 37 | unsigned short x { crc }; 38 | x ^= byte; 39 | 40 | // Check each bit of x 41 | const auto kBitsInByte { 8 }; 42 | for( auto count { 0 }; count < kBitsInByte; ++ count ) 43 | { 44 | bool carry = ( x & 1 ) != 0; 45 | x = ( x >> 1 ) & 0x7fff; // Shift right and mask 46 | if( carry ) 47 | x ^= kPoly; // XOR with the polynomial 48 | } 49 | 50 | return x & 0xFF; // Return CRC as a single byte 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | void CRC_Test( void ) 60 | { 61 | 62 | std::vector< unsigned char > data { 1, 7, 13, 7, 0, 0, 5, 55, 100 }; 63 | 64 | unsigned char crc { 0 }; 65 | 66 | for( auto d : data ) 67 | crc = CalcCRC( crc, d ); 68 | 69 | 70 | // To verify, if done again, the result should be 0 71 | data.push_back( crc ); 72 | crc = 0; 73 | for( auto d : data ) 74 | crc = CalcCRC( crc, d ); 75 | 76 | assert( crc == 0 ); 77 | 78 | // Simulate a bit error in the buffer 79 | data[ data.size() / 2 ] ^= 0x10; 80 | 81 | crc = 0; 82 | for( auto d : data ) 83 | crc = CalcCRC( crc, d ); 84 | 85 | assert( crc != 0 ); 86 | 87 | 88 | } 89 | 90 | 91 | // -------------------------------------------------------- 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /CCppBookCode/src/Calendar_struct.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | // Joins two different objects under one roof 21 | struct MonthDays 22 | { 23 | std::string fName {}; // Always use {} to initialize data members. 24 | int fDays {}; // Empty {} initialize to 0. 25 | }; 26 | 27 | 28 | // Creates and displays a simple calendar 29 | void SimpleCalendar( void ) 30 | { 31 | const std::vector< MonthDays > calendar { 32 | { "January", 31 }, 33 | { "February", 28 }, 34 | { "March", 31 }, 35 | { "April", 30 }, 36 | { "May", 31 }, 37 | { "June", 30 }, 38 | { "July", 31 }, 39 | { "August", 31 }, 40 | { "September", 30 }, 41 | { "October", 31 }, 42 | { "November", 30 }, 43 | { "December", 31 } 44 | 45 | }; 46 | 47 | // Print them on the screen 48 | auto sum_days { 0 }; 49 | for( auto month : calendar ) 50 | { 51 | sum_days += month.fDays; 52 | std::cout << month.fName << " has " << month.fDays << " days\n"; 53 | } 54 | 55 | std::cout << "\nTotal days: " << sum_days << std::endl; 56 | } 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /CCppBookCode/src/FloatingPoint.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/FloatingPoint.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/STLExamples.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | using namespace std; 21 | 22 | 23 | void iterators_ex( void ) 24 | { 25 | string str { "The quick brown fox." }; 26 | 27 | // Copy string to the screen 28 | copy( str.begin(), str.end(), ostream_iterator< string::value_type >( cout ) ); 29 | cout << endl; 30 | 31 | // Copy string to the screen 32 | // cbegin is const begin 33 | copy( str.cbegin(), str.cend(), ostream_iterator< string::value_type >( cout ) ); 34 | cout << endl; 35 | 36 | // Copy string in reverse order to the screen 37 | // rbegin is reverse begin 38 | copy( str.rbegin(), str.rend(), ostream_iterator< string::value_type >( cout ) ); 39 | cout << endl; 40 | 41 | 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CCppBookCode/src/SmartPointers.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/SmartPointers.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/StatementReview.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/StatementReview.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/TinyCube.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/TinyCube.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/VarConstArray.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/VarConstArray.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/Variables.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/Variables.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/letter_histogram.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CCppBookCode/src/letter_histogram.cpp -------------------------------------------------------------------------------- /CCppBookCode/src/range_test.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "range.h" 22 | 23 | 24 | 25 | 26 | using std::cout, std::endl; 27 | using std::vector; 28 | 29 | 30 | using CppBook::range; 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////// 33 | 34 | 35 | void RangeTest( void ) 36 | { 37 | std::ofstream ostr( "RangeTest.txt" ); 38 | if( ostr.is_open() == false ) 39 | return; 40 | 41 | // 1: 42 | ostr << "1st test:" << endl; 43 | 44 | vector< float > v = range( 256.0f ); 45 | std::copy( v.begin(), v.end(), std::ostream_iterator< float >( ostr, ", " ) ); 46 | 47 | // 2: 48 | ostr << endl << "2nd test:" << endl; 49 | 50 | const unsigned int rr { 5 }; 51 | vector< size_t > v_size_t( range<>( 0, 100, 13 ) ); 52 | for( auto a : v_size_t ) 53 | ostr << a << ", "; 54 | 55 | // 3: 56 | ostr << endl << "3rd test:" << endl; 57 | 58 | auto vvv = range( 123 ); // 0..122 inclusive, with step 1 59 | for( auto a : vvv ) 60 | ostr << a << ", "; 61 | 62 | // 4: 63 | ostr << endl << "4th test:" << endl; 64 | 65 | // Can be used in the nested loops as well 66 | for( auto i : range( 0.0, 256.0, 16.5 ) ) // Must be the same type, 0.0 not 0 67 | { 68 | for( auto j : range( -2, +16, 3 ) ) 69 | { 70 | ostr << j << ", "; 71 | } 72 | ostr << endl << i << endl; 73 | } 74 | 75 | } 76 | 77 | 78 | /////////////////////////////////////////////////////////////////////////////////////////////// 79 | 80 | 81 | -------------------------------------------------------------------------------- /CCppBookCode/src/tuple_vs_struct.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | 21 | 22 | 23 | 24 | using std::tuple, std::get, std::tie, std::tuple_size, std::make_tuple, std::ignore; 25 | using std::cout, std::endl; 26 | using std::string; 27 | 28 | 29 | 30 | 31 | 32 | void tuple_vs_struct( void ) 33 | { 34 | // ----------------------------- 35 | { 36 | // Let's store a date in a tuple 37 | // day month year 38 | tuple< int, string, int > t_date( 27, "June", 2019 ); 39 | 40 | // It can be easier with make_tuple 41 | auto t_date_2 = make_tuple( 27, "June", 2019 ); 42 | 43 | // tuple_size<>::value returns the number of elements 44 | cout << "t_date has " << tuple_size< decltype(t_date) >::value 45 | << " elems" << endl; 46 | 47 | // Print the elements 48 | cout << "D/M/Y:" << get< 0 >( t_date ) << "/" << 49 | get< 1 >( t_date ) << "/" << 50 | get< 2 >( t_date ) << endl; 51 | 52 | // Retrieve the elements to separate objects 53 | // with the structured binding 54 | const auto [ d, m, y ] = t_date; 55 | 56 | // Print the elements 57 | cout << "D/M/Y:" << d << "/" << 58 | m << "/" << y << endl; 59 | 60 | // Use tie with ingore to retrieve a few elements 61 | int dd {}; 62 | string mm {}; 63 | 64 | // Retrieve only day and month, ignore the year 65 | tie( dd, mm, ignore ) = t_date; 66 | 67 | // Print the elements 68 | cout << "D/M:" << dd << "/" << mm << endl; 69 | 70 | } 71 | 72 | // ------------------------------ 73 | { 74 | // The same with struct with no name 75 | struct 76 | { 77 | // Each field has its name 78 | int fDay { 27 }; 79 | string fMonth { "June" }; 80 | int fYear { 2019 }; 81 | } s_date; 82 | 83 | // We cannot enumerate a struct, 84 | // just provide its field names. 85 | 86 | // Print the elements 87 | cout << "D/M/Y:" << s_date.fDay << "/" << 88 | s_date.fMonth << "/" << 89 | s_date.fYear << endl; 90 | 91 | 92 | // Retrieve the elements to separate objects 93 | // with the structured binding 94 | const auto [ d, m, y ] = s_date; 95 | 96 | // Print the elements 97 | cout << "D/M/Y:" << d << "/" << 98 | m << "/" << y << endl; 99 | 100 | } 101 | 102 | } 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /CPro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CPro ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | if( WIN32 ) 13 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 14 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 15 | message( "Win settings chosen..." ) 16 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 17 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 18 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 19 | message( "Mac settings chosen..." ) 20 | elseif( UNIX ) 21 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 22 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 23 | message( "Linux settings chosen..." ) 24 | endif() 25 | 26 | 27 | # Inform CMake where the header files are 28 | include_directories( include ) 29 | 30 | 31 | # Automatically add all *.cpp and *.h files to the project 32 | file ( GLOB SOURCES "./src/*.c" "./include/*.h" ) 33 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 34 | 35 | # Set the default project 36 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 37 | 38 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 39 | -------------------------------------------------------------------------------- /CPro/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CPro/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CPro/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CPro/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CPro/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | // ========================================================================== 4 | // 5 | // Software written by Boguslaw Cyganek (C) to be used with the book: 6 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 7 | // Published by Wiley, 2020 8 | // 9 | // The software is supplied as is and for educational purposes 10 | // without any guarantees nor responsibility of its use in any application. 11 | // 12 | // ========================================================================== 13 | 14 | */ 15 | 16 | 17 | #include 18 | #include 19 | 20 | 21 | 22 | /* Function declaration. */ 23 | void ToBinConvert( int val ); 24 | 25 | 26 | /* The CProg converts a decimalvalue into an 27 | equivalent in one the bases: oct, bin, hex. 28 | Param no. 1 is a decimal integer value. 29 | An optional param no. 2 is the output base "oct", "bin", "hex" 30 | If not provided, then the same value is displayed. */ 31 | 32 | 33 | /* C program starts with the main function (assumed C99) */ 34 | int main( int argc, char ** argv ) 35 | { 36 | 37 | printf( "Value converter. Calling format:\nCPro.exe dec_val [bin,oct,hex]\n" ); 38 | 39 | switch( argc ) /* argc conveys the number of arguments */ 40 | { 41 | case 2: 42 | 43 | { /* Only one param - display as it is */ 44 | int val = atoi( argv[ 1 ] ); /* Converts ASCII to int */ 45 | printf( "%d [dec] = %d [dec]\n", val, val ); 46 | } 47 | 48 | break; 49 | 50 | case 3: 51 | 52 | { /* Two params */ 53 | int val = atoi( argv[ 1 ] ); 54 | char * base = argv[ 2 ]; 55 | 56 | /* For the base we need to check only its first letter */ 57 | switch( base[ 0 ] ) 58 | { 59 | case 'h': /* check lowercase */ 60 | case 'H': /* and uppercase at the same time */ 61 | 62 | /* printf will do conversion for us */ 63 | printf( "%d [dec] = 0x%x [hex]\n", val, val ); 64 | break; 65 | 66 | case 'o': 67 | case 'O': 68 | 69 | /* printf will do the conversion for us */ 70 | printf( "%d [dec] = 0%o [oct]\n", val, val ); 71 | 72 | break; 73 | 74 | case 'b': 75 | case 'B': 76 | 77 | /* Here we need to do the conversion ourselves */ 78 | printf( "%d [dec] = ", val ); 79 | ToBinConvert( val ); 80 | printf( " [bin]\n" ); 81 | 82 | break; 83 | 84 | default: 85 | 86 | printf( "Wrong name param. Should be one of: [bin,oct,hex]\n" ); 87 | break; 88 | 89 | } 90 | 91 | } 92 | 93 | break; 94 | 95 | default: 96 | 97 | printf( "Call with 1 or 2 params.\nCPro dec_val [hex,oct,bin]\n" ); 98 | break; 99 | 100 | } 101 | 102 | return 0; /* Return value 0 indicates SUCCESS. */ 103 | } 104 | 105 | 106 | /* Recursivly print bits in reverse order thanks to recursion. */ 107 | void ToBinConvert( int val ) 108 | { 109 | if( val > 1 ) 110 | ToBinConvert( val >> 1 ); /* Recursive call */ 111 | 112 | printf( "%d", val & 0x01 ); /* Print the last bit */ 113 | } 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /CPro/src/struct_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | // ========================================================================== 4 | // 5 | // Software written by Boguslaw Cyganek (C) to be used with the book: 6 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 7 | // Published by Wiley, 2020 8 | // 9 | // The software is supplied as is and for educational purposes 10 | // without any guarantees nor responsibility of its use in any application. 11 | // 12 | // ========================================================================== 13 | 14 | */ 15 | 16 | 17 | #include 18 | #include 19 | 20 | 21 | 22 | /* Simple struct to store coeffs of the quadratic equation */ 23 | struct QE 24 | { 25 | float a, b, c; 26 | }; 27 | 28 | /* struct QE is a tag and we need to introduce the type QE */ 29 | /* The name of a struct is a tag, rather than the type. */ 30 | typedef struct QE QE; 31 | 32 | 33 | 34 | 35 | /* Initialize QE to 0 */ 36 | void Init_0( QE * qe ) 37 | { 38 | qe->a = 0.0; 39 | qe->b = 0.0; 40 | qe->c = 0.0; 41 | } 42 | 43 | /* Initialize QE to values */ 44 | void Init( QE * qe, float a, float b, float c ) 45 | { 46 | qe->a = a; 47 | qe->b = b; 48 | qe->c = c; 49 | } 50 | 51 | 52 | 53 | 54 | /* Computes a discriminant of the quadratic equation */ 55 | float ComputeDelta( QE * qe ) 56 | { 57 | return qe->b * qe->b - 4.0 * qe->a * qe->c; 58 | } 59 | 60 | 61 | 62 | /* Function to test the behavior of QE */ 63 | void Test_QE( void ) 64 | { 65 | /* These objects are not initialized */ 66 | QE eq_1; 67 | QE eq_2; 68 | 69 | /* Initialize eq_1 to 0 */ 70 | Init_0( & eq_1 ); 71 | Init_0( & eq_2 ); 72 | 73 | 74 | float a = 0.0, b = 0.0, c = 0.0; 75 | 76 | /* Read 3 params from the keyboard. scanf accepts pointers, so & is used */ 77 | scanf( "%f%f%f", & a, & b, & c ); 78 | 79 | /* Directly set data members of eq_2 */ 80 | eq_2.a = a; 81 | eq_2.b = b; 82 | eq_2.c = c; 83 | 84 | /* Compute a discriminant */ 85 | float delta = ComputeDelta( & eq_2 ); 86 | 87 | /* Print delta on the screen */ 88 | printf( "delta=%lf\n", delta ); 89 | 90 | } 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /CPro/src/union_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | // ========================================================================== 4 | // 5 | // Software written by Boguslaw Cyganek (C) to be used with the book: 6 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 7 | // Published by Wiley, 2020 8 | // 9 | // The software is supplied as is and for educational purposes 10 | // without any guarantees nor responsibility of its use in any application. 11 | // 12 | // ========================================================================== 13 | 14 | */ 15 | 16 | 17 | #include 18 | #include 19 | 20 | 21 | 22 | 23 | void C_UnionTest( void ) 24 | { 25 | union LFValue 26 | { 27 | long fLongVal; 28 | double fDoubleVal; 29 | } LF_Obj = { 0 }; /* Create LF_obj and init to 0 */ 30 | 31 | /* With a union we gain size */ 32 | printf( "s_long = %d, s_float = %d, s_LFValue = %d\n", sizeof( long ), sizeof( double ), sizeof( union LFValue ) ); 33 | 34 | /* From LF_Obj we can use only one field at a time */ 35 | LF_Obj.fLongVal = 120; /* now we use LF_Obj as long */ 36 | 37 | /* Print the bytes */ 38 | int i = 0; 39 | printf( "\nBytes of LF_Obj.fLongVal = 120\n" ); 40 | for( i = 0; i < sizeof( union LFValue ); ++ i ) 41 | printf( "%x\t", * ( (unsigned char*)& LF_Obj + i ) ); 42 | 43 | LF_Obj.fDoubleVal = 120.0; /* Now we use LF_Obj as a float */ 44 | 45 | printf( "\nBytes of LF_Obj.fDoubleVal = 120.0\n" ); 46 | for( i = 0; i < sizeof( union LFValue ); ++ i ) 47 | printf( "%x\t", * ( (unsigned char*)& LF_Obj + i ) ); 48 | 49 | /* However, type punning through a union is not recommended */ 50 | /*printf( "\nfLongVal = %ld, fDoubleVal = %lf\n", LF_Obj.fLongVal, LF_Obj.fDoubleVal );*/ 51 | 52 | } 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /CompInterest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CompInterest ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | # Uncomment this to stop building the ZERO_CHECK project 9 | set( CMAKE_SUPPRESS_REGENERATION true ) 10 | 11 | set( CMAKE_BUILD_TYPE Debug ) 12 | #set( CMAKE_BUILD_TYPE Release ) 13 | 14 | 15 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 16 | 17 | if( WIN32 ) 18 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 19 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 20 | message( "Win settings chosen..." ) 21 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 22 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 23 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 24 | message( "Mac settings chosen..." ) 25 | elseif( UNIX ) 26 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 27 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 28 | message( "Linux settings chosen..." ) 29 | endif() 30 | 31 | 32 | # Inform CMake where the header files are 33 | include_directories( include ) 34 | 35 | 36 | # Automatically add all *.cpp and *.h files to the project 37 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 38 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 39 | 40 | 41 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 42 | -------------------------------------------------------------------------------- /CompInterest/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CompInterest/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CompInterest/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CompInterest/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CompInterest/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include 15 | 16 | 17 | 18 | // Introduce names of the I/O objects from the std namespace 19 | using std::cout, std::cin, std::endl; 20 | 21 | 22 | // This program computes the compound interest rate 23 | // 24 | int main() 25 | { 26 | 27 | // ---------------------------------------------------- 28 | cout << "Enter the initial amount to invest: " << endl; 29 | double C_0 {}; 30 | cin >> C_0; 31 | 32 | 33 | if( C_0 <= 0.0 ) 34 | { 35 | cout << "Wrong value, exiting..." << endl; 36 | return -1; 37 | } 38 | 39 | // ------------------------------------------- 40 | cout << "Enter the annual rate [% per 12 months]: " << endl; 41 | double r {}; 42 | cin >> r; 43 | if( r <= 0.0 || r >= 100.0 ) 44 | { 45 | cout << "Wrong value, exiting..." << endl; 46 | return -1; 47 | } 48 | 49 | // ------------------------------------------- 50 | cout << "Compound frequency is a period in months between computing interest" << endl; 51 | cout << "(e.g. if 2 times a year, enter 6)" << endl; 52 | cout << "If you don't know, enter 12 for a yearly compound frequency." << endl; 53 | cout << "Enter the compound frequency [months 1-72]: " << endl; 54 | double t {}; 55 | cin >> t; 56 | if( t <= 0.0 || t > 72.0 ) 57 | { 58 | cout << "Wrong value, exiting..." << endl; 59 | return -1; 60 | } 61 | // --------------------------------------------------- 62 | cout << "Enter the investment time [months 1-100]: " << endl; 63 | double m {}; 64 | cin >> m; 65 | if( m <= 0.0 || m > 100 ) 66 | { 67 | cout << "Wrong value, exiting..." << endl; 68 | return -1; 69 | } 70 | 71 | // ------------------------------ 72 | // Do computations 73 | 74 | const double kMontsPerYear = 12.0; 75 | const double kPercentageDiv = 100.0; 76 | 77 | double i = m / t; // compounding periods 78 | 79 | double C_i = C_0 * std::pow( ( 1.0 + ( r / kPercentageDiv ) / kMontsPerYear * t ), i ); 80 | 81 | cout << "Your balance before tax, after " << m; 82 | cout << " months of investment is: " << C_i << endl; 83 | 84 | // Compute the net income 85 | double income = C_i - C_0; 86 | cout << "Your income is " << income << endl; 87 | const double kIncomeTax = 19.0; // 19% 88 | cout << "After " << kIncomeTax << "% tax deduction you get: "; 89 | cout << ( 1.0 - kIncomeTax / kPercentageDiv ) * income << endl; 90 | 91 | return 0; 92 | } 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /Complex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME Complex ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /Complex/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Complex/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Complex/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Complex/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Complex/src/ComplexTest.cpp: -------------------------------------------------------------------------------- 1 | /// ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | #include 17 | 18 | #include "Complex.h" 19 | 20 | 21 | 22 | 23 | using std::cout, std::cin, std::endl; 24 | using std::ofstream, std::ifstream; 25 | 26 | using CppBook::TComplex; 27 | 28 | 29 | 30 | // Simple operations with complex numbers 31 | // using the keyboard and the screen 32 | void Complex_Test_Screen( void ) 33 | { 34 | ////////////////////////////////////////// 35 | // Let's create few TComplex objects: 36 | CppBook::TComplex a, b, // a and b by default constructor 37 | c( 10., 20. ); // c by the parametric constructor 38 | 39 | TComplex d( c ); // yet another one, this time d contains a copy of c 40 | 41 | // Let's test how to stream out object d to the screen 42 | cout << d << endl; 43 | operator << ( cout, d ); // we can also write like this 44 | cout << endl; // then move to the new line 45 | 46 | cout << "Write re, press Enter, then im, press Enter" << endl; 47 | cin >> a; // from the keyboard read new values to the object a 48 | 49 | c = b = a; // copy a to b, then b to c (= is right associative) 50 | 51 | // Let's add two complex numbers b and d and display the result 52 | cout << "( " << a << " ) + ( " << b << " ) = ( " << a + b << " ) " << endl; 53 | 54 | // To assign 5.0 to b, at first, 5.0 needs to be converted to TComplex, then assigned. 55 | b = 5.0; 56 | cout << "( " << a << " ) + ( " << b << " ) = ( " << a + b << " ) " << endl; 57 | } 58 | 59 | 60 | // Simple operations with complex numbers 61 | // using the keyboard, the screen, and a file 62 | void Complex_Test_File( void ) 63 | { 64 | // Create two complex objects 65 | TComplex a, b; 66 | 67 | // Enter two from the keyboard 68 | cout << "Enter 1st complex" << endl; 69 | cin >> a; 70 | 71 | cout << "Enter 2nd complex" << endl; 72 | cin >> b; 73 | 74 | // Let's try to copy results to a file opened in appending mode 75 | ofstream theFile( "ComplexTest.txt", std::ios::app ); 76 | 77 | // Always check if the file opened correctly 78 | if( theFile.is_open() == true ) 79 | { 80 | // Perform operations and print results to the file 81 | theFile << "a = " << a << ", b = " << b << endl; 82 | theFile << "a + b = " << a + b << endl; 83 | theFile << "a - b = " << a - b << endl; 84 | theFile << "a * b = " << a * b << endl; 85 | 86 | // However, division is different - it can throw an exception 87 | try 88 | { 89 | // Keep it in the try-catch clamp 90 | theFile << "a / b = " << a / b << endl << endl; 91 | } 92 | catch( std::exception & e ) // catch exceptions 93 | { 94 | // Standard exceptions will be processed here 95 | std::cerr << "Exception caught: " << e.what() << endl; // print the cause 96 | } 97 | catch( ... ) 98 | { 99 | // Any other exception will be caught here 100 | std::cerr << "Unknown error" << endl; 101 | } 102 | 103 | } 104 | 105 | } 106 | 107 | -------------------------------------------------------------------------------- /Complex/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | #include "Complex.h" 13 | 14 | // Declarations are sufficient to call functions 15 | void Complex_Test_Screen( void ); 16 | void Complex_Test_File( void ); 17 | 18 | 19 | 20 | // In C++ there are few versions of the main function 21 | int main( void ) 22 | { 23 | Complex_Test_Screen(); 24 | Complex_Test_File(); 25 | 26 | return 0; 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /ComplexQuadEq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME ComplexQuadEq ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | # We also need to add sources from other projects: Complex and QuadEq 31 | include_directories( include "./../Complex/include" "./../QuadEq/include" ) 32 | 33 | 34 | # Automatically add all *.cpp and *.h files to the project 35 | # We also need to add sources from other projects: Complex and QuadEq 36 | file ( GLOB SOURCES "./src/*.cpp" "./../Complex/src/Complex.cpp" "./../QuadEq/src/QuadEq.cpp" "./include/*.h" ) 37 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 38 | 39 | 40 | # Set the default project 41 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 42 | 43 | 44 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 45 | -------------------------------------------------------------------------------- /ComplexQuadEq/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | This project depends on sources from the projects Complex & QuadEq. 3 | The tree structure looks as follows: 4 | 5 | + Complex 6 | ----src 7 | ----include 8 | + ComplexQuadEq (this one) 9 | ----src 10 | ----include 11 | + QuadEq 12 | ----src 13 | ----include 14 | 15 | You do not need to build the Complex & QuadEq. They just need to 16 | be at the same directory level. 17 | 18 | 19 | 20 | 21 | To build a project do as follows: 22 | 23 | 1. Depending on your OS change directory to the one: 24 | build_win 25 | build_linux 26 | build_mac 27 | 28 | 2. Open terminal and set current directory to the above one. 29 | 30 | 3. type 31 | cmake .. 32 | 33 | 4. Go to the build_xxx directory and launch your project. 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ComplexQuadEq/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ComplexQuadEq/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ComplexQuadEq/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ComplexQuadEq/include/ComplexQuadEq.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | // Paths are relative to the position of 15 | // the project files 16 | #include "../../Complex/include/Complex.h" 17 | #include "../../QuadEq/include/QuadEq.h" 18 | 19 | 20 | using CppBook::TComplex; 21 | 22 | 23 | class TComplexQuadEq : public TQuadEq 24 | { 25 | public: 26 | 27 | // Introduce the EEqType from the base class 28 | using TQuadEq::EEqType; 29 | 30 | public: 31 | 32 | // =================================================== 33 | 34 | // class default constructor 35 | TComplexQuadEq( void ) 36 | {} 37 | 38 | // class parametric constructor 39 | TComplexQuadEq( double a, double b, double c ) 40 | : TQuadEq( a, b, c ) // call the base class constructor 41 | {} 42 | 43 | // Class default copy constructor 44 | TComplexQuadEq( const TComplexQuadEq & ) = default; 45 | 46 | // Class default destructor 47 | ~TComplexQuadEq() = default; 48 | 49 | // =================================================== 50 | 51 | public: 52 | 53 | /////////////////////////////////////////////////////////// 54 | // This function checks type of the equation 55 | /////////////////////////////////////////////////////////// 56 | // 57 | // INPUT: delta 58 | // OUTPUT: An exact type of the equation 59 | // represented by the parameters f_a, f_b, f_c 60 | // 61 | EEqType GetNumOfRoots( const double delta ) const; 62 | 63 | 64 | /////////////////////////////////////////////////////////// 65 | // This function computes the roots of the equation, if possible. 66 | /////////////////////////////////////////////////////////// 67 | // 68 | // INPUT: theRoot_1 - a reference to an object that 69 | // contains root 1 if returned kLinOne, kOne or kTwo 70 | // theRoot_2 - a reference to an object that 71 | // contains root 2 if returned kOne or kTwo 72 | // (in the first case root_1 == root_2) 73 | // 74 | // OUTPUT: status of the equation (number of roots) 75 | // 76 | // REMARKS: The values referenced to by theRoot_1 and theRoot_2 77 | // are undefined in all other cases than stated above. 78 | // 79 | EEqType GetRoots( TComplex & theRoot_1, TComplex & theRoot_2 ) const; 80 | 81 | }; 82 | 83 | 84 | -------------------------------------------------------------------------------- /ComplexQuadEq/src/ComplexQuadEqTest.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include "ComplexQuadEq.h" 15 | 16 | 17 | using std::cout, std::endl; 18 | 19 | 20 | 21 | void ComplexQuadEq_Test( void ) 22 | { 23 | double a { 5.0 }, b { 2.0 }, c { 1.0 }; 24 | 25 | TComplexQuadEq cqe( a, b, c ); 26 | 27 | 28 | TComplex r1, r2; 29 | 30 | TComplexQuadEq::EEqType eq_type = cqe.GetRoots( r1, r2 ); 31 | 32 | if( eq_type == TComplexQuadEq::EEqType::kOne || 33 | eq_type == TComplexQuadEq::EEqType::kTwo ) 34 | { 35 | // Check if correct - there are many abs functions, but 36 | // thanks to the CppBook namespace we do not confuse them 37 | assert( CppBook::abs( r1 * ( r1 * a + b ) + c ) < 1e-12 ); 38 | assert( CppBook::abs( r2 * ( r2 * a + b ) + c ) < 1e-12 ); 39 | 40 | // Print out the results: 41 | cout << "a=" << a << ", b=" << b << ", c=" << c << endl; 42 | cout << "Root_1=" << r1 << ", Root_2=" << r2 << endl; 43 | } 44 | else 45 | { 46 | cout << "This is a deficient quadratic equation" << endl; 47 | } 48 | 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ComplexQuadEq/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include 15 | 16 | void ComplexQuadEq_Test( void ); 17 | 18 | int main() 19 | { 20 | ComplexQuadEq_Test(); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /CurrencyCalc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CurrencyCalcProject ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | 9 | 10 | set( CMAKE_BUILD_TYPE Debug ) 11 | #set( CMAKE_BUILD_TYPE Release ) 12 | 13 | 14 | # Recurse into the subdirectories. CMake will walk through 15 | # the project's entire directory structure. 16 | 17 | add_subdirectory ( CurrencyCalc_Lib CurrencyCalc_Lib/build_win ) 18 | add_subdirectory ( CurrencyCalc_Terminal CurrencyCalc_Terminal/build_win ) 19 | add_subdirectory ( CurrencyCalc_WindowGUI CurrencyCalc_WindowGUI/build_win ) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CurrencyCalc_Lib ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | 13 | if( WIN32 ) 14 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 15 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 16 | message( "Win settings chosen..." ) 17 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 18 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 19 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 20 | message( "Mac settings chosen..." ) 21 | elseif( UNIX ) 22 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 23 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 24 | message( "Linux settings chosen..." ) 25 | endif() 26 | 27 | 28 | # Inform CMake where the header files are 29 | include_directories( include ) 30 | 31 | 32 | # Automatically add all *.cpp and *.h files to the project 33 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 34 | 35 | 36 | 37 | 38 | # This works 39 | #set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib ) 40 | 41 | 42 | 43 | #add_executable( ${PROJECT_NAME} ${SOURCES} ) 44 | add_library( ${PROJECT_NAME} STATIC ${SOURCES} ) 45 | 46 | 47 | # Make sure the compiler can find include files for the library 48 | # when other libraries or executables link to this one 49 | target_include_directories ( ${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) 50 | 51 | 52 | 53 | INSTALL( 54 | TARGETS ${PROJECT_NAME} 55 | ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib 56 | LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/lib 57 | COMPONENT library 58 | ) 59 | 60 | 61 | set( CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1 ) 62 | 63 | 64 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/include/Currency.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CurrencyCalc/CurrencyCalc_Lib/include/Currency.h -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/include/CurrencyCalcPlayGround.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #pragma once // include this header to the translation unit only once 14 | 15 | #include 16 | 17 | #include "XML_CurrencyExchanger.h" 18 | 19 | 20 | // -------------------- 21 | namespace CurrExchanger 22 | { 23 | using std::wstring; 24 | 25 | 26 | extern wstring initDefaultFileName; 27 | 28 | 29 | 30 | using CppBook::TCurrencyExchanger; 31 | 32 | using CurrExch_Optional = std::optional< TCurrencyExchanger >; 33 | 34 | 35 | 36 | auto CreateCurExchanger( const wstring & initFileFullPath ) -> CurrExch_Optional; 37 | 38 | 39 | void DisplayAllCurrencies( const TCurrencyExchanger & currencyExchangerObj ); 40 | 41 | 42 | void DisplayCurrentTime( void ); 43 | 44 | 45 | // Perform currency exchange based on user's commands. 46 | void UserInterface( const TCurrencyExchanger & currencyExchangerObj ); 47 | 48 | // Run if we already have the currency exchanger object 49 | void Run( const TCurrencyExchanger & currExchObj ); 50 | 51 | 52 | // All actions 53 | void Run( void ); 54 | 55 | 56 | 57 | // -------------------------------------------------------- 58 | // A version that can load from a HTTP downloaded XML file. 59 | namespace OnLine_CurrExchanger 60 | { 61 | extern wstring nbp_addr; 62 | 63 | using CppBook::XML_CurrencyExchanger; 64 | 65 | using XML_CurrExch_Optional = std::optional< XML_CurrencyExchanger >; 66 | 67 | // There are two options for the return object: 68 | // - It is either TCurrencyExchanger if properly built 69 | // - or empty CurrExch_Optional if cannot create 70 | auto CreateCurExchanger( const wstring & http_XML_FileName, const wstring & initFileFullPath ) -> XML_CurrExch_Optional; 71 | 72 | // All actions 73 | void Run( void ); 74 | 75 | bool CurExchanger_DownloadCurrencies( const wstring & http_addr, const wstring & local_XML_FullPath ); 76 | 77 | void CurExchanger_SaveInitFile( const XML_CurrencyExchanger & obj, const wstring & initFileFullPath ); 78 | 79 | } 80 | 81 | 82 | 83 | } 84 | 85 | 86 | 87 | 88 | 89 | ///////////////////////////////////////////////////////// 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/include/HTTP_File.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #pragma once 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | namespace CppBook 22 | { 23 | 24 | 25 | class HTTP_File_Body 26 | { 27 | 28 | public: 29 | 30 | virtual bool Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) = 0; 31 | 32 | virtual ~HTTP_File_Body() = default; // a virtual desctructor to allow inheritance 33 | 34 | }; 35 | 36 | 37 | class HTTP_File_Body_Windows : public HTTP_File_Body 38 | { 39 | 40 | public: 41 | 42 | bool Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) override; 43 | 44 | }; 45 | 46 | class HTTP_File_Body_Linux : public HTTP_File_Body 47 | { 48 | 49 | public: 50 | 51 | bool Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) override; 52 | 53 | }; 54 | 55 | class HTTP_File_Body_MacOS : public HTTP_File_Body 56 | { 57 | 58 | public: 59 | 60 | bool Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) override; 61 | 62 | }; 63 | 64 | 65 | 66 | class HTTP_File_Handle 67 | { 68 | private: 69 | 70 | using BodyPtr = std::unique_ptr< HTTP_File_Body >; 71 | 72 | BodyPtr fBodyObj; 73 | 74 | public: 75 | 76 | enum class EHandledSystems { kWindows, kLinux, kMac }; 77 | 78 | HTTP_File_Handle( EHandledSystems system ) 79 | { 80 | switch( system ) 81 | { 82 | case EHandledSystems::kWindows: 83 | fBodyObj = std::make_unique< HTTP_File_Body_Windows >(); 84 | break; 85 | 86 | case EHandledSystems::kLinux: 87 | fBodyObj = std::make_unique< HTTP_File_Body_Linux >(); 88 | break; 89 | 90 | case EHandledSystems::kMac: 91 | fBodyObj = std::make_unique< HTTP_File_Body_MacOS >(); 92 | break; 93 | 94 | default: 95 | assert( false ); // not supported 96 | break; 97 | } 98 | 99 | 100 | } 101 | 102 | public: 103 | 104 | virtual bool Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) 105 | { 106 | assert( fBodyObj ); 107 | return fBodyObj->Load_HTTP_File( internet_addr, localName ); // delegate an action to the body 108 | } 109 | 110 | 111 | public: 112 | 113 | virtual ~HTTP_File_Handle() = default; // a virtual desctuctor to allow inheritance 114 | 115 | }; 116 | 117 | 118 | 119 | } // CppBook 120 | 121 | 122 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/include/XML_CurrencyExchanger.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #pragma once 15 | 16 | 17 | #include "CurrencyExchanger.h" 18 | 19 | #include 20 | #include 21 | 22 | using std::wregex; 23 | 24 | 25 | // (1) Using regex 26 | // (2) Processing XML files 27 | // (3) Working with wstrings 28 | // (4) Using state machine 29 | 30 | 31 | namespace CppBook 32 | { 33 | 34 | 35 | 36 | class XML_CurrencyExchanger : public TCurrencyExchanger 37 | { 38 | 39 | private: 40 | 41 | 42 | // Simple state machine 43 | enum class ESearchStates { kIdle, k_Name_Processed, k_Code_Processed, k_BuyingRate_Processed, k_SellingRate_Processed }; 44 | 45 | private: 46 | 47 | // Let's define some patterns 48 | // We use raw string formats here R"( )" 49 | wregex f_curr_name_pat { LR"((.+))" }; 50 | wregex f_curr_code_pat { LR"(([[:upper:]][[:upper:]][[:upper:]]))" }; 51 | wregex f_buy_rate_pat { LR"(([[:d:]]+),([[:d:]]+))" }; // instead of 1.27, in Poland 1,27 is used (with comma) 52 | wregex f_sell_rate_pat { LR"(([[:d:]]+),([[:d:]]+))" }; 53 | 54 | public: 55 | 56 | // Allow other patterns 57 | void set_curr_name_pat( const wregex & pat ) { f_curr_name_pat = pat; } 58 | // ... 59 | 60 | public: 61 | 62 | /////////////////////////////////////////////////////////// 63 | // Fills currency table 64 | /////////////////////////////////////////////////////////// 65 | // 66 | // INPUT: 67 | // currencyFile - full path to the XML file 68 | // with currency entries 69 | // OUTPUT: 70 | // true if ok, false otherwise 71 | // 72 | // REMARKS: 73 | // 74 | // 75 | virtual bool FillCurrencyTableFrom( const wstring & currencyFile ); 76 | 77 | }; 78 | 79 | 80 | 81 | 82 | } // CppBook 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/lib/CurrencyCalc_Lib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/CurrencyCalc/CurrencyCalc_Lib/lib/CurrencyCalc_Lib.lib -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/src/Currency.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | 15 | #include "Currency.h" 16 | 17 | 18 | 19 | namespace CppBook 20 | { 21 | 22 | 23 | 24 | // "w" for wide-character streams 25 | std::wostream & operator << ( std::wostream & o, const TCurrency & c ) 26 | { 27 | const int kOutWidth { 10 }; // total width of numeric output 28 | const int kOutPrec { 4 }; // precision for the rates 29 | 30 | o << c.GetCurrKey() << "\t"; 31 | o << c.GetCurrName() << "\t"; 32 | 33 | o << std::fixed 34 | << std::setw( kOutWidth ) 35 | << std::setprecision( kOutPrec ) 36 | << c.GetSellRate() << "\t"; 37 | 38 | o << std::fixed 39 | << std::setw( kOutWidth ) 40 | << std::setprecision( kOutPrec ) 41 | << c.GetBuyRate() << "\t"; 42 | 43 | return o; 44 | } 45 | 46 | std::wistream & operator >> ( std::wistream & i, TCurrency & c ) 47 | { 48 | wstring s {}; // empty temporary string 49 | i >> s; c.SetCurrCode( s ); 50 | i >> s; c.SetCurrName( s ); 51 | 52 | double tmp {}; // temporary double 53 | i >> tmp; c.SetSellRate( tmp ); 54 | i >> tmp; c.SetBuyRate( tmp ); 55 | 56 | return i; 57 | } 58 | 59 | 60 | 61 | } // CppBook 62 | 63 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/src/CurrencyExchanger.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "CurrencyExchanger.h" 5 | #include 6 | 7 | 8 | 9 | 10 | namespace CppBook 11 | { 12 | 13 | using std::wostream, std::wistream; // Introduce these std objects to the scope 14 | 15 | 16 | wostream & operator << ( wostream & o, const TCurrencyExchanger & c ) 17 | { 18 | for( const auto & currency : c.fCurrencyMap ) 19 | o << currency.second << L"\n"; 20 | return o; 21 | } 22 | 23 | wistream & operator >> ( wistream & i, TCurrencyExchanger & c ) 24 | { 25 | TCurrency currency; // temporary currency (one line from file) 26 | 27 | // Read record-by-record and insert to the map; 28 | // The fCurrKey becomes the map key. 29 | while( i >> currency ) 30 | c.AddCurrency( currency ); 31 | 32 | return i; 33 | } 34 | 35 | bool TCurrencyExchanger::Convert( const wstring & from_key, const double from_val, const wstring & to_key, double & to_val ) const 36 | { 37 | try 38 | { 39 | // Get the exchange ratios 40 | double fromCurr_ExchRatio = fCurrencyMap.at( from_key ).GetSellRate(); 41 | double toCurr_ExchRatio = fCurrencyMap.at( to_key ).GetBuyRate(); 42 | 43 | // First we buy to the reference 44 | double val = from_val * fromCurr_ExchRatio; 45 | 46 | // The we sell 47 | assert( toCurr_ExchRatio > 1e-6 ); // check that we don't divide by 0 48 | to_val = val / toCurr_ExchRatio; 49 | } 50 | catch( ... ) 51 | { 52 | return false; // problems, sorry 53 | 54 | } 55 | 56 | return true; // operation ok 57 | } 58 | 59 | // Find and return currency by its code; 60 | // Returns true if ok, false if cannot find. 61 | bool TCurrencyExchanger::FindCurrency( const wstring & currency_code, TCurrency & outCurrency ) const 62 | { 63 | if( auto pos = fCurrencyMap.find( currency_code ); pos != fCurrencyMap.end() ) 64 | { 65 | outCurrency = ( * pos ).second; 66 | return true; 67 | } 68 | 69 | return false; 70 | } 71 | 72 | 73 | void TCurrencyExchanger::AddCurrency( const TCurrency & new_currency ) 74 | { 75 | fCurrencyMap[ new_currency.GetCurrKey() ] = new_currency; 76 | } 77 | 78 | 79 | 80 | 81 | } // CppBook 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Lib/src/HTTP_File.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | #include "HTTP_File.h" 16 | 17 | #if _WIN32 18 | 19 | #include 20 | 21 | #pragma comment(lib, "urlmon.lib") 22 | 23 | #else 24 | 25 | #endif 26 | 27 | 28 | namespace CppBook 29 | { 30 | 31 | 32 | bool HTTP_File_Body_Windows::Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) 33 | { 34 | #if _WIN32 // Should be 1 on 32 bit and 64 bit Windows 35 | return URLDownloadToFile ( NULL, internet_addr.c_str(), localName.c_str(), 0, NULL ) == S_OK; 36 | #else 37 | return false; 38 | #endif 39 | } 40 | 41 | 42 | 43 | 44 | } // CppBook 45 | 46 | 47 | /////////////////////////////////////// 48 | 49 | // This can go to a differetn .cpp file 50 | namespace CppBook 51 | { 52 | 53 | 54 | bool HTTP_File_Body_Linux::Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) 55 | { 56 | #if __linux__ // Should be 1 on 32 bit and 64 bit Linux 57 | return false; // To be implemented 58 | #else 59 | return false; 60 | #endif 61 | } 62 | 63 | 64 | 65 | 66 | } // CppBook 67 | 68 | 69 | /////////////////////////////////////// 70 | 71 | // This can go to a differetn .cpp file 72 | namespace CppBook 73 | { 74 | 75 | 76 | bool HTTP_File_Body_MacOS::Load_HTTP_File( const std::wstring & internet_addr, const std::wstring & localName ) 77 | { 78 | #if macintosh // Should be 1 on Apple 79 | return false; // To be implemented 80 | #else 81 | return false; 82 | #endif 83 | } 84 | 85 | 86 | 87 | 88 | } // CppBook 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Terminal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CurrencyCalc_Terminal ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | 13 | if( WIN32 ) 14 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 15 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 16 | message( "Win settings chosen..." ) 17 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 18 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 19 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 20 | message( "Mac settings chosen..." ) 21 | elseif( UNIX ) 22 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 23 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 24 | message( "Linux settings chosen..." ) 25 | endif() 26 | 27 | 28 | 29 | 30 | # Inform CMake where the header files are 31 | include_directories( ../CurrencyCalc_Lib/include ) 32 | include_directories( ./include ) 33 | 34 | 35 | 36 | # Add source file to the build executable 37 | add_executable( ${PROJECT_NAME} ./src/main.cpp ) 38 | 39 | 40 | 41 | # Add static library - here we can define what kind of a library we want 42 | find_library( PROJECT_LIBRARY CurrencyCalc_Lib HINTS ../CurrencyCalc_Lib/lib ) 43 | target_link_libraries( ${PROJECT_NAME} PUBLIC ${PROJECT_LIBRARY}) 44 | 45 | 46 | # Set the default project 47 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 48 | 49 | 50 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 51 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Terminal/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Terminal/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Terminal/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Terminal/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_Terminal/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | #include "CurrencyCalcPlayGround.h" 22 | 23 | #if 0 24 | namespace CurrExchanger 25 | { 26 | 27 | void Run( void ); 28 | 29 | } 30 | 31 | 32 | namespace CurrExchanger 33 | { 34 | namespace OnLine_CurrExchanger 35 | { 36 | void Run( void ); 37 | } 38 | } 39 | #endif 40 | 41 | 42 | #include 43 | #include 44 | 45 | 46 | int main( void ) 47 | { 48 | setlocale( /*LC_ALL*/LC_CTYPE, "Polish" ); // to display national letters (but don't change financial format ',' vs '.') 49 | CurrExchanger::OnLine_CurrExchanger::Run(); 50 | return 0; // Although not absolutely required, return the value from main 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME CurrencyCalc_GUI ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | 13 | if( WIN32 ) 14 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 15 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 16 | message( "Win settings chosen..." ) 17 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 18 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 19 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 20 | message( "Mac settings chosen..." ) 21 | elseif( UNIX ) 22 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 23 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 24 | message( "Linux settings chosen..." ) 25 | endif() 26 | 27 | 28 | 29 | 30 | # Inform CMake where the header files are 31 | include_directories( ../CurrencyCalc_Lib/include ) 32 | include_directories( ./include ) 33 | include_directories( ../../FLTK ) 34 | 35 | 36 | 37 | # Automatically add all *.cpp files to the project 38 | file ( GLOB SOURCES "./src/*.cpp" ) 39 | 40 | # Add source file to the build executable 41 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 42 | 43 | 44 | # Some system libraries 45 | if( WIN32 ) 46 | 47 | # Assuming Windows SDK is installed, so we do not need to call find_library() 48 | 49 | target_link_libraries( ${PROJECT_NAME} 50 | PUBLIC 51 | wsock32 52 | comctl32 53 | ) 54 | 55 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") 56 | 57 | find_library( COCOA_LIB Cocoa ) 58 | target_link_libraries( ${PROJECT_NAME} PUBLIC ${COCOA_LIB} ) 59 | 60 | endif() 61 | 62 | 63 | 64 | # Currency Calc library 65 | find_library( CURRENCY_CALC_LIB 66 | NAMES CurrencyCalc_Lib 67 | PATHS ../CurrencyCalc_Lib/lib ) 68 | 69 | # FLTK libraries 70 | find_library( FLTK_LIBRARY 71 | NAMES fltkd fltk 72 | PATHS ../../FLTK/lib/Debug ../../FLTK/lib/Release ../../FLTK/lib ) 73 | 74 | 75 | target_link_libraries( ${PROJECT_NAME} 76 | PUBLIC 77 | ${CURRENCY_CALC_LIB} 78 | ${FLTK_LIBRARY} 79 | ) 80 | 81 | 82 | 83 | # Set the default project 84 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 85 | 86 | 87 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/include/CloseWindow.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | /////////////////////////////////////////////////////////// 20 | // This function closes the console window 21 | /////////////////////////////////////////////////////////// 22 | // 23 | // INPUT: 24 | // none 25 | // 26 | // OUTPUT: 27 | // none 28 | // 29 | // REMARKS: 30 | // 31 | // 32 | void CloseConsoleWindow( void ); 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/include/StringConverters.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include 5 | #include 6 | 7 | std::wstring to_wstring ( const std::string & s, const std::locale & loc = std::locale() ) 8 | { 9 | std::wstring buf( s.size(), L' ' ); 10 | std::use_facet< std::ctype >(loc).widen( s.data(), s.data() + s.size(), buf.data() ); 11 | return std::wstring( buf.data(), buf.size() ); 12 | } 13 | 14 | 15 | std::string to_string (const std::wstring & s, const std::locale & loc = std::locale() ) 16 | { 17 | std::string buf( s.size(), ' ' ); 18 | std::use_facet< std::ctype >(loc).narrow( s.data(), s.data() + s.size(), '.', buf.data() ); 19 | return std::string( buf.data(), buf.size() ); 20 | } 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/src/CloseWindow.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #if _WIN32 14 | #include 15 | #endif 16 | 17 | 18 | 19 | #include "CloseWindow.h" 20 | 21 | 22 | 23 | 24 | #if _WIN32 25 | 26 | 27 | /////////////////////////////////////////////////////////// 28 | // This function closes the console window 29 | /////////////////////////////////////////////////////////// 30 | // 31 | // INPUT: 32 | // none 33 | // 34 | // OUTPUT: 35 | // none 36 | // 37 | // REMARKS: 38 | // 39 | // 40 | void CloseConsoleWindow( void ) 41 | { 42 | // Find a window and close it 43 | HWND h; 44 | TCHAR szOldTitle[ MAX_PATH ]; 45 | GetConsoleTitle( szOldTitle, MAX_PATH ); 46 | h = FindWindow( NULL, szOldTitle ); 47 | ShowWindow( h, SW_HIDE ); 48 | } 49 | 50 | #else 51 | 52 | void CloseConsoleWindow( void ) 53 | { 54 | // do we need it? 55 | 56 | } 57 | 58 | #endif 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /CurrencyCalc/CurrencyCalc_WindowGUI/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include 15 | 16 | #include "CurCalc_GUI.h" 17 | #include "CloseWindow.h" 18 | 19 | 20 | 21 | int main() 22 | { 23 | CloseConsoleWindow(); // Get rid of the console window 24 | 25 | namespace fs = std::filesystem; 26 | // Get full path to the initialization file 27 | std::wstring iniPath( fs::current_path() / fs::path( CurrExchanger::initDefaultFileName ) ); 28 | 29 | // Create the currency exchanger object 30 | auto curExchObj = OL_CE::CreateCurExchanger( OL_CE::nbp_addr, iniPath ); 31 | if( ! curExchObj ) 32 | return fl_alert( "Cannot load currency information (no ini file, no Internet) - exiting ..." ), -1; // Exit with error code 33 | 34 | // Create GUI object with the provided currency exchanger object 35 | CC_GUI gCC_GUI( * curExchObj ); 36 | 37 | // Run application 38 | return gCC_GUI.Create_GUI(); 39 | } 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /CurrencyCalc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /EasyMatrix/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME EasyMatrix ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | if( WIN32 ) 13 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 14 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 15 | message( "Win settings chosen..." ) 16 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 17 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 18 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 19 | message( "Mac settings chosen..." ) 20 | elseif( UNIX ) 21 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 22 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 23 | message( "Linux settings chosen..." ) 24 | endif() 25 | 26 | 27 | # Inform CMake where the header files are 28 | include_directories( include ) 29 | 30 | 31 | # Automatically add all *.cpp and *.h files to the project 32 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 33 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 34 | 35 | # Set the default project 36 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 37 | 38 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 39 | -------------------------------------------------------------------------------- /EasyMatrix/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /EasyMatrix/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EasyMatrix/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EasyMatrix/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EasyMatrix/include/EMUtility.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | // Own header in " " 14 | #include "EMatrix.h" 15 | 16 | 17 | 18 | 19 | // Add two matrices, return the result: 20 | // c = a + b 21 | // Dimensions of a and b must be the same. 22 | EMatrix AddMatrix( const EMatrix & a, const EMatrix & b ); 23 | 24 | // Multiply two matrices, return the result: 25 | // c = a * b 26 | // Dimensions of a and b must comply for multiplication 27 | EMatrix MultMatrix( const EMatrix & a, const EMatrix & b ); 28 | 29 | 30 | // Prints contents of a matrix m on the screen 31 | void ShowMatrix( const EMatrix & m ); 32 | 33 | // Solicitates a user to enter all matrix data 34 | // from the keyboard. 35 | void AskUserForMatrixData( EMatrix & m ); 36 | 37 | // Does random initialization of a matrix m 38 | void RandInit( EMatrix & m ); 39 | 40 | 41 | 42 | 43 | 44 | #if EM_VER > 1 45 | 46 | // Overloaded operators 47 | 48 | EMatrix operator + ( const EMatrix & a, const EMatrix & b ); 49 | 50 | EMatrix operator * ( const EMatrix & a, const EMatrix & b ); 51 | 52 | #endif 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /EasyMatrix/include/EMatrix.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/EasyMatrix/include/EMatrix.h -------------------------------------------------------------------------------- /EasyMatrix/include/MarsXorShift.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | // System headers in < > 14 | //#include 15 | #include 16 | 17 | 18 | // --------------------------------------- 19 | // A helper simple random number generator 20 | 21 | // Marsaglia's Xorshift random numbers 22 | struct MarsXorShift 23 | { 24 | // Start value - must be different from 0 25 | unsigned long r_a_n_d { (unsigned long) time( nullptr ) & 0xFF }; 26 | 27 | // These values were found by G. Marsaglia 28 | // to generate quite good random values 29 | unsigned long GetNext( void ) 30 | { 31 | r_a_n_d ^= r_a_n_d << 13; // << is bit left shift 32 | r_a_n_d ^= r_a_n_d >> 17; // ^= is XOR-and-assign 33 | r_a_n_d ^= r_a_n_d << 5; 34 | 35 | return r_a_n_d; 36 | } 37 | }; 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /EasyMatrix/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | // System headers in < > 14 | #include 15 | //#include 16 | 17 | 18 | // Own header in " " 19 | #include "EMatrix.h" 20 | 21 | 22 | void Easy_Matrix_Zeroth_Test( void ); 23 | void Easy_Matrix_First_Test( void ); 24 | void Easy_Matrix_Second_Test( void ); 25 | void Easy_Matrix_Third_Test( void ); 26 | void Easy_Matrix_Fourth_Test( void ); 27 | 28 | 29 | int main() 30 | { 31 | 32 | #if EM_VER == 1 33 | 34 | 35 | Easy_Matrix_First_Test(); 36 | 37 | Easy_Matrix_Second_Test(); 38 | 39 | #else 40 | 41 | Easy_Matrix_Zeroth_Test(); 42 | 43 | Easy_Matrix_Third_Test(); 44 | 45 | Easy_Matrix_Fourth_Test(); 46 | 47 | #endif 48 | 49 | char c{}; 50 | std::cin >> c; 51 | 52 | return c; 53 | } 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /EmptyPro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME EmptyPro ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /EmptyPro/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | The purpose of this project is to provide a template project 3 | for user's own projects. 4 | Assuming your project is named "MyPro", proceed as follows: 5 | 6 | 1. Make a directory named "MyPro" and copy to it all files 7 | and folders from the "EmptyPro". 8 | 9 | 2. In the ./MyPro/CMakeLists.txt find the line 10 | set( PROJECT_NAME EmptyPro ) 11 | and change "EmptyPro" to the name of your project, i.e. "MyPro" in our example 12 | set( PROJECT_NAME MyPro ) 13 | 14 | 3. Copy/create ALL your source files to the ./MyPro/src 15 | and ALL headers to the ./MyPro/include 16 | 17 | 4. Build your project in accordance with the common scheme (below). 18 | 19 | ================================= 20 | To build a project do as follows: 21 | 22 | 1. Depending on your OS change directory to the one: 23 | build_win 24 | build_linux 25 | build_mac 26 | 27 | 2. Open terminal and set current directory to the above one. 28 | 29 | 3. type 30 | cmake .. 31 | 32 | 4. Go to the build_xxx directory and launch your project. 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /EmptyPro/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EmptyPro/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EmptyPro/build_mac/MacReadMe.txt: -------------------------------------------------------------------------------- 1 | Please note that it is recommended to use Xcode 11 or newer to run this code. 2 | Xcode project can be generated by CMake using following command from within build_mac folder: 3 | cmake -G "Xcode" .. 4 | 5 | Although Apple's compiler name clang is mostly compatible with C++17, 6 | there are some things left out as of now (macOS 10.15, Xcode 11.1). 7 | Other compilers, like gcc, can be installed using 3rd party package 8 | managers such as Homebrew (https://brew.sh) or MacPorts (https://www.macports.org). 9 | -------------------------------------------------------------------------------- /EmptyPro/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EmptyPro/include/empty.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /EmptyPro/src/empty.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include "empty.h" 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EmptyPro/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "empty.h" 19 | 20 | 21 | int main() 22 | { 23 | std::cout << "Good day!" << std::endl; 24 | return 0; 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /FLTK/FLTK_ReadMe.txt: -------------------------------------------------------------------------------- 1 | Load and build here the FLTK library: 2 | https://www.fltk.org/ 3 | 4 | -------------------------------------------------------------------------------- /FixBinCalc/EnterNewValueDialog.cpp: -------------------------------------------------------------------------------- 1 | // EnterNewValueDialog.cpp : implementation file 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "FixBinCalc.h" 6 | #include "EnterNewValueDialog.h" 7 | 8 | #ifdef _DEBUG 9 | #define new DEBUG_NEW 10 | #undef THIS_FILE 11 | static char THIS_FILE[] = __FILE__; 12 | #endif 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | // CEnterNewValueDialog dialog 16 | 17 | 18 | CEnterNewValueDialog::CEnterNewValueDialog(CWnd* pParent /*=NULL*/) 19 | : CDialog(CEnterNewValueDialog::IDD, pParent) 20 | { 21 | //{{AFX_DATA_INIT(CEnterNewValueDialog) 22 | fNewValue = _T(""); 23 | //}}AFX_DATA_INIT 24 | } 25 | 26 | 27 | void CEnterNewValueDialog::DoDataExchange(CDataExchange* pDX) 28 | { 29 | CDialog::DoDataExchange(pDX); 30 | //{{AFX_DATA_MAP(CEnterNewValueDialog) 31 | DDX_Text(pDX, IDC_EDIT_VALUE, fNewValue); 32 | //}}AFX_DATA_MAP 33 | } 34 | 35 | 36 | BEGIN_MESSAGE_MAP(CEnterNewValueDialog, CDialog) 37 | //{{AFX_MSG_MAP(CEnterNewValueDialog) 38 | // NOTE: the ClassWizard will add message map macros here 39 | //}}AFX_MSG_MAP 40 | END_MESSAGE_MAP() 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | // CEnterNewValueDialog message handlers 44 | -------------------------------------------------------------------------------- /FixBinCalc/EnterNewValueDialog.h: -------------------------------------------------------------------------------- 1 | #if !defined(AFX_ENTERNEWVALUEDIALOG_H__90AB8C8D_DD33_4562_B5A1_933263A17737__INCLUDED_) 2 | #define AFX_ENTERNEWVALUEDIALOG_H__90AB8C8D_DD33_4562_B5A1_933263A17737__INCLUDED_ 3 | 4 | #if _MSC_VER > 1000 5 | #pragma once 6 | #endif // _MSC_VER > 1000 7 | // EnterNewValueDialog.h : header file 8 | // 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // CEnterNewValueDialog dialog 12 | 13 | class CEnterNewValueDialog : public CDialog 14 | { 15 | // Construction 16 | public: 17 | CEnterNewValueDialog(CWnd* pParent = NULL); // standard constructor 18 | 19 | // Dialog Data 20 | //{{AFX_DATA(CEnterNewValueDialog) 21 | enum { IDD = IDD_DIALOG_ENTER_NEW_VALUE }; 22 | CString fNewValue; 23 | //}}AFX_DATA 24 | 25 | 26 | // Overrides 27 | // ClassWizard generated virtual function overrides 28 | //{{AFX_VIRTUAL(CEnterNewValueDialog) 29 | protected: 30 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 31 | //}}AFX_VIRTUAL 32 | 33 | // Implementation 34 | protected: 35 | 36 | // Generated message map functions 37 | //{{AFX_MSG(CEnterNewValueDialog) 38 | // NOTE: the ClassWizard will add member functions here 39 | //}}AFX_MSG 40 | DECLARE_MESSAGE_MAP() 41 | }; 42 | 43 | //{{AFX_INSERT_LOCATION}} 44 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 45 | 46 | #endif // !defined(AFX_ENTERNEWVALUEDIALOG_H__90AB8C8D_DD33_4562_B5A1_933263A17737__INCLUDED_) 47 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalc.cpp: -------------------------------------------------------------------------------- 1 | // FixBinCalc.cpp : Defines the class behaviors for the application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "FixBinCalc.h" 6 | #include "FixBinCalcDlg.h" 7 | 8 | #ifdef _DEBUG 9 | #define new DEBUG_NEW 10 | #undef THIS_FILE 11 | static char THIS_FILE[] = __FILE__; 12 | #endif 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | // CFixBinCalcApp 16 | 17 | BEGIN_MESSAGE_MAP(CFixBinCalcApp, CWinApp) 18 | //{{AFX_MSG_MAP(CFixBinCalcApp) 19 | // NOTE - the ClassWizard will add and remove mapping macros here. 20 | // DO NOT EDIT what you see in these blocks of generated code! 21 | //}}AFX_MSG 22 | ON_COMMAND(ID_HELP, CWinApp::OnHelp) 23 | END_MESSAGE_MAP() 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // CFixBinCalcApp construction 27 | 28 | CFixBinCalcApp::CFixBinCalcApp() 29 | { 30 | // TODO: add construction code here, 31 | // Place all significant initialization in InitInstance 32 | } 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // The one and only CFixBinCalcApp object 36 | 37 | CFixBinCalcApp theApp; 38 | 39 | ///////////////////////////////////////////////////////////////////////////// 40 | // CFixBinCalcApp initialization 41 | 42 | BOOL CFixBinCalcApp::InitInstance() 43 | { 44 | AfxEnableControlContainer(); 45 | 46 | // Standard initialization 47 | // If you are not using these features and wish to reduce the size 48 | // of your final executable, you should remove from the following 49 | // the specific initialization routines you do not need. 50 | 51 | #ifdef _AFXDLL 52 | Enable3dControls(); // Call this when using MFC in a shared DLL 53 | #else 54 | Enable3dControlsStatic(); // Call this when linking to MFC statically 55 | #endif 56 | 57 | CFixBinCalcDlg dlg; 58 | m_pMainWnd = &dlg; 59 | int nResponse = dlg.DoModal(); 60 | if (nResponse == IDOK) 61 | { 62 | // TODO: Place code here to handle when the dialog is 63 | // dismissed with OK 64 | } 65 | else if (nResponse == IDCANCEL) 66 | { 67 | // TODO: Place code here to handle when the dialog is 68 | // dismissed with Cancel 69 | } 70 | 71 | // Since the dialog has been closed, return FALSE so that we exit the 72 | // application, rather than start the application's message pump. 73 | return FALSE; 74 | } 75 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalc.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "FixBinCalc"=.\FixBinCalc.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalc.h: -------------------------------------------------------------------------------- 1 | // FixBinCalc.h : main header file for the FIXBINCALC application 2 | // 3 | 4 | #if !defined(AFX_FIXBINCALC_H__A4644F60_3461_43BE_B8B2_B802DDEF125A__INCLUDED_) 5 | #define AFX_FIXBINCALC_H__A4644F60_3461_43BE_B8B2_B802DDEF125A__INCLUDED_ 6 | 7 | #if _MSC_VER > 1000 8 | #pragma once 9 | #endif // _MSC_VER > 1000 10 | 11 | #ifndef __AFXWIN_H__ 12 | #error include 'stdafx.h' before including this file for PCH 13 | #endif 14 | 15 | #include "resource.h" // main symbols 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // CFixBinCalcApp: 19 | // See FixBinCalc.cpp for the implementation of this class 20 | // 21 | 22 | class CFixBinCalcApp : public CWinApp 23 | { 24 | public: 25 | CFixBinCalcApp(); 26 | 27 | // Overrides 28 | // ClassWizard generated virtual function overrides 29 | //{{AFX_VIRTUAL(CFixBinCalcApp) 30 | public: 31 | virtual BOOL InitInstance(); 32 | //}}AFX_VIRTUAL 33 | 34 | // Implementation 35 | 36 | //{{AFX_MSG(CFixBinCalcApp) 37 | // NOTE - the ClassWizard will add and remove member functions here. 38 | // DO NOT EDIT what you see in these blocks of generated code ! 39 | //}}AFX_MSG 40 | DECLARE_MESSAGE_MAP() 41 | }; 42 | 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | 46 | //{{AFX_INSERT_LOCATION}} 47 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 48 | 49 | #endif // !defined(AFX_FIXBINCALC_H__A4644F60_3461_43BE_B8B2_B802DDEF125A__INCLUDED_) 50 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalc.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2042 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FixBinCalc", "FixBinCalc.vcxproj", "{D143E169-328F-439C-8EA9-9CE40BD5C3EE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D143E169-328F-439C-8EA9-9CE40BD5C3EE}.Debug|x86.ActiveCfg = Debug|Win32 15 | {D143E169-328F-439C-8EA9-9CE40BD5C3EE}.Debug|x86.Build.0 = Debug|Win32 16 | {D143E169-328F-439C-8EA9-9CE40BD5C3EE}.Release|x86.ActiveCfg = Release|Win32 17 | {D143E169-328F-439C-8EA9-9CE40BD5C3EE}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {47E254CA-C55E-492E-A358-E928A7DB6EDA} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalc.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {b8693f41-1659-409d-bd57-bb38781e024f} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat 7 | 8 | 9 | {d90233a5-3a96-4e6f-8bc2-ec1f86703beb} 10 | h;hpp;hxx;hm;inl 11 | 12 | 13 | {6020683a-31f3-4e7a-8b90-7e40bc03f466} 14 | ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | 32 | 33 | Source Files 34 | 35 | 36 | 37 | 38 | Header Files 39 | 40 | 41 | Header Files 42 | 43 | 44 | Header Files 45 | 46 | 47 | Header Files 48 | 49 | 50 | Header Files 51 | 52 | 53 | Header Files 54 | 55 | 56 | Header Files 57 | 58 | 59 | 60 | 61 | Resource Files 62 | 63 | 64 | Resource Files 65 | 66 | 67 | Resource Files 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Resource Files 76 | 77 | 78 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalc.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | FixBinCalc.rc 5 | 6 | -------------------------------------------------------------------------------- /FixBinCalc/FixBinCalcDlg.h: -------------------------------------------------------------------------------- 1 | // FixBinCalcDlg.h : header file 2 | // 3 | 4 | #if !defined(AFX_FIXBINCALCDLG_H__0365BA86_53E9_481D_8734_E9392DA1E78A__INCLUDED_) 5 | #define AFX_FIXBINCALCDLG_H__0365BA86_53E9_481D_8734_E9392DA1E78A__INCLUDED_ 6 | 7 | #if _MSC_VER > 1000 8 | #pragma once 9 | #endif // _MSC_VER > 1000 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // CFixBinCalcDlg dialog 13 | 14 | class CFixBinCalcDlg : public CDialog 15 | { 16 | public: 17 | 18 | typedef __int64 LongWord; 19 | typedef unsigned __int64 UnsignedLongWord; 20 | 21 | private: 22 | 23 | CString DoStringFromBinary( UnsignedLongWord value, int num_of_bits, unsigned int radix ); 24 | UnsignedLongWord DoBinaryFromString( CString & str, int num_of_bits, unsigned int radix ); 25 | bool Float2Fix( double inFloatVal, int fixIntLen, int fixFracLen, LongWord & outFixInteger, LongWord & outFixFractional ); 26 | bool Fix2Float( LongWord inFixInteger, LongWord inFixFractional, int fixFracLen, double & outFloatVal ); 27 | 28 | 29 | double ComputeError( double firstFloatValue, LongWord inFixInteger, LongWord inFixFractional, int fixFracLen ); 30 | void RecomputeRepresentation( void ); 31 | 32 | bool CheckStringValidity_Int( const CString & theString, int maxLen, int radix ); 33 | bool CheckStringValidity_Frac( const CString & theString, int maxLen, int radix ); 34 | 35 | CString ConvertRadices( const CString & theString, int inRadix, int outRadix ); 36 | 37 | 38 | CString ComputeDecimalRepresentation( void ); 39 | 40 | 41 | 42 | bool CheckChars( const CString & str, int r ); 43 | bool CheckChars( const CString & str, const CString & allowableChars ); 44 | 45 | 46 | // Construction 47 | public: 48 | CFixBinCalcDlg(CWnd* pParent = NULL); // standard constructor 49 | 50 | // Dialog Data 51 | //{{AFX_DATA(CFixBinCalcDlg) 52 | enum { IDD = IDD_FIXBINCALC_DIALOG }; 53 | int fFixFractionalLength; 54 | int fRadix; 55 | CString fFixValueRepresentation; 56 | CString fFixedValue_IntegerPart; 57 | CString fFixedValue_FractionalPart; 58 | int fFixIntegerLength; 59 | int fTotalLength; 60 | CString fTotalError; 61 | double fFloatValue; 62 | //}}AFX_DATA 63 | 64 | // ClassWizard generated virtual function overrides 65 | //{{AFX_VIRTUAL(CFixBinCalcDlg) 66 | protected: 67 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 68 | //}}AFX_VIRTUAL 69 | 70 | // Implementation 71 | protected: 72 | HICON m_hIcon; 73 | 74 | // Generated message map functions 75 | //{{AFX_MSG(CFixBinCalcDlg) 76 | virtual BOOL OnInitDialog(); 77 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 78 | afx_msg void OnPaint(); 79 | afx_msg HCURSOR OnQueryDragIcon(); 80 | afx_msg void OnButtonFix2Float(); 81 | afx_msg void OnButtonFloat2Fix(); 82 | afx_msg void OnRadioBin(); 83 | afx_msg void OnRadioHex(); 84 | afx_msg void OnRadioOct(); 85 | afx_msg void OnChangeEditIntLength(); 86 | afx_msg void OnChangeEditFixFractionalLength(); 87 | afx_msg void OnButtonForceValue(); 88 | afx_msg void OnRadioDec(); 89 | afx_msg void OnButtonClearAll(); 90 | //}}AFX_MSG 91 | DECLARE_MESSAGE_MAP() 92 | }; 93 | 94 | //{{AFX_INSERT_LOCATION}} 95 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 96 | 97 | #endif // !defined(AFX_FIXBINCALCDLG_H__0365BA86_53E9_481D_8734_E9392DA1E78A__INCLUDED_) 98 | -------------------------------------------------------------------------------- /FixBinCalc/Release/FixBinCalc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/FixBinCalc/Release/FixBinCalc.exe -------------------------------------------------------------------------------- /FixBinCalc/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // FixBinCalc.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FixBinCalc/StdAfx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #if !defined(AFX_STDAFX_H__AB79DE08_88A6_4E93_8FF3_69607A2B1408__INCLUDED_) 7 | #define AFX_STDAFX_H__AB79DE08_88A6_4E93_8FF3_69607A2B1408__INCLUDED_ 8 | 9 | #if _MSC_VER > 1000 10 | #pragma once 11 | #endif // _MSC_VER > 1000 12 | 13 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 14 | 15 | #include // MFC core and standard components 16 | #include // MFC extensions 17 | #include // MFC Automation classes 18 | #include // MFC support for Internet Explorer 4 Common Controls 19 | #ifndef _AFX_NO_AFXCMN_SUPPORT 20 | #include // MFC support for Windows Common Controls 21 | #endif // _AFX_NO_AFXCMN_SUPPORT 22 | 23 | 24 | //{{AFX_INSERT_LOCATION}} 25 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 26 | 27 | #endif // !defined(AFX_STDAFX_H__AB79DE08_88A6_4E93_8FF3_69607A2B1408__INCLUDED_) 28 | -------------------------------------------------------------------------------- /FixBinCalc/res/BoxySoft.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/FixBinCalc/res/BoxySoft.bmp -------------------------------------------------------------------------------- /FixBinCalc/res/FixBinCalc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/FixBinCalc/res/FixBinCalc.ico -------------------------------------------------------------------------------- /FixBinCalc/res/FixBinCalc.rc2: -------------------------------------------------------------------------------- 1 | // 2 | // FIXBINCALC.RC2 - resources Microsoft Visual C++ does not edit directly 3 | // 4 | 5 | #ifdef APSTUDIO_INVOKED 6 | #error this file is not editable by Microsoft Visual C++ 7 | #endif //APSTUDIO_INVOKED 8 | 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Add manually edited resources here... 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | -------------------------------------------------------------------------------- /FixBinCalc/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by FixBinCalc.rc 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_FIXBINCALC_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDD_DIALOG_ENTER_NEW_VALUE 129 11 | #define IDB_BITMAP_PANDORDA 130 12 | #define IDC_EDIT_FLOAT_VALUE 1000 13 | #define IDC_EDIT_FIXED_VAL_INTEGER 1001 14 | #define IDC_EDIT_FIXED_VAL_FRACTIONAL 1002 15 | #define IDC_EDIT_FIXED_VAL_REPRESENTATION 1003 16 | #define IDC_EDIT_FIX_FRACTIONAL_LENGTH 1006 17 | #define IDC_EDIT_TOTAL_LENGTH 1007 18 | #define IDC_RADIO_BIN 1008 19 | #define IDC_RADIO_OCT 1009 20 | #define IDC_RADIO_HEX 1010 21 | #define IDC_BUTTON_FIX_2_FLOAT 1011 22 | #define IDC_BUTTON_FLOAT_2_FIX 1012 23 | #define IDC_EDIT_FIX_INTEGER_LENGTH 1013 24 | #define IDC_EDIT_ERROR 1014 25 | #define IDC_RADIO_DEC 1015 26 | #define IDC_BUTTON_FORCE_VALUE 1016 27 | #define IDC_EDIT_VALUE 1017 28 | #define IDC_BUTTON_CLEAR_ALL 1018 29 | 30 | // Next default values for new objects 31 | // 32 | #ifdef APSTUDIO_INVOKED 33 | #ifndef APSTUDIO_READONLY_SYMBOLS 34 | #define _APS_NEXT_RESOURCE_VALUE 130 35 | #define _APS_NEXT_COMMAND_VALUE 32771 36 | #define _APS_NEXT_CONTROL_VALUE 1019 37 | #define _APS_NEXT_SYMED_VALUE 101 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /Grades/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME StudentGrades ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) -------------------------------------------------------------------------------- /Grades/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Grades/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Grades/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Grades/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Grades/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include // A header to use std::vector 15 | #include // Headers for input and output 16 | #include // and output formatting 17 | #include // For math functions 18 | 19 | 20 | // Introduce these, to write vector instead of std::vector 21 | using std::cout, std::cin, std::endl, std::vector; 22 | 23 | 24 | int main() 25 | { 26 | 27 | cout << "Enter your grades" << endl; 28 | 29 | vector< double > studentGradeVec; // An empty vector of doubles 30 | 31 | // Collect student's grades 32 | for( ;; ) 33 | { 34 | double grade {}; 35 | 36 | cin >> grade; 37 | 38 | // If ok, push new grade at the end of the vector 39 | if( grade >= 2.0 && grade <= 5.0 ) 40 | studentGradeVec.push_back( grade ); 41 | 42 | 43 | cout << "Enter more? [y/n] "; 44 | char ans {}; 45 | cin >> ans; 46 | 47 | if( ans == 'n' || ans == 'N' ) 48 | break; // the way to exit the loop 49 | } 50 | 51 | 52 | // Ok, if there are any grades compute the average 53 | if( studentGradeVec.size() > 0 ) 54 | { 55 | double sum { 0.0 }; 56 | // Add all the grades 57 | for( auto g : studentGradeVec ) 58 | sum += g; 59 | 60 | double av = sum / studentGradeVec.size(); 61 | 62 | double finalGrade {}; 63 | 64 | // Let it adjust 65 | if( av < 3.0 ) 66 | { 67 | finalGrade = 2.0; 68 | } 69 | else 70 | { 71 | double near_int = std::floor( av ); // get integer part 72 | double frac = av - near_int; // get only the fraction 73 | 74 | double adjust { 0.5 }; // new adjustment value 75 | 76 | if( frac < 0.25 ) 77 | adjust = 0.0; 78 | else if( frac > 0.75 ) 79 | adjust = 1.0; 80 | 81 | finalGrade = near_int + adjust; 82 | } 83 | 84 | cout << "Final grade: " 85 | << std::fixed << std::setw( 3 ) << std::setprecision( 1 ) 86 | << finalGrade << endl; 87 | 88 | } 89 | 90 | 91 | return 0; 92 | } 93 | 94 | 95 | -------------------------------------------------------------------------------- /LongNumber/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME LongNumber ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /LongNumber/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LongNumber/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LongNumber/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LongNumber/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LongNumber/include/Derived_PESEL.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #define ALLOW_INHERITANCE 1 14 | 15 | #include "LongNumberFor.h" 16 | 17 | 18 | 19 | 20 | 21 | 22 | ///////////////////////////////////////////////////////////////////////////////// 23 | // The "is-a" version 24 | class PESEL : public TLongNumberFor< 11 > 25 | { 26 | public: 27 | 28 | using BaseClass = TLongNumberFor< 11 >; 29 | using BaseClass::GetNumberAt; 30 | 31 | private: 32 | 33 | // Some constants specific to the Polish PESEL number 34 | enum { kBirthYear_Dec = 10, kBirthYear_Sngl = 9, kSex = 1 }; 35 | 36 | public: 37 | 38 | enum class ESex { kMan, kWoman }; 39 | 40 | public: 41 | 42 | PESEL( void ) {} 43 | PESEL( const string & s ) : BaseClass( s ) {} // initialize the base class from the string 44 | 45 | virtual ~PESEL() {} // this must be virtual, why? 46 | // also TLongNumberFor<> should have a virtual destructor 47 | public: 48 | 49 | auto GetYearOfBirth( void ) 50 | { 51 | return GetNumberAt( kBirthYear_Dec ) * 10 + GetNumberAt( kBirthYear_Sngl ); 52 | } 53 | 54 | ESex GetSex( void ) 55 | { 56 | return ( GetNumberAt( kSex ) & 0x01 ) == 0x01 ? ESex::kMan : ESex::kWoman; 57 | } 58 | }; 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /LongNumber/include/Embedded_PESEL.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #define ALLOW_INHERITANCE 0 14 | 15 | #include "LongNumberFor.h" 16 | 17 | 18 | 19 | 20 | 21 | 22 | ///////////////////////////////////////////////////////////////////////////////// 23 | // The "has-a" version 24 | class PESEL 25 | { 26 | private: 27 | 28 | // Some constants specific to the Polish PESEL number 29 | enum { kBirthYear_Dec = 10, kBirthYear_Sngl = 9, kSex = 1 }; 30 | 31 | public: 32 | 33 | enum class ESex { kMan, kWoman }; 34 | 35 | private: 36 | 37 | using LongNumberObject = TLongNumberFor< 11 >; 38 | LongNumberObject fData; 39 | 40 | public: 41 | 42 | PESEL( void ) {} 43 | PESEL( const string & s ) : fData( s ) {} 44 | 45 | public: 46 | 47 | auto GetYearOfBirth( void ) 48 | { 49 | return fData.GetNumberAt( kBirthYear_Dec ) * 10 + fData.GetNumberAt( kBirthYear_Sngl ); 50 | } 51 | 52 | ESex GetSex( void ) 53 | { 54 | return ( fData.GetNumberAt( kSex ) & 0x01 ) == 0x01 ? ESex::kMan : ESex::kWoman; 55 | } 56 | 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /LongNumber/src/Derived_PESEL_Test.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | #include "Derived_PESEL.h" 19 | 20 | 21 | 22 | 23 | void Derived_PESEL_Test( void ) 24 | { 25 | std::cout << "Size with inherited object: " << sizeof( PESEL ) << std::endl; 26 | std::cout << "Size of PESEL::BaseClass: " << sizeof( PESEL::BaseClass ) << std::endl; 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /LongNumber/src/Embedded_PESEL_Test.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | 17 | #include "Embedded_PESEL.h" 18 | 19 | 20 | 21 | 22 | void Embedded_PESEL_Test( void ) 23 | { 24 | std::cout << "Size with wrapped object: " << sizeof( PESEL ) << std::endl; 25 | } 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /LongNumber/src/LongNumber_Test.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include "LongNumberFor.h" 15 | 16 | using std::cout, std::endl; 17 | using std::ofstream, std::ifstream; 18 | 19 | 20 | 21 | // A function that checks main functionality 22 | // of the TLongNumberFor class 23 | void LongNumbers_Test( void ) 24 | { 25 | try 26 | { 27 | TLongNumberFor< 11 > pesel; 28 | 29 | pesel.SetNumberAt( 7, 7 ); 30 | pesel.SetNumberAt( 8, 8 ); 31 | 32 | assert( pesel.GetNumberAt( 7 ) == 7 ); 33 | assert( pesel.GetNumberAt( 8 ) == 8 ); 34 | 35 | 36 | // Try conversions 37 | TLongNumberFor< 5 > number_1( "1234" ); 38 | 39 | std::string str { "--" }; // Create std::string from number_1 40 | str += number_1; // Convert number_1 to std::string and concatenate with str 41 | std::cout << str << endl; // Let's see it 42 | 43 | { 44 | 45 | ofstream testFile( "TLongNumberFor.txt" ); 46 | testFile << number_1; 47 | testFile.close(); 48 | } 49 | 50 | 51 | TLongNumberFor< 5 > number_2; 52 | { 53 | ifstream testFile( "TLongNumberFor.txt" ); 54 | testFile >> number_2; 55 | testFile.close(); 56 | } 57 | 58 | assert( number_1 == number_2 ); 59 | 60 | // Now let's try to access at the wrong position 61 | //cout << number_1[ 33 ]; 62 | } 63 | catch( const std::exception & e ) 64 | { 65 | std::cerr << "Out of Range error: " << e.what() << '\n'; 66 | } 67 | catch( ... ) 68 | { 69 | std::cerr << "Unknown exception\n"; 70 | } 71 | } 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | // A function that checks main functionality 81 | // of the TLongNumberFor class that has the proxy pattern 82 | void LongNumbersWithProxy_Test( void ) 83 | { 84 | #ifdef TURN_ON_PROXY 85 | 86 | TLongNumberFor< 11 > id; 87 | 88 | int x = id[ 7 ]; // operator = to read only 89 | 90 | id[ 7 ] = 7; // use proxy here 91 | 92 | id[ 6 ] = id[ 8 ] = id[ 7 ] = 3; // use proxy as well 93 | 94 | assert( id[ 6 ] == 3 ); 95 | assert( id[ 7 ] == 3 ); 96 | assert( id[ 8 ] == 3 ); 97 | 98 | assert( id[ 10 ] == id[ 0 ] ); 99 | 100 | #endif 101 | 102 | // The concordant indexing: 9 ... 0 103 | const TLongNumberFor< 11 > cid( "9876543210" ); // cid contains "09876543210" 104 | assert( cid[ 10 ] == cid[ 0 ] ); // the leading 11th digit was set to 0 105 | 106 | //cid[ 0 ] = 5; cannot do that since cid is const 107 | int z = cid[ 7 ]; // calls const int TLongNumberFor< 11 >::operator [] ( int position ) const 108 | 109 | #ifdef TURN_ON_PROXY 110 | 111 | id[ 7 ] = cid[ 1 ]; 112 | assert( id[ 7 ] == 1 ); 113 | 114 | #endif 115 | } -------------------------------------------------------------------------------- /LongNumber/src/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/LongNumber/src/main.cpp -------------------------------------------------------------------------------- /ParallelCores/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME ParallelCores ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /ParallelCores/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ParallelCores/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ParallelCores/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ParallelCores/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ParallelCores/include/EMUtility.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | // Own header in " " 14 | #include "EMatrix.h" 15 | 16 | 17 | 18 | // Overloaded operators 19 | 20 | EMatrix operator + ( const EMatrix & a, const EMatrix & b ); 21 | 22 | EMatrix operator * ( const EMatrix & a, const EMatrix & b ); 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /ParallelCores/include/EMatrix.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | 17 | // ---------------------------------------- 18 | // Part I 19 | 20 | #include 21 | #include 22 | 23 | 24 | #define USE_OPEN_MP 1 25 | 26 | 27 | 28 | 29 | // A type alias declaration for a vector of double values (real approx.) 30 | using RealVec = std::vector< double >; 31 | 32 | // A type alias for vector dimensions (size) 33 | using Dim = RealVec::size_type; 34 | 35 | // A type alias for vector type (e.g. double) 36 | using DataType = RealVec::value_type; 37 | 38 | 39 | // A type alias for a vector of vectors with doubles = a real matrix 40 | using RealMatrix = std::vector< RealVec >; 41 | 42 | 43 | 44 | // ---------------------------------------- 45 | // Part II 46 | 47 | #include 48 | 49 | 50 | 51 | 52 | class EMatrix 53 | { 54 | 55 | private: 56 | 57 | RealMatrix fData; // data structure (encapsulation) 58 | 59 | public: 60 | 61 | // A parametric constructor 62 | EMatrix( Dim rows, Dim cols, DataType initVal = 0.0 ) 63 | : fData( rows, RealVec( cols, initVal ) ) 64 | { // matrix == a vector of vectors of double 65 | assert( cols > 0 ); 66 | assert( rows > 0 ); 67 | } 68 | 69 | 70 | // Helpers 71 | auto GetCols( void ) const { return fData[ 0 ].size(); } 72 | auto GetRows( void ) const { return fData.size(); } 73 | 74 | 75 | // Thanks to this overloaded subscript operators 76 | // instead of m.fData[2][3] we can write directly m[2][3] 77 | auto & operator[] ( Dim idx ) { return fData[ idx ]; } 78 | const auto & operator[] ( Dim idx ) const { return fData[ idx ]; } 79 | 80 | // We need only these two pairs of functions to have a range-based for loop 81 | auto begin() { return fData.begin(); } 82 | auto end() { return fData.end(); } 83 | 84 | auto begin() const { return fData.begin(); } 85 | auto end() const { return fData.end(); } 86 | 87 | 88 | 89 | // friends are functions which can freely access fData 90 | friend std::ostream & operator << ( std::ostream & o, const EMatrix & matrix ); 91 | friend std::istream & operator >> ( std::istream & i, EMatrix & matrix ); 92 | 93 | 94 | }; 95 | 96 | 97 | 98 | 99 | 100 | 101 | // ---------------------------------------- 102 | 103 | EMatrix operator + ( const EMatrix & a, const EMatrix & b ); 104 | 105 | EMatrix operator * ( const EMatrix & a, const EMatrix & b ); 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /ParallelCores/include/MarsXorShift.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | // System headers in < > 14 | #include 15 | 16 | 17 | // ------------------------------------ 18 | // A helper simple random generator 19 | 20 | // Marsaglia's Xorshift random numbers 21 | struct MarsXorShift 22 | { 23 | // Start value - must be different from 0 24 | unsigned long r_a_n_d { (unsigned long) time( nullptr ) & 0xFF }; 25 | 26 | // These values were found by G. Marsaglia 27 | // to generate quite good random values 28 | unsigned long GetNext( void ) 29 | { 30 | r_a_n_d ^= r_a_n_d << 13; // << is bit left shift 31 | r_a_n_d ^= r_a_n_d >> 17; // ^= is XOR 32 | r_a_n_d ^= r_a_n_d << 5; 33 | 34 | return r_a_n_d; 35 | } 36 | }; 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /ParallelCores/src/EMatrix.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include "EMatrix.h" 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | 21 | 22 | 23 | // Stream out a matrix to the stream out. Assume text mode. 24 | std::ostream & operator << ( std::ostream & out, const EMatrix & matrix ) 25 | { 26 | for( const auto & row : matrix/*.fData*/ ) // go row-by-row 27 | { 28 | for( const auto & data : row ) // go data in single row 29 | out << data << "\t"; 30 | 31 | out << std::endl; // print new line 32 | } 33 | 34 | return out; // return the stream, so they can be chained 35 | } 36 | 37 | // Stream in a matrix from the stream in. Assume text mode. 38 | std::istream & operator >> ( std::istream & in, EMatrix & matrix ) 39 | { 40 | // Dimensions have to be determined from the data layout. 41 | // Each new line constitutes a new row of a matrix. 42 | // So, we have to read strings line by line, and 43 | // from each string read data by data. 44 | 45 | matrix.fData.clear(); // get rid of whatever there was 46 | 47 | std::string str; // an empty string 48 | while( getline( in, str ) ) // read the whole line into the string 49 | { 50 | // Create a string-stream from a string 51 | std::istringstream istr( str ); 52 | 53 | using DType_Iter = std::istream_iterator< DataType >; 54 | 55 | // Here we move 56 | matrix.fData.emplace_back( std::make_move_iterator( DType_Iter{ istr } ), 57 | std::make_move_iterator( DType_Iter{} ) ); 58 | 59 | 60 | } 61 | 62 | return in; // return the stream, so they can be chained 63 | } 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /ParallelCores/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace InnerProducts 19 | { 20 | void InnerProduct_Test_GeneralExperiment( void ); 21 | } 22 | 23 | 24 | void OpenMP_Test( void ); 25 | void OpenMP_Pi_Test( void ); 26 | void OpenMP_MultMatrix_Test( void ); 27 | void OpenMP_MultMatrix_Test_1( void ); 28 | 29 | void Parallel_Tasks_Test(void); 30 | 31 | 32 | void FindMin_Test( void ); 33 | void MSE_Test( void ); 34 | 35 | 36 | 37 | int main() 38 | { 39 | std::cout << "Good day!" << std::endl; 40 | 41 | 42 | OpenMP_Test(); 43 | 44 | OpenMP_MultMatrix_Test(); 45 | OpenMP_MultMatrix_Test_1(); 46 | 47 | OpenMP_Pi_Test(); 48 | 49 | FindMin_Test(); 50 | 51 | MSE_Test(); 52 | 53 | Parallel_Tasks_Test(); 54 | 55 | InnerProducts::InnerProduct_Test_GeneralExperiment(); 56 | 57 | 58 | return 0; 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /Parser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME Parser ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /Parser/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Parser/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Parser/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Parser/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Parser/include/SimpleExpressionInterpreter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/Parser/include/SimpleExpressionInterpreter.h -------------------------------------------------------------------------------- /Parser/src/Nodes.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | #include "Nodes.h" 16 | #include "Visitors.h" 17 | 18 | 19 | // ---------------------------------------- 20 | 21 | // Although it is declared as pure virtual = 0, 22 | // it also needs a full definition. However, this 23 | // cannot be added in the header due to the =0 specifier. 24 | TNode::~TNode() 25 | { 26 | } 27 | 28 | // ---------------------------------------- 29 | 30 | 31 | void PlusOperator::Accept( TVisitor & v ) const 32 | { 33 | v.Visit( * this ); 34 | } 35 | 36 | void MinusOperator::Accept( TVisitor & v ) const 37 | { 38 | v.Visit( * this ); 39 | } 40 | 41 | void MultOperator::Accept( TVisitor & v ) const 42 | { 43 | v.Visit( * this ); 44 | } 45 | 46 | void DivOperator::Accept( TVisitor & v ) const 47 | { 48 | v.Visit( * this ); 49 | } 50 | 51 | void NumberLeafNode::Accept( TVisitor & v ) const 52 | { 53 | v.Visit( * this ); 54 | } 55 | 56 | 57 | // ---------------------------------------- 58 | 59 | 60 | Node_UP NumberLeafNode::Clone( void ) const 61 | { 62 | return std::make_unique< NumberLeafNode >( * this ); 63 | } 64 | 65 | 66 | Node_UP PlusOperator::Clone( void ) const 67 | { 68 | return std::make_unique< PlusOperator >( GetLeftChild()->Clone(), GetRightChild()->Clone() ); 69 | } 70 | 71 | Node_UP MinusOperator::Clone( void ) const 72 | { 73 | return std::make_unique< MinusOperator >( GetLeftChild()->Clone(), GetRightChild()->Clone() ); 74 | } 75 | 76 | Node_UP MultOperator::Clone( void ) const 77 | { 78 | return std::make_unique< MultOperator >( GetLeftChild()->Clone(), GetRightChild()->Clone() ); 79 | } 80 | 81 | Node_UP DivOperator::Clone( void ) const 82 | { 83 | return std::make_unique< DivOperator >( GetLeftChild()->Clone(), GetRightChild()->Clone() ); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /Parser/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | 16 | void SimpleExpression_Test( void ); 17 | void SyntaxTree_Test( void ); 18 | void RPN_Value_Test( void ); 19 | void RPN_Tree_Test( void ); 20 | 21 | 22 | int main( void ) 23 | { 24 | 25 | //SimpleExpression_Test(); 26 | //SyntaxTree_Test(); 27 | 28 | RPN_Value_Test(); 29 | //RPN_Tree_Test(); 30 | 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /QuadEq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME QuadEq ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /QuadEq/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /QuadEq/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /QuadEq/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /QuadEq/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /QuadEq/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | #include 16 | #include 17 | 18 | #include "QuadEq.h" 19 | 20 | 21 | // With these we can simply write cout 22 | // instead of std::cout, etc. 23 | using std::cout, std::cerr, std::cin, std::endl; 24 | 25 | 26 | 27 | // In C++ there are overloaded main functions 28 | int main( void ) 29 | { 30 | // Text corresponding to TQuadEq::EEquationType 31 | const std::string eq_types_text[] = { "No real roots", 32 | "One real root", 33 | "Two real roots", 34 | "Linear equation, one root", 35 | "A contradictory equation" 36 | }; 37 | 38 | 39 | cout << "Enter coefficients of the quadratic equation: a*x*x + b*x + c" << endl; 40 | double a = 0.0, b = 0.0, c = 0.0; 41 | cin >> a >> b >> c; 42 | 43 | TQuadEq eq( a, b, c ); // Create an initialized object 44 | 45 | // For the roots 46 | double x1 {}, x2 {}; // {} to initialize vars to zero 47 | 48 | TQuadEq::EEqType eq_type {}; 49 | 50 | try 51 | { 52 | eq_type = eq.GetRoots( x1, x2 ); // This can throw 53 | } 54 | catch( const std::exception & e ) 55 | { 56 | cerr << e.what() << endl; // print the reason 57 | return -1; // Exit with a failure code 58 | } 59 | 60 | 61 | // Everything ok, so print results 62 | cout << eq_types_text[ static_cast< int >( eq_type ) ]; 63 | 64 | // In addition, if there are roots, then print them out. 65 | switch( eq_type ) 66 | { 67 | case TQuadEq::EEqType::kOne: 68 | case TQuadEq::EEqType::kLinOne: 69 | cout << ": " << x1 << endl; 70 | break; 71 | 72 | case TQuadEq::EEqType::kTwo: 73 | cout << ": " << x1 << ", " << x2 << endl; 74 | break; 75 | 76 | default : 77 | break; 78 | } 79 | 80 | return 0; // Exit wit ok code 81 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BookCpp 2 | Contains code of the book "Introduction to Programming with C++ for Engineers" by prof. Bogusław Cyganek, Wiley-IEEE, 2020 3 | 4 | // ==========================================================================
5 | //
6 | // Software written by Boguslaw Cyganek (C) to be used with the book:
7 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS
8 | // Published by Wiley, 2020
9 | //
10 | // The software is supplied as is and for educational purposes
11 | // without any guarantees nor responsibility of its use in any application.
12 | //
13 | // ==========================================================================
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME RomanApp ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/include/Dec2Roman.h: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | bool Decimal_2_Roman_Chain_UnitTest( const int kFrom = 1, const int kTo = 3999, const int kNumOfTrials = 1000 ); 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void Dec_2_Roman_Test( void ); 19 | 20 | 21 | int main() 22 | { 23 | std::cout << "Good day!" << std::endl; 24 | 25 | Dec_2_Roman_Test(); 26 | 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME RomanApp_GTest ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include "../RomanApp/include" "./packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include" ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/build_mac/MacReadMe.txt: -------------------------------------------------------------------------------- 1 | Please note that it is recommended to use Xcode 11 or newer to run this code. 2 | Xcode project can be generated by CMake using following command from within build_mac folder: 3 | cmake -G "Xcode" .. 4 | 5 | Although Apple's compiler name clang is mostly compatible with C++17, 6 | there are some things left out as of now (macOS 10.15, Xcode 11.1). 7 | Other compilers, like gcc, can be installed using 3rd party package 8 | managers such as Homebrew (https://brew.sh) or MacPorts (https://www.macports.org). 9 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/include/pch.h: -------------------------------------------------------------------------------- 1 | // 2 | // pch.h 3 | // Header for standard system include files. 4 | // 5 | 6 | #pragma once 7 | 8 | #include "gtest/gtest.h" 9 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/ThirdPartyNotices.txt: -------------------------------------------------------------------------------- 1 | 2 | THIRD-PARTY SOFTWARE NOTICES AND INFORMATION 3 | Do Not Translate or Localize 4 | 5 | This package incorporates components from the projects listed below. Microsoft licenses these components to you under the license terms for the Microsoft package. The original copyright notices and the licenses under which Microsoft received such components are set forth below for informational purposes. Microsoft reserves all rights not expressly granted herein, whether by implication, estoppel or otherwise. 6 | 7 | 8 | 9 | 1. Google Test Framework (https://github.com/google/googletest) 10 | 11 | 12 | %% Google Test Framework NOTICES, INFORMATION, AND LICENSE BEGIN HERE 13 | ========================================= 14 | Copyright 2008, Google Inc. 15 | All rights reserved. 16 | 17 | Redistribution and use in source and binary forms, with or without 18 | modification, are permitted provided that the following conditions are 19 | met: 20 | 21 | * Redistributions of source code must retain the above copyright 22 | notice, this list of conditions and the following disclaimer. 23 | * Redistributions in binary form must reproduce the above 24 | copyright notice, this list of conditions and the following disclaimer 25 | in the documentation and/or other materials provided with the 26 | distribution. 27 | * Neither the name of Google Inc. nor the names of its 28 | contributors may be used to endorse or promote products derived from 29 | this software without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | ========================================= 43 | END OF Google Test Framework NOTICES, INFORMATION, AND LICENSE 44 | 45 | 46 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.propertiesui.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // Google C++ Testing and Mocking Framework definitions useful in production code. 32 | // GOOGLETEST_CM0003 DO NOT DELETE 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void PrivateMethod(); 44 | // FRIEND_TEST(MyClassTest, PrivateMethodWorks); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, PrivateMethodWorks) { 52 | // // Can call MyClass::PrivateMethod() here. 53 | // } 54 | // 55 | // Note: The test class must be in the same namespace as the class being tested. 56 | // For example, putting MyClassTest in an anonymous namespace will not work. 57 | 58 | #define FRIEND_TEST(test_case_name, test_name)\ 59 | friend class test_case_name##_##test_name##_Test 60 | 61 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 62 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/gtest/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gtest.h` 6 | 7 | ### The following macros can be defined: 8 | 9 | * `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of 10 | `OsStackTraceGetterInterface`. 11 | * `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See 12 | `testing::TempDir` for semantics and signature. 13 | 14 | ## Header `gtest-port.h` 15 | 16 | The following macros can be defined: 17 | 18 | ### Flag related macros: 19 | 20 | * `GTEST_FLAG(flag_name)` 21 | * `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its 22 | own flagfile flag parsing. 23 | * `GTEST_DECLARE_bool_(name)` 24 | * `GTEST_DECLARE_int32_(name)` 25 | * `GTEST_DECLARE_string_(name)` 26 | * `GTEST_DEFINE_bool_(name, default_val, doc)` 27 | * `GTEST_DEFINE_int32_(name, default_val, doc)` 28 | * `GTEST_DEFINE_string_(name, default_val, doc)` 29 | 30 | ### Logging: 31 | 32 | * `GTEST_LOG_(severity)` 33 | * `GTEST_CHECK_(condition)` 34 | * Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too. 35 | 36 | ### Threading: 37 | 38 | * `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided. 39 | * `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal` 40 | are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)` 41 | and `GTEST_DEFINE_STATIC_MUTEX_(mutex)` 42 | * `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)` 43 | * `GTEST_LOCK_EXCLUDED_(locks)` 44 | 45 | ### Underlying library support features 46 | 47 | * `GTEST_HAS_CXXABI_H_` 48 | 49 | ### Exporting API symbols: 50 | 51 | * `GTEST_API_` - Specifier for exported symbols. 52 | 53 | ## Header `gtest-printers.h` 54 | 55 | * See documentation at `gtest/gtest-printers.h` for details on how to define a 56 | custom printer. 57 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/gtest/internal/custom/gtest-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 35 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 36 | 37 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 38 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/gtest/internal/custom/gtest-printers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // This file provides an injection point for custom printers in a local 31 | // installation of gTest. 32 | // It will be included from gtest-printers.h and the overrides in this file 33 | // will be visible to everyone. 34 | // 35 | // Injection point for custom user configurations. See README for details 36 | // 37 | // ** Custom implementation starts here ** 38 | 39 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 40 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 41 | 42 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 43 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/gtest/internal/custom/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 35 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 36 | 37 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 38 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Debug/gtest_maind.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Debug/gtest_maind.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Debug/gtestd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Debug/gtestd.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Release/gtest.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Release/gtest.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Release/gtest_main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/Release/gtest_main.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Debug/gtest_maind.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Debug/gtest_maind.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Debug/gtestd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Debug/gtestd.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Release/gtest.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Release/gtest.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Release/gtest_main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/lib/native/v140/windesktop/msvcstl/static/rt-dyn/x86/Release/gtest_main.lib -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/license (MIT).txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogCyg/BookCpp/8a4e00a8afa8d4ba328e0635f89626bd81c6e0fb/RomanAppSuite/RomanApp_GTest/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/license (MIT).txt -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/src/pch.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pch.cpp 3 | // Include the standard header and generate the precompiled header. 4 | // 5 | 6 | #include "pch.h" 7 | -------------------------------------------------------------------------------- /RomanAppSuite/RomanApp_GTest/src/test.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | 3 | #include "Dec2Roman.h" 4 | 5 | TEST(TestCaseName, TestName) { 6 | EXPECT_EQ(1, 1); 7 | EXPECT_TRUE(true); 8 | } 9 | 10 | 11 | TEST( DecRoman_TestSuite, ChainTest ) 12 | { 13 | bool result = Decimal_2_Roman_Chain_UnitTest(); 14 | 15 | // NonFatal assertion 16 | EXPECT_EQ( result, true ) << "All decimals 1..3999 should pass and vice versa"; 17 | 18 | // Fatal assertion 19 | ASSERT_EQ( result, true ) << "All decimals 1..3999 should pass and vice versa"; 20 | } 21 | 22 | 23 | int main(int argc, char **argv) { 24 | ::testing::InitGoogleTest(&argc, argv); 25 | return RUN_ALL_TESTS(); 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /TheCube/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME TheCube ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /TheCube/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /TheCube/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TheCube/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TheCube/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TheCube/src/TheCube.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | 15 | #include "TheCube.h" 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | 29 | 30 | 31 | std::ostream & operator << ( std::ostream & o, const TheCube & cube ) 32 | { 33 | // Out data as binary streams 34 | o.write( reinterpret_cast< const char * >( & cube.fDim[ 0 ] ), 35 | sizeof( cube.fDim ) ); // sizeof returns size of the whole array 36 | o.write( reinterpret_cast< const char * >( cube.fDataBuf.get() ), 37 | cube.Size() * sizeof( TheCube::value_type ) ); 38 | return o; 39 | } 40 | 41 | 42 | std::istream & operator >> ( std::istream & i, TheCube & cube ) 43 | { 44 | // First read dimensions 45 | i.read( reinterpret_cast< char * >( & cube.fDim[ 0 ] ), sizeof( cube.fDim ) ); 46 | if( i ) // Check if the stream OK 47 | { 48 | cube.fDataBuf = std::make_unique< TheCube::value_type [] >( cube.Size() ); 49 | 50 | const auto cube_bytes = cube.Size() * sizeof( TheCube::value_type ); 51 | // read() accepts a number of bytes 52 | i.read( (char*)cube.fDataBuf.get(), cube_bytes ); // Read the rest of the data 53 | 54 | assert( i ); 55 | } 56 | return i; 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /TheCube/src/TheCubeTest.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | #include 15 | #include 16 | 17 | #include "TheCube.h" 18 | 19 | 20 | 21 | 22 | TheCube RetAbsCube( const TheCube & inCube ); 23 | 24 | 25 | // Test function for TheCube class 26 | void TheCube_Test( void ) 27 | { 28 | const int dx { 15 }, dy { 13 }, dz { 11 }; 29 | 30 | TheCube cube( dx, dy, dz ); 31 | 32 | // Random Mersenne twister 33 | std::mt19937 rand_gen{ std::random_device{}() }; 34 | 35 | // Fill the cube with random values; ref is a reference wrapper 36 | std::generate( cube.GetDataBuf(), cube.GetDataBuf() + cube.Size(), std::ref( rand_gen ) ); 37 | //std::generate( cube.GetDataBuf(), cube.GetDataBuf() + cube.Size(), std::mt19937( std::random_device{}() ) ); 38 | 39 | // Cannot move - only copy from cube since it is used further on 40 | TheCube mirror_cube( cube ); 41 | 42 | 43 | cube.Element( 5, 7, 9 ) = -100.0; // set an element 44 | assert( cube.Element( 5, 7, 9 ) == -100.0 ); // read and check 45 | 46 | std::ofstream outFile( "TheCube.bin", std::ios::binary ); 47 | outFile << cube; 48 | outFile.close(); // so we can open it in the next line 49 | 50 | std::ifstream inFile( "TheCube.bin", std::ios::binary ); 51 | TheCube testCube; 52 | inFile >> testCube; 53 | 54 | 55 | // Check if data the same byte after byte 56 | assert( std::memcmp( cube.GetDataBuf(), testCube.GetDataBuf(), cube.Size() * sizeof( TheCube::value_type ) ) == 0 ); 57 | 58 | 59 | // Call the move constructor 60 | TheCube abs_cube( RetAbsCube( cube ) ); 61 | 62 | // Explicitly call the move assignment operator 63 | cube = static_cast< TheCube && >( abs_cube ); 64 | 65 | 66 | std::ofstream outAbsFile( "TheAbsCube.bin", std::ios::binary ); 67 | outAbsFile << cube; 68 | 69 | } 70 | 71 | 72 | 73 | TheCube RetAbsCube( const TheCube & inCube ) 74 | { 75 | // Create an empty return cube of the same dimensions 76 | TheCube outCube( inCube.GetDim( TheCube::kx ), 77 | inCube.GetDim( TheCube::ky ), 78 | inCube.GetDim( TheCube::kz ) ); 79 | 80 | // Transform all elements to their absolute values 81 | std::transform( inCube.GetDataBuf(), inCube.GetDataBuf() + inCube.Size(), 82 | outCube.GetDataBuf(), [] ( TheCube::value_type v ) { return std::fabs( v ); } ); 83 | return outCube; // Invokes the move semantics 84 | } 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /TheCube/src/main.cpp: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // 3 | // Software written by Boguslaw Cyganek (C) to be used with the book: 4 | // INTRODUCTION TO PROGRAMMING WITH C++ FOR ENGINEERS 5 | // Published by Wiley, 2020 6 | // 7 | // The software is supplied as is and for educational purposes 8 | // without any guarantees nor responsibility of its use in any application. 9 | // 10 | // ========================================================================== 11 | 12 | 13 | 14 | void TheCube_Test( void ); 15 | 16 | 17 | 18 | int main() 19 | { 20 | TheCube_Test(); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /TheStack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.6.2 ) 2 | 3 | # For a new project it is sufficient to change only its name in the following line 4 | set( PROJECT_NAME TheStack ) 5 | 6 | project( ${PROJECT_NAME} ) 7 | 8 | set( CMAKE_BUILD_TYPE Debug ) 9 | #set( CMAKE_BUILD_TYPE Release ) 10 | 11 | 12 | #[[ADD_DEFINITIONS(-g++ -O2 -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)]] 13 | 14 | if( WIN32 ) 15 | set( CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /std:c++17 /D_UNICODE /DUNICODE" ) 16 | set( CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1 /std:c++17 /D_UNICODE /DUNICODE" ) 17 | message( "Win settings chosen..." ) 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) 19 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 20 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 21 | message( "Mac settings chosen..." ) 22 | elseif( UNIX ) 23 | set( CMAKE_CXX_FLAGS "-std=c++17 -Wall" ) 24 | set( CMAKE_CXX_FLAGS_DEBUG "-g -std=c++17 -Wall" ) 25 | message( "Linux settings chosen..." ) 26 | endif() 27 | 28 | 29 | # Inform CMake where the header files are 30 | include_directories( include ) 31 | 32 | 33 | # Automatically add all *.cpp and *.h files to the project 34 | file ( GLOB SOURCES "./src/*.cpp" "./include/*.h" ) 35 | add_executable( ${PROJECT_NAME} ${SOURCES} ) 36 | 37 | 38 | # Set the default project 39 | set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME} ) 40 | 41 | 42 | message( "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}" ) 43 | -------------------------------------------------------------------------------- /TheStack/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | To build a project do as follows: 3 | 4 | 1. Depending on your OS change directory to the one: 5 | build_win 6 | build_linux 7 | build_mac 8 | 9 | 2. Open terminal and set current directory to the above one. 10 | 11 | 3. type 12 | cmake .. 13 | 14 | 4. Go to the build_xxx directory and launch your project. 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /TheStack/build_linux/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TheStack/build_mac/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TheStack/build_win/Info.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a working project directory. 3 | Remember ALL its contents, including this file, can be deleted. 4 | Therefore do NOT put any source nor header files here. 5 | All source files should go to ../src 6 | All header files should go to ../include 7 | Remember to make frequent backups! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TheStack/src/TheStackTest.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include "range.h" 5 | #include "TheStack.h" 6 | 7 | 8 | 9 | 10 | // Partially specialized using 11 | template < auto MaxElems > 12 | using StackForInt_VarSize = CppBook::TStackFor< int, MaxElems >; 13 | 14 | // Full class 15 | using StackForInt = StackForInt_VarSize< 256 >; 16 | 17 | 18 | using std::cout, std::endl; 19 | 20 | 21 | 22 | void TheStackTest( void ) 23 | { 24 | StackForInt theStackForInt; 25 | 26 | cout << "\nValues pushed to the stack:\n"; 27 | 28 | // Push consecutive values 29 | for( auto a : CppBook::range( 16 ) ) 30 | cout << a << " ", theStackForInt.Push( a ); 31 | 32 | cout << "\nContent of the stack:\n"; 33 | 34 | // Print taking the top of the stack - for will do all 35 | for( StackForInt::value_type v {}; theStackForInt.Pop( v ); cout << v << " " ) 36 | ; 37 | } 38 | 39 | 40 | 41 | void TheStackTest_2( void ) 42 | { 43 | 44 | 45 | ////////////////////////////////////////////////////// 46 | 47 | // --------- 48 | class AClass 49 | { 50 | private: 51 | 52 | int fX {}; 53 | long fY {}; 54 | double fZ {}; 55 | 56 | public: 57 | 58 | AClass( int x = 0, long y = 0, double z = 0.0 ) : fX( x ), fY( y ), fZ( z ) 59 | {} 60 | 61 | }; 62 | 63 | using AStack_4_AClass = CppBook::TStackFor< AClass >; 64 | // --------- 65 | 66 | 67 | AStack_4_AClass theStackForAClass; 68 | 69 | 70 | AClass obj_1, obj_2; 71 | 72 | // Insert copies of the two objects 73 | for( int i = 0; i < 10; ++ i ) 74 | theStackForAClass.Push( obj_1 ), theStackForAClass.Push( obj_2 ); 75 | 76 | ////////////////////////////////////////////////////// 77 | 78 | 79 | } 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /TheStack/src/main.cpp: -------------------------------------------------------------------------------- 1 | // TheStack.cpp : Defines the entry point for the console application. 2 | // 3 | 4 | 5 | 6 | void TheStackTest( void ); 7 | 8 | 9 | int main() 10 | { 11 | TheStackTest(); 12 | return 0; 13 | } 14 | 15 | --------------------------------------------------------------------------------