├── .gitattributes ├── 01. Intro to cpp ├── addfruits.cpp └── example1.cpp ├── PyCpp ├── 01. Intro to cpp │ ├── addfruits - Copy.cpp │ ├── addfruits.cpp │ ├── example1 - Copy.cpp │ └── example1.cpp ├── 02. Development │ └── addfruits.cpp ├── 03. Input and output │ ├── Files1.cpp │ ├── FilesOut.cpp │ ├── LinkedList.cpp │ ├── States.txt │ ├── addfruits.cpp │ ├── fmtrs.cpp │ └── wbin.cpp ├── 04. Arrays and loops │ ├── arrayloops.cpp │ ├── numconv.cpp │ ├── stringdemo.cpp │ └── vectordemo.cpp ├── 05. Decisions │ ├── breakcont.cpp │ ├── ifcases.cpp │ ├── switcher.cpp │ ├── ternary.cpp │ └── ticketages.cpp ├── 06. Functions │ ├── constExample.cpp │ ├── funcdefault.cpp │ ├── funcproto.cpp │ └── functs.cpp ├── 07. Pointers │ ├── ChangeVec.cpp │ ├── charpointer.cpp │ └── pointers.cpp ├── 08. Sets and tuples │ ├── maps.cpp │ ├── setandTuple.cpp │ └── setsTuples.cpp ├── 09. Classes and OOP │ ├── EmployeeHeaders │ │ ├── Employee.cpp │ │ ├── Employee.h │ │ ├── EmployeeHeaders.cpp │ │ ├── Employees.cpp │ │ ├── Employees.h │ │ ├── Intern.cpp │ │ ├── Intern.h │ │ ├── TempEmployee.cpp │ │ └── TempEmployee.h │ ├── EmployeeProto.cpp │ ├── addNumsPoly.cpp │ ├── constClass.cpp │ ├── employee.cpp │ ├── publicEmployee.cpp │ ├── staticPoly.cpp │ └── textrectangle.cpp ├── 10. Pointers and memory │ ├── EmplUniqMove.cpp │ ├── EmplyUniquePtr.cpp │ └── destruct.cpp ├── 11. Linked lists │ ├── LinkedList.cpp │ └── copycon.cpp ├── 12. Templates │ ├── shapes.cpp │ ├── stack.cpp │ └── swapper.cpp ├── 13. wxWidgets I │ ├── Add2widgets │ │ ├── Add2widgets.cpp │ │ ├── BlueLabel.cpp │ │ └── BlueLabel.h │ ├── Frame1.cpp │ ├── Frame2.cpp │ ├── Frame3.cpp │ ├── HelloMenu │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ └── framework.h │ ├── HiThere │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ ├── Hithere.cpp │ │ └── framework.h │ ├── MoreAdding.cpp │ ├── dialogs.cpp │ ├── preproc.txt │ └── wxHello.py ├── 14. wxWidgets II Tables and lists │ ├── PizzaChecker.cpp │ ├── RadioButs.cpp │ ├── RadioButsBoxing │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ └── radioboxing.cpp │ ├── RadioColor │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ └── RadioColor.cpp │ ├── RadioColor2.cpp │ ├── SimpleListbox │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ └── SimpleListbox.cpp │ ├── StateListCombo │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ ├── State.cpp │ │ ├── State.h │ │ ├── StateListCombo.cpp │ │ ├── States.cpp │ │ ├── States.h │ │ ├── States.txt │ │ ├── StrFuncs.h │ │ └── Strfuncs.cpp │ ├── StateListGrid │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ ├── DButton.cpp │ │ ├── DButton.h │ │ ├── Mediator.cpp │ │ ├── Mediator.h │ │ ├── State.cpp │ │ ├── State.h │ │ ├── StateListGrid.cpp │ │ ├── States.cpp │ │ ├── States.h │ │ ├── States.txt │ │ ├── StrFuncs.h │ │ └── Strfuncs.cpp │ ├── StateLister │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ ├── State.cpp │ │ ├── State.h │ │ ├── StateLister.cpp │ │ ├── States.txt │ │ ├── Strfuncs.cpp │ │ └── Strfuncs.h │ ├── Treectl.cpp │ └── check3state.cpp ├── 15. Armadillo │ ├── ArmSimp.cpp │ ├── Fitbees │ │ ├── Fitbees.cpp │ │ ├── example1_win64.vcxproj │ │ └── fitbees.sln │ ├── SineFFT │ │ └── SineFFT │ │ │ ├── Mediator.cpp │ │ │ ├── Mediator.h │ │ │ ├── PaintWindow.cpp │ │ │ ├── PaintWindow.h │ │ │ ├── SineFFT.cpp │ │ │ ├── SineFFT.vcxproj │ │ │ ├── SineFFT.vcxproj.filters │ │ │ ├── SineFFT.vcxproj.user │ │ │ └── framework.h │ └── armamatrix.cpp ├── 16. Plotting │ ├── Fitbees.cpp │ ├── plotlines.C │ ├── plotlineserr.C │ ├── roottestplot.cpp │ ├── splottest │ │ ├── beedata.pdf │ │ └── splotest.cpp │ ├── wxBeePlotArray.cpp │ └── wxBeePlotVector │ │ ├── wxBeePlotVector.sln │ │ ├── wxBeePlotVector │ │ ├── framework.h │ │ ├── wxBeePlotVector.cpp │ │ ├── wxBeePlotVector.vcxproj │ │ ├── wxBeePlotVector.vcxproj.filters │ │ ├── wxBeePlotVector.vcxproj.user │ │ └── x64 │ │ │ └── Debug │ │ │ ├── vc143.idb │ │ │ ├── vc143.pdb │ │ │ ├── wxBeePlotVector.exe.recipe │ │ │ ├── wxBeePlotVector.ilk │ │ │ ├── wxBeePlotVector.log │ │ │ ├── wxBeePlotVector.obj │ │ │ └── wxBeePlotVector.tlog │ │ │ ├── CL.command.1.tlog │ │ │ ├── CL.read.1.tlog │ │ │ ├── CL.write.1.tlog │ │ │ ├── link.command.1.tlog │ │ │ ├── link.read.1.tlog │ │ │ ├── link.write.1.tlog │ │ │ └── wxBeePlotVector.lastbuildstate │ │ └── x64 │ │ └── Debug │ │ ├── wxBeePlotVector.exe │ │ └── wxBeePlotVector.pdb ├── 17. SQLite Databases │ ├── SQLite Prepared │ │ ├── Database.cpp │ │ ├── Database.h │ │ ├── Makegrocerydb.cpp │ │ ├── PreparedQuery1.cpp │ │ ├── PreparedQuery1.h │ │ ├── PriceTable.cpp │ │ ├── PriceTable.h │ │ ├── Results.cpp │ │ ├── Results.h │ │ ├── SQLite prepared.cpp │ │ ├── Table.cpp │ │ ├── Table.h │ │ ├── globaldefs.h │ │ ├── groceries.db │ │ ├── mygroc.db │ │ ├── sqltDatabase.cpp │ │ ├── sqltDatabase.h │ │ ├── sqltPrepQuery.cpp │ │ ├── sqltPrepQuery.h │ │ ├── sqltQuery.cpp │ │ └── sqltQuery.h │ ├── SQLite Tables │ │ ├── Makegrocerydb.cpp │ │ ├── PriceTable.cpp │ │ ├── PriceTable.h │ │ ├── Query.cpp │ │ ├── Query.h │ │ ├── Results.cpp │ │ ├── Results.h │ │ ├── Table.cpp │ │ ├── Table.h │ │ ├── globaldefs.h │ │ ├── groceries.db │ │ ├── mygroc.db │ │ ├── sqltDatabase.cpp │ │ └── sqltDatabase.h │ ├── SQLite external classes │ │ ├── Query.cpp │ │ ├── Query.h │ │ ├── Results.cpp │ │ ├── Results.h │ │ ├── SQlite external classes.cpp │ │ ├── globaldefs.h │ │ ├── groceries.db │ │ ├── sqltDatabase.cpp │ │ └── sqltDatabase.h │ ├── Simple SQLite Database Classes │ │ ├── SImple SQL Database classes.cpp │ │ └── groceries.db │ └── sqlitest │ │ ├── groceries.db │ │ └── sqllitest.cpp ├── 18. MySQL Databases │ ├── MySQL Prepared Query │ │ ├── Database.cpp │ │ ├── Database.h │ │ ├── MySQl Prepared.cpp │ │ ├── PreparedQuery.cpp │ │ ├── PreparedQuery.h │ │ ├── PriceTable.cpp │ │ ├── PriceTable.h │ │ ├── Query.cpp │ │ ├── Query.h │ │ ├── Results.cpp │ │ ├── Results.h │ │ ├── globaldefs.h │ │ ├── msqDatabase.cpp │ │ ├── msqDatabase.h │ │ ├── msqTable.cpp │ │ └── msqTable.h │ ├── MySQL Table rows │ │ └── MySQL table add.cpp │ ├── MySQL db tables │ │ ├── Database.cpp │ │ ├── Database.h │ │ ├── MySQl tables.cpp │ │ ├── PriceTable.cpp │ │ ├── PriceTable.h │ │ ├── Query.cpp │ │ ├── Query.h │ │ ├── Results.cpp │ │ ├── Results.h │ │ ├── globaldefs.h │ │ ├── msqDatabase.cpp │ │ ├── msqDatabase.h │ │ ├── msqTable.cpp │ │ └── msqTable.h │ ├── MySQL test.cpp │ └── Timing prepared │ │ └── MySQL test.cpp ├── 19. Namespaces and Modules │ ├── Our modules │ │ ├── Cuber.cpp │ │ ├── Minimath.cpp │ │ ├── Minimath.ixx │ │ └── Our Module.cpp │ ├── Tiny module │ │ ├── Cuber.cpp │ │ ├── Minimath.cpp │ │ ├── Minimath.ixx │ │ └── TinyModule.cpp │ └── Tiny namespace │ │ ├── Cuber.cpp │ │ ├── Minimath.cpp │ │ ├── TinyModule.cpp │ │ ├── TinyNamespace.cpp │ │ └── minimath.h ├── 20. Factory patterns │ ├── Console Namer │ │ ├── ConsoleNamer.cpp │ │ └── Namer.h │ ├── SwimDisplay │ │ ├── 100free.txt │ │ ├── 500free.txt │ │ ├── BlueLabel.cpp │ │ ├── BlueLabel.h │ │ ├── CircleSeeding.cpp │ │ ├── CircleSeeding.h │ │ ├── Event.cpp │ │ ├── Event.h │ │ ├── PrelimEvent.cpp │ │ ├── PrelimEvent.h │ │ ├── Seeding.cpp │ │ ├── Seeding.h │ │ ├── State.cpp │ │ ├── State.h │ │ ├── States.txt │ │ ├── StraightSeeding.cpp │ │ ├── StraightSeeding.h │ │ ├── Strfuncs.cpp │ │ ├── Strfuncs.h │ │ ├── Swimgui.cpp │ │ ├── Swimmer.cpp │ │ ├── Swimmer.h │ │ ├── SwmHeaders.h │ │ ├── TimedFinalEvent.h │ │ ├── TimedFinaleEvent.cpp │ │ └── framework.h │ ├── SwimGrid │ │ ├── 100free.txt │ │ ├── 500free.txt │ │ ├── CircleSeeding.cpp │ │ ├── CircleSeeding.h │ │ ├── Event.cpp │ │ ├── Event.h │ │ ├── PrelimEvent.cpp │ │ ├── PrelimEvent.h │ │ ├── Seeding.cpp │ │ ├── Seeding.h │ │ ├── StraightSeeding.cpp │ │ ├── StraightSeeding.h │ │ ├── SwimSeedclasses.cpp │ │ ├── Swimgrid.cpp │ │ ├── Swimmer.cpp │ │ ├── Swimmer.h │ │ ├── SwmHeaders.h │ │ ├── TimedFinalEvent.h │ │ ├── TimedFinaleEvent.cpp │ │ └── framework.h │ ├── SwimSeed classes │ │ ├── 100free.txt │ │ ├── 500free.txt │ │ ├── CircleSeeding.cpp │ │ ├── CircleSeeding.h │ │ ├── Event.cpp │ │ ├── Event.h │ │ ├── PrelimEvent.cpp │ │ ├── PrelimEvent.h │ │ ├── Seeding.cpp │ │ ├── Seeding.h │ │ ├── StraightSeeding.cpp │ │ ├── StraightSeeding.h │ │ ├── SwimSeedclasses.cpp │ │ ├── SwimSeedclassesorig.cpp │ │ ├── Swimmer.cpp │ │ ├── Swimmer.h │ │ ├── SwmHeaders.h │ │ ├── TimedFinalEvent.h │ │ └── TimedFinaleEvent.cpp │ ├── SwimSeed │ │ ├── 100free.txt │ │ ├── 500free.txt │ │ └── SwimSeed.cpp │ └── UI Namer │ │ └── UINamer.cpp ├── 21. Abstract Factory │ └── AbsFactory │ │ ├── AbsFactory.cpp │ │ ├── Garden.cpp │ │ └── Garden.h ├── 22. Adapters │ ├── Basic Adapter │ │ ├── BasicAdapter.cpp │ │ ├── DButton.cpp │ │ ├── DButton.h │ │ ├── Mediator.cpp │ │ ├── Mediator.h │ │ └── baseincludes.h │ ├── Grid Adapter │ │ ├── DButton.cpp │ │ ├── DButton.h │ │ ├── GridAdapter.cpp │ │ ├── GridAdapter.h │ │ ├── ListToGrid.cpp │ │ ├── Mediator.cpp │ │ ├── Mediator.h │ │ ├── StrFuncs.h │ │ ├── Strfuncs.cpp │ │ ├── baseincludes.h │ │ └── framework.h │ ├── StudentListAdapter │ │ ├── DButton.cpp │ │ ├── DButton.h │ │ ├── Mediator.cpp │ │ ├── Mediator.h │ │ ├── StrFuncs.h │ │ ├── Strfuncs.cpp │ │ ├── Student.cpp │ │ ├── Student.h │ │ ├── StudentList.cpp │ │ ├── StudentList.h │ │ ├── StudentListDisplay.cpp │ │ ├── baseincludes.h │ │ └── framework.h │ └── StudentListGridAdapter │ │ ├── DButton.cpp │ │ ├── DButton.h │ │ ├── GridAdapter.cpp │ │ ├── GridAdapter.h │ │ ├── GridAdapterClass.cpp │ │ ├── GridAdapterClass.h │ │ ├── Mediator.cpp │ │ ├── Mediator.h │ │ ├── StrFuncs.h │ │ ├── Strfuncs.cpp │ │ ├── Student.cpp │ │ ├── Student.h │ │ ├── StudentList.cpp │ │ ├── StudentList.h │ │ ├── StudentListDisplay.cpp │ │ ├── baseincludes.h │ │ └── framework.h └── 23. Bridge pattern │ ├── Bridger1 │ ├── Bridger.h │ ├── BridgerLists.cpp │ ├── GrdVisList.cpp │ ├── GrdVisList.h │ ├── GridBridge.cpp │ ├── GridBridge.h │ ├── LbVisList.cpp │ ├── LbVisList.h │ ├── ListBridge.cpp │ ├── ListBridge.h │ ├── Product.cpp │ ├── Product.h │ ├── Products.cpp │ ├── Products.h │ ├── VisList.cpp │ ├── VisList.h │ ├── baseincludes.h │ ├── framework.h │ └── products.txt │ └── SortBridges │ ├── Bridger.h │ ├── BridgerLists.cpp │ ├── GridBridge.cpp │ ├── GridBridge.h │ ├── ListBridge.h │ ├── Product.cpp │ ├── Product.h │ ├── Products.cpp │ ├── Products.h │ ├── SortGrdVisList.cpp │ ├── SortGrdVisList.h │ ├── SortLbVisList.cpp │ ├── SortLbVisList.h │ ├── SortListBridge.cpp │ ├── VisList.cpp │ ├── VisList.h │ ├── baseincludes.h │ ├── framework.h │ └── products.txt ├── Pythonpatterns ├── 1. Intorduction to Objects │ ├── BasicHR.py │ ├── Rectangle.py │ ├── Speaker.py │ ├── addnumstype.py │ ├── checkboxes.py │ └── hrclasses.py ├── 10. Prototype │ ├── Proto.py │ └── Swimmers.txt ├── 12. Adapter │ ├── addStudents.py │ └── addStudentsAdapter.py ├── 13. Bridge │ ├── BasicBridge.py │ ├── SortBridge.py │ ├── TreeBridge.py │ └── products.txt ├── 14. Composite │ ├── DoublyLinked.py │ ├── Employees.py │ └── EmployeesConsole.py ├── 15. Decorator │ ├── DecoCode.py │ ├── DecoFunc.py │ ├── SimpleDecoratorTk.py │ ├── SimpleDecoratorTtk.py │ ├── dclass.py │ └── dclasse.py ├── 16. Facade │ ├── DBobjects.py │ ├── GroceryDispLite.py │ ├── GroceryDisplay.py │ ├── Makedatabase.py │ ├── MysqlDatabase.py │ ├── SimpleDbObjects.py │ ├── SqltDatabase.py │ ├── dbtest.py │ ├── groceries.db │ └── makesqllite.py ├── 17. Flyweight │ └── Flyfolders.py ├── 18. Proxy │ ├── Canvasversion.py │ ├── ThreadCanvas.py │ ├── ThreadLogging.py │ └── edward.jpg ├── 2. Visual programming │ ├── Hellobuts.py │ ├── Menus.py │ ├── Messageboxes.py │ ├── ObjMenus.py │ ├── SimpleMath.py │ ├── YourName.py │ ├── add2Class.py │ ├── arm.py │ ├── checkboxes.py │ ├── derived2buts.py │ ├── disable.py │ ├── gridoptions.py │ ├── labelframetext.py │ ├── packoptions.py │ ├── radiobuts.py │ └── radioclassbuttons.py ├── 20. Chain │ ├── ChainDemo.py │ ├── HelpWindow.py │ └── mandrill.jpg ├── 21. Command │ ├── RedCommand.py │ ├── UndoDemo.py │ └── keyboardCommand.py ├── 22. Interpreter │ ├── 100free.txt │ ├── InterpretConsole.py │ └── InterpretDisplay.py ├── 23. Iterator │ ├── 100free.txt │ ├── FiboIter.py │ ├── FilteredIter.py │ ├── Simple iter examples.py │ ├── fiboclass.py │ └── fibogen.py ├── 24. Mediator │ ├── 100free.txt │ └── MedDemo.py ├── 25. Memento │ └── MementoRectHide.py ├── 26. Observer │ └── ObserveColors.py ├── 27. State │ ├── StateMaster.py │ ├── arrow.gif │ ├── circle for button.jpg │ ├── circlebutton.png │ ├── rectforbutton.jpg │ ├── rectforbutton.png │ ├── red for button.jpg │ └── redbutton.png ├── 28. Strategy │ ├── StrategyPlot.py │ └── data.txt ├── 29. Template │ └── Triangles.py ├── 3. Visual tables │ ├── ListBoxStateData.py │ ├── SimpleList.py │ ├── StateDisplayCombo.py │ ├── StateLIstbox.py │ ├── StateLiistScroll.py │ ├── States.txt │ ├── TreeStates.py │ ├── TreeTest.py │ └── t3.py ├── 30. Visitor │ └── EmployeeVisits.py ├── 31. Variables and Syntax │ ├── examples.py │ ├── inputdemo.py │ └── printbin.py ├── 32. Making Decisions │ ├── breaks.py │ ├── continue.py │ ├── decisions.py │ ├── examples.py │ └── matchtests.py ├── 34. Collections and files │ ├── Slicing.py │ ├── checkboxes.py │ ├── comprehend.py │ ├── exceptions.py │ ├── fibo.py │ ├── fibohard.py │ ├── maptest.py │ ├── sets.py │ ├── stateNames.txt │ ├── statearray.py │ ├── statedict.py │ └── tuplecase.py ├── 35. Functions │ ├── funcs.py │ └── upperlower.py ├── 5. SimpleFactory │ ├── Cocoon.py │ ├── NameUi.py │ └── NamerConsole.py ├── 6. FactoryMethod │ ├── 100free.txt │ ├── 500free.txt │ ├── SwimClasses.py │ ├── SwimFactory.py │ ├── SwimFactoryConsole.py │ └── SwimFactoryTable.py ├── 7. AbstractFactory │ └── Gardening.py ├── 8. Singleton │ ├── Spooler.py │ └── testlock.py ├── 9. Builder │ ├── BuildChoices.py │ └── TreeStates.py └── Appendix │ └── Helllobutsargs.py ├── README.md ├── articles ├── AddressBook │ └── AddLayout.py ├── CppClasses │ ├── Rectangles.cpp │ └── Rectangles.py ├── PyQt5 │ ├── Add2.py │ └── SATBDemo.py └── rockpaper │ ├── btnDisableRock.py │ ├── rockscis.py │ └── visRockpaper.py └── newsletter ├── Add2Numbers ├── Add2Radio.py ├── Add2lambda.py ├── Add2pyqt.py └── add2Class.py ├── Bingo ├── BingoCanvas.py ├── BingoTree.py ├── bingo.py └── bingoexamples.py ├── CSV files ├── Viewcsvtable.py ├── basecsv.py ├── csvheaders.py ├── namehlist.csv └── namelist.csv ├── Classes ├── BasicButtons.py ├── BasicHR.py ├── Buttonclick.py ├── ButtonclickClasses.py └── hrclasses.py ├── Countdown ├── CountThreadsStop.py ├── CountdownTHreads.py ├── Hms.py ├── HmsSimple.py ├── __pycache__ │ └── HmsSimple.cpython-310.pyc ├── countDownSimple.py ├── countDownTK.py └── countdown.py ├── Dataclass ├── dclass.py └── dclasse.py ├── Facade ├── DBObjects.py ├── GroceryDispLite.py ├── GroceryDisplay.py ├── Makedatabase.py ├── MysqlDatabase.py ├── SimpleDbObjects.py ├── SqltDatabase.py ├── dbtest.py ├── groceries.db └── makesqllite.py ├── FacadeDict ├── DBObjects.py ├── GroceryDispLite.py └── groceries.db ├── Generators ├── fibo.py ├── fiboclass.py └── geniter.py ├── Iter-Enumerators └── Iterdemos.py ├── Iterators ├── FiboIter.py └── Simple iter examples.py ├── Keyboard Command └── keyboardCommand.py ├── Kivy ├── AddNumbers.kv ├── AddNumbers.py ├── Calc.py ├── calc-tkinter.py ├── calc.kv ├── onebut.kv ├── onebut.py ├── onebut1.kv └── onebut2.kv ├── Maptest └── maptest.py ├── Match └── matchtests.py ├── NameUi.py ├── Overloading └── overload.py ├── Parseargs ├── ArgUI.py ├── OneArg.py ├── file.txt └── py-arg.py ├── Polymorphic ├── Employees.py ├── addArgs.py ├── addClass.py ├── addClasses.py ├── addFactory.py ├── addMatch.py ├── addNumsWrong.py ├── addnumstype.py └── lenTest.py ├── PyQt5 ├── buttons.py ├── qtd.py ├── qtd.ui ├── qtdplain.py └── vbdata │ ├── Form1.Designer.vb │ ├── Form1.resx │ └── Form1.vb ├── PySimpleGUI ├── add2.py ├── basicAdd2.py ├── basicCode.py ├── calc-izdr.py └── calc-tkinter.py ├── PythonToCpp ├── Add2.cpp ├── SimpleAdd.cpp └── timeloop.cpp ├── RankedVoting ├── RankVote.py ├── RankVote1.py └── RankedVoteTk.py ├── SwimClasses.py ├── SwimFactory.py ├── SwimFactoryConsole.py ├── SwimFactoryTable.py ├── Tictac └── board.py ├── Two buttons ├── twobuts.py └── twobutsClass.py ├── Typehints1 ├── adder.py ├── mmeta.py ├── mtimethod.py ├── multidisp.py ├── singledispatch.py └── typehints.py ├── Wordcounter └── WordCounter.py ├── listcomp.py └── wxpy ├── Add2wxpy.py ├── basicWxadd.py ├── firstTtk.py ├── hellowtkinter.py ├── wxExample.py ├── wxHello.py └── wxHello2.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /01. Intro to cpp/addfruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //using namespace std; 3 | using std::cout; 4 | using std::cin; 5 | using std::endl; 6 | 7 | //Add up the amount of fruit you have 8 | int main() { 9 | int apples, oranges; 10 | 11 | //get numbers of apples and oranges from keyboard 12 | cout << "Enter number of apples :"; 13 | cin >> apples; 14 | cout << "Enter number of oranges :"; 15 | cin >> oranges; 16 | 17 | //add them together 18 | int fruits = apples + oranges; 19 | 20 | // print out the sum 21 | cout << "Total fruit " << fruits << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /01. Intro to cpp/example1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //Add up the amount of fruit you have 5 | int main() { 6 | int apples = 5; 7 | int oranges = 7; 8 | int fruits = apples + oranges; 9 | 10 | // print out the sum 11 | cout << "Total fruit " << fruits << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /PyCpp/01. Intro to cpp/addfruits - Copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //using namespace std; 3 | using std::cout; 4 | using std::cin; 5 | using std::endl; 6 | 7 | //Add up the amount of fruit you have 8 | int main() { 9 | int apples, oranges; 10 | 11 | //get numbers of apples and oranges from keyboard 12 | cout << "Enter number of apples :"; 13 | cin >> apples; 14 | cout << "Enter number of oranges :"; 15 | cin >> oranges; 16 | 17 | //add them together 18 | int fruits = apples + oranges; 19 | 20 | // print out the sum 21 | cout << "Total fruit " << fruits << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /PyCpp/01. Intro to cpp/addfruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //using namespace std; 3 | using std::cout; 4 | using std::cin; 5 | using std::endl; 6 | 7 | //Add up the amount of fruit you have 8 | int main() { 9 | int apples, oranges; 10 | 11 | //get numbers of apples and oranges from keyboard 12 | cout << "Enter number of apples :"; 13 | cin >> apples; 14 | cout << "Enter number of oranges :"; 15 | cin >> oranges; 16 | 17 | //add them together 18 | int fruits = apples + oranges; 19 | 20 | // print out the sum 21 | cout << "Total fruit " << fruits << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /PyCpp/01. Intro to cpp/example1 - Copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //Add up the amount of fruit you have 5 | int main() { 6 | int apples = 5; 7 | int oranges = 7; 8 | int fruits = apples + oranges; 9 | 10 | // print out the sum 11 | cout << "Total fruit " << fruits << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /PyCpp/01. Intro to cpp/example1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //Add up the amount of fruit you have 5 | int main() { 6 | int apples = 5; 7 | int oranges = 7; 8 | int fruits = apples + oranges; 9 | 10 | // print out the sum 11 | cout << "Total fruit " << fruits << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /PyCpp/02. Development/addfruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //using namespace std; 3 | using std::cout; 4 | using std::cin; 5 | using std::endl; 6 | 7 | //Add up the amount of fruit you have 8 | int main() { 9 | int apples, oranges; 10 | 11 | //get numbers of apples and oranges from keyboard 12 | cout << "Enter number of apples :"; 13 | cin >> apples; 14 | cout << "Enter number of oranges :"; 15 | cin >> oranges; 16 | 17 | //add them together 18 | int fruits = apples + oranges; 19 | 20 | // print out the sum 21 | cout << "Total fruit " << fruits << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /PyCpp/03. Input and output/Files1.cpp: -------------------------------------------------------------------------------- 1 | // Files1.cpp : This file contains the 'main' function. Program execution begins and ends there. 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | const string FILENAME = "states.txt"; 13 | 14 | ifstream txtFile(FILENAME); //open the file 15 | if (txtFile.is_open()) { //if it is open 16 | string line; 17 | while (getline(txtFile, line)) { //read it a line at a time 18 | cout << line << endl; //print out each line 19 | } 20 | txtFile.close(); //close the file 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /PyCpp/03. Input and output/FilesOut.cpp: -------------------------------------------------------------------------------- 1 | // FilesOut.cpp : This file contains the 'main' function. 2 | // Program execution begins and ends there. 3 | // 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int main() { 13 | const string FILENAME = "states.txt"; 14 | const string OUTFILE = "mystates.txt"; 15 | 16 | ifstream txtFile(FILENAME); //open input file 17 | ofstream outFile(OUTFILE); //open output file 18 | 19 | 20 | if (txtFile.is_open() && outFile.is_open()) { //if it is open 21 | string line; 22 | while (getline(txtFile, line)) { //read it a line at a time 23 | cout << line << endl; //print out each line 24 | outFile << line << endl; //write to output file 25 | } 26 | txtFile.close(); //close both files 27 | outFile.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PyCpp/03. Input and output/addfruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //using namespace std; 3 | using std::cout; 4 | using std::cin; 5 | using std::endl; 6 | 7 | //Add up the amount of fruit you have 8 | int main() { 9 | int apples, oranges; 10 | 11 | //get numbers of apples and oranges from keyboard 12 | cout << "Enter number of apples :"; 13 | cin >> apples; 14 | cout << "Enter number of oranges :"; 15 | cin >> oranges; 16 | 17 | //add them together 18 | int fruits = apples + oranges; 19 | 20 | // print out the sum 21 | cout << "Total fruit " << fruits << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /PyCpp/03. Input and output/wbin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | double temps[] = {22.3,35.7,44.8,55.2,61.6,73.8,89.3}; 7 | 8 | //write entire file at once 9 | ofstream outfile; 10 | outfile.open("temps.dat", ios::binary | ios::out); 11 | outfile.write((const char*)&temps, sizeof(temps)); 12 | outfile.close(); 13 | 14 | //write a byte at a time 15 | outfile.open("tempsb1.dat", ios::binary |ios::out); 16 | for (int i=0; i< size(temps); i++){ 17 | outfile.write((const char*)&temps[i], sizeof(temps[i])); 18 | } 19 | outfile.close(); 20 | 21 | double newtemps[7]; //create empty array 22 | ifstream infile; 23 | // read in data all at once 24 | infile.open("tempsb1.dat", ios::binary | ios::in); 25 | infile.read((char*)&newtemps, sizeof(newtemps)); // reads 56 bytes 26 | infile.close(); 27 | 28 | //print out contents of new array 29 | for (double x:newtemps) { 30 | cout << x <<" "; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /PyCpp/04. Arrays and loops/numconv.cpp: -------------------------------------------------------------------------------- 1 | // numconv.cpp : 2 | // Examples of converting numbers and strings 3 | // This file contains the 'main' function. Program execution begins and ends there. 4 | // 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | using std::string; 11 | using std::stod; 12 | using std::cout; 13 | using std::endl; 14 | using std::to_string; 15 | using std::format; 16 | 17 | int main() 18 | { 19 | double x = 2.34; 20 | double y = 12; 21 | int k = (int)x; 22 | float f = y; //compiler warning 23 | float f1 = (float)y; //no warning 24 | 25 | //convert string to numbers 26 | string snum = "123.4"; 27 | double dnum = stod(snum); //convert to double 28 | float fnum = stof(snum); //convert to float 29 | int inum = stoi(snum); //convert to int 30 | cout << dnum << " " << inum << endl; 31 | 32 | //convert number to string 33 | string newst = to_string(dnum); 34 | cout << newst << endl; 35 | 36 | string outf = format("{:.2f}", dnum ); 37 | cout << outf << endl; 38 | 39 | 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /PyCpp/05. Decisions/breakcont.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | double xarray[] ={5, 7, 4, 3, 9, 12 ,6}; 6 | double sum = 0; 7 | for (double x: xarray) { 8 | sum += x; 9 | if (sum > 16) { 10 | break; 11 | } 12 | } 13 | cout << "Sum1 = " << sum < 16; 22 | } 23 | cout << "Sum2 = " << sum < 2 | using std::cout; 3 | using std::endl; 4 | 5 | int main() { 6 | int berries =100; 7 | int beans = 50; 8 | 9 | int produce = (berries > beans) ? berries : beans; 10 | cout <<"produce is: "<< produce << endl; 11 | 12 | if (berries > beans) 13 | produce = berries; 14 | else 15 | produce = beans; 16 | 17 | cout <<"produce is: "<< produce << endl; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /PyCpp/05. Decisions/ticketages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // if else demo using ticket prices 6 | int age = 22; //start with a non zero age. 7 | while (age > 0) { 8 | cout << "Enter age :"; 9 | cin >>age; 10 | int price = 35; 11 | if (age <= 6) 12 | price = 0; //toddlers are free 13 | else if ((age > 6) && (age <18)) 14 | price=15; //student price 15 | else if ((age >=18) && (age < 60)) 16 | price = 35; //adult 17 | else if ((age >=60) && (age <80)) 18 | price = 30; //senio 19 | else 20 | price = 20; //super senior 21 | 22 | cout << "Price is :"< 2 | 3 | using std::cout; 4 | using std::endl; 5 | 6 | double meanValue(const double x[], size_t size) { 7 | double sum = 0; 8 | for (size_t i=0; i 2 | using std::cout; using std::endl; 3 | 4 | //square the argument and return it 5 | double sq(double x) { 6 | double y = x * x; //create the square 7 | return y; //and return it 8 | } 9 | 10 | //cube the argument and return it 11 | double cube(double x) { 12 | double y = sq(x); 13 | y = y * x; //create the sube 14 | return y; //and return it 15 | } 16 | int sq(int x ){ 17 | return x*x; 18 | } 19 | double power (double x, int pwr) { 20 | if (pwr ==2) 21 | return sq(x); 22 | else if (pwr ==3) 23 | return cube(x); 24 | else{ 25 | double y=1; 26 | for (int i=1; i<= pwr; i++){ 27 | y =y * x; 28 | } 29 | return y; 30 | } 31 | 32 | 33 | } 34 | int main() { 35 | double asqd = sq(12.0); 36 | double cubed = cube(12.0); 37 | cout << asqd <<" "<< cubed<< endl; 38 | cout << sq(34)< 5 | #include 6 | using std::vector; 7 | using std::cout; 8 | using std::endl; 9 | 10 | //print out contents of vector 11 | void printvec(vector z) { 12 | for (auto k : z) { 13 | cout << k << " "; 14 | } 15 | cout << endl; 16 | } 17 | void changeVec(vector& px) { 18 | //void changeVec(vectorpx) { 19 | if (2 < px.size()) { 20 | px[2] = 123; 21 | } 22 | printvec(px); 23 | } 24 | 25 | int main(){ 26 | vector v = { 3,6,7,8,12 }; 27 | changeVec(v); 28 | printvec(v); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/Employee.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by James on 8/3/2022. 3 | // 4 | #include "Employee.h" 5 | //---Employee methods--- 6 | Employee::Employee(int id, string frnm, string lnm, double sal, double benefits ) { 7 | frname = frnm; 8 | lname = lnm; 9 | idNum = id; 10 | salary = sal; 11 | this->benefits = benefits; 12 | } 13 | double Employee::getSalary() {return salary; } 14 | string Employee::getName() {return frname + " " + lname; } 15 | int Employee::getId() {return idNum; } 16 | double Employee::getBenefit() {return benefits;} 17 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/Employee.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by James on 8/3/2022. 3 | // 4 | 5 | #ifndef EMPLOYEEHEADERS_EMPLOYEE_H 6 | #define EMPLOYEEHEADERS_EMPLOYEE_H 7 | #include 8 | using namespace std; 9 | 10 | class Employee { 11 | protected: 12 | int idNum; 13 | string frname, lname; 14 | double salary; 15 | double benefits ; 16 | public: 17 | Employee(int id, string frnm, string lnm, double sal, double benefits=1000); 18 | double getSalary(); 19 | string getName(); 20 | int getId(); 21 | double getBenefit(); 22 | }; 23 | 24 | #endif //EMPLOYEEHEADERS_EMPLOYEE_H 25 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/Employees.cpp: -------------------------------------------------------------------------------- 1 | // Created by James on 8/3/2022. 2 | // 3 | #include "Employees.h" 4 | #include "Employee.h" 5 | //---Employees methods--- 6 | void Employees::addEmployee(Employee* emp) { 7 | employees.push_back(emp); 8 | } 9 | //get the size of the vector 10 | int Employees::getCount() { 11 | return employees.size(); 12 | } 13 | //get the pointer to the i-th Employee 14 | Employee* Employees::get(int i) { 15 | return employees[i]; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/Employees.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by James on 8/3/2022. 3 | // 4 | 5 | #ifndef EMPLOYEEHEADERS_EMPLOYEES_H 6 | #define EMPLOYEEHEADERS_EMPLOYEES_H 7 | #include "Employee.h" 8 | #include 9 | using namespace std; 10 | 11 | class Employees { 12 | private: 13 | vector employees; 14 | public: 15 | void addEmployee(Employee* emp); 16 | int getCount(); 17 | Employee* get(int i); 18 | }; 19 | 20 | #endif //EMPLOYEEHEADERS_EMPLOYEES_H 21 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/Intern.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by James on 8/3/2022. 3 | // 4 | 5 | #include "Intern.h" 6 | #include 7 | using namespace std; 8 | 9 | //----Intern methods----- 10 | //cap the salary at 500 no matter what was entered 11 | void Intern::capSalary() { 12 | if (salary > 500) { 13 | salary = 500; 14 | } 15 | } 16 | 17 | Intern::Intern(int id, string frnm, string lnm, double sal) : 18 | Employee(id, frnm, lnm, sal) { 19 | benefits = 0; // no benefits either 20 | capSalary(); //cap the salary 21 | } 22 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/Intern.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by James on 8/3/2022. 3 | // 4 | 5 | #ifndef EMPLOYEEHEADERS_INTERN1_H 6 | #define EMPLOYEEHEADERS_INTERN1_H 7 | #include "Employee.h" 8 | 9 | class Intern : public Employee { 10 | private: 11 | //cap the salary at 500 no matter what was entered 12 | void capSalary(); 13 | 14 | public: 15 | Intern(int id, string frnm, string lnm, double sal); 16 | }; 17 | #endif //EMPLOYEEHEADERS_INTERN1_H 18 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/TempEmployee.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by James on 8/3/2022. 3 | // 4 | #include "Employee.h" 5 | #include "TempEmployee.h" 6 | 7 | #include 8 | using namespace std; 9 | 10 | //---Temp Employee methods-- 11 | TempEmployee::TempEmployee(int id, string frnm, string lnm, double sal) : 12 | Employee(id, frnm, lnm, sal) { 13 | benefits = 0; //temp employees do not get benefits 14 | } 15 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/EmployeeHeaders/TempEmployee.h: -------------------------------------------------------------------------------- 1 | 2 | // Created by James on 8/3/2022. 3 | // 4 | 5 | #ifndef EMPLOYEEHEADERS_TEMPEMPLOYEE_H 6 | #define EMPLOYEEHEADERS_TEMPEMPLOYEE_H 7 | class TempEmployee : public Employee { 8 | public: 9 | TempEmployee(int id, string frnm, string lnm, double sal); 10 | }; 11 | #endif //EMPLOYEEHEADERS_TEMPEMPLOYEE_H 12 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/addNumsPoly.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using std::string; 4 | using std::cout; 5 | using std::endl; 6 | 7 | class Adder { 8 | public: 9 | double addNums(double x, double y) { 10 | return x + y; 11 | } 12 | double addNums(string x, double y) { 13 | return stod(x) + y; 14 | } 15 | double addNums(string x, string y) { 16 | return stod(x) + stod(y); 17 | } 18 | double addNums(double x, string y) { 19 | return x + stod(y); 20 | } 21 | double addNums(double x, double y, double z){ 22 | return x + y + + z; 23 | } 24 | }; 25 | 26 | int main() { 27 | Adder adder; //create instance of Adder 28 | cout << adder.addNums(12.1, 14) << endl; 29 | cout << adder.addNums("22.4", "1.008") << endl; 30 | cout << adder.addNums(123.4, "6.02") << endl; 31 | cout << adder.addNums(122.3,303.4,45.6) << endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /PyCpp/09. Classes and OOP/constClass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using std::cout; 3 | using std::endl; 4 | 5 | class Rectangle { 6 | private: 7 | double width; 8 | double height; 9 | public: 10 | Rectangle(double w, double h):width{w}, height{h}{} 11 | //void setWidth(double w){width = w;} 12 | //void setHeight(double h) {height=h; } 13 | double getwidth() const {return width;} 14 | double getHeight() const {return height;} 15 | double getArea() const {return width * height;} 16 | }; 17 | 18 | int main() { 19 | const Rectangle rect{22,34}; 20 | // rect.setWidth(33); 21 | cout << rect.getArea()<<" "<< rect.getwidth()<<" "< 2 | #include 3 | using std::string; 4 | using std::cout; 5 | using std::endl; 6 | 7 | class Adder { 8 | public: 9 | //static methods do not need a class instance 10 | static double addNums(double x, double y) { 11 | return x + y; 12 | } 13 | static double addNums(string x, double y) { 14 | return stod(x) + y; 15 | } 16 | static double addNums(string x, string y) { 17 | return stod(x) + stod(y); 18 | } 19 | static double addNums(double x, string y) { 20 | return x + stod(y); 21 | } 22 | static double addNums(double x, double y, double z){ 23 | return x + y + + z; 24 | } 25 | }; 26 | 27 | int main() { 28 | cout << Adder::addNums(12.1, 14) << endl; 29 | cout << Adder::addNums("22.4", "1.008") << endl; 30 | cout << Adder::addNums(123.4, "6.02") << endl; 31 | cout << Adder::addNums(122.3,303.4,45.6) << endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /PyCpp/12. Templates/swapper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //using std::swap; 4 | using std::cout; 5 | using std::endl; 6 | using std::string; 7 | 8 | //our own swap template function 9 | template 10 | void myswap(myType a, myType b) { 11 | myType temp = a; 12 | a = b; 13 | b = temp; 14 | } 15 | 16 | int main() { 17 | double a =123; double b = 456; 18 | myswap(a,b); 19 | cout << "a="<< a <<" b="<< b <SetForegroundColour(wxColour(0, 0, 200)); 14 | SetForegroundColour("blue"); 15 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 16 | wxFONTWEIGHT_NORMAL, FALSE, ""); 17 | this->SetFont(font); 18 | } 19 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/Add2widgets/BlueLabel.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | 8 | class BlueLabel : public wxStaticText { 9 | public: 10 | BlueLabel(wxPanel* parent, int id, const wxString& label); 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/Frame1.cpp: -------------------------------------------------------------------------------- 1 | // For compilers that support precompilation, includes "wx/wx.h". 2 | #include 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #include "wx/app.h" 7 | #endif 8 | 9 | //create the app 10 | class MyApp : public wxApp 11 | { 12 | public: 13 | bool OnInit() { //called to start the UI 14 | wxFrame* frame = //create the frame 15 | new wxFrame(NULL, wxID_ANY, "Hello World"); 16 | 17 | frame->SetSize(250, 200); //set a size 18 | frame->Show(true); //and show it 19 | return true; 20 | } 21 | }; 22 | 23 | //launch the app 24 | wxIMPLEMENT_APP(MyApp); 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/Frame2.cpp: -------------------------------------------------------------------------------- 1 | // For compilers that support precompilation, includes "wx/wx.h". 2 | 3 | //Frame 2 introduces the Panel in which yo can position widgets 4 | //Here we use absolute positioning. 5 | #include 6 | 7 | #ifndef WX_PRECOMP 8 | #include 9 | #include "wx/app.h" 10 | #endif 11 | 12 | class MyApp : public wxApp 13 | { 14 | public: 15 | bool OnInit() { 16 | wxFrame* frame = new wxFrame(NULL, wxID_ANY, "Hello World"); 17 | frame->SetSize(250, 200); 18 | wxPanel* panel = new wxPanel(frame); 19 | wxStaticText* tx = new wxStaticText(panel, wxID_ANY, 20 | wxString("Greetings"), wxPoint(40,60)); 21 | 22 | frame->Show(true); 23 | return true; 24 | } 25 | }; 26 | 27 | wxIMPLEMENT_APP(MyApp); 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/HelloMenu/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | #include "BlueLabel.h" 7 | 8 | //----A derived class for blue labels------- 9 | 10 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 11 | wxStaticText(parent, id, label) { 12 | //this->SetForegroundColour(wxColour(0, 0, 200)); 13 | SetForegroundColour("blue"); 14 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 15 | wxFONTWEIGHT_NORMAL, FALSE, ""); 16 | this->SetFont(font); 17 | } 18 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/HelloMenu/BlueLabel.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | 8 | class BlueLabel : public wxStaticText { 9 | public: 10 | BlueLabel(wxPanel* parent, int id, const wxString& label); 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/HelloMenu/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/HiThere/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | #include "BlueLabel.h" 8 | 9 | //----A derived class for blue labels------- 10 | 11 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 12 | wxStaticText(parent, id, label) { 13 | //this->SetForegroundColour(wxColour(0, 0, 200)); 14 | SetForegroundColour("blue"); 15 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 16 | wxFONTWEIGHT_NORMAL, FALSE, ""); 17 | this->SetFont(font); 18 | } 19 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/HiThere/BlueLabel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | 7 | class BlueLabel : public wxStaticText { 8 | public: 9 | BlueLabel(wxPanel* parent, int id, const wxString& label); 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/HiThere/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/preproc.txt: -------------------------------------------------------------------------------- 1 | _DEBUG 2 | MOREADDING_EXPORTS 3 | _CONSOLE 4 | _CRT_SECURE_NO_DEPRECATE=1 5 | _CRT_NON_CONFORMING_SWPRINTFS=1 6 | _SCL_SECURE_NO_WARNINGS=1 7 | __WXMSW__ 8 | _UNICODE 9 | _WINDOWS 10 | NOPCH 11 | Win32_LEAN_AND_MEAN -------------------------------------------------------------------------------- /PyCpp/13. wxWidgets I/wxHello.py: -------------------------------------------------------------------------------- 1 | 2 | # Import the wxPython package. 3 | import wx 4 | 5 | app = wx.App() # Create an application object. 6 | frm = wx.Frame(None, title="Hello World") # Then a frame. 7 | frm.SetInitialSize((250, 200)) #et the size 8 | frm.Show() # Show it. 9 | 10 | # Start the event loop. 11 | 12 | app.MainLoop() -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/RadioButsBoxing/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | #include "BlueLabel.h" 8 | 9 | //----A derived class for blue labels------- 10 | 11 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 12 | wxStaticText(parent, id, label) { 13 | //this->SetForegroundColour(wxColour(0, 0, 200)); 14 | SetForegroundColour("blue"); 15 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 16 | wxFONTWEIGHT_NORMAL, FALSE, ""); 17 | this->SetFont(font); 18 | } 19 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/RadioButsBoxing/BlueLabel.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | 8 | class BlueLabel : public wxStaticText { 9 | public: 10 | BlueLabel(wxPanel* parent, int id, const wxString& label); 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/RadioColor/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | #include "BlueLabel.h" 7 | 8 | //----A derived class for blue labels------- 9 | 10 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 11 | wxStaticText(parent, id, label) { 12 | //this->SetForegroundColour(wxColour(0, 0, 200)); 13 | SetForegroundColour("blue"); 14 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 15 | wxFONTWEIGHT_NORMAL, FALSE, ""); 16 | this->SetFont(font); 17 | } 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/RadioColor/BlueLabel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | 7 | class BlueLabel : public wxStaticText { 8 | public: 9 | BlueLabel(wxPanel* parent, int id, const wxString& label); 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/SimpleListbox/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | #include "BlueLabel.h" 7 | 8 | //----A derived class for blue labels------- 9 | 10 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 11 | wxStaticText(parent, id, label) { 12 | //this->SetForegroundColour(wxColour(0, 0, 200)); 13 | SetForegroundColour("blue"); 14 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 15 | wxFONTWEIGHT_NORMAL, FALSE, ""); 16 | this->SetFont(font); 17 | } 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/SimpleListbox/BlueLabel.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | 8 | class BlueLabel : public wxStaticText { 9 | public: 10 | BlueLabel(wxPanel* parent, int id, const wxString& label); 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | #include "BlueLabel.h" 7 | 8 | //----A derived class for blue labels------- 9 | 10 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 11 | wxStaticText(parent, id, label) 12 | { 13 | this->SetForegroundColour(wxColour(0, 0, 200)); 14 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 15 | wxFONTWEIGHT_NORMAL, FALSE, ""); 16 | this->SetFont(font); 17 | } 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/BlueLabel.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | 8 | class BlueLabel : public wxStaticText { 9 | public: 10 | BlueLabel(wxPanel* parent, int id, const wxString& label); 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/State.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "State.h" 5 | 6 | using std::string; 7 | using std::vector; 8 | 9 | State::State(std::string line) { 10 | vector tokens = Strfuncs::split(line, ","); 11 | name = tokens[0]; 12 | abbrev = tokens[1]; 13 | date = tokens[2]; 14 | capital = tokens[3]; 15 | } 16 | string State::getName() { return name; } 17 | string State::getAbbrev() { return abbrev; } 18 | string State::getDate() { return date; } 19 | string State::getCapital() { return capital; } 20 | 21 | 22 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "StrFuncs.h" 6 | 7 | using std::string; 8 | 9 | class State { 10 | private: 11 | string name; 12 | string abbrev; 13 | string date; 14 | string capital; 15 | 16 | 17 | public: 18 | State(std::string line); 19 | string getName(); 20 | string getAbbrev(); 21 | string getDate(); 22 | string getCapital(); 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/States.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "States.h" 6 | 7 | using namespace std; 8 | 9 | States::States(string fileName) { 10 | 11 | std::ifstream myfile(fileName); 12 | std::string line; 13 | if (myfile.is_open()) { 14 | while (getline(myfile, line)) { 15 | states.push_back(new State(line)); 16 | } 17 | myfile.close(); 18 | } 19 | 20 | else cout << "Unable to open file"; 21 | } 22 | vector States::getStates() { 23 | return states; 24 | } 25 | State* States::getState(int index) { 26 | return states[index]; 27 | } -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/States.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "State.h" 5 | 6 | using std::vector; 7 | 8 | class States { 9 | protected: 10 | vector states; 11 | 12 | public: 13 | States(string fileName); 14 | vector getStates(); 15 | State* getState(int index); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListCombo/StrFuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | using std::string; 6 | using std::vector; 7 | 8 | class Strfuncs { 9 | //trim a string to remove whitespace 10 | //characters from the beginning and end 11 | public: 12 | static string strip(string line); 13 | 14 | //Split a string at the delimiter into a vector of strings, 15 | // each stripped of whitespace 16 | static vector split(string line, string delim); 17 | static string to_Lower(string str); 18 | }; 19 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | #include "BlueLabel.h" 7 | 8 | //----A derived class for blue labels------- 9 | 10 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 11 | wxStaticText(parent, id, label) 12 | { 13 | this->SetForegroundColour(wxColour(0, 0, 200)); 14 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 15 | wxFONTWEIGHT_NORMAL, FALSE, ""); 16 | this->SetFont(font); 17 | } 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/BlueLabel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | 7 | class BlueLabel : public wxStaticText { 8 | public: 9 | BlueLabel(wxPanel* parent, int id, const wxString& label); 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/DButton.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef WX_PRECOMP 3 | #include 4 | 5 | #endif 6 | #include 7 | #include "wx/app.h" 8 | #include "wx/sizer.h" 9 | 10 | #include "wx/button.h" 11 | 12 | #include "DButton.h" 13 | 14 | 15 | DButton::DButton(wxPanel* panel, int id, const std::string label, Mediator* med) : 16 | wxButton(panel, id, wxString::wxString(label), wxDefaultPosition, 17 | wxDefaultSize) 18 | { 19 | this->med = med; 20 | Bind(wxEVT_BUTTON, &DButton::comd, this); 21 | } 22 | 23 | //abstract method to be completed in derived classes 24 | // void comd(wxCommandEvent& event) {} 25 | 26 | 27 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/Mediator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BlueLabel.h" 3 | #include "wx/grid.h" 4 | #include 5 | #include "States.h" 6 | /* communicates between visual controls*/ 7 | class Mediator { 8 | protected: 9 | 10 | // wxListBox* stateListBox {NULL}; 11 | wxGrid* stateGrid{ NULL }; 12 | BlueLabel* lbName{ NULL }; 13 | BlueLabel* lbAbbrev{ NULL }; 14 | BlueLabel* lbDate{ NULL }; 15 | BlueLabel* lbCapital{ NULL }; 16 | States* stateList{ NULL }; 17 | 18 | 19 | public: 20 | Mediator(wxGrid* sl); 21 | 22 | void setStateList(States* slist); 23 | void saveState(wxGridEvent& ev); 24 | void rangeClick(wxCommandEvent& ev); 25 | void saveStates(); 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/State.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "State.h" 5 | using std::string; 6 | using std::vector; 7 | 8 | State::State(std::string line) { 9 | vector tokens = Strfuncs::split(line, ","); 10 | name = tokens[0]; 11 | abbrev = tokens[1]; 12 | date = tokens[2]; 13 | capital = tokens[3]; 14 | } 15 | string State::getName() { return name; } 16 | string State::getAbbrev() { return abbrev; } 17 | string State::getDate() { return date; } 18 | string State::getCapital() { return capital; } 19 | void State::setName(string nm) {name = nm; } 20 | void State::setAbbrev(string ab) { abbrev = ab; }; 21 | void State::setDate(string dt) { date = dt; }; 22 | void State::setCapital(string cap) { capital = cap; }; 23 | string State::getLineString() { 24 | return name + ", " + abbrev + ", " + capital + ", " + date; 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "StrFuncs.h" 6 | 7 | using std::string; 8 | 9 | class State { 10 | private: 11 | string name; 12 | string abbrev; 13 | string date; 14 | string capital; 15 | 16 | 17 | public: 18 | State(string line); 19 | string getName(); 20 | string getAbbrev(); 21 | string getDate(); 22 | string getCapital(); 23 | void setName(string nm); 24 | void setAbbrev(string ab); 25 | void setDate(string dt); 26 | void setCapital(string cap); 27 | string getLineString(); 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/States.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "States.h" 6 | 7 | using std::string; 8 | using std::ifstream; 9 | 10 | States::States(string fileName) { 11 | 12 | ifstream myfile(fileName); 13 | string line; 14 | if (myfile.is_open()) { 15 | while (getline(myfile, line)) { 16 | states.push_back(new State(line)); 17 | } 18 | myfile.close(); 19 | } 20 | 21 | else cout << "Unable to open file"; 22 | } 23 | vector States::getStates() { 24 | return states; 25 | } 26 | State* States::getState(int index) { 27 | return states[index]; 28 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/States.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "State.h" 5 | 6 | using namespace std; 7 | 8 | class States { 9 | protected: 10 | vector states; 11 | 12 | public: 13 | States(string fileName); 14 | vector getStates(); 15 | State* getState(int index); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/StrFuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Strfuncs { 7 | //trim a string to remove whitespace 8 | //characters from the beginning and end 9 | public: 10 | static std::string strip(std::string line); 11 | 12 | //Split a string at the delimiter into a vector of strings, 13 | // each stripped of whitespace 14 | static std::vector split(std::string line, std::string delim); 15 | }; 16 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateListGrid/Strfuncs.cpp: -------------------------------------------------------------------------------- 1 | //String functions 2 | 3 | #include 4 | #include "StrFuncs.h" 5 | #include 6 | using namespace std; 7 | 8 | string Strfuncs::strip(string line) { 9 | const string WHITESPACE = " \n\r\t\f\v"; //whitespace characters 10 | size_t first = line.find_first_not_of(WHITESPACE); 11 | size_t last = line.find_last_not_of(WHITESPACE) + 1; 12 | return line.substr(first, last); //strip whitespaces 13 | } 14 | 15 | std::vector Strfuncs::split(string line, string delim) { 16 | 17 | vector tokens; //create vector of tokens 18 | 19 | size_t start = 0; 20 | while (start >= 0 && start <= line.length()) { 21 | start = line.find(delim, 0); 22 | string val = strip(line.substr(0, start)); 23 | tokens.push_back(val); //add each token to vector 24 | line = strip(line.substr(start + 1, line.length())); 25 | } 26 | return tokens; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateLister/BlueLabel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | #include "BlueLabel.h" 7 | 8 | //----A derived class for blue labels------- 9 | 10 | BlueLabel::BlueLabel(wxPanel* parent, int id, const wxString& label) : 11 | wxStaticText(parent, id, label) 12 | { 13 | this->SetForegroundColour(wxColour(0, 0, 200)); 14 | wxFont font = wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, 15 | wxFONTWEIGHT_NORMAL, FALSE, ""); 16 | this->SetFont(font); 17 | } 18 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateLister/BlueLabel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef WX_PRECOMP 4 | #include 5 | #endif 6 | 7 | class BlueLabel : public wxStaticText { 8 | public: 9 | BlueLabel(wxPanel* parent, int id, const wxString& label); 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateLister/State.cpp: -------------------------------------------------------------------------------- 1 | #include "State.h" 2 | #include 3 | #include "Strfuncs.h" 4 | using std::vector; 5 | 6 | State::State(std::string line) { 7 | vector tokens = Strfuncs::split(line, ","); 8 | name = tokens[0]; 9 | abbrev = tokens[1]; 10 | date = tokens[2]; 11 | capital = tokens[3]; 12 | } 13 | string State::getName() { return name; } 14 | string State::getAbbrev() { return abbrev; } 15 | string State::getDate() { return date; } 16 | string State::getCapital() { return capital; } 17 | -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateLister/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using std::string; 4 | 5 | class State { 6 | private: 7 | string name; 8 | string abbrev; 9 | string date; 10 | string capital; 11 | 12 | 13 | public: 14 | State(std::string line); 15 | string getName(); 16 | string getAbbrev(); 17 | string getDate(); 18 | string getCapital(); 19 | }; -------------------------------------------------------------------------------- /PyCpp/14. wxWidgets II Tables and lists/StateLister/Strfuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Strfuncs { 7 | //trim a string to remove whitespace 8 | //characters from the beginning and end 9 | public: 10 | static std::string strip(std::string line); 11 | 12 | //Split a string at the delimiter into a vector of strings, 13 | // each stripped of whitespace 14 | static std::vector split(std::string line, std::string delim); 15 | static std::string to_Lower(std::string str); 16 | }; 17 | -------------------------------------------------------------------------------- /PyCpp/15. Armadillo/Fitbees/fitbees.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2012 for Windows Desktop 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example1_win64", "example1_win64.vcxproj", "{BDE105B5-0B52-4D77-832F-3465D464A901}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x64 = Debug|x64 9 | Release|x64 = Release|x64 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {BDE105B5-0B52-4D77-832F-3465D464A901}.Debug|x64.ActiveCfg = Debug|x64 13 | {BDE105B5-0B52-4D77-832F-3465D464A901}.Debug|x64.Build.0 = Debug|x64 14 | {BDE105B5-0B52-4D77-832F-3465D464A901}.Release|x64.ActiveCfg = Release|x64 15 | {BDE105B5-0B52-4D77-832F-3465D464A901}.Release|x64.Build.0 = Release|x64 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /PyCpp/15. Armadillo/SineFFT/SineFFT/Mediator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PaintWindow.h" 3 | #include 4 | #include 5 | 6 | using std::vector; 7 | using arma::vec; 8 | //using namespace arma; 9 | 10 | 11 | class Mediator { 12 | private: 13 | PaintWindow* paintWin; 14 | const int WIDTH = 1000; 15 | const int HEIGHT = 600; 16 | wxPoint* wavePoints; 17 | wxPoint* peakPoints; 18 | size_t ASize; 19 | 20 | vector waveData; 21 | vec sinedata; 22 | bool ftFlag; 23 | int Width; 24 | int Height; 25 | public: 26 | int width(); 27 | int height(); 28 | Mediator(size_t Asize); 29 | void ftClick(); 30 | void createWaves(); 31 | void setPaintWin(PaintWindow* pw); 32 | 33 | wxPoint* getWaves(); 34 | wxPoint* getPeaks(); 35 | 36 | -------------------------------------------------------------------------------- /PyCpp/15. Armadillo/SineFFT/SineFFT/PaintWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "wx/gdicmn.h" 4 | #include "wx/log.h" 5 | #include 6 | #include 7 | 8 | using std::vector; 9 | 10 | class PaintWindow : public wxFrame { 11 | private: 12 | int Width; 13 | int Height; 14 | int Asize; 15 | 16 | wxPoint* wavePoints; 17 | wxPoint* peakPoints; 18 | vector waveData; 19 | // vec sinedata; 20 | wxPanel* panel; 21 | wxPanel* botPanel; 22 | wxButton* ftButton; 23 | bool ftFlag; 24 | 25 | public: 26 | PaintWindow(const wxString& title, size_t asize, int width, int height); 27 | void OnPaint(wxPaintEvent& event); 28 | void setWaves(wxPoint* waves); 29 | void setPeaks(wxPoint* peaks); 30 | void OnClick(wxCommandEvent& event); 31 | void setDataVector(vector sw); 32 | }; 33 | -------------------------------------------------------------------------------- /PyCpp/15. Armadillo/SineFFT/SineFFT/SineFFT.vcxproj.user: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 |  3 | 4 | 5 | ======= 6 |  7 | 8 | 9 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 10 | -------------------------------------------------------------------------------- /PyCpp/15. Armadillo/SineFFT/SineFFT/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/plotlines.C: -------------------------------------------------------------------------------- 1 | #include "TF1.h" 2 | #include "TApplication.h" 3 | #include "TCanvas.h" 4 | #include "TRootCanvas.h" 5 | #include "TGraph.h" 6 | #include "TLegend.h" 7 | #include "TGFont.h" 8 | #include "TPad.h" 9 | 10 | // Draw a simple x-y plot 11 | void plotlines() { 12 | auto c = new TCanvas("c1", "Demo example"); 13 | auto gr = new TGraph("plotdata1.txt"); //read in data file 14 | gr->SetTitle("Demo data"); //title on the plot 15 | gr->SetMarkerStyle(20); //filled circle marker 16 | gr->Draw("APL"); //plot axis and lines 17 | c->Print("demo.pdf"); //save PDF of plot 18 | return 0; 19 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/plotlineserr.C: -------------------------------------------------------------------------------- 1 | #include "TF1.h" 2 | #include "TApplication.h" 3 | #include "TCanvas.h" 4 | #include "TRootCanvas.h" 5 | #include "TGraph.h" 6 | #include "TLegend.h" 7 | #include "TGFont.h" 8 | #include "TPad.h" 9 | 10 | // Draw a simple x-y plot 11 | void plotlineserr() { 12 | auto c = new TCanvas("c1", "Demo example"); 13 | auto gr = new TGraphErrors("plotdataerr1.txt"); //read in data file 14 | gr->SetTitle("Demo error data"); //title on the plot 15 | gr->SetMarkerStyle(1); //filled circle marker 16 | gr->Draw("APL"); //plot axis and lines 17 | c->Print("demo.pdf"); //save PDF of plot 18 | return 0; 19 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/splottest/beedata.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/splottest/beedata.pdf -------------------------------------------------------------------------------- /PyCpp/16. Plotting/splottest/splotest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace sciplot; 3 | 4 | int main(int argc, char** argv) { 5 | // the bee plotting data 6 | Vec x = { 7,8,9,10,11,12,13,14,15,16,17 }; 7 | Vec y = { 32,35,29,34,30,24,32,24,23,28,21 }; 8 | 9 | // xy pairs descibing the fitted line 10 | Vec xa = { 7,17 }; 11 | Vec ya = { 33, 22.94 }; 12 | 13 | // Create a Plot object 14 | Plot2D plot; 15 | 16 | // This disables the deletion of the created gnuplot script and data file. 17 | plot.autoclean(false); 18 | 19 | // Plot the data and the fitted line 20 | plot.drawCurveWithPoints(x, y).label("bees"); 21 | plot.drawCurveWithPoints(xa, ya).label("fit"); 22 | 23 | // Create figure to hold plot 24 | Figure fig = { {plot} }; 25 | 26 | // Create canvas to hold figure 27 | Canvas canvas = { {fig} }; 28 | canvas.size(800, 500); 29 | 30 | // Show the plot in a pop-up window 31 | canvas.show(); 32 | 33 | // Save the plot to a PDF file 34 | canvas.save("beedata.pdf"); 35 | } 36 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/wxBeePlotVector.vcxproj.user: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 |  3 | 4 | 5 | ======= 6 |  7 | 8 | 9 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 10 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/vc143.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/vc143.idb -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/vc143.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/vc143.pdb -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.exe.recipe: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | C:\Users\James\source\repos\wxBeePlotVector\x64\Debug\wxBeePlotVector.exe 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.ilk -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.obj -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/wxBeePlotVector/x64/Debug/wxBeePlotVector.tlog/wxBeePlotVector.lastbuildstate: -------------------------------------------------------------------------------- 1 | PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.34.31933:TargetPlatformVersion=10.0.19041.0: 2 | Debug|x64|C:\Users\James\source\repos\wxBeePlotVector\| 3 | -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/x64/Debug/wxBeePlotVector.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/x64/Debug/wxBeePlotVector.exe -------------------------------------------------------------------------------- /PyCpp/16. Plotting/wxBeePlotVector/x64/Debug/wxBeePlotVector.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/16. Plotting/wxBeePlotVector/x64/Debug/wxBeePlotVector.pdb -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/Database.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Database.h" 3 | #include "globaldefs.h" 4 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/Database.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | class Database { 4 | public: 5 | virtual int open(std::string filename) = 0; 6 | virtual int create(std::string filename) = 0; 7 | 8 | virtual string getName() =0; 9 | virtual vector getTableNames() =0; 10 | //close the database connection 11 | virtual void close() = 0; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/PreparedQuery1.cpp: -------------------------------------------------------------------------------- 1 | #include "PreparedQuery.h" 2 | #include "Query.h" 3 | 4 | 5 | PreparedQuery::PreparedQuery(sqltDatabase db, string query): 6 | Query(db, query) { 7 | int rc = sqlite3_prepare_v2(db.getDb(), query.c_str(), query.size(), 8 | &stmt, nullptr); 9 | checkerr(rc); 10 | } 11 | void PreparedQuery::setVariable(int index, string value) { 12 | int rc = sqlite3_bind_text(stmt, 1,value.c_str(), value.length(), NULL); 13 | checkerr(rc); 14 | } 15 | void PreparedQuery::setVariable(int index, double value) { 16 | int rc = sqlite3_bind_text(stmt, 1, value.c_str(), value.length(), NULL); 17 | checkerr(rc); 18 | } 19 | 20 | int PreparedQuery::execute() { 21 | int rc = 0; 22 | while (SQLITE_ROW == (rc = sqlite3_step(stmt))) { 23 | const unsigned char* name = sqlite3_column_text(stmt, 0); 24 | const unsigned char* val = sqlite3_column_text(stmt, 1); 25 | std::cout << name << " is " << val << std::endl; 26 | } 27 | sqlite3_finalize(stmt); 28 | return 0; 29 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/PreparedQuery1.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "sqltDatabase.h" 4 | #include "Query.h" 5 | class PreparedQuery:public Query 6 | { 7 | private: 8 | sqlite3_stmt* stmt{ NULL }; 9 | 10 | public: 11 | PreparedQuery(sqltDatabase db, string query); 12 | void setVariable(int index, string value); 13 | void setVariable(int index, double value); 14 | int execute(); 15 | 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/PriceTable.cpp: -------------------------------------------------------------------------------- 1 | #include "PriceTable.h" 2 | 3 | PriceTable::PriceTable (sqltDatabase sqldb) : Table("prices", sqldb){ 4 | addColumn(new PrimaryCol("pricekey")); 5 | addColumn(new IntCol("foodkey")); 6 | addColumn(new IntCol("storekey")); 7 | addColumn(new FloatCol("price")); 8 | create(); 9 | } 10 | 11 | int PriceTable::addRow( pricetuple ptuple) { 12 | string sql = "insert into " + tbName; 13 | sql += " (storekey, foodkey, price) "; 14 | sql += "values (" ; 15 | int fkey; 16 | int skey; 17 | float price; 18 | std::tie(fkey, skey, price) = ptuple; 19 | sql += to_string(fkey) + ","; 20 | sql += to_string(skey) + ","; 21 | sql += to_string(price) ; 22 | sql += ")"; 23 | sqltQuery qry(db, sql); 24 | qry.execute(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/PriceTable.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "Table.h" 4 | #include "Query.h" 5 | #include 6 | using std::to_string; 7 | 8 | typedef std::tuple pricetuple; 9 | 10 | class PriceTable : 11 | public Table { 12 | public: 13 | PriceTable(sqltDatabase sqldb); 14 | int addRow(pricetuple ptuple); 15 | 16 | 17 | }; -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/Results.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "globaldefs.h" 4 | 5 | #include 6 | 7 | //header for Results class 8 | 9 | using std::cout; 10 | using std::endl; 11 | 12 | class Results { 13 | protected: 14 | vector rows; 15 | size_t cursor = 0; 16 | public: 17 | Results(vector crows); 18 | Results(vector *); 19 | dbMap getRow(); 20 | string getVal(string name); 21 | size_t getSize(); 22 | string getCol(int index); 23 | void setCursor(size_t cval); 24 | vector getRows(); 25 | 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/globaldefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using std::string; 8 | using std::vector; 9 | using std::tuple; 10 | using std::map; 11 | 12 | //convenient abbreviation for the map 13 | typedef map dbMap; 14 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/SQLite Prepared/groceries.db -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/mygroc.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/SQLite Prepared/mygroc.db -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/sqltDatabase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "Database.h" 4 | 5 | class sqltDatabase:public Database { 6 | private: 7 | sqlite3* sqldb{ NULL }; 8 | string filename; 9 | string dbname; 10 | bool exists(const std::string& name); 11 | vector tableNames; 12 | int rc{ -1 }; 13 | 14 | public: 15 | //open the database if it exists 16 | // sqlite otherwise would create an empty one 17 | // here we check for existence to avoid creating one 18 | int open(std::string filename); 19 | int create (std::string filename); 20 | sqltDatabase(); 21 | //return the sqlite pointer 22 | sqlite3* getDb(); 23 | string getName(); 24 | vector getTableNames(); 25 | //close the database connection 26 | void close(); 27 | 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/sqltPrepQuery.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "sqltDatabase.h" 4 | #include "Query.h" 5 | class sqltPrepQuery:public sqltQuery 6 | { 7 | private: 8 | sqlite3_stmt* stmt{ NULL }; 9 | string sval; //used in bind_text 10 | vector * stpRows{ NULL }; 11 | dbMap* stpRow{ NULL }; 12 | vector* prepqueries; 13 | 14 | public: 15 | sqltPrepQuery(sqltDatabase db, string query); 16 | void setVariable(int index, string value); 17 | void setVariable(int index, double value); 18 | void setVariable(int index, int value); 19 | Results* execute(); 20 | void closeStatement(); 21 | void rewindStatement(); 22 | 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Prepared/sqltQuery.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "Results.h" 4 | #include "sqltDatabase.h" 5 | 6 | //The query class executes an SQL statment 7 | //and returns the results in an Results object 8 | class sqltQuery { 9 | public: 10 | static vector stRows; 11 | static map stRow; 12 | static int returnCode; 13 | protected: 14 | string qstring; 15 | sqlite3* sqdb; 16 | char* errMsg = 0; 17 | 18 | public: 19 | sqltQuery(sqltDatabase db, string sqlstring); 20 | static int callback(void* data, int count, char** colVal, char** colName); 21 | Results* execute(); 22 | void checkerr(int rc); 23 | }; 24 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/PriceTable.cpp: -------------------------------------------------------------------------------- 1 | #include "PriceTable.h" 2 | 3 | PriceTable::PriceTable (sqltDatabase sqldb) : Table("prices", sqldb){ 4 | addColumn(new PrimaryCol("pricekey")); 5 | addColumn(new IntCol("foodkey")); 6 | addColumn(new IntCol("storekey")); 7 | addColumn(new FloatCol("price")); 8 | create(); 9 | } 10 | 11 | //adds a row to the pricetable 12 | int PriceTable::addRow( pricetuple ptuple) { 13 | string sql = "insert into " + tbName; 14 | sql += " (storekey, foodkey, price) "; 15 | sql += "values (" ; 16 | int fkey; int skey; float price; 17 | //unpack tuple into 3 variables 18 | std::tie(fkey, skey, price) = ptuple; 19 | sql += to_string(fkey) + ","; 20 | sql += to_string(skey) + ","; 21 | sql += to_string(price) ; 22 | sql += ")"; 23 | Query qry(db, sql); 24 | qry.execute(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/PriceTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Table.h" 3 | #include "Query.h" 4 | #include 5 | using std::to_string; 6 | 7 | typedef std::tuple pricetuple; 8 | 9 | class PriceTable : 10 | public Table { 11 | public: 12 | PriceTable(sqltDatabase sqldb); 13 | int addRow(pricetuple ptuple); 14 | 15 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/Query.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "Results.h" 4 | #include "sqltDatabase.h" 5 | 6 | //The query class executes an SQL statment 7 | //and returns the results in an Results object 8 | class Query { 9 | public: 10 | static vector stRows; 11 | static map stRow; 12 | static int returnCode; 13 | private: 14 | string qstring; 15 | sqlite3* sqdb; 16 | char* errMsg = 0; 17 | 18 | public: 19 | Query(sqltDatabase db, string sqlstring); 20 | static int callback(void* data, int count, char** colVal, char** colName); 21 | Results* execute(); 22 | }; 23 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/Results.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | 4 | #include 5 | 6 | //header for Results class 7 | 8 | using std::cout; 9 | using std::endl; 10 | 11 | class Results { 12 | protected: 13 | vector rows; 14 | size_t cursor = 0; 15 | public: 16 | Results(vector crows); 17 | dbMap getRow(); 18 | string getVal(string name); 19 | size_t getSize(); 20 | string getCol(int index); 21 | void setCursor(size_t cval); 22 | vector getRows(); 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/globaldefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using std::string; 8 | using std::vector; 9 | using std::tuple; 10 | using std::map; 11 | 12 | //convenient abbreviation for the map 13 | typedef map dbMap; 14 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/SQLite Tables/groceries.db -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/mygroc.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/SQLite Tables/mygroc.db -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite Tables/sqltDatabase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | 4 | class sqltDatabase { 5 | private: 6 | sqlite3* sqldb{ NULL }; 7 | string filename; 8 | string dbname; 9 | bool exists(const std::string& name); 10 | vector tableNames; 11 | int rc{ -1 }; 12 | 13 | public: 14 | //open the database if it exists 15 | // sqlite otherwise would create an empty one 16 | // here we check for existence to avoid creating one 17 | int open(std::string filename); 18 | int create (std::string filename); 19 | sqltDatabase(); 20 | //return the sqlite pointer 21 | sqlite3* getDb(); 22 | string getName(); 23 | vector getTableNames(); 24 | //close the database connection 25 | void close(); 26 | 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite external classes/Query.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "Results.h" 4 | #include "sqltDatabase.h" 5 | 6 | //The query class executes an SQL statment 7 | //and returns the results in an Results object 8 | class Query { 9 | public: 10 | static vector stRows; 11 | static map stRow; 12 | private: 13 | string qstring; 14 | sqlite3* sqdb; 15 | char* errMsg = 0; 16 | 17 | public: 18 | Query(sqltDatabase db, string sqlstring); 19 | static int callback(void* data, int count, char** colVal, char** colName); 20 | Results* execute(); 21 | }; 22 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite external classes/Results.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | 4 | #include 5 | 6 | //header for Results class 7 | 8 | using std::cout; 9 | using std::endl; 10 | 11 | class Results { 12 | private: 13 | vector rows; 14 | size_t cursor = 0; 15 | public: 16 | Results(vector> crows); 17 | dbMap getRow(); 18 | string getVal(string name); 19 | size_t getSize(); 20 | string getCol(int index); 21 | void setCursor(size_t cval); 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite external classes/globaldefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using std::string; 8 | using std::vector; 9 | using std::tuple; 10 | using std::map; 11 | 12 | //convenient abbreviation for the map 13 | typedef map dbMap; 14 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite external classes/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/SQLite external classes/groceries.db -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite external classes/sqltDatabase.cpp: -------------------------------------------------------------------------------- 1 | #include "globaldefs.h" 2 | #include "sqltDatabase.h" 3 | #include 4 | using std::ifstream; 5 | 6 | //open the database if it exists 7 | // sqlite otherwise would create an empty one 8 | // here we check for existence to avoid creating one 9 | bool sqltDatabase::exists(const std::string& name) { 10 | ifstream f(name.c_str()); 11 | return f.good(); 12 | } 13 | sqltDatabase::sqltDatabase(std::string filename) { 14 | 15 | /* Open database */ 16 | dbname = filename; 17 | //only open if it exists 18 | if (exists(dbname.c_str())) { 19 | int rc = sqlite3_open("groceries.db", &sqldb); 20 | 21 | } 22 | // sqldb will be NULL if this fails 23 | } 24 | //return the sqlite pointer 25 | sqlite3* sqltDatabase::sqltDatabase:: getDb() { 26 | return sqldb; 27 | } 28 | //close the database connection 29 | void sqltDatabase::close() { 30 | sqlite3_close(sqldb); 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/SQLite external classes/sqltDatabase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | 4 | class sqltDatabase { 5 | private: 6 | sqlite3* sqldb{ NULL }; 7 | string dbname; 8 | bool exists(const std::string& name); 9 | 10 | public: 11 | //open the database if it exists 12 | // sqlite otherwise would create an empty one 13 | // here we check for existence to avoid creating one 14 | sqltDatabase(std::string filename); 15 | //return the sqlite pointer 16 | sqlite3* getDb(); 17 | //close the database connection 18 | void close(); 19 | 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/Simple SQLite Database Classes/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/Simple SQLite Database Classes/groceries.db -------------------------------------------------------------------------------- /PyCpp/17. SQLite Databases/sqlitest/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/PyCpp/17. SQLite Databases/sqlitest/groceries.db -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/Database.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Database.h" 3 | #include "globaldefs.h" 4 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/Database.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "globaldefs.h" 4 | class Database { 5 | public: 6 | virtual int open(std::string filename) = 0; 7 | virtual int create(std::string filename, bool del) = 0; 8 | 9 | virtual string getName() =0; 10 | virtual vector getTableNames() =0; 11 | //close the database connection 12 | virtual void close() = 0; 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/PreparedQuery.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "Query.h" 4 | class msqPreparedQuery : 5 | public Query 6 | { 7 | private: 8 | msqDatabase* db; 9 | public: 10 | mysqlx::SqlStatement* sqQuery; 11 | msqPreparedQuery(msqDatabase* db, mysqlx::SqlStatement* psQuery); 12 | void setVariable(string value); 13 | void setVariable(double value); 14 | void setVariable( int value); 15 | Results* execute(); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/PriceTable.cpp: -------------------------------------------------------------------------------- 1 | #include "globaldefs.h" 2 | #include "PriceTable.h" 3 | #include "msqDatabase.h" 4 | 5 | PriceTable::PriceTable (msqDatabase* msqdb) : msqTable("prices", msqdb){ 6 | addColumn(new PrimaryCol("pricekey")); 7 | addColumn(new IntCol("foodkey")); 8 | addColumn(new IntCol("storekey")); 9 | addColumn(new FloatCol("price")); 10 | create(); 11 | } 12 | 13 | //adds a row to the pricetable 14 | int PriceTable::addRow( pricetuple ptuple) { 15 | string sql = "insert into " + tbName; 16 | sql += " (storekey, foodkey, price) "; 17 | sql += "values (" ; 18 | int fkey; int skey; float price; 19 | //unpack tuple into 3 variables 20 | std::tie(fkey, skey, price) = ptuple; 21 | sql += to_string(fkey) + ","; 22 | sql += to_string(skey) + ","; 23 | sql += to_string(price) ; 24 | sql += ")"; 25 | Query qry(db, sql); 26 | qry.execute(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/PriceTable.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "msqTable.h" 4 | #include "Query.h" 5 | #include 6 | using std::to_string; 7 | 8 | typedef std::tuple pricetuple; 9 | 10 | class PriceTable : 11 | public msqTable { 12 | public: 13 | PriceTable(msqDatabase* msqdb); 14 | int addRow(pricetuple ptuple); 15 | 16 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/Query.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "msqDatabase.h" 4 | #include "Query.h" 5 | #include "Results.h" 6 | 7 | 8 | class Query 9 | { 10 | protected: 11 | //sqlite3_stmt* stmt{ NULL }; 12 | string sql; 13 | msqDatabase* db; 14 | mysqlx::SqlStatement* sqQuery; 15 | mysqlx::Session* session; 16 | vector * stpRows{ NULL }; 17 | dbMap* stpRow{ NULL }; 18 | vector* prepqueries; 19 | 20 | public: 21 | Query(msqDatabase* db, string query); 22 | Query() = default; 23 | Results* execute(); 24 | void closeStatement(); 25 | void rewindStatement(); 26 | string makeString(mysqlx::Value r); 27 | 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/Results.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | 4 | #include 5 | 6 | //header for Results class 7 | 8 | using std::cout; 9 | using std::endl; 10 | 11 | class Results { 12 | protected: 13 | vector rows; 14 | size_t cursor = 0; 15 | public: 16 | Results(vector crows); 17 | Results(vector *); 18 | dbMap getRow(); 19 | //string getVal(string name); 20 | mysqlx::Value getVal(string name); 21 | size_t getSize(); 22 | string getCol(int index); 23 | void setCursor(size_t cval); 24 | vector getRows(); 25 | 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/globaldefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using std::string; 9 | using std::vector; 10 | using std::tuple; 11 | using std::map; 12 | 13 | //convenient abbreviation for the map 14 | //typedef map dbMap; 15 | typedef map dbMap; 16 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL Prepared Query/msqDatabase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Database.h" 3 | #include "globaldefs.h" 4 | #include 5 | #include 6 | 7 | using std::vector; 8 | using std::string; 9 | 10 | class msqDatabase :public Database 11 | { 12 | private: 13 | mysqlx::Session* session; 14 | string dbName; 15 | mysqlx::Schema* db; //actual database 16 | void setSchema(); 17 | 18 | public: 19 | msqDatabase(string host, int port, string user, string password); 20 | msqDatabase(); 21 | mysqlx::Session* getSession(); 22 | mysqlx::SqlStatement getSqlStatement(string sql); 23 | mysqlx::SqlStatement* psqStatement; 24 | 25 | int open(string name); 26 | int create(string name, bool del =true); 27 | string getName(); 28 | void close(); 29 | vector getTableNames(); 30 | void runSql(string sqltext); 31 | mysqlx::SqlResult runQuery(string sqltext); 32 | 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/Database.cpp: -------------------------------------------------------------------------------- 1 | #include "Database.h" 2 | #include "globaldefs.h" 3 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/Database.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | class Database { 4 | public: 5 | virtual int open(std::string filename) = 0; 6 | virtual int create(std::string filename, bool del) = 0; 7 | 8 | virtual string getName() =0; 9 | virtual vector getTableNames() =0; 10 | //close the database connection 11 | virtual void close() = 0; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/PriceTable.cpp: -------------------------------------------------------------------------------- 1 | #include "globaldefs.h" 2 | #include "PriceTable.h" 3 | #include "msqDatabase.h" 4 | 5 | PriceTable::PriceTable (msqDatabase* msqdb) : msqTable("prices", msqdb){ 6 | addColumn(new PrimaryCol("pricekey")); 7 | addColumn(new IntCol("foodkey")); 8 | addColumn(new IntCol("storekey")); 9 | addColumn(new FloatCol("price")); 10 | create(); 11 | } 12 | 13 | //adds a row to the pricetable 14 | int PriceTable::addRow( pricetuple ptuple) { 15 | string sql = "insert into " + tbName; 16 | sql += " (storekey, foodkey, price) "; 17 | sql += "values (" ; 18 | int fkey; int skey; float price; 19 | //unpack tuple into 3 variables 20 | std::tie(fkey, skey, price) = ptuple; 21 | sql += to_string(fkey) + ","; 22 | sql += to_string(skey) + ","; 23 | sql += to_string(price) ; 24 | sql += ")"; 25 | Query qry(db, sql); 26 | qry.execute(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/PriceTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "msqTable.h" 3 | #include "Query.h" 4 | #include 5 | using std::to_string; 6 | 7 | typedef std::tuple pricetuple; 8 | 9 | class PriceTable : 10 | public msqTable { 11 | public: 12 | PriceTable(msqDatabase* msqdb); 13 | int addRow(pricetuple ptuple); 14 | 15 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/Query.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | #include "msqDatabase.h" 4 | #include "Query.h" 5 | #include "Results.h" 6 | 7 | 8 | class Query 9 | { 10 | protected: 11 | //sqlite3_stmt* stmt{ NULL }; 12 | string sql; 13 | msqDatabase* db; 14 | mysqlx::SqlStatement* sqQuery; 15 | mysqlx::Session* session; 16 | vector * stpRows{ NULL }; 17 | dbMap* stpRow{ NULL }; 18 | vector* prepqueries; 19 | 20 | public: 21 | Query(msqDatabase* db, string query); 22 | Query() = default; 23 | Results* execute(); 24 | void closeStatement(); 25 | void rewindStatement(); 26 | string makeString(mysqlx::Value r); 27 | 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/Results.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "globaldefs.h" 3 | 4 | #include 5 | 6 | //header for Results class 7 | 8 | using std::cout; 9 | using std::endl; 10 | 11 | class Results { 12 | protected: 13 | vector rows; 14 | size_t cursor = 0; 15 | public: 16 | Results(vector crows); 17 | Results(vector *); 18 | dbMap getRow(); 19 | //string getVal(string name); 20 | mysqlx::Value getVal(string name); 21 | size_t getSize(); 22 | string getCol(int index); 23 | void setCursor(size_t cval); 24 | vector getRows(); 25 | 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/globaldefs.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using std::string; 10 | using std::vector; 11 | using std::tuple; 12 | using std::map; 13 | 14 | //convenient abbreviation for the map 15 | //typedef map dbMap; 16 | typedef map dbMap; 17 | -------------------------------------------------------------------------------- /PyCpp/18. MySQL Databases/MySQL db tables/msqDatabase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Database.h" 3 | #include "globaldefs.h" 4 | #include 5 | #include 6 | 7 | using std::vector; 8 | using std::string; 9 | 10 | class msqDatabase :public Database 11 | { 12 | private: 13 | mysqlx::Session* session; 14 | string dbName; 15 | mysqlx::Schema* db; //actual database 16 | void setSchema(); 17 | 18 | public: 19 | msqDatabase(string host, int port, string user, string password); 20 | msqDatabase(); 21 | mysqlx::Session* getSession(); 22 | mysqlx::SqlStatement getSqlStatement(string sql); 23 | mysqlx::SqlStatement* psqStatement; 24 | 25 | int open(string name); 26 | int create(string name, bool del =true); 27 | string getName(); 28 | void close(); 29 | vector getTableNames(); 30 | void runSql(string sqltext); 31 | mysqlx::SqlResult runQuery(string sqltext); 32 | 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Our modules/Cuber.cpp: -------------------------------------------------------------------------------- 1 | 2 | module Minimath; 3 | 4 | double cube(const double x) { 5 | return x * x * x; 6 | } 7 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Our modules/Minimath.cpp: -------------------------------------------------------------------------------- 1 | 2 | module Minimath; 3 | 4 | double square(const double x) { 5 | return x * x; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Our modules/Minimath.ixx: -------------------------------------------------------------------------------- 1 | 2 | //module descriptor file 3 | export module Minimath; 4 | export double square(const double x); 5 | export double cube(const double x); 6 | 7 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Our modules/Our Module.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Our Module.cpp : 3 | // Calling program to use the Minimath module (Note capitalization) 4 | // 5 | 6 | #include 7 | using std::cout; 8 | using std::endl; 9 | 10 | import Minimath; //import the Minimath module 11 | 12 | int main() { 13 | double x = 12; 14 | cout << "x^2 =" << square(x) << endl; 15 | cout << "x cubed is" << cube(x) << endl; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny module/Cuber.cpp: -------------------------------------------------------------------------------- 1 | 2 | module Minimath; 3 | namespace minimath { 4 | double cube(const double x) { 5 | return x * x * x; 6 | } 7 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny module/Minimath.cpp: -------------------------------------------------------------------------------- 1 | module Minimath; 2 | namespace minimath { 3 | double square(const double x) { 4 | return x * x; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny module/Minimath.ixx: -------------------------------------------------------------------------------- 1 | export module Minimath; 2 | namespace minimath { 3 | export double square(const double x); 4 | export double cube(const double x); 5 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny module/TinyModule.cpp: -------------------------------------------------------------------------------- 1 | 2 | // TinyModule.cpp : This file contains the 'main' function. Program execution begins and ends there. 3 | // 4 | 5 | #include 6 | using std::cout; 7 | using std::endl; 8 | 9 | import Minimath; 10 | using minimath::square; 11 | using minimath::cube; 12 | 13 | 14 | int main() { 15 | double y = 123.45; 16 | double z = square(y); 17 | cout << "x^2 =" << z << endl; 18 | cout << "x cubed is : " << cube(y) << endl; 19 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny namespace/Cuber.cpp: -------------------------------------------------------------------------------- 1 | 2 | namespace minimath { 3 | double cube(const double x) { 4 | return x * x * x; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny namespace/Minimath.cpp: -------------------------------------------------------------------------------- 1 | namespace minimath { 2 | double square(const double x) { 3 | return x * x; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny namespace/TinyModule.cpp: -------------------------------------------------------------------------------- 1 | 2 | // TinyModule.cpp : This file contains the 'main' function. Program execution begins and ends there. 3 | // 4 | 5 | #include 6 | import Minimath; 7 | using std::cout; 8 | using std::endl; 9 | 10 | using minimath::square; 11 | using minimath::cube; 12 | 13 | 14 | int main() 15 | { 16 | double y = 123.45; 17 | double z = square(y); 18 | cout << "x^2 =" << z << endl; 19 | cout << "x cubed is : " << cube(y) << endl; 20 | 21 | } -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny namespace/TinyNamespace.cpp: -------------------------------------------------------------------------------- 1 | // TinyNamespace.cpp : This file contains the 'main' function. Program execution begins and ends there. 2 | // 3 | 4 | #include 5 | #include "minimath.h" 6 | 7 | using std::cout; 8 | using std::endl; 9 | 10 | using minimath::square; 11 | using minimath::cube; 12 | 13 | int main() { 14 | double y = 123.45; 15 | double z = square(y); 16 | cout << "x^2 =" << z << endl; 17 | cout << "x cubed is : " << cube(y) << endl; 18 | 19 | } -------------------------------------------------------------------------------- /PyCpp/19. Namespaces and Modules/Tiny namespace/minimath.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace minimath { 3 | double square(const double x); 4 | double cube(const double x); 5 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/Console Namer/Namer.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | using std::string; 5 | 6 | class Namer 7 | { 8 | protected: 9 | string frname{ NULL }; 10 | string lname{ NULL }; 11 | 12 | public: 13 | string getFrname(); 14 | string getLname(); 15 | 16 | }; 17 | 18 | ======= 19 | #pragma once 20 | #include 21 | using std::string; 22 | 23 | class Namer 24 | { 25 | protected: 26 | string frname{ NULL }; 27 | string lname{ NULL }; 28 | 29 | public: 30 | string getFrname(); 31 | string getLname(); 32 | 33 | }; 34 | 35 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 36 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/BlueLabel.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | 4 | #ifndef WX_PRECOMP 5 | #include 6 | #endif 7 | 8 | class BlueLabel : public wxStaticText { 9 | public: 10 | BlueLabel(wxPanel* parent, int id, const wxString& label); 11 | 12 | }; 13 | ======= 14 | #pragma once 15 | 16 | #ifndef WX_PRECOMP 17 | #include 18 | #endif 19 | 20 | class BlueLabel : public wxStaticText { 21 | public: 22 | BlueLabel(wxPanel* parent, int id, const wxString& label); 23 | 24 | }; 25 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 26 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/CircleSeeding.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "StraightSeeding.h" 4 | class CircleSeeding :public StraightSeeding { 5 | private: 6 | int circle = 0; 7 | public: 8 | CircleSeeding(vector sw, int nlanes); 9 | void seed(); 10 | ======= 11 | #pragma once 12 | #include "StraightSeeding.h" 13 | class CircleSeeding :public StraightSeeding { 14 | private: 15 | int circle = 0; 16 | public: 17 | CircleSeeding(vector sw, int nlanes); 18 | void seed(); 19 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 20 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/Event.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Swimmer.h" 5 | #include "Seeding.h" 6 | class Event { 7 | protected: 8 | int numLanes; 9 | vector swimmers; 10 | public: 11 | Event(string filename, int lanes); 12 | Event(); 13 | virtual Seeding* getSeeding() = 0; 14 | }; 15 | ======= 16 | #pragma once 17 | #include "SwmHeaders.h" 18 | #include "Swimmer.h" 19 | #include "Seeding.h" 20 | class Event { 21 | protected: 22 | int numLanes; 23 | vector swimmers; 24 | public: 25 | Event(string filename, int lanes); 26 | Event(); 27 | virtual Seeding* getSeeding() = 0; 28 | }; 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/PrelimEvent.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 3 | #include "SwmHeaders.h" 4 | #include "Event.h" 5 | #include "TimedFinalEvent.h" 6 | #include "CircleSeeding.h" 7 | #include "PrelimEvent.h" 8 | 9 | //creates a preliminary event which is circle seeded 10 | PrelimEvent::PrelimEvent(string filename, int lanes) :Event(filename, lanes) {} 11 | 12 | Seeding* PrelimEvent::getSeeding() { 13 | return new CircleSeeding(swimmers, numLanes); 14 | } 15 | ======= 16 | 17 | #include "SwmHeaders.h" 18 | #include "Event.h" 19 | #include "TimedFinalEvent.h" 20 | #include "CircleSeeding.h" 21 | #include "PrelimEvent.h" 22 | 23 | //creates a preliminary event which is circle seeded 24 | PrelimEvent::PrelimEvent(string filename, int lanes) :Event(filename, lanes) {} 25 | 26 | Seeding* PrelimEvent::getSeeding() { 27 | return new CircleSeeding(swimmers, numLanes); 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/PrelimEvent.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Event.h" 4 | #include "Seeding.h" 5 | #include "CircleSeeding.h" 6 | //----------------------- 7 | class PrelimEvent :public Event { 8 | public: 9 | //creates a preliminary event which is circle seeded 10 | PrelimEvent(string filename, int lanes); 11 | 12 | Seeding* getSeeding(); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Event.h" 18 | #include "Seeding.h" 19 | #include "CircleSeeding.h" 20 | //----------------------- 21 | class PrelimEvent :public Event { 22 | public: 23 | //creates a preliminary event which is circle seeded 24 | PrelimEvent(string filename, int lanes); 25 | 26 | Seeding* getSeeding(); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/Seeding.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "SwmHeaders.h" 3 | #include "Seeding.h" 4 | 5 | 6 | //virtual void Seeding::seed() = 0; 7 | vector Seeding::getSwimmers() { 8 | return swimmers; 9 | } 10 | 11 | ======= 12 | #include "SwmHeaders.h" 13 | #include "Seeding.h" 14 | 15 | 16 | //virtual void Seeding::seed() = 0; 17 | vector Seeding::getSwimmers() { 18 | return swimmers; 19 | } 20 | 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/Seeding.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Swimmer.h" 5 | class Seeding { 6 | protected: 7 | vector swimmers; 8 | public: 9 | virtual void seed() = 0; 10 | vector getSwimmers(); 11 | }; 12 | ======= 13 | #pragma once 14 | #include "SwmHeaders.h" 15 | #include "Swimmer.h" 16 | class Seeding { 17 | protected: 18 | vector swimmers; 19 | public: 20 | virtual void seed() = 0; 21 | vector getSwimmers(); 22 | }; 23 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 24 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/State.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | using std::string; 5 | 6 | class State { 7 | private: 8 | string name; 9 | string abbrev; 10 | string date; 11 | string capital; 12 | 13 | 14 | public: 15 | State(std::string line); 16 | string getName(); 17 | string getAbbrev(); 18 | string getDate(); 19 | string getCapital(); 20 | ======= 21 | #pragma once 22 | #include 23 | using std::string; 24 | 25 | class State { 26 | private: 27 | string name; 28 | string abbrev; 29 | string date; 30 | string capital; 31 | 32 | 33 | public: 34 | State(std::string line); 35 | string getName(); 36 | string getAbbrev(); 37 | string getDate(); 38 | string getCapital(); 39 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 40 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/SwmHeaders.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using std::cout; 11 | using std::endl; 12 | using std::cin; 13 | using std::string; 14 | using std::stringstream; 15 | using std::ifstream; 16 | using std::vector; 17 | using std::format; 18 | 19 | ======= 20 | #pragma once 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using std::cout; 29 | using std::endl; 30 | using std::cin; 31 | using std::string; 32 | using std::stringstream; 33 | using std::ifstream; 34 | using std::vector; 35 | using std::format; 36 | 37 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 38 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/TimedFinalEvent.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Event.h" 5 | #include "StraightSeeding.h" 6 | class TimedFinalEvent : public Event { 7 | //creates an event that will be straight seeded 8 | public: 9 | TimedFinalEvent(string filename, int lanes); 10 | 11 | Seeding* getSeeding(); 12 | ======= 13 | #pragma once 14 | #include "SwmHeaders.h" 15 | #include "Event.h" 16 | #include "StraightSeeding.h" 17 | class TimedFinalEvent : public Event { 18 | //creates an event that will be straight seeded 19 | public: 20 | TimedFinalEvent(string filename, int lanes); 21 | 22 | Seeding* getSeeding(); 23 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 24 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/TimedFinaleEvent.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "SwmHeaders.h" 3 | #include "Event.h" 4 | #include "Seeding.h" 5 | #include"TimedFinalEvent.h" 6 | 7 | 8 | TimedFinalEvent::TimedFinalEvent(string filename, int lanes) 9 | : Event(filename, lanes){ 10 | } 11 | 12 | Seeding* TimedFinalEvent::getSeeding() { 13 | return new StraightSeeding(swimmers, numLanes); 14 | } 15 | ======= 16 | #include "SwmHeaders.h" 17 | #include "Event.h" 18 | #include "Seeding.h" 19 | #include"TimedFinalEvent.h" 20 | 21 | 22 | TimedFinalEvent::TimedFinalEvent(string filename, int lanes) 23 | : Event(filename, lanes){ 24 | } 25 | 26 | Seeding* TimedFinalEvent::getSeeding() { 27 | return new StraightSeeding(swimmers, numLanes); 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimDisplay/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/CircleSeeding.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "StraightSeeding.h" 4 | class CircleSeeding :public StraightSeeding { 5 | private: 6 | int circle = 0; 7 | public: 8 | CircleSeeding(vector sw, int nlanes); 9 | void seed(); 10 | ======= 11 | #pragma once 12 | #include "StraightSeeding.h" 13 | class CircleSeeding :public StraightSeeding { 14 | private: 15 | int circle = 0; 16 | public: 17 | CircleSeeding(vector sw, int nlanes); 18 | void seed(); 19 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 20 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/Event.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Swimmer.h" 5 | #include "Seeding.h" 6 | class Event { 7 | protected: 8 | int numLanes; 9 | vector swimmers; 10 | public: 11 | Event(string filename, int lanes); 12 | Event(); 13 | virtual Seeding* getSeeding() = 0; 14 | }; 15 | ======= 16 | #pragma once 17 | #include "SwmHeaders.h" 18 | #include "Swimmer.h" 19 | #include "Seeding.h" 20 | class Event { 21 | protected: 22 | int numLanes; 23 | vector swimmers; 24 | public: 25 | Event(string filename, int lanes); 26 | Event(); 27 | virtual Seeding* getSeeding() = 0; 28 | }; 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/PrelimEvent.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 3 | #include "SwmHeaders.h" 4 | #include "Event.h" 5 | #include "TimedFinalEvent.h" 6 | #include "CircleSeeding.h" 7 | #include "PrelimEvent.h" 8 | 9 | //creates a preliminary event which is circle seeded 10 | PrelimEvent::PrelimEvent(string filename, int lanes) :Event(filename, lanes) {} 11 | 12 | Seeding* PrelimEvent::getSeeding() { 13 | return new CircleSeeding(swimmers, numLanes); 14 | } 15 | ======= 16 | 17 | #include "SwmHeaders.h" 18 | #include "Event.h" 19 | #include "TimedFinalEvent.h" 20 | #include "CircleSeeding.h" 21 | #include "PrelimEvent.h" 22 | 23 | //creates a preliminary event which is circle seeded 24 | PrelimEvent::PrelimEvent(string filename, int lanes) :Event(filename, lanes) {} 25 | 26 | Seeding* PrelimEvent::getSeeding() { 27 | return new CircleSeeding(swimmers, numLanes); 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/PrelimEvent.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Event.h" 4 | #include "Seeding.h" 5 | #include "CircleSeeding.h" 6 | //----------------------- 7 | class PrelimEvent :public Event { 8 | public: 9 | //creates a preliminary event which is circle seeded 10 | PrelimEvent(string filename, int lanes); 11 | 12 | Seeding* getSeeding(); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Event.h" 18 | #include "Seeding.h" 19 | #include "CircleSeeding.h" 20 | //----------------------- 21 | class PrelimEvent :public Event { 22 | public: 23 | //creates a preliminary event which is circle seeded 24 | PrelimEvent(string filename, int lanes); 25 | 26 | Seeding* getSeeding(); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/Seeding.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "SwmHeaders.h" 3 | #include "Seeding.h" 4 | 5 | 6 | //virtual void Seeding::seed() = 0; 7 | vector Seeding::getSwimmers() { 8 | return swimmers; 9 | } 10 | 11 | ======= 12 | #include "SwmHeaders.h" 13 | #include "Seeding.h" 14 | 15 | 16 | //virtual void Seeding::seed() = 0; 17 | vector Seeding::getSwimmers() { 18 | return swimmers; 19 | } 20 | 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/Seeding.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Swimmer.h" 5 | class Seeding { 6 | protected: 7 | vector swimmers; 8 | public: 9 | //virtual void seed() = 0; 10 | vector getSwimmers(); 11 | }; 12 | ======= 13 | #pragma once 14 | #include "SwmHeaders.h" 15 | #include "Swimmer.h" 16 | class Seeding { 17 | protected: 18 | vector swimmers; 19 | public: 20 | //virtual void seed() = 0; 21 | vector getSwimmers(); 22 | }; 23 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 24 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/SwmHeaders.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using std::cout; 11 | using std::endl; 12 | using std::cin; 13 | using std::string; 14 | using std::stringstream; 15 | using std::ifstream; 16 | using std::vector; 17 | using std::format; 18 | 19 | ======= 20 | #pragma once 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using std::cout; 29 | using std::endl; 30 | using std::cin; 31 | using std::string; 32 | using std::stringstream; 33 | using std::ifstream; 34 | using std::vector; 35 | using std::format; 36 | 37 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 38 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/TimedFinalEvent.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Event.h" 5 | #include "StraightSeeding.h" 6 | class TimedFinalEvent : public Event { 7 | //creates an event that will be straight seeded 8 | public: 9 | TimedFinalEvent(string filename, int lanes); 10 | 11 | Seeding* getSeeding(); 12 | ======= 13 | #pragma once 14 | #include "SwmHeaders.h" 15 | #include "Event.h" 16 | #include "StraightSeeding.h" 17 | class TimedFinalEvent : public Event { 18 | //creates an event that will be straight seeded 19 | public: 20 | TimedFinalEvent(string filename, int lanes); 21 | 22 | Seeding* getSeeding(); 23 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 24 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/TimedFinaleEvent.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "SwmHeaders.h" 3 | #include "Event.h" 4 | #include "Seeding.h" 5 | #include"TimedFinalEvent.h" 6 | 7 | 8 | TimedFinalEvent::TimedFinalEvent(string filename, int lanes) 9 | : Event(filename, lanes){ 10 | } 11 | 12 | Seeding* TimedFinalEvent::getSeeding() { 13 | return new StraightSeeding(swimmers, numLanes); 14 | } 15 | ======= 16 | #include "SwmHeaders.h" 17 | #include "Event.h" 18 | #include "Seeding.h" 19 | #include"TimedFinalEvent.h" 20 | 21 | 22 | TimedFinalEvent::TimedFinalEvent(string filename, int lanes) 23 | : Event(filename, lanes){ 24 | } 25 | 26 | Seeding* TimedFinalEvent::getSeeding() { 27 | return new StraightSeeding(swimmers, numLanes); 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimGrid/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/CircleSeeding.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "StraightSeeding.h" 4 | class CircleSeeding :public StraightSeeding { 5 | private: 6 | int circle = 0; 7 | public: 8 | CircleSeeding(vector sw, int nlanes); 9 | void seed(); 10 | ======= 11 | #pragma once 12 | #include "StraightSeeding.h" 13 | class CircleSeeding :public StraightSeeding { 14 | private: 15 | int circle = 0; 16 | public: 17 | CircleSeeding(vector sw, int nlanes); 18 | void seed(); 19 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 20 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/Event.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Swimmer.h" 5 | #include "Seeding.h" 6 | class Event { 7 | protected: 8 | int numLanes; 9 | vector swimmers; 10 | public: 11 | Event(string filename, int lanes); 12 | Event(); 13 | virtual Seeding* getSeeding() = 0; 14 | }; 15 | ======= 16 | #pragma once 17 | #include "SwmHeaders.h" 18 | #include "Swimmer.h" 19 | #include "Seeding.h" 20 | class Event { 21 | protected: 22 | int numLanes; 23 | vector swimmers; 24 | public: 25 | Event(string filename, int lanes); 26 | Event(); 27 | virtual Seeding* getSeeding() = 0; 28 | }; 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/PrelimEvent.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 3 | #include "SwmHeaders.h" 4 | #include "Event.h" 5 | #include "TimedFinalEvent.h" 6 | #include "CircleSeeding.h" 7 | #include "PrelimEvent.h" 8 | 9 | //creates a preliminary event which is circle seeded 10 | PrelimEvent::PrelimEvent(string filename, int lanes) :Event(filename, lanes) {} 11 | 12 | Seeding* PrelimEvent::getSeeding() { 13 | return new CircleSeeding(swimmers, numLanes); 14 | } 15 | ======= 16 | 17 | #include "SwmHeaders.h" 18 | #include "Event.h" 19 | #include "TimedFinalEvent.h" 20 | #include "CircleSeeding.h" 21 | #include "PrelimEvent.h" 22 | 23 | //creates a preliminary event which is circle seeded 24 | PrelimEvent::PrelimEvent(string filename, int lanes) :Event(filename, lanes) {} 25 | 26 | Seeding* PrelimEvent::getSeeding() { 27 | return new CircleSeeding(swimmers, numLanes); 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/PrelimEvent.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Event.h" 4 | #include "Seeding.h" 5 | #include "CircleSeeding.h" 6 | //----------------------- 7 | class PrelimEvent :public Event { 8 | public: 9 | //creates a preliminary event which is circle seeded 10 | PrelimEvent(string filename, int lanes); 11 | 12 | Seeding* getSeeding(); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Event.h" 18 | #include "Seeding.h" 19 | #include "CircleSeeding.h" 20 | //----------------------- 21 | class PrelimEvent :public Event { 22 | public: 23 | //creates a preliminary event which is circle seeded 24 | PrelimEvent(string filename, int lanes); 25 | 26 | Seeding* getSeeding(); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/Seeding.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "SwmHeaders.h" 3 | #include "Seeding.h" 4 | 5 | 6 | //virtual void Seeding::seed() = 0; 7 | vector Seeding::getSwimmers() { 8 | return swimmers; 9 | } 10 | 11 | ======= 12 | #include "SwmHeaders.h" 13 | #include "Seeding.h" 14 | 15 | 16 | //virtual void Seeding::seed() = 0; 17 | vector Seeding::getSwimmers() { 18 | return swimmers; 19 | } 20 | 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/Seeding.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Swimmer.h" 5 | class Seeding { 6 | protected: 7 | vector swimmers; 8 | public: 9 | //virtual void seed() = 0; 10 | vector getSwimmers(); 11 | }; 12 | ======= 13 | #pragma once 14 | #include "SwmHeaders.h" 15 | #include "Swimmer.h" 16 | class Seeding { 17 | protected: 18 | vector swimmers; 19 | public: 20 | //virtual void seed() = 0; 21 | vector getSwimmers(); 22 | }; 23 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 24 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/SwmHeaders.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using std::cout; 11 | using std::endl; 12 | using std::cin; 13 | using std::string; 14 | using std::stringstream; 15 | using std::ifstream; 16 | using std::vector; 17 | using std::format; 18 | 19 | ======= 20 | #pragma once 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using std::cout; 29 | using std::endl; 30 | using std::cin; 31 | using std::string; 32 | using std::stringstream; 33 | using std::ifstream; 34 | using std::vector; 35 | using std::format; 36 | 37 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 38 | -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/TimedFinalEvent.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "SwmHeaders.h" 4 | #include "Event.h" 5 | #include "StraightSeeding.h" 6 | class TimedFinalEvent : public Event { 7 | //creates an event that will be straight seeded 8 | public: 9 | TimedFinalEvent(string filename, int lanes); 10 | 11 | Seeding* getSeeding(); 12 | ======= 13 | #pragma once 14 | #include "SwmHeaders.h" 15 | #include "Event.h" 16 | #include "StraightSeeding.h" 17 | class TimedFinalEvent : public Event { 18 | //creates an event that will be straight seeded 19 | public: 20 | TimedFinalEvent(string filename, int lanes); 21 | 22 | Seeding* getSeeding(); 23 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 24 | }; -------------------------------------------------------------------------------- /PyCpp/20. Factory patterns/SwimSeed classes/TimedFinaleEvent.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "SwmHeaders.h" 3 | #include "Event.h" 4 | #include "Seeding.h" 5 | #include"TimedFinalEvent.h" 6 | 7 | 8 | TimedFinalEvent::TimedFinalEvent(string filename, int lanes) 9 | : Event(filename, lanes){ 10 | } 11 | 12 | Seeding* TimedFinalEvent::getSeeding() { 13 | return new StraightSeeding(swimmers, numLanes); 14 | } 15 | ======= 16 | #include "SwmHeaders.h" 17 | #include "Event.h" 18 | #include "Seeding.h" 19 | #include"TimedFinalEvent.h" 20 | 21 | 22 | TimedFinalEvent::TimedFinalEvent(string filename, int lanes) 23 | : Event(filename, lanes){ 24 | } 25 | 26 | Seeding* TimedFinalEvent::getSeeding() { 27 | return new StraightSeeding(swimmers, numLanes); 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/Basic Adapter/baseincludes.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | using std::vector; 13 | ======= 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | using std::vector; 25 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 26 | using std::string; -------------------------------------------------------------------------------- /PyCpp/22. Adapters/Grid Adapter/GridAdapter.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "baseincludes.h" 4 | class GridAdapter 5 | { 6 | private: 7 | wxGrid* grid; 8 | int curRow; 9 | public: 10 | 11 | GridAdapter(wxGrid* grd); 12 | void Clear(); 13 | int GetSelection(); 14 | wxString GetString(int index); 15 | void Append(wxString name); 16 | void Delete(); 17 | void Refresh(); 18 | void setCurrentRow(int row); 19 | void onClick(wxGridEvent& event); 20 | int getSelectedRow(); 21 | }; 22 | 23 | ======= 24 | #pragma once 25 | #include "baseincludes.h" 26 | class GridAdapter 27 | { 28 | private: 29 | wxGrid* grid; 30 | int curRow; 31 | public: 32 | 33 | GridAdapter(wxGrid* grd); 34 | void Clear(); 35 | int GetSelection(); 36 | wxString GetString(int index); 37 | void Append(wxString name); 38 | void Delete(); 39 | void Refresh(); 40 | void setCurrentRow(int row); 41 | void onClick(wxGridEvent& event); 42 | int getSelectedRow(); 43 | }; 44 | 45 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 46 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/Grid Adapter/StrFuncs.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | class Strfuncs { 8 | //trim a string to remove whitespace 9 | //characters from the beginning and end 10 | public: 11 | static std::string strip(std::string line); 12 | 13 | //Split a string at the delimiter into a vector of strings, 14 | // each stripped of whitespace 15 | static std::vector split(std::string line, std::string delim); 16 | }; 17 | ======= 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | class Strfuncs { 24 | //trim a string to remove whitespace 25 | //characters from the beginning and end 26 | public: 27 | static std::string strip(std::string line); 28 | 29 | //Split a string at the delimiter into a vector of strings, 30 | // each stripped of whitespace 31 | static std::vector split(std::string line, std::string delim); 32 | }; 33 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 34 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/Grid Adapter/baseincludes.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | using std::vector; 14 | ======= 15 | #pragma once 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | using std::vector; 27 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 28 | using std::string; -------------------------------------------------------------------------------- /PyCpp/22. Adapters/Grid Adapter/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListAdapter/StrFuncs.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | class Strfuncs { 8 | //trim a string to remove whitespace 9 | //characters from the beginning and end 10 | public: 11 | static std::string strip(std::string line); 12 | 13 | //Split a string at the delimiter into a vector of strings, 14 | // each stripped of whitespace 15 | static std::vector split(std::string line, std::string delim); 16 | }; 17 | ======= 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | class Strfuncs { 24 | //trim a string to remove whitespace 25 | //characters from the beginning and end 26 | public: 27 | static std::string strip(std::string line); 28 | 29 | //Split a string at the delimiter into a vector of strings, 30 | // each stripped of whitespace 31 | static std::vector split(std::string line, std::string delim); 32 | }; 33 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 34 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListAdapter/Student.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include "baseincludes.h" 5 | class Student { 6 | static int randint(int min, int max) { 7 | int value = rand(); 8 | int range = value % (max - min); 9 | return range + min; 10 | } 11 | private: 12 | string name; 13 | string frname{ "" }; 14 | string lname{" "}; 15 | int iq; 16 | int score; 17 | public: 18 | Student(wxString nm); 19 | string getName(); 20 | int getIQ(); 21 | int getScore(); 22 | ======= 23 | #pragma once 24 | #include 25 | #include "baseincludes.h" 26 | class Student { 27 | static int randint(int min, int max) { 28 | int value = rand(); 29 | int range = value % (max - min); 30 | return range + min; 31 | } 32 | private: 33 | string name; 34 | string frname{ "" }; 35 | string lname{" "}; 36 | int iq; 37 | int score; 38 | public: 39 | Student(wxString nm); 40 | string getName(); 41 | int getIQ(); 42 | int getScore(); 43 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 44 | }; -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListAdapter/StudentList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "baseincludes.h" 4 | #include "Student.h" 5 | using std::vector; 6 | class StudentList : 7 | public wxListBox 8 | { 9 | private: 10 | vector students; 11 | public: 12 | StudentList(wxPanel* panel, wxSize size); 13 | void append(Student* st); 14 | void redraw(); 15 | void remove(int index); 16 | Student* getSelected(); 17 | }; 18 | 19 | ======= 20 | #pragma once 21 | #include "baseincludes.h" 22 | #include "Student.h" 23 | using std::vector; 24 | class StudentList : 25 | public wxListBox 26 | { 27 | private: 28 | vector students; 29 | public: 30 | StudentList(wxPanel* panel, wxSize size); 31 | void append(Student* st); 32 | void redraw(); 33 | void remove(int index); 34 | Student* getSelected(); 35 | }; 36 | 37 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 38 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListAdapter/baseincludes.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | using std::vector; 13 | ======= 14 | #pragma once 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | using std::vector; 25 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 26 | using std::string; -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListAdapter/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListGridAdapter/StrFuncs.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | class Strfuncs { 8 | //trim a string to remove whitespace 9 | //characters from the beginning and end 10 | public: 11 | static std::string strip(std::string line); 12 | 13 | //Split a string at the delimiter into a vector of strings, 14 | // each stripped of whitespace 15 | static std::vector split(std::string line, std::string delim); 16 | }; 17 | ======= 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | class Strfuncs { 24 | //trim a string to remove whitespace 25 | //characters from the beginning and end 26 | public: 27 | static std::string strip(std::string line); 28 | 29 | //Split a string at the delimiter into a vector of strings, 30 | // each stripped of whitespace 31 | static std::vector split(std::string line, std::string delim); 32 | }; 33 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 34 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListGridAdapter/StudentList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "baseincludes.h" 4 | #include "Student.h" 5 | using std::vector; 6 | class StudentList : 7 | public wxListBox 8 | { 9 | private: 10 | vector students; 11 | public: 12 | ~StudentList() { 13 | 14 | } 15 | StudentList(wxPanel* panel, wxSize size); 16 | void append(Student* st); 17 | void redraw(); 18 | void remove(int index); 19 | Student* getSelected(); 20 | 21 | }; 22 | 23 | ======= 24 | #pragma once 25 | #include "baseincludes.h" 26 | #include "Student.h" 27 | using std::vector; 28 | class StudentList : 29 | public wxListBox 30 | { 31 | private: 32 | vector students; 33 | public: 34 | ~StudentList() { 35 | 36 | } 37 | StudentList(wxPanel* panel, wxSize size); 38 | void append(Student* st); 39 | void redraw(); 40 | void remove(int index); 41 | Student* getSelected(); 42 | 43 | }; 44 | 45 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 46 | -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListGridAdapter/baseincludes.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | using std::vector; 14 | ======= 15 | #pragma once 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | using std::vector; 27 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 28 | using std::string; -------------------------------------------------------------------------------- /PyCpp/22. Adapters/StudentListGridAdapter/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/Bridger.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Products.h" 4 | //abstract Bridge class 5 | 6 | class Bridger { 7 | //add data to the other side of the bridge 8 | virtual void addData(Products* prod) = 0; 9 | }; 10 | 11 | ======= 12 | #pragma once 13 | #include "Products.h" 14 | //abstract Bridge class 15 | 16 | class Bridger { 17 | //add data to the other side of the bridge 18 | virtual void addData(Products* prod) = 0; 19 | }; 20 | 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/GrdVisList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "VisList.h" 4 | #include "Products.h" 5 | #include "baseincludes.h" 6 | 7 | //A VisList view of a Grid 8 | 9 | class GrdVisList :public VisList, public wxGrid 10 | { 11 | public: 12 | GrdVisList(wxPanel* p, wxSize sz); 13 | void addLines(Products* prods); 14 | }; 15 | 16 | ======= 17 | #pragma once 18 | #include "VisList.h" 19 | #include "Products.h" 20 | #include "baseincludes.h" 21 | 22 | //A VisList view of a Grid 23 | 24 | class GrdVisList :public VisList, public wxGrid 25 | { 26 | public: 27 | GrdVisList(wxPanel* p, wxSize sz); 28 | void addLines(Products* prods); 29 | }; 30 | 31 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 32 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/GridBridge.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 3 | #include "Products.h" 4 | #include "VisList.h" 5 | #include "GridBridge.h" 6 | 7 | //bridge betwen grid and products 8 | GridBridge::GridBridge(VisList* vl) { 9 | visList = vl; 10 | 11 | } 12 | void GridBridge::addData(Products* prod) { 13 | visList->addLines(prod); 14 | 15 | } 16 | ======= 17 | 18 | #include "Products.h" 19 | #include "VisList.h" 20 | #include "GridBridge.h" 21 | 22 | //bridge betwen grid and products 23 | GridBridge::GridBridge(VisList* vl) { 24 | visList = vl; 25 | 26 | } 27 | void GridBridge::addData(Products* prod) { 28 | visList->addLines(prod); 29 | 30 | } 31 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 32 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/GridBridge.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Bridger.h" 4 | #include "VisList.h" 5 | #include "Products.h" 6 | //General bridge between data and any VisList class 7 | class GridBridge :public Bridger { 8 | private: 9 | VisList* visList; 10 | public: 11 | GridBridge(VisList* vl); 12 | void addData(Products* prod); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Bridger.h" 18 | #include "VisList.h" 19 | #include "Products.h" 20 | //General bridge between data and any VisList class 21 | class GridBridge :public Bridger { 22 | private: 23 | VisList* visList; 24 | public: 25 | GridBridge(VisList* vl); 26 | void addData(Products* prod); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/LbVisList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Products.h" 4 | #include "VisList.h" 5 | #include "baseincludes.h" 6 | 7 | //a listbox that holds a list of products, derived from VisList and ListBox 8 | class LbVisList:public VisList,public wxListBox 9 | { 10 | public: 11 | LbVisList(wxPanel* p, wxSize sz); 12 | void addLines(Products* prods); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Products.h" 18 | #include "VisList.h" 19 | #include "baseincludes.h" 20 | 21 | //a listbox that holds a list of products, derived from VisList and ListBox 22 | class LbVisList:public VisList,public wxListBox 23 | { 24 | public: 25 | LbVisList(wxPanel* p, wxSize sz); 26 | void addLines(Products* prods); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/ListBridge.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "ListBridge.h" 3 | #include "Products.h" 4 | #include "VisList.h" 5 | 6 | ListBridge::ListBridge(VisList* vl) { 7 | visList = vl; 8 | 9 | } 10 | void ListBridge::addData(Products* prod) { 11 | visList->addLines(prod); 12 | 13 | } 14 | ======= 15 | #include "ListBridge.h" 16 | #include "Products.h" 17 | #include "VisList.h" 18 | 19 | ListBridge::ListBridge(VisList* vl) { 20 | visList = vl; 21 | 22 | } 23 | void ListBridge::addData(Products* prod) { 24 | visList->addLines(prod); 25 | 26 | } 27 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 28 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/ListBridge.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Bridger.h" 4 | #include "VisList.h" 5 | #include "Products.h" 6 | //General bridge between data and any VisList class 7 | class ListBridge :public Bridger { 8 | private: 9 | VisList* visList; 10 | public: 11 | ListBridge(VisList* vl); 12 | void addData(Products* prod); 13 | ======= 14 | #pragma once 15 | #include "Bridger.h" 16 | #include "VisList.h" 17 | #include "Products.h" 18 | //General bridge between data and any VisList class 19 | class ListBridge :public Bridger { 20 | private: 21 | VisList* visList; 22 | public: 23 | ListBridge(VisList* vl); 24 | void addData(Products* prod); 25 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 26 | }; -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/Product.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "Product.h" 3 | #include 4 | Product::Product(const string nstring) { 5 | size_t index = nstring.find("--"); 6 | name = nstring.substr(0, index - 1); 7 | count = nstring.substr(index + 2, nstring.length()); 8 | } 9 | string Product::getName() { 10 | return name; 11 | } 12 | string Product::getCount() { 13 | return count; 14 | } 15 | ======= 16 | #include "Product.h" 17 | #include 18 | Product::Product(const string nstring) { 19 | size_t index = nstring.find("--"); 20 | name = nstring.substr(0, index - 1); 21 | count = nstring.substr(index + 2, nstring.length()); 22 | } 23 | string Product::getName() { 24 | return name; 25 | } 26 | string Product::getCount() { 27 | return count; 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/Product.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | using std::string; 5 | //Holds one producr name and count 6 | 7 | class Product{ 8 | private: 9 | string name; //product name 10 | string count; //inventory or sales count 11 | public: 12 | Product(const string nstring); 13 | string getName(); //return the name 14 | string getCount(); //return the count 15 | }; 16 | 17 | ======= 18 | #pragma once 19 | #include 20 | using std::string; 21 | //Holds one producr name and count 22 | 23 | class Product{ 24 | private: 25 | string name; //product name 26 | string count; //inventory or sales count 27 | public: 28 | Product(const string nstring); 29 | string getName(); //return the name 30 | string getCount(); //return the count 31 | }; 32 | 33 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 34 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/Products.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | 6 | #include "Product.h" 7 | using std::string; 8 | using std::vector; 9 | //holds a collection of products in a vector 10 | 11 | class Products { 12 | private: 13 | vector prods; // list of products 14 | public: 15 | Products(const string filename); //read the file 16 | vector getProducts(); //return the vector 17 | }; 18 | 19 | ======= 20 | #pragma once 21 | #include 22 | #include 23 | 24 | #include "Product.h" 25 | using std::string; 26 | using std::vector; 27 | //holds a collection of products in a vector 28 | 29 | class Products { 30 | private: 31 | vector prods; // list of products 32 | public: 33 | Products(const string filename); //read the file 34 | vector getProducts(); //return the vector 35 | }; 36 | 37 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 38 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/VisList.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "VisList.h" 3 | #include "Products.h" 4 | 5 | ======= 6 | #include "VisList.h" 7 | #include "Products.h" 8 | 9 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 10 | void VisList:: addLines(Products* prod) {} -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/VisList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Products.h" 4 | //abstract class defining the one method in the VisList class 5 | class VisList { 6 | public: 7 | virtual void addLines(Products* prod)=0; 8 | }; 9 | 10 | ======= 11 | #pragma once 12 | #include "Products.h" 13 | //abstract class defining the one method in the VisList class 14 | class VisList { 15 | public: 16 | virtual void addLines(Products* prod)=0; 17 | }; 18 | 19 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 20 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/baseincludes.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | using std::vector; 14 | ======= 15 | #pragma once 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | using std::vector; 27 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 28 | using std::string; -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/Bridger1/products.txt: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | Brass plated widgets --1,000,076 3 | Furled frammis --75,000 4 | Detailed rat brushes --700 5 | Zero-based hex dumps--80,000 6 | Anterior antelope collars --578 7 | Washable softwear --789,000 8 | Steel-toed wing-tips --456,666 9 | ======= 10 | Brass plated widgets --1,000,076 11 | Furled frammis --75,000 12 | Detailed rat brushes --700 13 | Zero-based hex dumps--80,000 14 | Anterior antelope collars --578 15 | Washable softwear --789,000 16 | Steel-toed wing-tips --456,666 17 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 18 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/Bridger.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Products.h" 4 | //abstract Bridge class 5 | 6 | class Bridger { 7 | //add data to the other side of the bridge 8 | virtual void addData(Products* prod) = 0; 9 | }; 10 | 11 | ======= 12 | #pragma once 13 | #include "Products.h" 14 | //abstract Bridge class 15 | 16 | class Bridger { 17 | //add data to the other side of the bridge 18 | virtual void addData(Products* prod) = 0; 19 | }; 20 | 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/GridBridge.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 3 | #include "Products.h" 4 | #include "VisList.h" 5 | #include "GridBridge.h" 6 | 7 | //bridge betwen grid and products 8 | GridBridge::GridBridge(VisList* vl) { 9 | visList = vl; 10 | 11 | } 12 | void GridBridge::addData(Products* prod) { 13 | visList->addLines(prod); 14 | 15 | } 16 | ======= 17 | 18 | #include "Products.h" 19 | #include "VisList.h" 20 | #include "GridBridge.h" 21 | 22 | //bridge betwen grid and products 23 | GridBridge::GridBridge(VisList* vl) { 24 | visList = vl; 25 | 26 | } 27 | void GridBridge::addData(Products* prod) { 28 | visList->addLines(prod); 29 | 30 | } 31 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 32 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/GridBridge.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Bridger.h" 4 | #include "VisList.h" 5 | #include "Products.h" 6 | //General bridge between data and any VisList class 7 | class GridBridge :public Bridger { 8 | private: 9 | VisList* visList; 10 | public: 11 | GridBridge(VisList* vl); 12 | void addData(Products* prod); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Bridger.h" 18 | #include "VisList.h" 19 | #include "Products.h" 20 | //General bridge between data and any VisList class 21 | class GridBridge :public Bridger { 22 | private: 23 | VisList* visList; 24 | public: 25 | GridBridge(VisList* vl); 26 | void addData(Products* prod); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/ListBridge.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Bridger.h" 4 | #include "VisList.h" 5 | #include "Products.h" 6 | //General bridge between data and any VisList class 7 | class ListBridge :public Bridger { 8 | private: 9 | VisList* visList; 10 | public: 11 | ListBridge(VisList* vl); 12 | void addData(Products* prod); 13 | ======= 14 | #pragma once 15 | #include "Bridger.h" 16 | #include "VisList.h" 17 | #include "Products.h" 18 | //General bridge between data and any VisList class 19 | class ListBridge :public Bridger { 20 | private: 21 | VisList* visList; 22 | public: 23 | ListBridge(VisList* vl); 24 | void addData(Products* prod); 25 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 26 | }; -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/Product.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "Product.h" 3 | #include 4 | Product::Product(const string nstring) { 5 | size_t index = nstring.find("--"); 6 | name = nstring.substr(0, index - 1); 7 | count = nstring.substr(index + 2, nstring.length()); 8 | } 9 | string Product::getName() { 10 | return name; 11 | } 12 | string Product::getCount() { 13 | return count; 14 | } 15 | ======= 16 | #include "Product.h" 17 | #include 18 | Product::Product(const string nstring) { 19 | size_t index = nstring.find("--"); 20 | name = nstring.substr(0, index - 1); 21 | count = nstring.substr(index + 2, nstring.length()); 22 | } 23 | string Product::getName() { 24 | return name; 25 | } 26 | string Product::getCount() { 27 | return count; 28 | } 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/Product.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | using std::string; 5 | //Holds one producr name and count 6 | 7 | class Product{ 8 | private: 9 | string name; //product name 10 | string count; //inventory or sales count 11 | public: 12 | Product(const string nstring); 13 | string getName(); //return the name 14 | string getCount(); //return the count 15 | }; 16 | 17 | ======= 18 | #pragma once 19 | #include 20 | using std::string; 21 | //Holds one producr name and count 22 | 23 | class Product{ 24 | private: 25 | string name; //product name 26 | string count; //inventory or sales count 27 | public: 28 | Product(const string nstring); 29 | string getName(); //return the name 30 | string getCount(); //return the count 31 | }; 32 | 33 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 34 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/Products.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | 6 | #include "Product.h" 7 | using std::string; 8 | using std::vector; 9 | //holds a collection of products in a vector 10 | 11 | class Products { 12 | private: 13 | vector prods; // list of products 14 | public: 15 | Products(const string filename); //read the file 16 | vector getProducts(); //return the vector 17 | }; 18 | 19 | ======= 20 | #pragma once 21 | #include 22 | #include 23 | 24 | #include "Product.h" 25 | using std::string; 26 | using std::vector; 27 | //holds a collection of products in a vector 28 | 29 | class Products { 30 | private: 31 | vector prods; // list of products 32 | public: 33 | Products(const string filename); //read the file 34 | vector getProducts(); //return the vector 35 | }; 36 | 37 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 38 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/SortGrdVisList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "VisList.h" 4 | #include "Products.h" 5 | #include "baseincludes.h" 6 | 7 | //A VisList view of a Grid 8 | 9 | class GrdVisList :public VisList, public wxGrid 10 | { 11 | public: 12 | GrdVisList(wxPanel* p, wxSize sz); 13 | void addLines(Products* prods); 14 | int getInteger(string s); 15 | }; 16 | 17 | ======= 18 | #pragma once 19 | #include "VisList.h" 20 | #include "Products.h" 21 | #include "baseincludes.h" 22 | 23 | //A VisList view of a Grid 24 | 25 | class GrdVisList :public VisList, public wxGrid 26 | { 27 | public: 28 | GrdVisList(wxPanel* p, wxSize sz); 29 | void addLines(Products* prods); 30 | int getInteger(string s); 31 | }; 32 | 33 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 34 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/SortLbVisList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Products.h" 4 | #include "VisList.h" 5 | #include "baseincludes.h" 6 | 7 | //a listbox that holds a list of products, derived from VisList and ListBox 8 | class LbVisList:public VisList,public wxListBox 9 | { 10 | public: 11 | LbVisList(wxPanel* p, wxSize sz); 12 | void addLines(Products* prods); 13 | }; 14 | 15 | ======= 16 | #pragma once 17 | #include "Products.h" 18 | #include "VisList.h" 19 | #include "baseincludes.h" 20 | 21 | //a listbox that holds a list of products, derived from VisList and ListBox 22 | class LbVisList:public VisList,public wxListBox 23 | { 24 | public: 25 | LbVisList(wxPanel* p, wxSize sz); 26 | void addLines(Products* prods); 27 | }; 28 | 29 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 30 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/SortListBridge.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "ListBridge.h" 3 | #include "Products.h" 4 | #include "VisList.h" 5 | 6 | ListBridge::ListBridge(VisList* vl) { 7 | visList = vl; 8 | 9 | } 10 | void ListBridge::addData(Products* prod) { 11 | visList->addLines(prod); 12 | 13 | } 14 | ======= 15 | #include "ListBridge.h" 16 | #include "Products.h" 17 | #include "VisList.h" 18 | 19 | ListBridge::ListBridge(VisList* vl) { 20 | visList = vl; 21 | 22 | } 23 | void ListBridge::addData(Products* prod) { 24 | visList->addLines(prod); 25 | 26 | } 27 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 28 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/VisList.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #include "VisList.h" 3 | #include "Products.h" 4 | 5 | ======= 6 | #include "VisList.h" 7 | #include "Products.h" 8 | 9 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 10 | void VisList:: addLines(Products* prod) {} -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/VisList.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include "Products.h" 4 | //abstract class defining the one method in the VisList class 5 | class VisList { 6 | public: 7 | virtual void addLines(Products* prod)=0; 8 | }; 9 | 10 | ======= 11 | #pragma once 12 | #include "Products.h" 13 | //abstract class defining the one method in the VisList class 14 | class VisList { 15 | public: 16 | virtual void addLines(Products* prod)=0; 17 | }; 18 | 19 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 20 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/baseincludes.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | using std::vector; 14 | ======= 15 | #pragma once 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | using std::vector; 27 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 28 | using std::string; -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/framework.h: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | // header.h : include file for standard system include files, 3 | // or project specific include files 4 | // 5 | 6 | #pragma once 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | // Windows Header Files 10 | #include 11 | ======= 12 | // header.h : include file for standard system include files, 13 | // or project specific include files 14 | // 15 | 16 | #pragma once 17 | 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | // Windows Header Files 20 | #include 21 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 22 | -------------------------------------------------------------------------------- /PyCpp/23. Bridge pattern/SortBridges/products.txt: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | Brass plated widgets --1,000,076 3 | Furled frammis --75,000 4 | Detailed rat brushes --700 5 | Zero-based hex dumps--80,000 6 | Anterior antelope collars --578 7 | Washable softwear --789,000 8 | Steel-toed wing-tips --456,666 9 | ======= 10 | Brass plated widgets --1,000,076 11 | Furled frammis --75,000 12 | Detailed rat brushes --700 13 | Zero-based hex dumps--80,000 14 | Anterior antelope collars --578 15 | Washable softwear --789,000 16 | Steel-toed wing-tips --456,666 17 | >>>>>>> 788375d648c18c4339961a2476115e1a0e78bd31 18 | -------------------------------------------------------------------------------- /Pythonpatterns/10. Prototype/Swimmers.txt: -------------------------------------------------------------------------------- 1 | Kristen Frost, 9, CAT, 26.31, F 2 | Kimberly Watcke, 10, CDEV,27.37, F 3 | Jaclyn Carey, 10, ARAC, 27.53, F 4 | Megan Crapster, 10, LEHY, 27.68, F 5 | Kaitlyn Ament, 10, HNHS, 28.20, F 6 | Jackie Rogers, 10, WCA, 28.68, F 7 | Erin McLaughlin, 9, HMST, 28.80, F 8 | Emily Ferrier, 10, NMIL, 28.85, F 9 | Aurora Lee, 8, FFLY, 28.88, F 10 | Kate Isselee, 9, NMIL, 28.91, F 11 | Luke Mester, 10, GYWD, 24.88, M 12 | Stephen Cosme, 9, OAK, 27.89, M 13 | Jeffrey Sudbury, 10, WYW, 28.24, M 14 | Ernest Verrico, 9, SHKS, 28.46, M 15 | David Liebovitz, 10, WYW, 28.78, M 16 | Ryan Rynazewski, 10, AJSC, 28.83, M 17 | Matthew Donch, 9, PSDY, 28.95, M 18 | Christopher Prus, 10, RAYS, 29.02, M 19 | Charles Baker, 10, PSDY, 29.06, M 20 | Matthew Sweitzer, 10, SHKS, 29.10, M 21 | -------------------------------------------------------------------------------- /Pythonpatterns/13. Bridge/products.txt: -------------------------------------------------------------------------------- 1 | Brass plated widgets --1,000,076 2 | Furled frammis --75,000 3 | Detailed rat brushes --700 4 | Zero-based hex dumps--80,000 5 | Anterior antelope collars --578 6 | Washable softwear --789,000 7 | Steel-toed wing-tips --456,666 8 | -------------------------------------------------------------------------------- /Pythonpatterns/15. Decorator/DecoCode.py: -------------------------------------------------------------------------------- 1 | """Illustrates an interior function that can be 2 | wrapped as a decorator""" 3 | #decorator that wraps a function 4 | def mathFunc(func): 5 | def wrapper(x): 6 | print("b4 func") 7 | func(x) 8 | print("after func") 9 | return wrapper 10 | 11 | # print out a name or phrase 12 | def sayMath(x): 13 | print("math") 14 | 15 | # create wrapped function 16 | sayMath = mathFunc(sayMath) 17 | print("call after making decorator") 18 | 19 | sayMath(12) 20 | -------------------------------------------------------------------------------- /Pythonpatterns/15. Decorator/DecoFunc.py: -------------------------------------------------------------------------------- 1 | """Illustrates a simple interior function 2 | used as a decorator""" 3 | #decorator that wraps a function 4 | def mathFunc(func): 5 | def wrapper(x): 6 | print("b4 func") 7 | func(x) 8 | print("after func") 9 | return wrapper 10 | # Decorator wraps sayMath 11 | @mathFunc 12 | def sayMath(x): 13 | print("math") 14 | 15 | 16 | # create wrapped function 17 | print("call after making decorator") 18 | 19 | sayMath(12) #call decorated function -------------------------------------------------------------------------------- /Pythonpatterns/16. Facade/dbtest.py: -------------------------------------------------------------------------------- 1 | import MySQLdb 2 | 3 | # Open database connection 4 | db = MySQLdb.connect("localhost","newuser","new_user","groceries" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | print (cursor) 9 | # execute SQL query using execute() method. 10 | cursor.execute("""select foods.foodname, stores.storename, 11 | prices.price from prices 12 | join foods on (foods.foodkey=prices.foodkey) 13 | join stores on (stores.storekey = prices.storekey ) 14 | where foods.foodname='Butter' order by price""") 15 | row = cursor.fetchone() 16 | while row is not None: 17 | print(row) 18 | row = cursor.fetchone() 19 | 20 | cursor.execute("show tables") 21 | rows = cursor.fetchall() 22 | for r in rows: 23 | print(r) 24 | 25 | -------------------------------------------------------------------------------- /Pythonpatterns/16. Facade/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/16. Facade/groceries.db -------------------------------------------------------------------------------- /Pythonpatterns/18. Proxy/edward.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/18. Proxy/edward.jpg -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/Hellobuts.py: -------------------------------------------------------------------------------- 1 | """Create a 2 button window""" 2 | import tkinter as tk 3 | from tkinter import Button, messagebox, LEFT, RIGHT 4 | #from tkinter.ttk import Button 5 | import sys 6 | 7 | 8 | # write slogan out in a message box 9 | def disp_slogan(): 10 | messagebox.showinfo("our message", 11 | "tkinter is easy to use") 12 | 13 | 14 | # set up the window 15 | root = tk.Tk() # get the window 16 | root.geometry("100x100+300+300") # x, y window size and position 17 | 18 | # create Hello button 19 | slogan = Button(root, 20 | text="Hello", 21 | command=disp_slogan) 22 | slogan.pack(side=LEFT, padx=10) 23 | # slogan.pack() 24 | 25 | # create exit button with red letters 26 | button = Button(root, 27 | text="QUIT", 28 | fg="red", 29 | command=sys.exit) 30 | button.pack(side=RIGHT, padx=10) 31 | 32 | # start running the tkinter loop 33 | root.mainloop() 34 | -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/Menus.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | 4 | def InitUI(root): 5 | menubar = Menu(root) 6 | root.config(menu=menubar) 7 | root.title("Menu demo") 8 | root.geometry("300x200") 9 | filemenu = Menu(menubar, tearoff=0) 10 | menubar.add_cascade(label="File", menu=filemenu) 11 | 12 | filemenu.add_command(label="New", command=None) 13 | filemenu.add_command(label="Open", command=None) 14 | filemenu.add_separator() 15 | filemenu.add_command(label="Exit", command=None) 16 | 17 | drawmenu = Menu(menubar, tearoff=0) 18 | menubar.add_cascade(label="Draw", menu=drawmenu) 19 | drawmenu.add_command(label="Circle", command=None) 20 | drawmenu.add_command(label="Square", command=None) 21 | 22 | mainloop() 23 | 24 | 25 | 26 | 27 | def main(): 28 | root = Tk() 29 | InitUI(root) 30 | 31 | ### Here we go #### 32 | if __name__== "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/Messageboxes.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import messagebox, filedialog 3 | 4 | messagebox.showwarning("Warning", "file not found") 5 | messagebox.showerror("Error", "Division by zero") 6 | result = messagebox.askokcancel("Continue", "Go on?") 7 | result= messagebox.askyesnocancel("Really", "Want to go on?") 8 | 9 | # open a single file 10 | fname = filedialog.askopenfilename(defaultextension="*.csv") 11 | print(fname) 12 | 13 | # select several files -returns a tuple 14 | fnames = filedialog.askopenfilenames(defaultextension="*.py") 15 | print(fnames) -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/arm.py: -------------------------------------------------------------------------------- 1 | import time 2 | import dis 3 | 4 | """"List comprehension""" 5 | 6 | def comprehend(): 7 | for i in range(0, 1000000): 8 | squares = [value**2 for value in range (1,21)] 9 | 10 | 11 | #print(squares) 12 | 13 | #equivalent code 14 | 15 | def fularray(): 16 | for i in range(0, 1000000): 17 | squares = [] 18 | for value in range(1,21): 19 | squares.append(value**2) 20 | 21 | #print (squares) 22 | 23 | #conditional comprehension 24 | #nlist = [x for x in range(20) if x%2==0] 25 | #print (nlist) 26 | 27 | #start here 28 | stime = time.monotonic() 29 | comprehend() 30 | etime=time.monotonic() 31 | print(etime- stime) 32 | 33 | stime = time.monotonic() 34 | fularray() 35 | etime=time.monotonic() 36 | print(etime- stime) 37 | 38 | dis.dis(comprehend()) 39 | 40 | dis.dis(fularray()) 41 | 42 | 43 | -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/gridoptions.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | from tkinter.ttk import * 4 | 5 | """Illustrates most of the common options for grid 6 | """ 7 | root=Tk() 8 | root.title("grid") 9 | #lbl1 = Label( text="Name", width=7) 10 | lbl1 = Label( text="Name") 11 | lbl1.grid(row=0, column=0, padx=5, pady=5, sticky=W) 12 | #lbl1.grid(row=0, column=0, padx=5, pady=5) 13 | entry1 = Entry() 14 | entry1.grid(row=0, column=1) 15 | 16 | #lbl2 = Label( text="Address", width=7) 17 | lbl2 = Label( text="Address") 18 | #lbl2.grid(row=1, column=0, padx=5, pady=5) 19 | lbl2.grid(row=1, column=0, padx=5, pady=5, sticky=W) 20 | entry2 = Entry() 21 | entry2.grid(row=1, column=1, padx=5) 22 | 23 | root.mainloop() 24 | 25 | -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/labelframetext.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | 4 | import tkinter.ttk as ttk 5 | from tkinter.ttk import * 6 | 7 | 8 | # main begins here 9 | def main(): 10 | root = tk.Tk() 11 | root.geometry("100x250") 12 | # style required if used on Windows 10 13 | style = Style() 14 | style.theme_use('alt') 15 | 16 | # create LabelFrame 17 | labelframe = LabelFrame(root, text="State data", 18 | borderwidth=7, relief=RAISED) 19 | labelframe.pack(pady=5) 20 | 21 | # add 4 labels 22 | Label(labelframe, text="State").pack() 23 | Label(labelframe, text="Abbrev").pack() 24 | Label(labelframe, text="Capital").pack() 25 | Label(labelframe, text="Founded").pack() 26 | 27 | mainloop() 28 | 29 | 30 | ### Here we go #### 31 | if __name__ == "__main__": 32 | main() 33 | 34 | 35 | -------------------------------------------------------------------------------- /Pythonpatterns/2. Visual programming/packoptions.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | from tkinter.ttk import * 4 | 5 | """Illustrates most of the common options for pack 6 | Note that this works better using the ttk toolkit 7 | Otherwise the labels end up right justified""" 8 | root=tk 9 | 10 | frame1 = Frame() #first row 11 | frame1.pack(fill=X) #fill all of X 12 | 13 | lbl1 = Label(frame1, text="Name", width=7) #add a label 14 | lbl1.pack(side=LEFT, padx=5, pady=5) #on the left 15 | entry1 = Entry(frame1) # add an entry field 16 | entry1.pack(fill=X, padx=5, expand=True) 17 | 18 | frame2 = Frame() #second riw 19 | frame2.pack(fill=X) 20 | 21 | lbl2 = Label(frame2, text="Address", width=7) #add label 22 | lbl2.pack(side=LEFT, padx=5, pady=5) 23 | entry2 = Entry(frame2) #and entry 24 | entry2.pack(fill=X, padx=5, expand=True) 25 | 26 | root.mainloop() 27 | 28 | -------------------------------------------------------------------------------- /Pythonpatterns/20. Chain/mandrill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/20. Chain/mandrill.jpg -------------------------------------------------------------------------------- /Pythonpatterns/23. Iterator/Simple iter examples.py: -------------------------------------------------------------------------------- 1 | # Iterate through an array 2 | people = ["Fred", "Mary", "Sam"] 3 | for p in people: 4 | print (p) 5 | 6 | # Create your own iterator using iter() 7 | pIter = iter(people) 8 | 9 | try: 10 | while p != None: 11 | p = next(pIter) 12 | print (p) 13 | except StopIteration: 14 | pass -------------------------------------------------------------------------------- /Pythonpatterns/23. Iterator/fiboclass.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | @dataclass 4 | class Fibo(): 5 | max:int 6 | 7 | def fibo(self): 8 | current, prev = 0, 1 #initialize 9 | 10 | while current < self.max: # but stops at max 11 | secondLast, prev = prev, current 12 | # compute next x as sum of previous 2 13 | current = prev + secondLast 14 | yield current 15 | 16 | fb = Fibo(100).fibo() 17 | for f in fb: 18 | print(f) 19 | -------------------------------------------------------------------------------- /Pythonpatterns/23. Iterator/fibogen.py: -------------------------------------------------------------------------------- 1 | """ Fibonacci iterator using a generator """ 2 | 3 | def fibo(max=0): 4 | current, prev = 0, 1 # initialize variables 5 | 6 | while current < max: #but stops at max 7 | secondLast, prev = prev, current 8 | # compute next x as sum of previous 2 9 | current = prev + secondLast 10 | yield current # returns next value in series 11 | 12 | fb = fibo(100) 13 | for f in fb: 14 | print(f, end=', ') 15 | -------------------------------------------------------------------------------- /Pythonpatterns/27. State/arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/arrow.gif -------------------------------------------------------------------------------- /Pythonpatterns/27. State/circle for button.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/circle for button.jpg -------------------------------------------------------------------------------- /Pythonpatterns/27. State/circlebutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/circlebutton.png -------------------------------------------------------------------------------- /Pythonpatterns/27. State/rectforbutton.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/rectforbutton.jpg -------------------------------------------------------------------------------- /Pythonpatterns/27. State/rectforbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/rectforbutton.png -------------------------------------------------------------------------------- /Pythonpatterns/27. State/red for button.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/red for button.jpg -------------------------------------------------------------------------------- /Pythonpatterns/27. State/redbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/Pythonpatterns/27. State/redbutton.png -------------------------------------------------------------------------------- /Pythonpatterns/28. Strategy/data.txt: -------------------------------------------------------------------------------- 1 | 1 22 2 | 2 35 3 | 3 27 4 | 4 52 5 | 5 44 6 | -------------------------------------------------------------------------------- /Pythonpatterns/3. Visual tables/t3.py: -------------------------------------------------------------------------------- 1 | cmplx = complex(5.43, 2.22) # a complex number 2 | cmplx2 = 5.5 + 2.2j # also complex number 3 | print (cmplx, cmplx2) 4 | 5 | c = cmplx + cmplx2 6 | print(c) 7 | 8 | d = cmplx/cmplx2 9 | print(d) -------------------------------------------------------------------------------- /Pythonpatterns/31. Variables and Syntax/inputdemo.py: -------------------------------------------------------------------------------- 1 | # Demonstration of input function 2 | 3 | name = input("What is your name? ") 4 | print("Hi "+name +" boy!") 5 | 6 | x = float(input("Enter x: ")) 7 | y = float(input("Enter y: ")) 8 | print("The sum is: ", x+y) -------------------------------------------------------------------------------- /Pythonpatterns/31. Variables and Syntax/printbin.py: -------------------------------------------------------------------------------- 1 | x=7 # 0111 2 | #print(bin(x)) 3 | print(f"{x:04b}") 4 | z = 10 #1010 5 | print(f"{z:04b}") 6 | res = x & z # 7 & 10 is 0010 7 | #print(bin(res)) 8 | print(f"{res:04b}") 9 | res= x | z # 7 | 10 is 1111 10 | print(f"{res:04b}") 11 | res= x ^ z # 7 xor 10 = 1101 12 | print(f"{res:04b}") 13 | 14 | # left shift 15 | print(f"{ x<<1 :04b}") 16 | #right shift 17 | print(f"{ x>>1 :04b}") 18 | 19 | # Exclusive OR gives one if only one of the bits is set, 20 | res = x ^ z 21 | print(f"{res:04b}") 22 | 23 | res= ~z 24 | print(f"{res:04b}") 25 | print(bin(res)) -------------------------------------------------------------------------------- /Pythonpatterns/32. Making Decisions/breaks.py: -------------------------------------------------------------------------------- 1 | xarray= [5,7,4,3,9,12,6] 2 | sum = 0 3 | for x in xarray: 4 | sum += x 5 | if sum > 16: 6 | break #leave loop 7 | print (sum) 8 | 9 | # same code without break 10 | sum = 0 11 | for x in xarray: 12 | sum += x 13 | if sum <= 16: 14 | print (sum) 15 | 16 | # using quit flag 17 | sum = i = 0 18 | quit = False 19 | while sum <=16 and not quit: 20 | sum += xarray[i] 21 | i += 1 22 | quit = sum >= 16 23 | print (sum) 24 | 25 | # reset quit on sum 26 | sum = i = 0 27 | quit = False 28 | while not quit: 29 | sum += xarray[i] 30 | print(sum) 31 | i += 1 32 | quit = sum >= 16 33 | 34 | # use iterator 35 | xiter = iter(xarray) 36 | sum=0 37 | while sum < 16: 38 | sum += next(xiter) 39 | print(sum) -------------------------------------------------------------------------------- /Pythonpatterns/32. Making Decisions/continue.py: -------------------------------------------------------------------------------- 1 | for i in range(10): 2 | if i==6: 3 | continue 4 | print(i) 5 | 6 | for i in range(10): 7 | if i != 6: 8 | print (i) -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/Slicing.py: -------------------------------------------------------------------------------- 1 | # String slicing 2 | text = "Learn Python" 3 | # first 3 characters 4 | print(text[0:3]) #Lea 5 | #first four (0-4) 6 | print(text[:4]) #Lear 7 | # last 4 8 | print(text[-4:]) #thon 9 | #9 to end 10 | print(text[9:]) #hon 11 | ln= len(text) 12 | print(text[ln-6:ln+1]) #Python 13 | 14 | #using stride 15 | print(text[0:6:1]) #Learn 16 | print(text[0:6:2]) #Lan 17 | 18 | # reverse a string 19 | name = "I love Python" 20 | newname = name[-1::-1] # nohtyP evol I 21 | 22 | -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/comprehend.py: -------------------------------------------------------------------------------- 1 | """List comprehension""" 2 | squares = [value**2 for value in range (1,21)] 3 | print(squares) 4 | 5 | #equivalent code 6 | squares = [] 7 | for value in range(1,21): 8 | squares.append(value**2) 9 | print (squares) 10 | 11 | #conditional comprehension 12 | nlist = [x for x in range(20) if x%2==0] 13 | print (nlist) -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/exceptions.py: -------------------------------------------------------------------------------- 1 | """Illustrates using exceptions""" 2 | try: 3 | f = open("shrubbery", "r") 4 | except FileNotFoundError: 5 | print("Can''t find that file") 6 | 7 | x = 5.63 8 | y = 0 9 | 10 | try: 11 | z = x/y 12 | except ZeroDivisionError: 13 | print("Division by zero!") 14 | else: 15 | print("result=",z) -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/fibo.py: -------------------------------------------------------------------------------- 1 | """Print out Fibonacci series""" 2 | current=0 3 | prev=1 4 | secondLast=0 5 | 6 | while current < 1000: 7 | print (current, end=" ") #without newline characters 8 | secondLast = prev #copy n-1st to secondLast 9 | prev = current #copy nth to prev 10 | current = prev + secondLast #compute next x as sum of previous 2 11 | -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/fibohard.py: -------------------------------------------------------------------------------- 1 | # Carries out Fibonacci in harder to read code 2 | 3 | a, b = 0, 1 #assign a=0 and b=1 4 | while a < 1000: 5 | print(a) 6 | a,b = b, a + b # here we swap b for a and a+b for b 7 | -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/sets.py: -------------------------------------------------------------------------------- 1 | # This is a sample Python script. 2 | # Examples of set uses 3 | 4 | fruit = {'apples', 'pears', 'lemons'} 5 | fruitPie = {'apples', 'pears'} 6 | 7 | # both are true if fruitPie 8 | # is a member of fruit 9 | print (fruitPie.issubset(fruit)) 10 | print (fruitPie < fruit) 11 | 12 | # combine sets 13 | nuts = {'walnuts', 'pecans'} 14 | granola = fruit | nuts 15 | print(granola) 16 | 17 | data = set() # create an empty set 18 | data.add (2.3) # and add vales 19 | data.add (4.6) 20 | data.add(7.0) 21 | data.add(2.3) 22 | print (data) -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/stateNames.txt: -------------------------------------------------------------------------------- 1 | Alabama 2 | Alaska 3 | Arizona 4 | Arkansas 5 | California 6 | Colorado 7 | Connecticut 8 | Delaware 9 | Florida 10 | Georgia 11 | Hawaii 12 | Idaho 13 | Illinois 14 | Indiana 15 | Iowa 16 | Kansas 17 | Kentucky 18 | Louisiana 19 | Maine 20 | Maryland 21 | Massachusetts 22 | Michigan 23 | Minnesota 24 | Mississippi 25 | Missouri 26 | Montana 27 | Nebraska 28 | Nevada 29 | New Hampshire 30 | New Jersey 31 | New Mexico 32 | New York 33 | North Carolina 34 | North Dakota 35 | Ohio 36 | Oklahoma 37 | Oregon 38 | Pennsylvania 39 | Rhode Island 40 | South Carolina 41 | South Dakota 42 | Tennessee 43 | Texas 44 | Utah 45 | Vermont 46 | Virginia 47 | Washington 48 | West Virginia 49 | Wisconsin 50 | Wyoming -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/statearray.py: -------------------------------------------------------------------------------- 1 | """Read file into array""" 2 | DATAFILE="stateNames.txt" 3 | 4 | with open(DATAFILE, "r") as f: 5 | statenames=[] 6 | for sname in f: 7 | statenames.append(sname.rstrip()) 8 | 9 | print(statenames[0:3]) 10 | print(len(statenames)) 11 | 12 | f = open(DATAFILE, "r") # open the file 13 | statenames=[] # create the empty list 14 | 15 | # read in the state names 16 | for sname in f: 17 | statenames.append(sname.rstrip()) 18 | f.close() 19 | 20 | print(statenames[0:4]) 21 | print(len(statenames)) 22 | 23 | f = open(DATAFILE, "r") # open the file 24 | statenames=[] 25 | statenames = f.readlines() 26 | print(statenames[0:3]) 27 | print(len(statenames)) -------------------------------------------------------------------------------- /Pythonpatterns/34. Collections and files/tuplecase.py: -------------------------------------------------------------------------------- 1 | # count upper and lowercase letters 2 | def upperLower(s): 3 | upper = 0 4 | lower = 0 5 | for c in s: 6 | if c.islower(): 7 | lower += 1 8 | elif c.isupper(): 9 | upper += 1 10 | return (upper,lower) #return a tuple 11 | 12 | # get counts as a tuple 13 | up, low = upperLower("Hello") 14 | print(up, low) -------------------------------------------------------------------------------- /Pythonpatterns/35. Functions/funcs.py: -------------------------------------------------------------------------------- 1 | """Some simple functions""" 2 | # return a square of the input value 3 | def sqr(x): 4 | y = x * x #square ihe input 5 | return y #and return it 6 | 7 | def cube(a): 8 | b = sqr(a) * a #compute the cube using the square 9 | return b 10 | 11 | """main program begins here""" 12 | def main(): 13 | xvar = 12 14 | print(xvar, sqr(xvar), cube(xvar)) 15 | 16 | ### This is the real entry point #### 17 | if __name__ == "__main__": 18 | main() #call main() here 19 | -------------------------------------------------------------------------------- /Pythonpatterns/35. Functions/upperlower.py: -------------------------------------------------------------------------------- 1 | # count upper and lowercase letters 2 | def upperLower(s): 3 | upper = 0 4 | lower = 0 5 | for c in s: 6 | if c.islower(): 7 | lower += 1 8 | elif c.isupper(): 9 | upper += 1 10 | return (upper,lower) #return a tuple 11 | 12 | # get counts as a tuple 13 | up, low = upperLower("Hello") 14 | print(up, low) 15 | -------------------------------------------------------------------------------- /Pythonpatterns/5. SimpleFactory/Cocoon.py: -------------------------------------------------------------------------------- 1 | 2 | class Butterfly(): 3 | def addSub(self,x,y): pass 4 | 5 | class TrigButterfly(Butterfly): 6 | def addSub(self,x,y):pass 7 | 8 | class AddButterfly(Butterfly): 9 | def addSub(self, x, y):pass 10 | 11 | class Cocoon(): 12 | def getButterfly(self, y:float): 13 | if y !=0: 14 | return TrigButterfly(y) 15 | else: 16 | return AddButterfly(y) -------------------------------------------------------------------------------- /Pythonpatterns/8. Singleton/Spooler.py: -------------------------------------------------------------------------------- 1 | class Spooler: 2 | @staticmethod 3 | def printit(text): 4 | print(text) #simulate printing 5 | 6 | name = "Fred" 7 | Spooler.printit(name) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jameswcooper 2 | Programming files 3 | -------------------------------------------------------------------------------- /newsletter/Bingo/bingoexamples.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | for i in range(0,5): 4 | num = random.randint(1, 15) 5 | print(num, end=" ") 6 | print() 7 | 8 | bset=set() 9 | while len(bset) < 5: 10 | num = random.randint(1, 15) 11 | bset.add(num) 12 | print(bset) 13 | 14 | bset=set() 15 | while len(bset) < 5: 16 | num = random.randint(1,15) 17 | bset.add(num) 18 | bara = list(bset) 19 | random.shuffle(bara) 20 | 21 | print(bara) 22 | -------------------------------------------------------------------------------- /newsletter/CSV files/basecsv.py: -------------------------------------------------------------------------------- 1 | import csv 2 | from csv import reader 3 | 4 | nm =[] 5 | nm.append(['Fred', 'Farkel', '1245 Bridge St','Bridgeport', 'CT']) 6 | nm.append(['Sam', "O'Kelley", '42 Secret Lane', 'Mystic', 'CT']) 7 | nm.append(["Sarah", 'Smythe', '205 Frazzle Rd, Apt B', 'Fairfield', 'CT']) 8 | 9 | # create the csv file 10 | with open ('namelist.csv', 'w', newline='') as csvfile: 11 | addWriter = csv.writer(csvfile) 12 | for row in nm: 13 | addWriter.writerow(row) 14 | 15 | # now read it back in 16 | with open ('namelist.csv', newline='') as csvfile: 17 | addReader = csv.reader(csvfile) 18 | for row in addReader: 19 | print(row) 20 | -------------------------------------------------------------------------------- /newsletter/CSV files/namehlist.csv: -------------------------------------------------------------------------------- 1 | frname,lname,address,town,state 2 | Fred,Farkel,1245 Bridge St,Bridgeport,CT 3 | Sam,O'Kelley,42 Secret Lane,Mystic,CT 4 | Sarah,Smythe,"205 Frazzle Rd, Apt B",Fairfield,CT 5 | -------------------------------------------------------------------------------- /newsletter/CSV files/namelist.csv: -------------------------------------------------------------------------------- 1 | Fred,Farkel,1245 Bridge St,Bridgeport,CT 2 | Sam,O'Kelley,42 Secret Lane,Mystic,CT 3 | Sarah,Smythe,"205 Frazzle Rd, Apt B",Fairfield,CT 4 | -------------------------------------------------------------------------------- /newsletter/Classes/BasicButtons.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | from tkinter import * 3 | from tkinter import messagebox 4 | import sys 5 | 6 | 7 | class Builder() : 8 | 9 | def build(self): 10 | root = Tk() 11 | root.geometry("200x100") 12 | root.title("Basic buttons") 13 | 14 | helloButton = Button(root, text="Hello", width=8) 15 | helloButton.pack(side=LEFT, padx=20) 16 | leaveButton = Button(root, text="Leave", width=8) 17 | leaveButton.pack(side=RIGHT, padx=20) 18 | mainloop() 19 | 20 | def main(): 21 | bld =Builder() 22 | bld.build() 23 | 24 | 25 | if __name__ == '__main__': 26 | main() -------------------------------------------------------------------------------- /newsletter/Classes/Buttonclick.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | from tkinter import * 3 | from tkinter import messagebox 4 | import sys 5 | 6 | class ButtonFuncs(): 7 | def __init__(self): 8 | pass 9 | def hello(self): 10 | messagebox.showinfo("Hi", "Hello") 11 | def exit(self): 12 | ans = messagebox.askquestion("Leaving so soon?", 13 | "Do you really want to exit") 14 | if ans == 'yes': 15 | sys.exit() 16 | 17 | 18 | class Builder() : 19 | 20 | def build(self): 21 | root = Tk() 22 | root.geometry("200x100") 23 | bf = ButtonFuncs() 24 | helloButton = Button(root, text="Hello", width=8, command = bf.hello) 25 | helloButton.pack(side=LEFT, padx=20) 26 | leaveButton = Button(root, text="Leave", width=8, command = bf.exit) 27 | leaveButton.pack(side=RIGHT, padx=20) 28 | mainloop() 29 | 30 | def main(): 31 | bld =Builder() 32 | bld.build() 33 | 34 | 35 | if __name__ == '__main__': 36 | main() -------------------------------------------------------------------------------- /newsletter/Countdown/HmsSimple.py: -------------------------------------------------------------------------------- 1 | class Hms: 2 | # split comma separated entry into hours, mins, secs 3 | def __init__(self, entry): 4 | tarray = entry.split(',') 5 | hours = int(tarray[0]) 6 | minutes = int(tarray[1]) 7 | seconds = int(tarray[2]) 8 | self.error = False 9 | self.totalSeconds = hours * 3600 \ 10 | + minutes * 60 + seconds 11 | 12 | # calculate hours, mins, secs from totalSeconds 13 | # and return as tuple 14 | # and decrement the totalSeconds 15 | def makeHms(self): 16 | # compute hours, with seconds as remainder 17 | h = divmod(self.totalSeconds, 3600) 18 | self.hrs = h[0] 19 | 20 | # compute minutes with seconds as remainder 21 | s = divmod(h[1], 60) 22 | self.secs = s[1] # seconds 23 | self.mins = s[0] # minutes 24 | self.totalSeconds -= 1 # decrease count here 25 | 26 | # return h,m,s tuple 27 | return self.hrs, self.mins, self.secs 28 | -------------------------------------------------------------------------------- /newsletter/Countdown/__pycache__/HmsSimple.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/newsletter/Countdown/__pycache__/HmsSimple.cpython-310.pyc -------------------------------------------------------------------------------- /newsletter/Countdown/countDownSimple.py: -------------------------------------------------------------------------------- 1 | import time 2 | from HmsSimple import Hms 3 | """Simple program to count down hours, minutes, seconds 4 | Makes use of the Hms class to compute them from seconds 5 | """ 6 | def main(): 7 | # get the keyboard input 8 | entry = input("Enter hours, minutes, seconds:") 9 | hms = Hms(entry) # convert to seconds inside HMS 10 | 11 | while hms.totalSeconds > 0 : 12 | h,m,s = hms.makeHms() # get the current values and print them out each second 13 | print(f'{h:02}:{m:02}:{s:02}') 14 | time.sleep(1) 15 | if __name__ == '__main__': 16 | main() 17 | 18 | -------------------------------------------------------------------------------- /newsletter/Countdown/countdown.py: -------------------------------------------------------------------------------- 1 | import time 2 | from HmsSimple import Hms 3 | """Simple program to count down hours, minutes, seconds 4 | Makes use of the Hms class to compute them from seconds 5 | """ 6 | def main(): 7 | entry = input("Enter hours, minutes, seconds:") 8 | hms = Hms(entry) 9 | if hms.error: 10 | print (hms.errorMessage) 11 | else: 12 | while hms.totalSeconds > 0 : 13 | h,m,s = hms.makeHms() 14 | print(f'{h:02}:{m:02}:{s:02}') 15 | time.sleep(1) 16 | if __name__ == '__main__': 17 | main() 18 | 19 | -------------------------------------------------------------------------------- /newsletter/Facade/dbtest.py: -------------------------------------------------------------------------------- 1 | import MySQLdb 2 | 3 | # Open database connection 4 | db = MySQLdb.connect("localhost","newuser","new_user","groceries" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | print (cursor) 9 | # execute SQL query using execute() method. 10 | cursor.execute("""select foods.foodname, stores.storename, 11 | prices.price from prices 12 | join foods on (foods.foodkey=prices.foodkey) 13 | join stores on (stores.storekey = prices.storekey ) 14 | where foods.foodname='Butter' order by price""") 15 | row = cursor.fetchone() 16 | while row is not None: 17 | print(row) 18 | row = cursor.fetchone() 19 | 20 | cursor.execute("show tables") 21 | rows = cursor.fetchall() 22 | for r in rows: 23 | print(r) 24 | 25 | -------------------------------------------------------------------------------- /newsletter/Facade/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/newsletter/Facade/groceries.db -------------------------------------------------------------------------------- /newsletter/FacadeDict/groceries.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcnmr/jameswcooper/c083d8c476f950527a3e0851ba8c03bfa9240cc4/newsletter/FacadeDict/groceries.db -------------------------------------------------------------------------------- /newsletter/Generators/fibo.py: -------------------------------------------------------------------------------- 1 | """ Fibonacci iterator using a generator """ 2 | 3 | def fibo(max=0): 4 | current, prev = 0, 1 # initialize variables 5 | 6 | while current < max: #but stops at max 7 | secondLast, prev = prev, current 8 | # compute next x as sum of previous 2 9 | current = prev + secondLast 10 | yield current # returns next value in series 11 | 12 | fb = fibo(100) 13 | for f in fb: 14 | print(f, end=', ') 15 | -------------------------------------------------------------------------------- /newsletter/Generators/fiboclass.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | @dataclass 4 | class Fibo(): 5 | max:int 6 | 7 | def fibo(self): 8 | current, prev = 0, 1 #initialize 9 | 10 | while current < self.max: # but stops at max 11 | secondLast, prev = prev, current 12 | # compute next x as sum of previous 2 13 | current = prev + secondLast 14 | yield current 15 | 16 | fb = Fibo(100).fibo() 17 | for f in fb: 18 | print(f) 19 | -------------------------------------------------------------------------------- /newsletter/Generators/geniter.py: -------------------------------------------------------------------------------- 1 | """ Generic illustration of generator and yield""" 2 | def sqrit(max=0): 3 | n = 0 4 | while n < max: 5 | yield n*n # return each result 6 | n += 1 # code resumes here 7 | 8 | # call sqrit and iterate up to max 9 | sq = sqrit(10) # returns an iterator 10 | for s in sq: 11 | print(s) 12 | 13 | -------------------------------------------------------------------------------- /newsletter/Iterators/Simple iter examples.py: -------------------------------------------------------------------------------- 1 | # Iterate through an array 2 | people = ["Fred", "Mary", "Sam"] 3 | for p in people: 4 | print (p) 5 | 6 | # Create your own iterator using iter() 7 | pIter = iter(people) 8 | 9 | try: 10 | while p != None: 11 | p = next(pIter) 12 | print (p) 13 | except StopIteration: 14 | pass 15 | 16 | # iterate to get elements and store them 17 | person = ["Fred", "Smith", "80901210"] 18 | pIter = iter(person) 19 | 20 | frname = next(pIter) 21 | lname = next(pIter) 22 | serial = next(pIter) 23 | print(frname, lname, serial) -------------------------------------------------------------------------------- /newsletter/Kivy/AddNumbers.py: -------------------------------------------------------------------------------- 1 | from kivy.app import App 2 | from kivy.core.window import Window 3 | from kivy.uix.boxlayout import BoxLayout 4 | 5 | class AddNums(BoxLayout): 6 | def build(self): 7 | self.title = "Add two numbers" 8 | Window.size = (300, 200) 9 | self.load_kv('AddNumbers.kv') 10 | 11 | # Add click event 12 | def bclick(self): 13 | val1= float(self.ids.frnum.text) 14 | val2 = float(self.ids.secnum.text) 15 | self.ids.sumlabel.text = "Sum is: "+ str(val1+val2) 16 | 17 | # Clear button click event 18 | def cclick(self): 19 | self.ids.frnum.text = '' 20 | self.ids.secnum.text = '' 21 | self.ids.sumlabel.text ='' 22 | 23 | class MainApp(App): 24 | def build(self): 25 | Window.size = (300, 200) 26 | self.load_kv('AddNumbers.kv') 27 | return AddNums() 28 | 29 | MainApp().run() -------------------------------------------------------------------------------- /newsletter/Kivy/onebut.kv: -------------------------------------------------------------------------------- 1 | # class and layout for one button display (with label) 2 | : 3 | FloatLayout: 4 | Label: 5 | id: toplabel 6 | color: 0,0,1,1 7 | text: 'Hi there' 8 | Button: 9 | text: 'Hello' 10 | color: 0,0,0,1 11 | background_color: .9,.9,.9, 12 | on_press: 13 | root.butclick() -------------------------------------------------------------------------------- /newsletter/Kivy/onebut.py: -------------------------------------------------------------------------------- 1 | from kivy.app import App 2 | from kivy.core.window import Window 3 | from kivy.uix.floatlayout import FloatLayout 4 | 5 | 6 | class OneBut(FloatLayout): 7 | def butclick(self): 8 | self.ids.toplabel.text='Hello again' 9 | 10 | class MainApp(App): 11 | def build(self): 12 | Window.size = (300, 200) 13 | self.load_kv('onebut.kv') 14 | return OneBut() 15 | 16 | MainApp().run() -------------------------------------------------------------------------------- /newsletter/Kivy/onebut1.kv: -------------------------------------------------------------------------------- 1 | # class and layout for one button display (with label) 2 | : 3 | FloatLayout: 4 | Label 5 | id: toplabel 6 | color: 0,0,1,1 #blue text 7 | text: 'Hi there' 8 | Button: 9 | text: 'Hello' 10 | color: 0,0,0,1 #black text 11 | size_hint: (0.7,0.2) 12 | #background_normal: '' 13 | background_color: .9,.9,.9, # gray background 14 | on_press: 15 | root.butclick() -------------------------------------------------------------------------------- /newsletter/Kivy/onebut2.kv: -------------------------------------------------------------------------------- 1 | # class and layout for one button display (with label) 2 | : 3 | FloatLayout: 4 | canvas.before: 5 | Color: 6 | rgba: .8, .8, .8, 1 7 | Rectangle: 8 | size: self.size 9 | pos: self.pos 10 | 11 | Label 12 | id: toplabel 13 | color: 0,0,1,1 14 | text: 'Hi there' 15 | Button: 16 | text: 'Hello' 17 | color: 0,0,0,1 18 | background_normal: '' 19 | size_hint: (0.7,0.2) 20 | background_color: .9,.9,.9, 21 | on_press: 22 | root.butclick() 23 | -------------------------------------------------------------------------------- /newsletter/Maptest/maptest.py: -------------------------------------------------------------------------------- 1 | import dis 2 | from datetime import datetime 3 | 4 | def sq(x): 5 | return x*x 6 | 7 | def f1(): 8 | start = datetime.now() 9 | for i in range (0, 1000000): 10 | ara=[2,3,6,8,5,4] 11 | amap = map(sq, ara) 12 | ara1 = list(amap) 13 | #print (ara1) 14 | endt = datetime.now() 15 | print("time=", endt-start) 16 | print(ara1) 17 | return endt-start 18 | 19 | 20 | def f2(): 21 | start = datetime.now() 22 | for i in range (0, 1000000): 23 | ara=[2,3,6,8,5,4] 24 | 25 | amap = [] 26 | for a in ara: 27 | amap.append(sq(a)) 28 | endt = datetime.now() 29 | print("time=", endt-start) 30 | return endt-start 31 | 32 | t1 = f1() 33 | t2 = f2() 34 | print (t1,t2, (t2-t1)/t2) 35 | #dis.dis(f1) 36 | -------------------------------------------------------------------------------- /newsletter/Overloading/overload.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | @dataclass 4 | class Point: 5 | x:int # both become part of init 6 | y:int 7 | 8 | # generate string output representation 9 | def __str__(self): 10 | return f'({self.x}, {self.y})' 11 | 12 | # overload + operator 13 | def __add__(self, other): 14 | x1 = self.x + other.x # add the two coordinates 15 | y1 = self.y + other.y 16 | return Point(x1, y1) # return a new Point 17 | 18 | # overload - operator 19 | def __sub__(self, other): 20 | x1 = self.x - other.x # subtract coordinates 21 | y1 = self.y - other.y 22 | return Point(x1, y1) # return a new Point 23 | 24 | 25 | 26 | 27 | p1 = Point(20,40) # create a point 28 | print(p1) # show string output 29 | p2 = Point(50,70) # create another point 30 | p3 = p1 + p2 # overload + sign 31 | p4 = p2 - p1 # overload - sign 32 | print(p3, p4) -------------------------------------------------------------------------------- /newsletter/Parseargs/OneArg.py: -------------------------------------------------------------------------------- 1 | import sys 2 | """Get one argument from the command line and print it out""" 3 | def main(): 4 | if len(sys.argv)>1: 5 | datafile = sys.argv[1] 6 | print (sys.argv[1]) 7 | else: 8 | datafile ="" 9 | 10 | # print all of the command line args 11 | print (sys.argv[1:]) 12 | 13 | ### Here we go #### 14 | if __name__ == "__main__": 15 | main() -------------------------------------------------------------------------------- /newsletter/Parseargs/file.txt: -------------------------------------------------------------------------------- 1 | This is a test file. -------------------------------------------------------------------------------- /newsletter/Parseargs/py-arg.py: -------------------------------------------------------------------------------- 1 | """ illustration of parsing command line args""" 2 | import sys, argparse 3 | def main(): 4 | 5 | # create ArgumentParser for -f and -d 6 | parser = argparse.ArgumentParser() 7 | parser.add_argument('-f', help='filename') 8 | parser.add_argument('-d', help='delete (yes or no)') 9 | 10 | args = parser.parse_args() 11 | print(args) 12 | print(args.f) 13 | print(args.d) 14 | 15 | 16 | 17 | 18 | ### Here we go #### 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /newsletter/Polymorphic/Employees.py: -------------------------------------------------------------------------------- 1 | """Illustrtaes polymorphism in derived classes 2 | Here the compensation method returns different data 3 | in the two classes """ 4 | 5 | from dataclasses import dataclass 6 | @dataclass 7 | class Employee: 8 | frname: str 9 | lname: str 10 | salary: int 11 | 12 | def compensation(self): 13 | return self.salary 14 | 15 | class TopEmployee(Employee): 16 | def __init__(self, frname, lname, salary): 17 | super().__init__(frname, lname, salary) 18 | self.stockOptions = 0 19 | 20 | def setOptions (self, stockval): 21 | self.stockOptions = stockval 22 | 23 | def compensation(self): 24 | return self.salary + self.stockOptions 25 | 26 | emp = Employee('Snuffy', 'Smith', 11000) 27 | topEmp = TopEmployee('James', 'Bond', 100000) 28 | topEmp.setOptions(5000) 29 | print(emp.frname, emp.compensation()) 30 | print (topEmp.frname, topEmp.compensation()) 31 | -------------------------------------------------------------------------------- /newsletter/Polymorphic/addArgs.py: -------------------------------------------------------------------------------- 1 | """ This is a revised version of this class. 2 | Actually Python does not allow multiple methods with the same name 3 | since it uses a one-pass compiler. So the intended polymorphism doesn't actually work. 4 | 5 | This example uses an argument list and the float operation to convert them all to floats 6 | Note that the list can be any length 7 | """ 8 | 9 | class Summer(): 10 | 11 | def addArgs(self, *args): 12 | fsum = 0 13 | for num in args: 14 | fsum += float(num) 15 | return fsum 16 | 17 | #---------------------------------- 18 | def main(): 19 | sumr = Summer() 20 | print(sumr.addArgs(12.0, 2.3)) 21 | print(sumr.addArgs(22.3, "13.5")) 22 | print (sumr.addArgs(31,"13", 22.4, True)) 23 | 24 | 25 | ### Here we go #### 26 | if __name__== "__main__": 27 | main() -------------------------------------------------------------------------------- /newsletter/Polymorphic/addClasses.py: -------------------------------------------------------------------------------- 1 | #base adder class 2 | class Summerf(): 3 | def addNums(self, x: float, y: float) ->float: 4 | return x + y 5 | 6 | class Summers(): 7 | def addNums(self, s1: str, s2: str) -> float: 8 | fsum = float(s1) + float(s2) 9 | return fsum 10 | 11 | #---------------------------------- 12 | def main(): 13 | sumrf = Summerf() 14 | sumrs = Summers() 15 | 16 | print(sumrf.addNums(12.0, 2.3)) 17 | print(sumrs.addNums(22.3, "13.5")) 18 | 19 | ### Here we go #### 20 | if __name__== "__main__": 21 | main() 22 | -------------------------------------------------------------------------------- /newsletter/Polymorphic/addMatch.py: -------------------------------------------------------------------------------- 1 | """ This is a revised version of this class. 2 | Actually Python does not allow multiple methods with the same name 3 | since it uses a one-pass compiler. So the intended polymorphism doesn't actually work. 4 | 5 | This example uses the match operator to decide on which operation to carry out. 6 | Note that the list can be any length 7 | """ 8 | 9 | class Summer(): 10 | 11 | def calcNums(self, oper, f, s)->float: 12 | fsum = 0 13 | match oper: 14 | case '+': 15 | fsum = float(f) + float(s) 16 | case '-': 17 | fsum = float(f) - float(s) 18 | return fsum 19 | 20 | 21 | #---------------------------------- 22 | def main(): 23 | sumr = Summer() 24 | print(sumr.calcNums('+', 12.0, 2.3)) 25 | print(sumr.calcNums('-', 22.3, "13.5")) 26 | 27 | 28 | 29 | ### Here we go #### 30 | if __name__== "__main__": 31 | main() -------------------------------------------------------------------------------- /newsletter/Polymorphic/addNumsWrong.py: -------------------------------------------------------------------------------- 1 | """This example appears to illustrate polymorphic calls to addNums 2 | But it is misleading. Python does not allow tow methods with the same name 3 | and it just keeps the last one it sees. 4 | This looks like polymorphism, but it actually only calls 5 | the second method, which works because float(string) and float(float) 6 | both return floats.""" 7 | 8 | class Summer(): 9 | def addNums(self, x: float, y: float) ->float: 10 | return x + y 11 | 12 | def addNums(self, f: float, s: str)->float: 13 | fsum = f + float(s) 14 | return fsum 15 | #---------------------------------- 16 | def main(): 17 | sumr = Summer() 18 | print(sumr.addNums(12.0, 2.3)) 19 | print(sumr.addNums(22.3, "13.5")) 20 | 21 | ### Here we go #### 22 | if __name__== "__main__": 23 | main() -------------------------------------------------------------------------------- /newsletter/Polymorphic/addnumstype.py: -------------------------------------------------------------------------------- 1 | """ This is a revised version of this class. 2 | Actually Python does not allow multiple methods with the same name 3 | since it uses a one-pass compiler. So the intended polymorphism doesn't actually work. 4 | 5 | This example uses the type function to dispatch addNums(f,f) to addNumsF 6 | """ 7 | 8 | class Summer(): 9 | def addNumsf(self, x: float, y: float) ->float: 10 | return x + y 11 | 12 | def addNums(self, f: float, s: str)->float: 13 | if type(s) is float: 14 | return self.addNumsf(f,s) 15 | else: 16 | fsum = f + float(s) 17 | return fsum 18 | 19 | #---------------------------------- 20 | def main(): 21 | sumr = Summer() 22 | print(sumr.addNums(12.0, 2.3)) 23 | print(sumr.addNums(22.3, "13.5")) 24 | # This will fail 25 | # val = sumr.addNums('22.3', '13.5') 26 | #print(val) 27 | 28 | ### Here we go #### 29 | if __name__== "__main__": 30 | main() -------------------------------------------------------------------------------- /newsletter/Polymorphic/lenTest.py: -------------------------------------------------------------------------------- 1 | """Illustrates how len function works polymorphically""" 2 | from dataclasses import dataclass 3 | @dataclass 4 | class Employee: 5 | frname: str 6 | lname: str 7 | salary: int 8 | height: int 9 | 10 | def compensation(self): 11 | return self.salary 12 | def __len__(self): 13 | return self.height 14 | 15 | name = 'Snuffy Smith' 16 | mylist = [1,4,6,4,8,7] 17 | myset= {'apples', 'oranges', 'grapes'} 18 | mytuple = (23,42, 76, 143) 19 | 20 | print(len(name), len(mylist), len(myset), len(mytuple)) 21 | emp =Employee('Snuffy', 'Smith', 1200, 67) 22 | print (emp.frname, len(emp)) -------------------------------------------------------------------------------- /newsletter/PyQt5/vbdata/Form1.vb: -------------------------------------------------------------------------------- 1 | Public Class Form1 2 | Private Sub Addbutton_Click(sender As Object, e As EventArgs) Handles Addbutton.Click 3 | Dim crb As RadioButton, tx As String, rb As RadioButton, rx As String 4 | 5 | 'get the voice part text and shorten it 6 | crb = GetRadio(VoiceBox) 7 | tx = crb.Text.Substring(0, 3) 8 | 9 | 'get the role name 10 | rb = GetRadio(RoleBox) 11 | rx = rb.Text.Substring(0, 3) 12 | 13 | 'add to listbox 14 | Namelist.Items.Add(tx + " " + rx + " -- " + namebox.Text) 15 | namebox.Text = "" 16 | End Sub 17 | 18 | Private Sub Clearbutton_Click(sender As Object, e As EventArgs) Handles Clearbutton.Click 19 | namebox.Text = "" 20 | Namelist.Items.Clear() 21 | 22 | End Sub 23 | 24 | Private Function GetRadio(rbox As GroupBox) 25 | Return rbox.Controls.OfType(Of RadioButton)().FirstOrDefault(Function(radioButton) radioButton.Checked) 26 | End Function 27 | 28 | End Class 29 | -------------------------------------------------------------------------------- /newsletter/PySimpleGUI/basicCode.py: -------------------------------------------------------------------------------- 1 | import PySimpleGUI as sg 2 | 3 | # create layout 4 | layout = [[sg.Text('Add 2 numbers')], 5 | [sg.Text('Num1: ', size=(5, 1)), sg.InputText()], 6 | [sg.Text('Num2: ', size=(5, 1)), sg.InputText()], 7 | [sg.Text('Result: ', size=(6, 1)), sg.Text(size=(5,1))], 8 | [sg.Button('Add'), sg.Button('Clear')]] 9 | # create the window 10 | window = sg.Window('Adder', layout) 11 | 12 | # window event loop is here 13 | quit = False 14 | while not quit: 15 | event, values = window.read() # get the event 16 | quit = (event == None) # corner 'X' clicked 17 | window.close() # close window 18 | 19 | -------------------------------------------------------------------------------- /newsletter/PythonToCpp/Add2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | // Simple program to add two numbers 5 | 6 | //function to read in a number and convert to float. 7 | float getnum(string message) { 8 | cout << message; 9 | string ans; 10 | cin >> ans; 11 | float val1 = stof(ans); 12 | return val1; 13 | } 14 | int main() { 15 | // get the first number 16 | float val1 = getnum( "Enter first number: "); 17 | 18 | // get the second number 19 | float val2 = getnum( "Enter second number: "); 20 | 21 | // add them and print out the result 22 | cout << "The sum is " << val1 + val2 << endl; 23 | } -------------------------------------------------------------------------------- /newsletter/PythonToCpp/SimpleAdd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | // Simple program to add two numbers 5 | 6 | int main() { 7 | String ans1, ans2; 8 | // get the first number 9 | cout << "Enter first number: "; 10 | cin >> ans1; 11 | float val1 = stof(ans1) 12 | 13 | 14 | // get the second number 15 | cout << "Enter second number: "; 16 | cin >> ans1; 17 | float val1 = stof(ans2) 18 | 19 | // add them and print out the result 20 | cout << "The sum is " << val1 + val2 << endl; 21 | } -------------------------------------------------------------------------------- /newsletter/PythonToCpp/timeloop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int sq(int a) { 7 | return a*a; 8 | } 9 | int main() { 10 | auto start = chrono::steady_clock::now(); 11 | for (int i=0; i < 1000000; i++){ 12 | int ara[] = {2,3,6,8,5,4}; 13 | //vector v={0}; 14 | int dest[6]; 15 | int k = 0; 16 | for (auto a: ara) { 17 | //v.push_back(sq(a)); 18 | dest[k++] = sq(a); 19 | } 20 | } 21 | auto end = chrono::steady_clock::now(); 22 | cout << "Elapsed time in milliseconds: " 23 | << chrono::duration_cast(end - start).count() 24 | << " ms" << endl; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /newsletter/Two buttons/twobuts.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | import sys 4 | 5 | class Builder(): 6 | # enable quit button 7 | def bEnable(self): 8 | self.quitBut['state']=NORMAL 9 | 10 | # exit from program 11 | def exit(self): 12 | sys.exit() 13 | 14 | # construct the UI 15 | def build(self): 16 | root = tk.Tk() 17 | root.geometry("160x50") 18 | root.title("2 buttons") 19 | 20 | # the OK button 21 | self.okBut = Button(root, text="OK", command=self.bEnable) 22 | self.okBut.pack() 23 | 24 | # the quit button 25 | self.quitBut = Button(root, text="Quit", command=self.exit) 26 | self.quitBut.pack() 27 | # disable the quit button 28 | self.quitBut['state'] = DISABLED 29 | 30 | # wait for UI events 31 | mainloop() 32 | 33 | def main(): 34 | bld = Builder() 35 | bld.build() 36 | 37 | # Program starts here 38 | if __name__ == '__main__': 39 | main() 40 | 41 | 42 | -------------------------------------------------------------------------------- /newsletter/Typehints1/adder.py: -------------------------------------------------------------------------------- 1 | class Adder: 2 | 3 | # save first value in the initializer 4 | def __init__(self, aval: int): 5 | self.aval = aval # save as instance variable 6 | 7 | # second value entered in add method 8 | def add(self, bval:int)->float: 9 | self.bval=bval # save 2nd as instance variable 10 | return self.aval+self.bval #return sum 11 | 12 | addr = Adder(20) # create the Adder class 13 | theSum = addr.add(30) # call add with 2nd argument- sum returned 14 | print(theSum) -------------------------------------------------------------------------------- /newsletter/Typehints1/mmeta.py: -------------------------------------------------------------------------------- 1 | from multimethod import multimeta 2 | 3 | class Add(metaclass=multimeta): 4 | # float, float 5 | def add(self, aval: float, bval: float) -> float: 6 | return aval + bval 7 | # string, float 8 | def add(self, sval: str, bval: float) -> float: 9 | return float(sval) + bval 10 | 11 | adder = Add() 12 | theSum = adder.add(33.2,31.2) 13 | print(f'{theSum:5.2f}') 14 | 15 | theSum = adder.add('44.2', 23.2) 16 | print(f'{theSum:5.2f}') -------------------------------------------------------------------------------- /newsletter/Typehints1/mtimethod.py: -------------------------------------------------------------------------------- 1 | from mtimethod import multimethod 2 | 3 | # declare the float, float version 4 | @multimethod 5 | def add(aval:float, bval:float)->float: 6 | return aval + bval 7 | 8 | # declare the string, float version 9 | @multimethod 10 | def add(sval: str, bval: float)->float: 11 | return float(sval)+ bval 12 | 13 | # call the float, float version 14 | theSum = add(22.1, 33.2) 15 | print(f'{theSum:5.2f}') 16 | 17 | # call the string, float version 18 | theSum = add('32.2', 33.1) 19 | print(f'{theSum:5.2f}') -------------------------------------------------------------------------------- /newsletter/Typehints1/multidisp.py: -------------------------------------------------------------------------------- 1 | from multipledispatch import dispatch 2 | 3 | @dispatch( float) 4 | def add(aval:float )->float: 5 | return aval + sumval 6 | 7 | @dispatch(str) 8 | def add(sval: str)->float: 9 | return float(sval)+ sumval 10 | 11 | sumval = 12 12 | theSum = add(30.1) 13 | print(theSum) 14 | 15 | sumval=22 16 | theSum = add("34") 17 | print(theSum) 18 | 19 | -------------------------------------------------------------------------------- /newsletter/Typehints1/singledispatch.py: -------------------------------------------------------------------------------- 1 | from functools import singledispatchmethod 2 | 3 | class Adder: 4 | @singledispatchmethod 5 | def __init__(self, aval: float): # init with a float 6 | self.aval = aval 7 | self.bval = 0 8 | 9 | @__init__.register(str) # init with a string 10 | def _from_str(self, str): 11 | self.aval = float(str) 12 | 13 | @singledispatchmethod 14 | def add(self, bval: float)->float: # add a float 15 | self.bval=bval 16 | return self.aval+self.bval 17 | 18 | @add.register 19 | def _(self, sval: str)->float: # add a string 20 | self.bval = float(sval) 21 | return self.aval + self.bval 22 | 23 | addr = Adder(20) 24 | theSum = addr.add(30) 25 | print(theSum) 26 | 27 | addr = Adder("21") 28 | theSum = addr.add(30) 29 | print(theSum) 30 | 31 | addr = Adder("22") 32 | theSum = addr.add("32") 33 | print(theSum) 34 | -------------------------------------------------------------------------------- /newsletter/Typehints1/typehints.py: -------------------------------------------------------------------------------- 1 | """ Illustration of type hints """ 2 | def adder(x:float, s:str)->float: 3 | sumRes: float = x + float(s) 4 | return sumRes 5 | 6 | def adder(x: float, y: float) -> float: 7 | sumRes: float = x + y 8 | return sumRes 9 | 10 | result: float = adder(2, "3") 11 | print(result) 12 | result = adder(1, 2) 13 | print(result) 14 | -------------------------------------------------------------------------------- /newsletter/wxpy/firstTtk.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | #from tkinter import * 3 | 4 | root = tk.Tk() 5 | root.geometry('250x150') 6 | root.title("Hello world") 7 | #lbl = Label(root, text='Hello World').pack() 8 | root.mainloop() -------------------------------------------------------------------------------- /newsletter/wxpy/hellowtkinter.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | 4 | root = tk.Tk() 5 | root.geometry('100x100') 6 | topLabel = Label(root, text= 'Hello World') 7 | topLabel.grid(row=0, column=0, columnspan=2) 8 | 9 | root.mainloop() -------------------------------------------------------------------------------- /newsletter/wxpy/wxHello.py: -------------------------------------------------------------------------------- 1 | # Import the wxPython package. 2 | import wx 3 | 4 | app = wx.App() # Create an application object. 5 | frm = wx.Frame(None, title="Hello World") # Then a frame. 6 | frm.Show() # Show it. 7 | 8 | # Start the event loop. 9 | app.MainLoop() -------------------------------------------------------------------------------- /newsletter/wxpy/wxHello2.py: -------------------------------------------------------------------------------- 1 | # Import the wxPython package. 2 | import wx 3 | 4 | app = wx.App() # Create an application object. 5 | frm = wx.Frame(None, title="Hello World") # Then a frame. 6 | frm.SetInitialSize((300, 200)) 7 | panel = wx.Panel(frm) # contains all the widgets 8 | 9 | # create the label and place it at 20,20 10 | st = wx.StaticText(panel, label="Hello World!") 11 | st.SetPosition((20,20)) 12 | frm.Show() # Show it. 13 | 14 | app.MainLoop() --------------------------------------------------------------------------------