├── .gitignore ├── .vs ├── CPP │ └── v16 │ │ ├── .suo │ │ └── Browse.VC.db ├── ProjectSettings.json ├── VSWorkspaceState.json └── slnx.sqlite ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── 01. C++ Basics ├── 1. Skleton │ └── Skeleton_of_Program.cpp ├── 2. Operators │ ├── Bitwise_Operator │ │ ├── and.cpp │ │ ├── leftShift.cpp │ │ ├── not.cpp │ │ ├── or.cpp │ │ └── xor.cpp │ ├── operators.cpp │ └── qudratic_equation.cpp ├── 3. Statements │ ├── MaxOfTwo.cpp │ └── syntax.cpp ├── RTTI.cpp ├── What is the basic structure of a CPP.docx ├── size_of_data_types.cpp ├── stack_heap_memory.cpp ├── statements.cpp └── static_variable.cpp ├── 02. Array ├── .vscode │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── Array Search │ ├── Linear_search_array.cpp │ ├── a.exe │ ├── binary.cpp │ ├── binary.exe │ └── linear_search.cpp ├── Array.cpp ├── Multi_dimentional.cpp ├── Switch_case.cpp └── user.cpp ├── 03. Loops ├── Examples │ ├── Ascii_Values.cpp │ ├── Calculate_overtime_pay.cpp │ ├── Count_zeros.cpp │ ├── Factorial.cpp │ ├── Multiplication_Table.cpp │ ├── Power_of_number.cpp │ ├── User_input_for_loop.cpp │ ├── octal_value.cpp │ └── sum_of_numbers.cpp ├── For Loop │ ├── For_Loop.cpp │ └── Syntax_For_Loop.cpp ├── Loops.txt └── loops.cpp ├── 04. Pointers ├── 1.Intro.cpp ├── 2.ArthmeticOperators.cpp ├── Dynamci_Memory_Allocation_New.cpp ├── Dynamic.cpp ├── a.exe ├── error.cpp ├── refrence.cpp └── update.cpp ├── 05. Strings ├── 1.char_array.cpp ├── 10.Palindrome.cpp ├── 10.Palindrome.exe ├── 11.UsernameFromEmail.cpp ├── 2.String_Function_Len_concat_copy.cpp ├── 3.String_Fuction_substring_compare.cpp ├── 4.Class_String.cpp ├── 6.Basic_Functions_Class_String.cpp ├── 7.String_Class_Iterator.cpp ├── 8.ChangeCaseStrings.cpp ├── 9.VowelsSpaceConsonant.cpp ├── Strings.txt └── a.exe ├── 06. Functions ├── Lambda Functions │ ├── a.exe │ └── lam.cpp ├── a.exe ├── callByRefrence.cpp ├── callByValue.cpp ├── default.cpp ├── fabonocci_series.cpp ├── inline_function.cpp ├── intro.cpp ├── recursive.cpp ├── scope_of_fucntions.cpp ├── tempCodeRunnerFile.cpp └── templating.cpp ├── 07. Introduction to OOP ├── Accesors_and_Mutators.cpp ├── Constructor │ ├── Definationa and Types.txt │ ├── DemoConstructors.cpp │ ├── default_Constructor.cpp │ └── parameterized_Constructor.cpp ├── PointerToObject.cpp ├── Quiz.cpp ├── dataHiding.cpp ├── index.cpp ├── modifiers.cpp ├── scopeResolutionOperator.cpp ├── test2.cpp └── writingClass.cpp ├── 08. Operator_Overloading ├── FriendOverloading.cpp ├── InerstionOverloading.cpp ├── OperatorOverloading.cpp ├── RationalNo.cpp └── test.cpp ├── 09. Inheritance ├── ConstructorInheritance.cpp └── Examples │ └── cubiod.cpp ├── 10. Base_Class_Pointer_Derived_Class_Object ├── a.exe ├── demo1.cpp ├── demo2.cpp └── first.cpp ├── 11. Polymorphism ├── Polymorhpism.txt ├── abstract.cpp ├── carExample.cpp ├── demo.cpp └── virtualFunctions.cpp ├── 12. Some_Keywords ├── friendClass.cpp ├── friendFunction.cpp ├── staticFucntion.cpp └── staticMember.cpp ├── 13. Exception_Handling ├── a.exe └── exceptionConstruct.cpp ├── 14. Template_Function └── demo.cpp ├── 15. Preprosessor ├── a.exe └── demo.cpp ├── 16. Destructor ├── classDestructor.cpp ├── destructor.cpp └── resourceDestructor.cpp ├── 17. C_++11 ├── lambda.cpp └── smartPointer.cpp ├── 18. Patterns ├── Half_pyramid_using_asterik.cpp ├── Half_pyramid_using_asterik_after_180.cpp ├── Half_pyramid_using_no.cpp ├── Half_pyramid_using_no_after_180.cpp ├── Hollow_Rectangle.cpp ├── Rectangle_Pattern.cpp ├── Rombous_Patterns.cpp ├── Snaps │ ├── Half pyramid using asterik after 180 degree.png │ ├── Half pyramid using asterik.png │ ├── Half pyramid using no after 180.png │ ├── Half pyramid using no.png │ ├── Hollow rectangle.png │ ├── Rectangle patterns.png │ ├── Rombous Patterns.png │ └── program to print the ascii values.png └── dumy.cpp ├── 19. STL ├── 0. Codes - All Modules │ ├── .DS_Store │ ├── Algorithms │ │ ├── .DS_Store │ │ ├── algo_stl_01_find.cpp │ │ ├── algo_stl_02_binary_search_lower_upper.cpp │ │ ├── algo_stl_06_next_permuation.cpp │ │ ├── algo_stl_money_change_problem.cpp │ │ ├── money.cpp │ │ ├── other_methods.cpp │ │ └── pair_stl.cpp │ ├── Generic Programming │ │ ├── .DS_Store │ │ └── iterators_.cpp │ ├── Lists │ │ ├── .DS_Store │ │ └── list_stl.cpp │ ├── Maps │ │ ├── .DS_Store │ │ ├── map_stl_01.cpp │ │ ├── map_stl_02.cpp │ │ ├── map_stl_03_multimap.cpp │ │ ├── map_stl_04.cpp │ │ └── maps_stl.cpp │ ├── Priority Queue │ │ ├── .DS_Store │ │ ├── functor.cpp │ │ ├── priority_queue.stl │ │ ├── priority_queue_compartor_class.cpp │ │ └── queue_stl.cpp │ ├── Sets │ │ ├── .DS_Store │ │ └── permute.cpp │ ├── Stack │ │ ├── .DS_Store │ │ ├── list_stl.cpp │ │ ├── stack_stl.cpp │ │ └── stack_using_q.cpp │ ├── Strings │ │ ├── .DS_Store │ │ ├── string_stl_01 2.cpp │ │ ├── string_stl_01.cpp │ │ ├── string_stl_02 2.cpp │ │ ├── string_stl_02.cpp │ │ ├── string_stl_03 2.cpp │ │ ├── string_stl_03.cpp │ │ ├── string_stl_04_tokneizer_implement 2.cpp │ │ └── string_stl_04_tokneizer_implement.cpp │ ├── Unordered Map │ │ ├── .DS_Store │ │ ├── phonebook.cpp │ │ ├── trie_map.cpp │ │ └── unordered_map_stl_01.cpp │ └── Vectors │ │ ├── .DS_Store │ │ ├── pair_stl.cpp │ │ ├── vector.h │ │ ├── vector_demo.cpp │ │ ├── vector_stl_01.cpp │ │ ├── vector_stl_02.cpp │ │ └── vector_stl_1.cpp ├── Queue │ ├── Priority_Queue.cpp │ └── queue.cpp ├── binary.cpp ├── pair.cpp ├── set │ └── code.cpp └── vector │ ├── code.cpp │ ├── doc.txt │ ├── vecotr_iterator.cpp │ ├── vector_emplace_back.cpp │ ├── vector_func.cpp │ ├── vector_pair.cpp │ └── vector_push_back.cpp ├── CPP ├── CPP.cbp ├── CPP.layout ├── bin │ └── Debug │ │ └── CPP.exe ├── main.cpp └── obj │ └── Debug │ └── main.o ├── CppProperties.json ├── DSA CPP ├── Array │ └── array.cpp └── structures │ └── structure.cpp ├── Final Term Exam Preperation ├── .vscode │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── Function │ ├── 1.Armstrong.cpp │ ├── 2.Palindrome.cpp │ ├── 3.Factorial.cpp │ ├── built_in.cpp │ ├── dum.exe │ ├── dumy.cpp │ ├── fac.exe │ ├── func.py │ ├── isPrime.cpp │ └── userdefined.cpp ├── Mul & De │ ├── De.py │ ├── Mul.py │ └── adder.py ├── a.exe ├── add.cpp ├── add.exe ├── boil.cpp ├── boil.exe ├── boot.html ├── brain.cpp ├── brain.exe ├── ddd.ipynb ├── def.py ├── diabates.ipynb ├── diabates.py ├── diabetes.csv ├── even.cpp ├── even.exe ├── file_handling.ipynb ├── filename.csv ├── func.cpp ├── func.exe ├── germany.csv ├── images │ ├── 1.jpg │ ├── men1.jpg │ └── photo-1492447166138-50c3889fccb1.avif ├── index,colums.ipynb ├── inner.py ├── pandas.ipynb ├── power.py ├── prime.cpp ├── prime.exe ├── python mega course.ipynb ├── search.cpp ├── search.exe └── wifi.py ├── LeetCodeProblems └── ArmstrongNumbers.cpp ├── Object Oriented Programming ├── OOP_Examples │ ├── BankAccount.cpp │ ├── car.cpp │ ├── inheritance.cpp │ ├── person.cpp │ ├── rectangle.cpp │ └── student.cpp └── Principles │ ├── polymor.cpp │ └── test.cpp ├── Projects ├── Atm.cpp └── snake_game.cpp ├── README.md └── strings ├── class_strings.cpp ├── intro-strings.cpp ├── practice.cpp ├── reading_strings.cpp ├── string_concatenation.cpp ├── string_copy.cpp ├── string_iterator.cpp ├── string_length.cpp └── strings.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe -------------------------------------------------------------------------------- /.vs/CPP/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/.vs/CPP/v16/.suo -------------------------------------------------------------------------------- /.vs/CPP/v16/Browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/.vs/CPP/v16/Browse.VC.db -------------------------------------------------------------------------------- /.vs/ProjectSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "CurrentProjectSetting": "Mingw64" 3 | } -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "", 4 | "\\2. Array" 5 | ], 6 | "PreviewInSolutionExplorer": false 7 | } -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/.vs/slnx.sqlite -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x86", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [ 9 | "_DEBUG", 10 | "UNICODE", 11 | "_UNICODE" 12 | ], 13 | "cStandard": "${default}", 14 | "cppStandard": "${default}", 15 | "compilerPath": "C:/MinGW/bin/gcc.exe", 16 | "intelliSenseMode": "windows-gcc-x86" 17 | } 18 | ], 19 | "version": 4 20 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "java", 6 | "name": "dumy", 7 | "request": "launch", 8 | "mainClass": "dumy", 9 | "projectName": "CPP_abe0318c" 10 | }, 11 | { 12 | "name": "C/C++ Runner: Debug Session", 13 | "type": "cppdbg", 14 | "request": "launch", 15 | "args": [], 16 | "stopAtEntry": false, 17 | "externalConsole": true, 18 | "cwd": "d:/Open Source/CPP/Object Oriented Programming/Constructor", 19 | "program": "d:/Open Source/CPP/Object Oriented Programming/Constructor/build/Debug/outDebug", 20 | "MIMode": "gdb", 21 | "miDebuggerPath": "gdb", 22 | "setupCommands": [ 23 | { 24 | "description": "Enable pretty-printing for gdb", 25 | "text": "-enable-pretty-printing", 26 | "ignoreFailures": true 27 | } 28 | ] 29 | } 30 | ] 31 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "ostream": "cpp", 4 | "iostream": "cpp", 5 | "array": "cpp", 6 | "deque": "cpp", 7 | "string": "cpp", 8 | "vector": "cpp", 9 | "iterator": "cpp", 10 | "initializer_list": "cpp", 11 | "unordered_map": "cpp", 12 | "*.tcc": "cpp", 13 | "cctype": "cpp", 14 | "clocale": "cpp", 15 | "cmath": "cpp", 16 | "cstdarg": "cpp", 17 | "cstddef": "cpp", 18 | "cstdio": "cpp", 19 | "cstdlib": "cpp", 20 | "cstring": "cpp", 21 | "ctime": "cpp", 22 | "cwchar": "cpp", 23 | "cwctype": "cpp", 24 | "exception": "cpp", 25 | "fstream": "cpp", 26 | "iosfwd": "cpp", 27 | "istream": "cpp", 28 | "limits": "cpp", 29 | "memory": "cpp", 30 | "new": "cpp", 31 | "sstream": "cpp", 32 | "stdexcept": "cpp", 33 | "streambuf": "cpp", 34 | "typeinfo": "cpp", 35 | "atomic": "cpp", 36 | "cstdint": "cpp", 37 | "algorithm": "cpp", 38 | "functional": "cpp", 39 | "memory_resource": "cpp", 40 | "numeric": "cpp", 41 | "random": "cpp", 42 | "system_error": "cpp", 43 | "tuple": "cpp", 44 | "type_traits": "cpp", 45 | "utility": "cpp", 46 | "cinttypes": "cpp" 47 | }, 48 | "C_Cpp.errorSquiggles": "disabled", 49 | "C_Cpp_Runner.msvcBatchPath": "", 50 | "C_Cpp_Runner.cCompilerPath": "gcc", 51 | "C_Cpp_Runner.cppCompilerPath": "g++", 52 | "C_Cpp_Runner.debuggerPath": "gdb", 53 | "C_Cpp_Runner.cStandard": "", 54 | "C_Cpp_Runner.cppStandard": "", 55 | "C_Cpp_Runner.useMsvc": false, 56 | "C_Cpp_Runner.warnings": [ 57 | "-Wall", 58 | "-Wextra", 59 | "-Wpedantic", 60 | "-Wshadow", 61 | "-Wformat=2", 62 | "-Wcast-align", 63 | "-Wconversion", 64 | "-Wsign-conversion", 65 | "-Wnull-dereference" 66 | ], 67 | "C_Cpp_Runner.msvcWarnings": [ 68 | "/W4", 69 | "/permissive-", 70 | "/w14242", 71 | "/w14287", 72 | "/w14296", 73 | "/w14311", 74 | "/w14826", 75 | "/w44062", 76 | "/w44242", 77 | "/w14905", 78 | "/w14906", 79 | "/w14263", 80 | "/w44265", 81 | "/w14928" 82 | ], 83 | "C_Cpp_Runner.enableWarnings": true, 84 | "C_Cpp_Runner.warningsAsError": false, 85 | "C_Cpp_Runner.compilerArgs": [], 86 | "C_Cpp_Runner.linkerArgs": [], 87 | "C_Cpp_Runner.includePaths": [], 88 | "C_Cpp_Runner.includeSearch": [ 89 | "*", 90 | "**/*" 91 | ], 92 | "C_Cpp_Runner.excludeSearch": [ 93 | "**/build", 94 | "**/build/**", 95 | "**/.*", 96 | "**/.*/**", 97 | "**/.vscode", 98 | "**/.vscode/**" 99 | ], 100 | "C_Cpp_Runner.useAddressSanitizer": false, 101 | "C_Cpp_Runner.useUndefinedSanitizer": false, 102 | "C_Cpp_Runner.useLeakSanitizer": false, 103 | "C_Cpp_Runner.showCompilationTime": false, 104 | "C_Cpp_Runner.useLinkTimeOptimization": false, 105 | "C_Cpp_Runner.msvcSecureNoWarnings": false 106 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\MinGW\\bin\\g++.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /01. C++ Basics/1. Skleton/Skeleton_of_Program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | cout << "Hello World"; 7 | return 0; 8 | } -------------------------------------------------------------------------------- /01. C++ Basics/2. Operators/Bitwise_Operator/and.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 12; 6 | int b = 25; 7 | cout<<"Value of a: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 20; 6 | cout<<"Value of shift by 2: "<<(a << 2); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /01. C++ Basics/2. Operators/Bitwise_Operator/not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | return 0; 7 | } -------------------------------------------------------------------------------- /01. C++ Basics/2. Operators/Bitwise_Operator/or.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 12; 6 | int b = 25; 7 | cout<<"Value of a | b :"<<(a | b); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /01. C++ Basics/2. Operators/Bitwise_Operator/xor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 12; 6 | int b = 25; 7 | cout<<"Value of a ^ b: "<<( a ^ b); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /01. C++ Basics/2. Operators/operators.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | // Assignment operators in cpp 6 | // Declare two variable of int data_Type 7 | int a = 10, b = 20; 8 | int result = !(a < b); // it will reverse the answer 9 | // if the anwer is 1, it will change to 0 10 | cout< 2 | #include 3 | using namespace std; 4 | int main(){ 5 | // Qudratic Eqaution 6 | int a,b,c; 7 | cout<<"Enter your Values Respectively a, b ,c "<> a >> b >>c ; 9 | int result1 =((-b+sqrt(pow(b,2)-(4*a*c)))/(2*a)); 10 | int result2 =((-b-sqrt(pow(b,2)-(4*a*c)))/(2*a)); 11 | cout<<"Positive Values : "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a,b; 6 | cout<<"Enter two numbers a & b Respectively: "; 7 | cin>>a >> b; 8 | cout<<"First NUmbers is : "<b){ 11 | cout<<"First Number is greater which is "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 20 , b = 30 , c = 40; 6 | if(a > b ){ 7 | if (a > c ){ 8 | cout<<"A is greater: "< c) 12 | { 13 | cout<<"B is greater: "< should be included to use typeid. 9 | 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | int main(){ 15 | int a = 20; 16 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | 7 | int x=47385; 8 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | int hello(){ 6 | int a = 100; 7 | return a; 8 | } 9 | int main(){ 10 | int a; 11 | int b = 20; 12 | int *p = &b; 13 | int d = hello(); 14 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | // statements 6 | // if statements 7 | string button; 8 | getline(cin,button); 9 | if(button =="yes" && button == "Yes"){ 10 | cout<<"Yes you're are "; 11 | } 12 | else if (button == "no" && button == "No") 13 | { 14 | cout<<"You can't"; 15 | } 16 | else { 17 | cout<<"Bye Bye"; 18 | 19 | } 20 | 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /01. C++ Basics/static_variable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int add(int a, int b){ 5 | static int c = 0 ; 6 | c = c + 1; 7 | return a + b + c; 8 | } 9 | int main(){ 10 | cout<<"First Time: "< 4 | using namespace std; 5 | int main(){ 6 | int key; 7 | // int A[] = {12,4,5,6,66,77,88,983,374,433},n=10; 8 | int A[6],n=6; 9 | cout<<"Enter Array Elements "; 10 | for(int i=0; i< n; ++i){ 11 | cin>>A[i]; 12 | } 13 | cout<<"Enter the Key to Find "; 14 | cin>>key; 15 | for(int i=0; i 2 | using namespace std; 3 | int main(){ 4 | int arr[6] = {3,4,5,6,9,12}; 5 | int key; 6 | cout<<"Enter the Key to find out "<>key; 8 | int l = 0 , h = 5; 9 | while (l<=h) 10 | { 11 | int mid = (l+h)/2; 12 | if(key == arr[mid]){ 13 | cout<<"key found at index "< 2 | using namespace std; 3 | int main(){ 4 | int arr[4] = {3,4,5,6}; 5 | int key; 6 | cin>>key; 7 | for (int i = 0; i < 4; i++) 8 | { 9 | if(key==arr[i]){ 10 | cout<<"Key found at "< 2 | using namespace std; 3 | 4 | int main(){ 5 | // data_type name_array[size] = {elements}; 6 | int arr[5] = {1,2,3,4,5}; 7 | // cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a[2][3]= {{1,2,3}, 6 | {4,5,6}}; 7 | // cout<<"Elements of Row 1"<>a[i][j]; 24 | } 25 | } 26 | 27 | // Display the Array Elements 28 | for (int i = 0; i < 2; i++) 29 | { 30 | // Columns 31 | for (int j = 0; j <3; j++) 32 | { 33 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int no1, no2; 7 | char button; 8 | cout<<"Enter two Nomber "; 9 | cin>>no1>>no2; 10 | cout<<"Enter Action +, - , / *, ** " ; 11 | cin>>button; 12 | switch (button) 13 | { 14 | case '+': 15 | cout<<"Additon of Given Numbers "< 2 | using namespace std; 3 | 4 | int main(){ 5 | // int a[5] = {0,1,2,3,4}, 6 | int a[5]; 7 | for (int i = 0; i < 5; i++) 8 | { 9 | cin>>a[i]; 10 | } 11 | for (int i = 0; i <5; i++) 12 | { 13 | cout< 2 | using namespace std; 3 | int main(){ 4 | 5 | for (int i = 0; i <= 255; i++) 6 | { 7 | cout<< i <<" = " << char(i)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int hours, employ = 1, overtime_hours ; 6 | double overtime_pay; 7 | while (employ <=10) 8 | { 9 | cout<<"Enter the Hours of Employ: "<>hours; 11 | if(hours>=40){ 12 | int overtime_hours = hours - 40; 13 | overtime_pay = overtime_hours * 12.0; 14 | } 15 | else{ 16 | overtime_pay = 0; 17 | } 18 | cout<<"Pay of Employ "< 2 | using namespace std; 3 | 4 | int main() { 5 | // Initialize variables 6 | int num, pos_count = 0, neg_count = 0, zero_count = 0; 7 | char choice = 'y'; 8 | 9 | // Ask the user to enter numbers until they choose to stop 10 | while (choice == 'y' || choice == 'Y') { 11 | cout << "Enter a number: "; 12 | cin >> num; 13 | 14 | // Check if the number is positive, negative, or zero and increment the corresponding count 15 | if (num > 0) { 16 | pos_count++; 17 | } else if (num < 0) { 18 | neg_count++; 19 | } else { 20 | zero_count++; 21 | } 22 | 23 | // Ask the user if they want to enter another number 24 | cout << "Do you want to enter another number? (y/n): "; 25 | cin >> choice; 26 | } 27 | 28 | // Print the count of positive, negative, and zero numbers entered 29 | cout << "Total positive numbers entered: " << pos_count << endl; 30 | cout << "Total negative numbers entered: " << neg_count << endl; 31 | cout << "Total zeros entered: " << zero_count << endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /03. Loops/Examples/Factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int number,factorial =1 ; 6 | cout<<"Enter the Number to Calculate the Factorial: "; 7 | cin>>number; 8 | for (int i = 1 ; i <= number; i++) 9 | { 10 | factorial *=i; 11 | } 12 | cout<<"Factorial of "<< number<<" is: "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | // Table is 7 | // Value * Length(1,10) = Answer 8 | // like 6 * 1 = 6 9 | 10 | int table; 11 | cout << "Enter the Desired Table: "; 12 | cin >> table; 13 | for (int i = 1; i <= 10; i++) 14 | { 15 | cout << table << " * " << i << " = " << table * i << endl; 16 | } 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /03. Loops/Examples/Power_of_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() { 5 | // Initialize variables 6 | double base, exponent, result; 7 | // Ask the user to input the base and exponent 8 | cout << "Enter the base number: "; 9 | cin >> base; 10 | cout << "Enter the exponent: "; 11 | cin >> exponent; 12 | // Calculate the result using the pow() function from the cmath library 13 | result = pow(base, exponent); 14 | // Print the result 15 | cout << base << " raised to the power of " << exponent << " is " << result << endl; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /03. Loops/Examples/User_input_for_loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int value; 7 | cout << "Enter The Number of iteration: "; 8 | cin >> value; 9 | for (int i = 0; i <= value; i++) 10 | { 11 | cout << "Here is number of iteration: " << i << endl; 12 | } 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /03. Loops/Examples/octal_value.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // Initialize variables 6 | int decimal_num, octal_num = 0, place_value = 1; 7 | 8 | // Ask the user to enter a decimal number 9 | cout << "Enter a decimal number: "; 10 | cin >> decimal_num; 11 | 12 | // Convert the decimal number to octal 13 | while (decimal_num > 0) { 14 | octal_num += (decimal_num % 8) * place_value; 15 | decimal_num /= 8; 16 | place_value *= 10; 17 | } 18 | 19 | // Print the octal equivalent of the entered number 20 | cout << "The octal equivalent is: " << octal_num << endl; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /03. Loops/Examples/sum_of_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int sum = 0; 7 | for (int i = 1; i <= 10; ++i) 8 | { 9 | sum = sum + i; 10 | } 11 | cout << sum; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /03. Loops/For Loop/For_Loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | // Print the 100 Number with message 7 | for (int i = 0; i <= 100; i++) 8 | { 9 | cout << "This is my message no: " << i << endl; 10 | } 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /03. Loops/For Loop/Syntax_For_Loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | // Foor loop syntax 7 | // for (initilization ; Condition; Update) 8 | // { 9 | // Body of the Loop 10 | // } 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /03. Loops/Loops.txt: -------------------------------------------------------------------------------- 1 | * Repeating statements 2 | * Itrating statements 3 | 4 | Types of Loops: 5 | * For Loop 6 | * For Each Loop 7 | * While Loop 8 | * Do while Loop -------------------------------------------------------------------------------- /03. Loops/loops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | // loops 7 | // while loop 8 | // int i = 0; 9 | // while (i < 20) 10 | // { 11 | // cout< 9 | using namespace std; 10 | 11 | int main(){ 12 | int x = 20; 13 | // 1. Declartion 14 | int *p; 15 | 16 | // 2. inlization 17 | p = &x; 18 | 19 | 20 | cout<<"Value of x: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 20; 6 | int *p = &a; 7 | cout<<"Size of int data type in MySystem: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | // it is for signle variable. dont forget to delete the memory other wise it will cuase the memory leak 6 | // int *ptr = new int; 7 | // *ptr = 20; 8 | // *ptr = 40; 9 | // cout<<"Value of Ptr is : "<<*ptr; 10 | // delete ptr; 11 | 12 | // it is for array 13 | 14 | int *ptr = new int[10]; 15 | system("cls"); 16 | for (int i = 0; i <= 10; i++) 17 | { 18 | ptr[i] = i * 10; 19 | } 20 | 21 | for (int i = 0; i <= 10; i++) 22 | { 23 | cout<<"Value at index: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | void *null_ptr; 6 | int a = 20; 7 | null_ptr = &a; 8 | cout<<"Value of intger Data Type: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int *p = new int[5]; 6 | 7 | p[0] = 1; 8 | p[1] = 2; 9 | p[2] = 3; 10 | p[3] = 4; 11 | p[4] = 5; 12 | cout<<"Starting Pointer from here: "< 8 | using namespace std; 9 | 10 | int main(){ 11 | int x = 30; 12 | int &y = x; 13 | y +=30; 14 | cout<<"x: "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a = 20; 7 | int &p = a; 8 | p = 29; 9 | cout<<"Value of a: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | char s[10] = "Abdullah"; 6 | cout<<"Value of Char Array is: "< 0) 23 | // { 24 | // cout<0); 36 | 37 | }; -------------------------------------------------------------------------------- /05. Strings/10.Palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s = "madam"; 7 | string rev = ""; 8 | int len = (int)s.length(); 9 | rev.resize(len); 10 | for (int i = 0, j = len - 1; i < len; i++, j--) 11 | { 12 | rev[i] = s[j]; 13 | } 14 | rev[len] = '\0'; 15 | cout << "Palindrome: " << rev; 16 | return 0; 17 | }; -------------------------------------------------------------------------------- /05. Strings/10.Palindrome.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/05. Strings/10.Palindrome.exe -------------------------------------------------------------------------------- /05. Strings/11.UsernameFromEmail.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | string user = "AbdulahNiaz@gmail.com"; 6 | int i = user.find('@'); 7 | string name = user.substr(0,i); 8 | cout<<"UserName is : "< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | char s1[20] = "Hello World"; 7 | char s2[20] = " I am a student"; 8 | cout<<"Length of s1: "< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | char s1[20]= "HelloWrold"; 7 | char s2[20] = "helloworld"; 8 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | string s,y; 6 | // cin>>s; 7 | getline(cin,s); 8 | cout<<"Value os "<>y; 12 | getline(cin,y); 13 | cout<<"Value of y: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | string s = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; 6 | int value = s.find(","); 7 | cout<<"Total Number of , in Code "< 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | string s = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; 8 | 9 | string str = "Hello World"; 10 | string::iterator it; 11 | for (it = s.begin(); it != s.end(); ++it) 12 | { 13 | cout << *it; 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | 7 | 8 | // From Upper Case to Lower Case 9 | string s = "WELLCOME"; 10 | for (int i = 0; s[i] != '\0'; i++) 11 | { 12 | 13 | if (s[i] >= 65 && s[i]<=90) 14 | { 15 | /* code */ 16 | s[i] = s[i] + 32 ; 17 | } 18 | 19 | } 20 | cout<<"Converted from Upper to Lower: "<= 97 && b[i] <= 122) 27 | { 28 | b[i] = b[i] - 32; 29 | } 30 | } 31 | cout<<"Converted from Lower To Upper: "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int vowels=0,space=0,consonant=0; 6 | string h = "How are you"; 7 | for (int i = 0; h[i]!= '\0'; i++) 8 | { 9 | if (h[i] == 'A' || h[i] == 'E' || h[i] == 'I' || h[i] == 'O' || h[i] == 'U' || 10 | h[i] == 'a' || h[i] == 'e' || h[i] == 'i' || h[i] == 'o' || h[i] == 'u') 11 | { 12 | vowels++; 13 | } 14 | else if (h[i] == ' ') 15 | { 16 | space++; 17 | } 18 | else{ 19 | consonant++; 20 | } 21 | } 22 | cout<<"Vowels: "< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | 8 | //? lambda Functions 9 | 10 | //! Simple Syntax 11 | //Note [] = lambda introuducer 12 | // () parameter list 13 | 14 | //Todo 1---------------simple 15 | // [](){ 16 | // cout<<"Hello into the world of lambda functions"; 17 | // }(); 18 | 19 | 20 | //Todo 2--------------- name 21 | 22 | // auto info = [](){ 23 | // cout<<"hello World"; 24 | // }; 25 | // info(); 26 | 27 | 28 | //Todo 3--------------- parameters 29 | // auto add = [](int a, int b){ 30 | // cout<<"a + b: "<< a + b; 31 | // }; 32 | // add(2,3); 33 | 34 | //Todo 4--------------- Return Type 35 | // auto add = [](int a, int b, int c)->int{ 36 | // return a + b + c; 37 | // }; 38 | // using type = decltype(add); 39 | // int a = add(2,3,4); 40 | // cout< 2 | using namespace std; 3 | 4 | int swapByRefrence(int &a, int &b){ 5 | a = a + b; 6 | b = a - b; 7 | a = a - b; 8 | } 9 | int main(){ 10 | int a =20, b = 30; 11 | swapByRefrence(a,b); 12 | cout<<"Value of a: "< 2 | using namespace std; 3 | 4 | // This is call by value 5 | int swap(int a, int b){ 6 | a = a + b; // 20 + 30 = 50 7 | b = a - b; // 50 - 30 = 20 8 | a = a - b; // 50 - 20 = 30 9 | } 10 | int main(){ 11 | int a = 20 ,b = 30; 12 | swap(a,b); 13 | cout<<"value of a: "< 2 | using namespace std; 3 | template 4 | 5 | T Sub(T a = 0 , T b = 0 , T c = 0){ 6 | return a + b + c; 7 | } 8 | // Position Arguments should be before the Default arguments 9 | int add(int a , int b = 0 ,int c = 0){ 10 | return a + b + c; 11 | }; 12 | int main() 13 | { 14 | int a = 2; 15 | int t = Sub(2,2); 16 | cout<<"T: "< 2 | using namespace std; 3 | 4 | int fabonici(int n) 5 | { 6 | if (n < 2) 7 | { 8 | return 1; 9 | } 10 | else 11 | { 12 | return fabonici(n - 2) + fabonici(n - 1); 13 | } 14 | } 15 | int main() 16 | { 17 | for (int i = 0; i <= 10; i++) 18 | { 19 | cout<<"fabonici of: " << i <<" is: "<< fabonici(i) < 2 | using namespace std; 3 | 4 | 5 | inline int add(int a, int b){ 6 | return a + b; 7 | } 8 | int main(){ 9 | int a,b; 10 | cout<<"Enter the Values a,b: "; 11 | cin>>a>>b; 12 | cout<<"Values: "< 2 | using namespace std; 3 | int compare(int a, int b, int c){ 4 | if(a > b && a > c){ 5 | return a; 6 | } 7 | else if (b > c) 8 | { 9 | return b; 10 | } 11 | else{ 12 | return c; 13 | } 14 | } 15 | 16 | int add(int a , int b , int c ){ 17 | return a + b + c ; 18 | } 19 | int main(){ 20 | int x = 20, y = 17 , z = 15, result; 21 | result = compare(x,y,z); 22 | cout<<"Here is the result "<< result< 2 | using namespace std; 3 | 4 | 5 | // recursive: A function that calls itself until the certain condition met. 6 | int recursive(int n){ 7 | if (n == 1){ 8 | return 1; 9 | } 10 | else{ 11 | return n * recursive(n - 1 ); 12 | } 13 | } 14 | int main(){ 15 | cout<<"Recusive Functions: "< 2 | using namespace std; 3 | //write a Max() function template for 2 numbers 4 | // Templating of fucntions 5 | // template 6 | // T Max(T a,T b) 7 | // { 8 | // if(a>b) 9 | // return a; 10 | // else 11 | // return b; 12 | // } 13 | 14 | int add(int a = 0 , int b = 0 , int c = 0 ){ 15 | return a + b + c; 16 | } 17 | int main() 18 | { 19 | int x = 10 , y = 15 , z = 20; 20 | int result1 = add(); 21 | int result2 = add(2,5); 22 | int result3 = add(2,7,8); 23 | int result4 = add(2,7,0); 24 | cout< 2 | using namespace std; 3 | 4 | // void func() 5 | // { 6 | // // this variable is local to the 7 | // // function func() and cannot be 8 | // // accessed outside this function 9 | // int age=18; 10 | // } 11 | 12 | int main() 13 | { 14 | int age; 15 | cout<<"Age is: "< 2 | using namespace std; 3 | template 4 | 5 | T max(T a, T b , T c){ 6 | 7 | return a + b + c; 8 | }; 9 | 10 | int main(){ 11 | int a = max(2,3,4); 12 | float b = max(2.2,3.3,4.4); 13 | cout<<"Integer Value: "<< a< 2 | using namespace std; 3 | 4 | // Accessors: Are to Set the values of instance/data variables 5 | // Getters: Are to get the value of instance/data variable 6 | class Rectangle{ 7 | private: 8 | int width; 9 | int height; 10 | 11 | public: 12 | 13 | int set_width(int a){ 14 | if (a >= 0 ){ 15 | width = a; 16 | } 17 | else{ 18 | cout<<"It can't be negative"; 19 | } 20 | } 21 | 22 | int set_height(int b){ 23 | if (b >= 0 ){ 24 | height = b; 25 | } 26 | else{ 27 | cout<<"It can't be negative"; 28 | } 29 | } 30 | 31 | 32 | int get_width(){ 33 | return width; 34 | } 35 | int get_height(){ 36 | return height; 37 | } 38 | 39 | }; 40 | 41 | int main(){ 42 | Rectangle d; 43 | d.set_width(10); 44 | d.set_height(20); 45 | cout<<"Value of Width is: "< 2 | using namespace std; 3 | 4 | class Rectangle{ 5 | private: 6 | int length; 7 | int breadth; 8 | 9 | public: 10 | Rectangle(){ 11 | length = 0; 12 | breadth = 0; 13 | } 14 | Rectangle(int l, int b){ 15 | // length = l; 16 | // breadth = b; 17 | 18 | setlength(l); 19 | setbreadth(b); 20 | } 21 | void setlength(int l){ 22 | if( l > 0 ){ 23 | length = l; 24 | } 25 | else{ 26 | length = 0; 27 | } 28 | } 29 | void setbreadth(int b){ 30 | if( b > 0 ){ 31 | breadth = b; 32 | } 33 | else{ 34 | breadth = 0; 35 | } 36 | } 37 | 38 | int Area(){ 39 | return length + breadth; 40 | } 41 | 42 | int Perimeter(){ 43 | return (2 + (length + breadth)); 44 | } 45 | }; 46 | 47 | int main(){ 48 | Rectangle r(3,4); 49 | int a = r.Area(); 50 | cout< 2 | using namespace std; 3 | 4 | class default_Constructor 5 | { 6 | public: 7 | int r; 8 | const int value = 20; 9 | }; 10 | 11 | int main() 12 | { 13 | default_Constructor def; // object 14 | 15 | def.r = 30; 16 | 17 | int r = def.r; // Stored niside the variable 18 | int val = def.value; // Same here as above 19 | 20 | cout << "Value of R is: " << r << endl; 21 | cout << "Value of value is: " << val << endl; 22 | return 0; 23 | }; -------------------------------------------------------------------------------- /07. Introduction to OOP/Constructor/parameterized_Constructor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class perametrized_Constructor 5 | { 6 | public: 7 | int a, b, c; 8 | 9 | perametrized_Constructor() 10 | { 11 | cout << "Default Constructor"; 12 | a = 20, b = 30, c = 40; 13 | show(); 14 | } 15 | 16 | perametrized_Constructor(int a, int b, int c) 17 | { 18 | cout << "Perametrized Constructor"; 19 | this->a = a; 20 | this->b = b; 21 | this->c = c; 22 | show(); 23 | } 24 | void show() 25 | { 26 | cout << "\nFunction which we are going to call inside the constructor to check it's working"; 27 | } 28 | }; 29 | int main() 30 | { 31 | int value; 32 | cout << "Enter the Value to Check the Type of Constructor: "; 33 | cin >> value; 34 | if (value == 1) 35 | { 36 | /* code */ 37 | perametrized_Constructor obj; 38 | obj; 39 | } 40 | else 41 | { 42 | perametrized_Constructor ob(20, 30, 40); 43 | ob; 44 | } 45 | 46 | return 0; 47 | }; -------------------------------------------------------------------------------- /07. Introduction to OOP/PointerToObject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Rectangle{ 5 | public: 6 | int length,breath; 7 | 8 | int area(){ 9 | return length * breath; 10 | } 11 | 12 | int Perameter(){ 13 | return 2 * (length + breath); 14 | } 15 | }; 16 | 17 | int main(){ 18 | Rectangle r; 19 | Rectangle *p; 20 | p = &r; 21 | r.length = 10; 22 | r.breath = 20; 23 | cout<<"Area is: "<length = 20; 29 | p->breath = 30; 30 | cout<<"Area is: "<area()<Perameter(); 32 | 33 | return 0; 34 | }; -------------------------------------------------------------------------------- /07. Introduction to OOP/Quiz.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Student 5 | { 6 | private: 7 | int roll; 8 | string name; 9 | int phy, bio, math; 10 | 11 | public: 12 | 13 | 14 | Student(int roll, string name, int phy, int bio, int math){ 15 | this->roll = roll; 16 | this->name = name; 17 | this->phy = phy; 18 | this->bio = bio; 19 | this->math = math; 20 | } 21 | int total(){ 22 | return phy + bio + math; 23 | } 24 | char grade(){ 25 | float averagem = total()/3; 26 | if (averagem > 80 ){ 27 | return 'A'; 28 | } 29 | else{ 30 | return 'B'; 31 | } 32 | } 33 | }; 34 | int main(){ 35 | int r,p,b,m; 36 | string n; 37 | 38 | cout<<"Enter the Roll: "; 39 | cin>>r; 40 | 41 | cout<>n; 45 | 46 | cout<<"Enter the Marks of PHY, Bio, Math: "; 47 | cin>>p>>b>>m; 48 | 49 | Student st(r,n,p,b,m); 50 | cout< 2 | using namespace std; 3 | 4 | 5 | class BankAccount { 6 | private: 7 | double balance; 8 | 9 | public: 10 | void showMenu(){ 11 | cout<<"1.Initial Balance Setup: "< 0) { 22 | balance += amount; 23 | cout<<"Amount you Desposited is: "< 3 | using namespace std; 4 | 5 | //! modifiers in c++ 6 | //Todo Public: which can be accesed anywhere 7 | //Todo Private: which can be accessed only in that class 8 | //Todo Protected: Both Public & Private 9 | 10 | class Car 11 | { 12 | public: 13 | string name; 14 | string model; 15 | string color; 16 | int price; 17 | 18 | // Methods 19 | int intro(){ 20 | cout<<"Name of Car is: "< 2 | using namespace std; 3 | 4 | class student 5 | { 6 | private: 7 | int a,b,c; 8 | public: 9 | int d,e; 10 | 11 | void setData(int a1, int b1, int c1, int d1,int e1); // Declaration of fucntion for setting up data 12 | void getData(){ 13 | cout<<"Value of a: "<d = 124; 44 | p->e = 250; 45 | 46 | p->setData(11,22,33,44,55); 47 | p->getData(); 48 | 49 | return 0; 50 | }; -------------------------------------------------------------------------------- /07. Introduction to OOP/scopeResolutionOperator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | class Rectangle{ 7 | public: 8 | int length; 9 | int breadth; 10 | 11 | public: 12 | Rectangle(){ 13 | length,breadth = 1; 14 | } 15 | Rectangle(int l, int b){ 16 | setlength(l); 17 | setbreadth(b); 18 | } 19 | void setlength(int l){ 20 | if(l > 0 ){ 21 | breadth = l; 22 | } 23 | else{ 24 | breadth = 1; 25 | } 26 | } 27 | void setbreadth(int b){ 28 | if ( b > 0 ){ 29 | length = b; 30 | } 31 | else{ 32 | breadth = 1; 33 | } 34 | } 35 | 36 | 37 | int Area(){ 38 | return length * breadth; 39 | } 40 | int Perimeter(); 41 | ~Rectangle(); 42 | }; 43 | 44 | 45 | 46 | 47 | int Rectangle::Perimeter(){ 48 | return 2 * (length + breadth); 49 | } 50 | 51 | Rectangle::~Rectangle(){ 52 | cout<<"Rectangle Destroyed"; 53 | } 54 | 55 | 56 | int main() 57 | { 58 | Rectangle r(3,4); 59 | cout<<"Area is : "< 2 | using namespace std; 3 | 4 | class rec{ 5 | public: 6 | int length,breadth; 7 | 8 | int getLenght(){ 9 | return length; 10 | } 11 | int getBreadth(){ 12 | return breadth; 13 | } 14 | }; 15 | int main() 16 | { 17 | rec r; 18 | rec *Ptr; 19 | Ptr = &r; 20 | Ptr->length = 20; 21 | Ptr->breadth = 30; 22 | cout<<"Value of Length: "<getLenght()<getBreadth()< 3 | using namespace std; 4 | 5 | 6 | 7 | // Delcare a Class of Recntangle 8 | class Rectangle{ 9 | public: 10 | // Aritbutes of Rctangle 11 | int length; 12 | int width; 13 | 14 | // Functions of Rectangle 15 | int area(){ 16 | return length * width; 17 | } 18 | int perameters(){ 19 | return 2 * (length + width); 20 | } 21 | }; 22 | int main(){ 23 | 24 | // Create a objects of class 25 | Rectangle r1,r2,r3; 26 | r1.length = 10; 27 | r1.width = 15; 28 | 29 | r2.length = 20; 30 | r2.width = 15; 31 | 32 | r3.length = 30; 33 | r3.width = 15; 34 | 35 | cout<<"Area of Rectangle r1 is: "< 2 | using namespace std; 3 | class Complex 4 | { 5 | private: 6 | int real; 7 | int imag; 8 | 9 | public: 10 | Complex(int real = 0, int imag = 0) 11 | { 12 | this->real = real; 13 | this->imag = imag; 14 | } 15 | void display() 16 | { 17 | cout << real << "+i" << imag; 18 | } 19 | // Complex add(Complex x){ 20 | // Complex operator+(Complex x) 21 | friend Complex operator+(Complex c1, Complex c2); 22 | }; 23 | 24 | Complex operator+(Complex c1, Complex c2) 25 | { 26 | Complex temp; 27 | temp.real = c1.real + c2.real; 28 | temp.imag = c1.imag + c2.imag; 29 | return temp; 30 | }; 31 | int main() 32 | { 33 | Complex c1(4, 5); 34 | Complex c2(3, 6); 35 | Complex c3; 36 | // c3 = c1.add(c2) ; 37 | c3 = c1 + c2; 38 | // cout << "Value of C3 is: " << c3.real << "+ i" << c3.imag; 39 | c3.display(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /08. Operator_Overloading/InerstionOverloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | class Complex 6 | { 7 | private: 8 | int real; 9 | int imag; 10 | 11 | public: 12 | Complex(int real = 0, int imag = 0) 13 | { 14 | this->real = real; 15 | this->imag = imag; 16 | } 17 | void display() 18 | { 19 | cout << real << "+i" << imag; 20 | } 21 | // Complex add(Complex x){ 22 | // Complex operator+(Complex x) 23 | friend Complex operator+(Complex c1, Complex c2); 24 | friend ostream & operator<<(ostream &o, Complex c1); 25 | }; 26 | 27 | Complex operator+(Complex c1, Complex c2) 28 | { 29 | Complex temp; 30 | temp.real = c1.real + c2.real; 31 | temp.imag = c1.imag + c2.imag; 32 | return temp; 33 | }; 34 | ostream &operator<<(ostream &o, Complex c1){ 35 | o< 2 | using namespace std; 3 | class Complex{ 4 | public: 5 | int real; 6 | int imag; 7 | 8 | public: 9 | Complex(int real = 0 , int imag = 0){ 10 | this->real = real; 11 | this->imag = imag; 12 | } 13 | 14 | // Complex add(Complex x){ 15 | Complex operator+(Complex x){ 16 | Complex temp; 17 | temp.real = real + x.real; 18 | temp.imag = imag + x.imag; 19 | return temp; 20 | } 21 | }; 22 | int main(){ 23 | Complex c1(4,5); 24 | Complex c2(3,6); 25 | Complex c3; 26 | // c3 = c1.add(c2) ; 27 | c3 = c1+c2 ; 28 | cout<<"Value of C3 is: "< 2 | using namespace std; 3 | 4 | class Rational{ 5 | private: 6 | int nu; 7 | int du; 8 | public: 9 | Rational(int nu = 0 , int du = 0 ){ 10 | this->nu = nu; 11 | this->du = du; 12 | } 13 | 14 | friend Rational operator+(Rational r1,Rational r2); 15 | friend ostream & operator<<(ostream &o,Rational &c3); 16 | }; 17 | Rational operator+(Rational r1, Rational r2) 18 | { 19 | Rational temp; 20 | temp.nu = r1.nu * r2.du + r1.du * r2.nu; 21 | temp.du = r1.du * r2.du; 22 | return temp; 23 | } 24 | 25 | ostream &operator<<(ostream &o, Rational &c3) { 26 | o< 2 | using namespace std; 3 | 4 | class Complex 5 | { 6 | private: 7 | int real; 8 | int imag; 9 | 10 | public: 11 | Complex(int real = 0, int imag = 0) 12 | { 13 | this->real = real; 14 | this->imag = imag; 15 | } 16 | 17 | // void display(){ 18 | // cout< 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | Base() 8 | { 9 | cout << "Default of Base Class"< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int width; 9 | 10 | public: 11 | void rectangle(int l = 0, int b = 0) 12 | { 13 | setLength(l); 14 | setWidth(b); 15 | } 16 | int setLength(int l) 17 | { 18 | if (l > 0) 19 | { 20 | this->length = l; 21 | } 22 | else 23 | { 24 | this->length = 0; 25 | } 26 | } 27 | 28 | int setWidth(int b) 29 | { 30 | if (b > 0) 31 | { 32 | this->width = b; 33 | } 34 | else 35 | { 36 | this->width = 0; 37 | } 38 | } 39 | 40 | int getLength() 41 | { 42 | return length; 43 | } 44 | int getwidth() 45 | { 46 | return width; 47 | } 48 | 49 | double area() 50 | { 51 | return (length * width); 52 | } 53 | 54 | double perimeter() 55 | { 56 | return 2 * (length + width); 57 | } 58 | }; 59 | 60 | class Cubiod : public Rectangle 61 | { 62 | private: 63 | int height; 64 | 65 | public: 66 | Cubiod(int h, int l, int b){ 67 | setHeight(h); 68 | setLength(l); 69 | setWidth(b); 70 | } 71 | 72 | int setHeight(int h){ 73 | this->height = h; 74 | } 75 | 76 | int getHeight(){ 77 | return this->height; 78 | } 79 | 80 | int volume(){ 81 | return getLength() * getwidth() * height; 82 | } 83 | public: 84 | }; 85 | int main(){ 86 | Cubiod c(10,20,30); 87 | cout<<"Area is: "< 2 | using namespace std; 3 | 4 | class Base{ 5 | public: 6 | void fun1(){ 7 | cout<<"fun1"<fun1(); 33 | b->fun2(); 34 | b->fun3(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /10. Base_Class_Pointer_Derived_Class_Object/demo2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class BaseCar{ 5 | public: 6 | void start(){ 7 | cout<<"Starting Car"; 8 | } 9 | }; 10 | 11 | class AdvanceCar:public BaseCar{ 12 | public: 13 | void playMusic(){ 14 | cout<<"Playing Music"; 15 | } 16 | }; 17 | 18 | int main(){ 19 | // BaseCar *b; 20 | // b = new AdvanceCar(); 21 | 22 | AdvanceCar *A; 23 | A = new AdvanceCar(); 24 | A->start(); 25 | A->playMusic(); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /10. Base_Class_Pointer_Derived_Class_Object/first.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base{ 4 | public: 5 | Base(){ 6 | cout<<"Base Class"; 7 | } 8 | }; 9 | 10 | class Derived:public Base{ 11 | public: 12 | Derived(){ 13 | cout<<"Derived Class"; 14 | } 15 | }; 16 | 17 | int main(){ 18 | Base *b; 19 | b = new Derived(); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /11. Polymorphism/Polymorhpism.txt: -------------------------------------------------------------------------------- 1 | Redefining the functions -------------------------------------------------------------------------------- /11. Polymorphism/abstract.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Car{ 5 | public: 6 | virtual void display()=0; 7 | }; 8 | 9 | class Range: public Car{ 10 | public: 11 | void display(){ 12 | cout<<"Car Started"; 13 | } 14 | }; 15 | 16 | int main(){ 17 | Car *c; 18 | c = new Range(); 19 | c->display(); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /11. Polymorphism/carExample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Base{ 5 | public: 6 | virtual void start(){ 7 | cout<<"Base Car Started"; 8 | } 9 | }; 10 | 11 | class Child:public Base{ 12 | public: 13 | void start(){ 14 | cout<<"Child Car Started"; 15 | } 16 | }; 17 | 18 | int main(){ 19 | // Child c; 20 | // Base *b; 21 | // b = &c; 22 | 23 | Base *b = new Child(); 24 | b->start(); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /11. Polymorphism/demo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Parent{ 4 | public: 5 | void display(){ 6 | cout<<"Display Parent"; 7 | } 8 | }; 9 | 10 | int main(){ 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /11. Polymorphism/virtualFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Base{ 5 | public: 6 | virtual void display(){ 7 | cout<<"Base Class Display"; 8 | } 9 | }; 10 | 11 | class Child:public Base{ 12 | public: 13 | void display(){ 14 | cout<<"Child Class Display"; 15 | } 16 | }; 17 | 18 | int main(){ 19 | Base *b = new Child(); 20 | b->display(); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /12. Some_Keywords/friendClass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | class your; 6 | class my{ 7 | private: 8 | int a; 9 | protected: 10 | int b; 11 | public: 12 | int c; 13 | 14 | friend your; 15 | 16 | }; 17 | class your{ 18 | public: 19 | my m; 20 | void fun(){ 21 | m.a = 20; 22 | m.b = 40; 23 | m.c = 50; 24 | cout<<"Value of a: "< 2 | using namespace std; 3 | 4 | class Test{ 5 | private: 6 | int a; 7 | protected: 8 | int b; 9 | public: 10 | int c; 11 | 12 | friend void fun(); 13 | 14 | }; 15 | 16 | void fun(){ 17 | Test t; // has-a relationship 18 | t.a = 20 ; 19 | t.b = 40; 20 | t.c = 50; 21 | cout< 2 | using namespace std; 3 | 4 | class Test 5 | { 6 | private: 7 | int a, b; 8 | 9 | public: 10 | static int count; 11 | 12 | Test() 13 | { 14 | a = 10; 15 | b = 20; 16 | count++; 17 | } 18 | static int coutnadd(){ 19 | return count; 20 | } 21 | }; 22 | 23 | int Test::count = 0; 24 | 25 | int main() 26 | { 27 | Test t1; 28 | Test t2; 29 | Test t3; 30 | 31 | cout< 2 | using namespace std; 3 | 4 | class Test{ 5 | private: 6 | int a,b; 7 | public: 8 | static int count; 9 | 10 | Test(){ 11 | a = 10; 12 | b = 20; 13 | count++; 14 | } 15 | }; 16 | 17 | int Test::count = 0; 18 | 19 | int main(){ 20 | Test t1; 21 | Test t2; 22 | Test t3; 23 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int x = -1; 7 | 8 | // Some code 9 | cout << "Before try \n"; 10 | try 11 | { 12 | cout << "Inside try \n"; 13 | if (x < 0) 14 | { 15 | throw x; 16 | cout << "After throw (Never executed) \n"; 17 | } 18 | } 19 | catch (int e) 20 | { 21 | cout << "Exception Caught "< 2 | using namespace std; 3 | template 4 | 5 | // T add(T x,T y){ 6 | // return x + y; 7 | // } 8 | 9 | R maxi(T x, R y){ 10 | return x>y?x:y; 11 | } 12 | 13 | int main(){ 14 | // cout< 2 | #define sqr(x)(x*x); 3 | #define co cout; 4 | #define ci cin; 5 | #define p 3.23; 6 | using namespace std; 7 | 8 | int main(){ 9 | cout< 2 | using namespace std; 3 | 4 | class Base{ 5 | public: 6 | Base(){ 7 | cout<<"Base Class Constructor"< 2 | using namespace std; 3 | 4 | class Demo{ 5 | public: 6 | Demo(){ 7 | cout<<"Base Class Constructor"< 2 | using namespace std; 3 | 4 | class Demo{ 5 | public: 6 | int *p; 7 | 8 | Demo(){ 9 | p = new int[5]; 10 | cout<<"Enter the Array Values: "; 11 | for (int i = 0; i < 5; i++) 12 | { 13 | cin>>p[i]; 14 | } 15 | for (int i = 0; i < 5; i++) 16 | { 17 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 20; 6 | int b =40; 7 | int result = [&]() ->auto{return a + b;}(); 8 | cout<<"result: "< 2 | #include 3 | using namespace std; 4 | 5 | class Rectangle 6 | { 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | Rectangle(int a, int b) 12 | { 13 | length = a; 14 | breadth = b; 15 | } 16 | 17 | int area() 18 | { 19 | return length * breadth; 20 | } 21 | int perimeter() 22 | { 23 | return 2 + (length + breadth); 24 | } 25 | }; 26 | 27 | int main() 28 | { 29 | unique_ptr ptr(new Rectangle(3,4)); 30 | // unique_ptr ptr(new Rectangle(3, 4)); 31 | cout << ptr->area(); 32 | cout << ptr->perimeter(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /18. Patterns/Half_pyramid_using_asterik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | 5 | int row; 6 | cout<<"Enter the Row: "; 7 | cin>>row; 8 | for (int i = 1; i <= row; i++) 9 | { 10 | for (int j = 1; j <= i; j++){ 11 | cout<<" * "; 12 | } 13 | cout< 2 | using namespace std; 3 | int main(){ 4 | 5 | int row; 6 | cout<<"Enter the Row: "; 7 | cin>>row; 8 | for (int i = row; i >=1; i--) 9 | { 10 | for (int j = 1; j <= i; j++){ 11 | cout<<" * "; 12 | } 13 | cout< 2 | using namespace std; 3 | int main(){ 4 | 5 | int row; 6 | cout<<"Enter the Row: "; 7 | cin>>row; 8 | for (int i = 1; i <= row; i++) 9 | { 10 | for (int j = 1; j <= i; j++){ 11 | cout< 2 | using namespace std; 3 | int main(){ 4 | 5 | int row; 6 | cout<<"Enter the Row: "; 7 | cin>>row; 8 | for (int i = row; i >=1; i--) 9 | { 10 | for (int j = 1; j <= i; j++){ 11 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int row,col; 7 | cout<<"Enter the Row and columns: "; 8 | cin>>row>>col; 9 | for (int i = 1; i <= row; i++) 10 | { 11 | for (int j = 1; j <= col; j++) 12 | { 13 | if (i == 1 || i == row || 14 | j == 1 || j == col) 15 | cout << "*"; 16 | else 17 | cout << " "; 18 | } 19 | cout << endl; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /18. Patterns/Rectangle_Pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int cols,rows; 5 | cout<<"Enter the Cols "<>cols; 7 | cout<<"Enter the Rows "<>rows; 9 | for(int i=1 ; i<=cols ; ++i){ 10 | for(int j=1 ; j<=rows ;++j){ 11 | cout<<"*"; 12 | } 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int row; 6 | cout << "Enter your rows: "; 7 | cin >> row; 8 | for (int i = 1; i <= row; i++) 9 | { 10 | for (int j = 1; j <= row - i; j++) 11 | { 12 | cout << " & "; 13 | } 14 | for (int j = 1; j <=row; j++) 15 | { 16 | cout<<" * "; 17 | } 18 | cout << endl; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /18. Patterns/Snaps/Half pyramid using asterik after 180 degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Half pyramid using asterik after 180 degree.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/Half pyramid using asterik.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Half pyramid using asterik.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/Half pyramid using no after 180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Half pyramid using no after 180.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/Half pyramid using no.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Half pyramid using no.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/Hollow rectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Hollow rectangle.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/Rectangle patterns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Rectangle patterns.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/Rombous Patterns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/Rombous Patterns.png -------------------------------------------------------------------------------- /18. Patterns/Snaps/program to print the ascii values.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/18. Patterns/Snaps/program to print the ascii values.png -------------------------------------------------------------------------------- /18. Patterns/dumy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int row; 6 | cout << "Enter your rows: "; 7 | cin >> row; 8 | for (int i = 1; i <= row; i++) 9 | { 10 | for (int j = 1; j <= row - i; j++) 11 | { 12 | cout << " & "; 13 | } 14 | for (int j = 1; j <=row; j++) 15 | { 16 | cout<<" * "; 17 | } 18 | cout << endl; 19 | 20 | } 21 | 22 | } // namespace std; 23 | 24 | // #include 25 | // using namespace std; 26 | // int main(){ 27 | 28 | // int row; 29 | // cout<<"Enter the Row: "; 30 | // cin>>row; 31 | // for (int i = 1; i <= row; i++) 32 | // { 33 | // for (int j = 1; j <= row-i; j++){ 34 | // cout<<" - "; 35 | // } 36 | // for (int j = 1; j <= row; j++) 37 | // { 38 | // cout<<" * "; 39 | // } 40 | 41 | // cout< 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | 8 | int arr[] = {1, 10, 11, 9, 100}; 9 | int n = sizeof(arr) / sizeof(int); 10 | //Search --> find 11 | 12 | int key ; 13 | cin >> key; 14 | auto it = find(arr, arr + n, key); 15 | int index = it - arr; 16 | if (index == n) { 17 | cout << key << " not present"; 18 | } 19 | else { 20 | cout << "Present at index " << index; 21 | } 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Algorithms/algo_stl_02_binary_search_lower_upper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | 8 | int arr[] = {20, 30, 40, 40, 40, 50, 100, 1100}; 9 | int n = sizeof(arr) / sizeof(int); 10 | //Search in a sorted array 11 | int key ; 12 | cin >> key; 13 | 14 | bool present = binary_search(arr, arr + n, key); //logN 15 | if (present) { 16 | cout << "Present"; 17 | } 18 | else { 19 | cout << "Absent!"; 20 | } 21 | 22 | //Two more things 23 | // Get the index of the element 24 | // lower_bound(s,e,key) and upper_bound(s,e,key) 25 | 26 | auto lb = lower_bound(arr, arr + n, 41); 27 | cout << endl << "Lower bound of 40 is" << (lb - arr) << endl; 28 | 29 | 30 | //uppper bound method 31 | auto ub = upper_bound(arr, arr + n, 40); 32 | cout << endl << "Upper bound of 40 is" << (ub - arr) << endl; 33 | 34 | cout << "Occ Freq of 40 is " << (ub - lb) << endl; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Algorithms/algo_stl_06_next_permuation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() { 6 | 7 | int arr[] = {10, 20, 30, 40, 50}; 8 | int n = sizeof(arr) / sizeof(int); 9 | rotate(arr, arr + 2, arr + n); 10 | 11 | for (int i = 0; i < n; i++) { 12 | cout << arr[i] << " "; 13 | } 14 | cout << endl; 15 | //Apply the same on a vector 16 | vector v{1, 2, 3}; 17 | 18 | //rotate(v.begin(),v.begin()+3,v.end()); 19 | 20 | for (int i = 0; i < v.size(); i++) { 21 | cout << v[i] << " "; 22 | } 23 | 24 | //Next_permuation 25 | next_permutation(v.begin(), v.end()); 26 | next_permutation(v.begin(), v.end()); 27 | cout << endl; 28 | //for each loop 29 | for (int x : v) { 30 | cout << x << " "; 31 | } 32 | 33 | 34 | 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Algorithms/algo_stl_money_change_problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int a = 10; 8 | int b = 20; 9 | 10 | swap(a, b); 11 | cout << a << " and " << b << endl; 12 | 13 | cout << max(a, b) << endl; 14 | cout << min(a, b) << endl; 15 | 16 | int arr[] = {1, 2, 3, 4, 4, 5}; 17 | reverse(arr, arr + 4); 18 | 19 | swap(arr[0], arr[1]); 20 | 21 | int n = sizeof(arr) / sizeof(int); 22 | for (int i = 0; i < n; i++) { 23 | cout << arr[i] << " "; 24 | } 25 | next_permutation(arr, arr + n); 26 | cout << endl; 27 | for (int i = 0; i < n; i++) { 28 | cout << arr[i] << " "; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Algorithms/money.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | 7 | int indian_currency[] = {1, 2, 5, 10, 20, 50, 100, 200, 500, 2000}; 8 | int n = sizeof(indian_currency) / sizeof(int); 9 | 10 | bool compare(int a, int b) { 11 | return a <= b; 12 | } 13 | 14 | void count_notes(int money) { 15 | 16 | // Base Case 17 | if (money == 0) { 18 | return; 19 | } 20 | //Recursive Case 21 | // lower_bound will return an iterator 22 | // Log (T) where T is the type of coins you have! 23 | 24 | int largest_idx = lower_bound(indian_currency, indian_currency + n, money, compare) - indian_currency - 1; 25 | int m = indian_currency[largest_idx]; 26 | cout << m << " " << endl; 27 | 28 | //Recursive Call 29 | count_notes(money - m); 30 | 31 | return; 32 | 33 | } 34 | 35 | int main() { 36 | 37 | int money; 38 | cin >> money; 39 | 40 | count_notes(money); 41 | 42 | 43 | return 0 ; 44 | } -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Algorithms/other_methods.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int a = 10; 8 | int b = 20; 9 | 10 | swap(a, b); 11 | cout << a << " and " << b << endl; 12 | 13 | cout << max(a, b) << endl; 14 | cout << min(a, b) << endl; 15 | 16 | int arr[] = {1, 2, 3, 4, 4, 5}; 17 | reverse(arr, arr + 4); 18 | 19 | swap(arr[0], arr[1]); 20 | 21 | int n = sizeof(arr) / sizeof(int); 22 | for (int i = 0; i < n; i++) { 23 | cout << arr[i] << " "; 24 | } 25 | next_permutation(arr, arr + n); 26 | cout << endl; 27 | for (int i = 0; i < n; i++) { 28 | cout << arr[i] << " "; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Algorithms/pair_stl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | 7 | 8 | //Pair 9 | pair p; 10 | p.first = 10; 11 | p.second = 'B'; 12 | 13 | //Another way 14 | pair p2(p); 15 | 16 | cout<< p2.first< p3 = make_pair(100,"Audi"); 20 | cout<>a>>b; 25 | 26 | pair p4 = make_pair(a,b); 27 | //Array of Pairs 28 | //Vector of Pairs 29 | pair, string> car; 30 | car.second = "Audi"; 31 | car.first.first = 10; 32 | car.first.second = 20; 33 | 34 | cout< 2 | #include 3 | using namespace std; 4 | 5 | template 6 | int search(T arr[],int n,T key){ 7 | 8 | for(int p=0;p 18 | ForwardIterator search(ForwardIterator start,ForwardIterator end, T key){ 19 | 20 | while(start!=end){ 21 | if(*start==key){ 22 | return start; 23 | } 24 | start++; 25 | } 26 | return end; 27 | } 28 | 29 | int main() { 30 | /* 31 | int arr[] = {1,3,5,7,10,12}; 32 | int n = sizeof(arr)/sizeof(int); 33 | cout< l; 36 | 37 | l.push_back(1); 38 | l.push_back(2); 39 | l.push_back(5); 40 | l.push_back(3); 41 | 42 | auto it = search(l.begin(),l.end(),50); 43 | if(it==l.end()){ 44 | cout<<"element not present"; 45 | } 46 | else{ 47 | cout<<*it< 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | list l; 8 | 9 | //Init 10 | list l1{1,2,3,10,8,5}; 11 | //Different Datatype 12 | list l2{"apple","guava","mango","banana"}; 13 | l2.push_back("pineapple"); 14 | 15 | //sort 16 | l2.sort(); 17 | 18 | //reverse 19 | l2.reverse(); 20 | 21 | // pop_front 22 | cout< "; 33 | } 34 | cout<"; 43 | } 44 | cout<>f; 48 | //l2.remove(f); 49 | for(string s:l2){ 50 | cout<"; 51 | } 52 | cout<"; 62 | } 63 | cout<"; 72 | } 73 | 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Maps/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/19. STL/0. Codes - All Modules/Maps/.DS_Store -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Maps/map_stl_01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | map m; 9 | 10 | //1. Insert 11 | m.insert(make_pair("Mango",100)); 12 | 13 | pair p; 14 | p.first = "Apple"; 15 | p.second = 120; 16 | 17 | m.insert(p); 18 | 19 | m["Banana"] = 20; 20 | 21 | //2. Search 22 | string fruit; 23 | cin>>fruit; 24 | 25 | //update the price 26 | m[fruit] += 22; 27 | 28 | auto it = m.find(fruit); 29 | 30 | if(it!=m.end()){ 31 | cout<<"price of "<first<<" and "<second< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class node{ 7 | public: 8 | int data; 9 | node*left; 10 | node*right; 11 | 12 | node(int d){ 13 | data = d; 14 | left = right = NULL; 15 | } 16 | }; 17 | //pass it by reference 18 | void verticalOrderPrint(node*root, int d,map > &m){ 19 | //base case 20 | if(root==NULL){ 21 | return; 22 | } 23 | //otherwise 24 | m[d].push_back(root->data); 25 | verticalOrderPrint(root->left,d-1,m); 26 | verticalOrderPrint(root->right,d+1,m); 27 | return; 28 | } 29 | 30 | int main(){ 31 | 32 | node*root = new node(1); 33 | root->left = new node(2); 34 | root->right = new node(3); 35 | root->left->left = new node(4); 36 | root->left->right = new node(5); 37 | 38 | root->right->left = new node(6); 39 | root->right->right = new node(7); 40 | 41 | root->right->right->right = new node(9); 42 | 43 | root->left->right->right = new node(8); 44 | 45 | map > m; 46 | int d = 0; 47 | verticalOrderPrint(root,d,m); 48 | 49 | for(auto p:m){ 50 | // cout<"; 51 | for(int x:p.second){ 52 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | multimap m; 8 | int n; 9 | cin>>n; 10 | 11 | for(int i=0;i>ch>>s; 15 | m.insert(make_pair(ch,s)); 16 | } 17 | auto it = m.begin(); 18 | m.erase(it); 19 | 20 | auto it2 = m.lower_bound('b'); //batman 21 | auto it3 = m.upper_bound('d'); //elephant 22 | for(auto it4=it2;it4!=it3;it4++){ 23 | cout<second<<" ,"<second=="cat"){ 28 | m.erase(f); 29 | } 30 | 31 | //Try to print the entire map 32 | for(auto p:m){ 33 | cout< "< 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | map > > citymap; 10 | 11 | int E; 12 | cin>>E; 13 | for(int i=0;i>src>>dest>>dist; 17 | citymap[src].push_back(make_pair(dest,dist)); 18 | citymap[dest].push_back(make_pair(src,dist)); 19 | } 20 | 21 | //Iterate over this 22 | for(auto p:citymap){ 23 | cout<"; 24 | for(auto dd:p.second){ 25 | cout<<"("< 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | 7 | 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Priority Queue/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/19. STL/0. Codes - All Modules/Priority Queue/.DS_Store -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Priority Queue/functor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Fun{ 6 | public: 7 | void operator()(string s){ 8 | cout<<"Having Fun with "< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | priority pq_max; //max priority queue 7 | priority_queue, greater > pq; //min priority queue 8 | 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=1;i>no; 15 | pq.push(no); //O(LogN) 16 | } 17 | 18 | //Remove the elements from the heap 19 | while(!pq.empty()){ 20 | cout<< pq.top()<<" "; 21 | pq.pop(); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Priority Queue/priority_queue_compartor_class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Fun{ 7 | public: 8 | void operator()(string s){ 9 | cout<<"Having Fun with "< B.age; 32 | } 33 | }; 34 | 35 | 36 | int main() { 37 | 38 | int n; 39 | cin>>n; 40 | 41 | priority_queue, PersonCompare > pq; 42 | 43 | for(int i=0;i>name>>age; 47 | Person p(name,age); 48 | pq.push(p); 49 | } 50 | int k = 3; 51 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | queue q; 8 | 9 | for(int i=1;i<=5;i++){ 10 | q.push(i); 11 | } 12 | 13 | while(!q.empty()){ 14 | cout<< q.front() <<" <-"; 15 | q.pop(); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Sets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/19. STL/0. Codes - All Modules/Sets/.DS_Store -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Sets/permute.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void permute(char a[],int i,set &s){ 7 | if(a[i]=='\0'){ 8 | //cout<>a; 25 | set s; 26 | permute(a,0,s); 27 | 28 | //loop over the s 29 | for(auto str:s){ 30 | cout< 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | list l; 8 | 9 | //Init 10 | list l1{1,2,3,10,8,5}; 11 | //Different Datatype 12 | list l2{"apple","guava","mango","banana"}; 13 | l2.push_back("pineapple"); 14 | 15 | //sort 16 | l2.sort(); 17 | 18 | //reverse 19 | l2.reverse(); 20 | 21 | // pop_front 22 | cout< "; 33 | } 34 | cout<"; 43 | } 44 | cout<>f; 48 | //l2.remove(f); 49 | for(string s:l2){ 50 | cout<"; 51 | } 52 | cout<"; 62 | } 63 | cout<"; 72 | } 73 | 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Stack/stack_stl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | 8 | stack s; 9 | 10 | for(int i=0;i<=5;i++){ 11 | s.push(i); 12 | } 13 | 14 | //Loop 15 | while(!s.empty()){ 16 | cout< 2 | #include 3 | using namespace std; 4 | 5 | // Implement a Stack using 2 Queues 6 | 7 | template 8 | class Stack{ 9 | queue q1,q2; 10 | public: 11 | void push(T x){ 12 | q1.push(x); 13 | } 14 | void pop(){ 15 | //remove the last added element from q1 16 | //we have to move first n-1 elements in q2 17 | //interchange the names of q1 and q2 18 | if(q1.empty()){ 19 | return; 20 | } 21 | while(q1.size()>1){ 22 | T element = q1.front(); 23 | q2.push(element); 24 | q1.pop(); 25 | } 26 | //removes the last element 27 | q1.pop(); 28 | //swap the names of q1 and q2 29 | swap(q1,q2); 30 | } 31 | T top(){ 32 | 33 | while(q1.size()>1){ 34 | T element = q1.front(); 35 | q2.push(element); 36 | q1.pop(); 37 | } 38 | 39 | //1 element in Q1 40 | T element = q1.front(); 41 | q1.pop(); 42 | q2.push(element); 43 | 44 | swap(q1,q2); 45 | return element; 46 | } 47 | int size(){ 48 | return q1.size() + q2.size(); 49 | } 50 | bool empty(){ 51 | return size()==0; 52 | } 53 | 54 | }; 55 | 56 | int main() { 57 | 58 | Stack s; 59 | s.push(1); 60 | s.push(2); 61 | s.push(3); 62 | 63 | while(!s.empty()){ 64 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | //String Init 8 | string s0; 9 | string s1("Hello"); 10 | 11 | string s2 = "Hello World!"; 12 | string s3(s2); 13 | 14 | string s4 = s3; 15 | 16 | char a[] = {'a','b','c','\0'}; 17 | string s5(a); 18 | 19 | cout< 0 or < 0 45 | 46 | 47 | //Overloaded Operator operators 48 | if(s1 > s0){ 49 | cout<<"Mango is lexi greater than Apple"< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | //String Init 8 | string s0; 9 | string s1("Hello"); 10 | 11 | string s2 = "Hello World!"; 12 | string s3(s2); 13 | 14 | string s4 = s3; 15 | 16 | char a[] = {'a','b','c','\0'}; 17 | string s5(a); 18 | 19 | cout< 0 or < 0 45 | 46 | 47 | //Overloaded Operator operators 48 | if(s1 > s0){ 49 | cout<<"Mango is lexi greater than Apple"< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | bool compare(string a,string b){ 7 | if(a.length()==b.length()){ 8 | return ab.length(); 11 | } 12 | 13 | int main() { 14 | int n; 15 | cin>>n; 16 | cin.get(); 17 | 18 | string s[100]; //Vector 19 | 20 | for(int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | bool compare(string a,string b){ 7 | if(a.length()==b.length()){ 8 | return ab.length(); 11 | } 12 | 13 | int main() { 14 | int n; 15 | cin>>n; 16 | cin.get(); 17 | 18 | string s[100]; //Vector 19 | 20 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | //char *strtok(char *s,char *delimiters) 6 | // returns a token on each subsequent call 7 | // on the first call function should be passed with string argument for 's' 8 | // on subsequent calls we should pass the string argument as null 9 | 10 | int main() { 11 | 12 | char s[100] = "Today, is a rainy, day"; 13 | 14 | char *ptr = strtok(s," "); 15 | cout< 2 | #include 3 | using namespace std; 4 | 5 | //char *strtok(char *s,char *delimiters) 6 | // returns a token on each subsequent call 7 | // on the first call function should be passed with string argument for 's' 8 | // on subsequent calls we should pass the string argument as null 9 | 10 | int main() { 11 | 12 | char s[100] = "Today, is a rainy, day"; 13 | 14 | char *ptr = strtok(s," "); 15 | cout< 2 | #include 3 | using namespace std; 4 | 5 | char *mystrtok(char *str,char delim){ 6 | //string and single char acts as delimiter 7 | static char*input = NULL; 8 | if(str!=NULL){ 9 | //we are maing the first call 10 | input = str; 11 | } 12 | //check here -base case after the final token has been returned 13 | if(input==NULL){ 14 | return NULL; 15 | } 16 | 17 | //start extracting tokens and store them in an array 18 | char *output = new char[strlen(input)+1]; 19 | int i=0; 20 | for( ;input[i]!='\0';i++){ 21 | if(input[i]!=delim){ 22 | output[i] = input[i]; 23 | } 24 | else{ 25 | output[i] = '\0'; 26 | input = input + i + 1; 27 | return output; 28 | } 29 | } 30 | //corner case 31 | output[i] = '\0'; 32 | input = NULL; 33 | return output; 34 | } 35 | 36 | 37 | 38 | int main() { 39 | 40 | char s[100] = "Today, is a rainy, day"; 41 | 42 | char *ptr = mystrtok(s,' '); 43 | cout< 2 | #include 3 | using namespace std; 4 | 5 | char *mystrtok(char *str,char delim){ 6 | //string and single char acts as delimiter 7 | static char*input = NULL; 8 | if(str!=NULL){ 9 | //we are maing the first call 10 | input = str; 11 | } 12 | //check here -base case after the final token has been returned 13 | if(input==NULL){ 14 | return NULL; 15 | } 16 | 17 | //start extracting tokens and store them in an array 18 | char *output = new char[strlen(input)+1]; 19 | int i=0; 20 | for( ;input[i]!='\0';i++){ 21 | if(input[i]!=delim){ 22 | output[i] = input[i]; 23 | } 24 | else{ 25 | output[i] = '\0'; 26 | input = input + i + 1; 27 | return output; 28 | } 29 | } 30 | //corner case 31 | output[i] = '\0'; 32 | input = NULL; 33 | return output; 34 | } 35 | 36 | 37 | 38 | int main() { 39 | 40 | char s[100] = "Today, is a rainy, day"; 41 | 42 | char *ptr = mystrtok(s,' '); 43 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main(){ 8 | 9 | unordered_map > phonebook; 10 | 11 | phonebook["rahul"].push_back("9110"); 12 | phonebook["rahul"].push_back("9112"); 13 | phonebook["rahul"].push_back("9113"); 14 | phonebook["rahul"].push_back("9114"); 15 | phonebook["kajal"].push_back("8112"); 16 | phonebook["kajal"].push_back("8113"); 17 | phonebook["kajal"].push_back("8114"); 18 | 19 | for(auto p:phonebook){ 20 | cout<<"Name" <"; 21 | for(string s:p.second){ 22 | cout<>name; 29 | 30 | if(phonebook.count(name)==0){ 31 | cout<<"Absent "; 32 | } 33 | else{ 34 | for(string s:phonebook[name]){ 35 | cout< 2 | #include 3 | using namespace std; 4 | 5 | class Node{ 6 | public: 7 | char data; 8 | unordered_map children; 9 | bool terminal; 10 | 11 | Node(char d){ 12 | data = d; 13 | terminal = false; 14 | } 15 | }; 16 | 17 | class Trie{ 18 | Node* root; 19 | int cnt; 20 | 21 | public: 22 | 23 | Trie(){ 24 | root = new Node('\0'); 25 | cnt = 0; 26 | } 27 | 28 | void insert(char *w){ 29 | 30 | Node* temp = root; 31 | for(int i=0;w[i]!='\0';i++){ 32 | 33 | char ch = w[i]; 34 | if(temp->children.count(ch)){ 35 | temp = temp->children[ch]; 36 | } 37 | else{ 38 | Node* n = new Node(ch); 39 | temp->children[ch] = n; 40 | temp = n; 41 | } 42 | } 43 | temp->terminal = true; 44 | } 45 | 46 | bool find(char *w){ 47 | Node* temp = root; 48 | for(int i=0;w[i]!='\0';i++){ 49 | char ch = w[i]; 50 | if(temp->children.count(ch)==0){ 51 | return false; 52 | } 53 | else{ 54 | temp = temp->children[ch]; 55 | } 56 | } 57 | return temp->terminal; 58 | } 59 | }; 60 | 61 | int main(){ 62 | 63 | Trie t; 64 | char words[][10] = {"a","hello","not","news","apple"}; 65 | char w[10]; 66 | cin>>w; 67 | 68 | for(int i=0;i<5;i++){ 69 | t.insert(words[i]); 70 | } 71 | 72 | if(t.find(w)){ 73 | cout<<"Present"; 74 | } 75 | else{ 76 | cout<<"Absent"; 77 | } 78 | 79 | return 0; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Unordered Map/unordered_map_stl_01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | unordered_map m; 9 | 10 | //1. Insert 11 | m.insert(make_pair("Mango",100)); 12 | 13 | pair p; 14 | p.first = "Apple"; 15 | p.second = 120; 16 | 17 | m.insert(p); 18 | 19 | m["Banana"] = 20; 20 | 21 | //2. Search 22 | string fruit; 23 | cin>>fruit; 24 | 25 | //update the price 26 | m[fruit] += 22; 27 | 28 | auto it = m.find(fruit); 29 | 30 | if(it!=m.end()){ 31 | cout<<"price of "<first<<" and "<second< 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | 7 | 8 | //Pair 9 | pair p; 10 | p.first = 10; 11 | p.second = 'B'; 12 | 13 | //Another way 14 | pair p2(p); 15 | 16 | cout<< p2.first< p3 = make_pair(100,"Audi"); 20 | cout<>a>>b; 25 | 26 | pair p4 = make_pair(a,b); 27 | //Array of Pairs 28 | //Vector of Pairs 29 | pair, string> car; 30 | car.second = "Audi"; 31 | car.first.first = 10; 32 | car.first.second = 20; 33 | 34 | cout< 4 | class Vector { 5 | int cs; 6 | int ms; 7 | T *arr; 8 | 9 | public: 10 | Vector() { 11 | cs = 0; 12 | ms = 1; 13 | arr = new T[ms]; 14 | } 15 | void push_back(const T d) { 16 | if (cs == ms) { 17 | //Array if full 18 | T *oldArr = arr; 19 | arr = new T[2 * ms]; 20 | ms = 2 * ms; 21 | for (int i = 0; i < cs; i++) { 22 | arr[i] = oldArr[i]; 23 | } 24 | //clear the old memory 25 | delete [] oldArr; 26 | } 27 | arr[cs] = d; 28 | cs++; 29 | } 30 | void pop_back() { 31 | cs--; 32 | } 33 | 34 | T front() const { 35 | return arr[0]; 36 | } 37 | T back() const { 38 | return arr[cs - 1]; 39 | } 40 | bool empty() const { 41 | return cs == 0; 42 | } 43 | 44 | int capacity() const { 45 | return ms; 46 | } 47 | T at(const int i) { 48 | return arr[i]; 49 | } 50 | int size() const { 51 | return cs; 52 | } 53 | 54 | //operator overloading 55 | T operator[](const int i) { 56 | return arr[i]; 57 | } 58 | 59 | }; -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Vectors/vector_demo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "vector.h" 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | Vector v; 8 | 9 | v.push_back(71); 10 | 11 | v.push_back(72); 12 | 13 | v.push_back(73); 14 | 15 | v.push_back(74); 16 | v.pop_back(); 17 | v.push_back(76); 18 | v.push_back(80); 19 | 20 | cout << "Capacity " << v.capacity() << endl; 21 | 22 | for (int i = 0; i < v.size(); i++) { 23 | cout << v[i] << " "; 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Vectors/vector_stl_01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | int main() { 6 | 7 | //You can create and initalise a vector 8 | vector a; 9 | vector b(5, 10); //five int with value 10 - init a vector of zeros (n,0) 10 | vector c(b.begin(), b.end()); 11 | vector d{1, 2, 3, 10, 14}; 12 | vector v(10); //vector of 10 zeroes 13 | 14 | 15 | //Look at how we can iterate over the vector 16 | for (int i = 0; i < c.size(); i++) { 17 | cout << c[i] << ","; 18 | } 19 | cout << endl; 20 | 21 | for (auto it = b.begin(); it != b.end(); it++) { 22 | cout << (*it) << ","; 23 | } 24 | cout << endl; 25 | //For each loop 26 | for (int x : d) { 27 | cout << x << ","; 28 | } 29 | cout << endl; 30 | 31 | //Discuss more functions 32 | vector v; 33 | int n; 34 | cin >> n; 35 | for (int i = 0; i < n; i++) { 36 | int no; 37 | cin >> no; 38 | v.push_back(no); 39 | } 40 | 41 | for (int x : v) { 42 | cout << x << ","; 43 | } 44 | cout << endl; 45 | //Understand at memory level, what are the differences in the two 46 | cout << v.size() << endl; 47 | cout << v.capacity() << endl; //size of underlying array 48 | cout << v.max_size() << endl; // maximum no of elements a vector can hold in the worst case acc to avbl memory in the system 49 | 50 | 51 | cout << d.size() << endl; 52 | cout << d.capacity() << endl; //size of underlying array 53 | cout << d.max_size() << endl; // maximum no of elements a vector can hold in the worst case acc to avbl memory in the system 54 | 55 | 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /19. STL/0. Codes - All Modules/Vectors/vector_stl_02.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | int main() { 6 | 7 | 8 | vector d{1,2,3,10,14}; 9 | //Push Back O(1) for most of the time 10 | d.push_back(16); 11 | 12 | //Pop Back / Removes the last element O(1) 13 | d.pop_back(); 14 | 15 | //Insert some elements in the middle O(N) 16 | d.insert(d.begin() + 3,4,100); 17 | 18 | //erase some elements in the middle 19 | d.erase(d.begin()+2); 20 | d.erase(d.begin()+2,d.begin()+5); 21 | 22 | //size 23 | cout<>n; 53 | vector v; 54 | //To avoid doubling, we will use reserve function 55 | v.reserve(1000); 56 | 57 | for(int i=0;i>no; 60 | v.push_back(no); 61 | cout<<"Changing capacity "< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | vector a; 7 | vector b(5,10); //five ints with value 10 8 | vector c(b.begin(),b.end()); 9 | vector d{1,2,3,4,5}; 10 | 11 | int A[] = {1,2,3,4,5}; 12 | vector v; 13 | for(int i=0;i<5;i++){ 14 | v.push_back(A[i]); 15 | } 16 | 17 | for(int x:v){ 18 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | priority_queue v; 6 | v.push(1); 7 | v.push(2); 8 | 9 | cout<<"Item at Top: " << v.top() < 2 | using namespace std; 3 | 4 | int main(){ 5 | queue v; 6 | v.push(1); 7 | v.push(2); 8 | v.push(3); 9 | v.push(4); 10 | 11 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int A[] = {1, 2, 4, 5, 6, 7}; 6 | int n = sizeof(A) / sizeof(A[0]); 7 | 8 | // Perform binary search 9 | bool re = binary_search(A, A + n, 3); 10 | 11 | // Print the result 12 | if (re) { 13 | cout << "Element found in the array." << endl; 14 | } else { 15 | cout << "Element not found in the array." << endl; 16 | } 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /19. STL/pair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | // pair contains the pair of two hetrogenous elements like this 8 | // pair(first, second ) pariName; 9 | 10 | pair abdullah = {"Abdullah", 20}; 11 | // cout << abdullah.first << endl; 12 | // cout << abdullah.second << endl; 13 | 14 | 15 | // array of pairs 16 | pair arr[3] = {{1,2},{4,5},{7,8}}; 17 | 18 | // Accessing and printing elements of pairs 19 | // Accessing the first element of the first pair 20 | cout << arr[0].first << endl; // Output: 1 21 | 22 | // Accessing the second element of the first pair 23 | cout << arr[0].second << endl; // Output: 2 24 | 25 | // Accessing the first element of the second pair 26 | cout << arr[1].first << endl; // Output: 4 27 | 28 | // Accessing the second element of the second pair 29 | cout << arr[1].second << endl; // Output: 5 30 | 31 | // Accessing the first element of the third pair 32 | cout << arr[2].first << endl; // Output: 7 33 | 34 | // Accessing the second element of the third pair 35 | cout << arr[2].second << endl; // Output: 8 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /19. STL/set/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | // set is unique and sorted 6 | set s; 7 | s.insert(1); 8 | s.insert(2); 9 | s.insert(2); 10 | s.insert(3); 11 | s.insert(4); 12 | s.insert(5); 13 | 14 | auto it = s.find(4); 15 | for(const int& elm:s){ 16 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | // pair pair_name = {"Abdullah",20}; 7 | // pair_name.first = "Omer"; 8 | // pair_name.second = 20; 9 | // cout< v; 13 | // v.push_back(1); 14 | // v.push_back(2); 15 | // v.push_back(3); 16 | // v.push_back(4); 17 | 18 | // v.emplace_back(5); 19 | // v.emplace_back(6); 20 | // v.emplace_back(7); 21 | 22 | // for (int i = 0; i < v.size(); i++) 23 | // { 24 | // cout<::iterator it = v.begin(); 28 | // for (; it != v.end(); ++it) 29 | // { 30 | // cout << *(it) << " "; 31 | // } 32 | 33 | // cout<::iterator its = v.end(); 36 | // its--; 37 | // cout << "Its Value: " << *(its) << endl; 38 | 39 | vector v(5,100); 40 | for(int i = 0 ; i < v.size(); i++){ 41 | cout< {1,2} 23 | v.emplace_back(3) {1,2} -> {1,2,3} 24 | 25 | 26 | vector can also be used as a pair 27 | 28 | vector> vector_name(5); 29 | vector_name.push_back({1,2}); // you have to put as a pair 30 | vector_name.push_back({3,4}); 31 | vector_name.push_back({5,6}); 32 | vector_name.push_back({7,8}); 33 | vector_name.push_back({9,10}); 34 | First value of 0 index is 1 35 | Second value of 0 index is 2 36 | First value of 1 index is 3 37 | Second value of 1 index is 4 38 | First value of 2 index is 5 39 | Second value of 2 index is 6 40 | First value of 3 index is 7 41 | Second value of 3 index is 8 42 | First value of 4 index is 9 43 | Second value of 4 index is 10 44 | 45 | 46 | 47 | vector < int > v(5); // mean five instance of 0 like this {0,0,0,0,0} 48 | v.push_back(1); {1} 49 | v.push_back(2); {1,2} 50 | v.push_back(3); { 1,2,3}; 51 | v.push_back(4); { 1,2,3,4}; 52 | 53 | v.emplace_back(1); {1} 54 | v.emplace_back(2); {1} -> {1,2} 55 | v.emplace_back(2); {1,2} -> {1,2,3} 56 | v.emplace_back(2); {1,2,3} -> {1,2,3,4} 57 | 58 | vector < int > v(5,100); // mean five instance of 100 like this {100,100,100,100,100} 59 | 60 | Copying Vector to Anther 61 | 62 | vector < int > v(5); 63 | vector c(v); -------------------------------------------------------------------------------- /19. STL/vector/vecotr_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | vector v; 6 | v.push_back(1); 7 | v.push_back(2); 8 | v.push_back(3); 9 | v.push_back(4); 10 | v.push_back(5); 11 | 12 | vector::iterator it = v.begin(); 13 | for (int i = 0; i < v.size(); i++) 14 | { 15 | cout<< *(it) << " "; 16 | it++; 17 | } 18 | vector::iterator its = v.end(); 19 | its--; 20 | cout<<"it: "<<*(its); 21 | 22 | 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /19. STL/vector/vector_emplace_back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | vector v; 6 | // v.emplace_back(1); 7 | // v.emplace_back(2); 8 | // v.emplace_back(3); 9 | // v.emplace_back(4); 10 | for (int i = 0; i < 1000; i++) 11 | { 12 | v.emplace_back(rand() * 10); 13 | } 14 | 15 | 16 | for (int i = 0; i < v.size(); i++) 17 | { 18 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | vector v = {1,2,3,4,5}; 6 | // for (auto it = v.begin() ; it != v.end() ; it++) 7 | // { 8 | // cout<<*(it) <<" "; 9 | // } 10 | // cout<::reverse_iterator its = v.rbegin(); 13 | // cout<<*(its); 14 | // cout< v1 = {1,2,3,4,5}; 54 | for (auto it = v1.begin() ; it != v1.end() ; it++) 55 | { 56 | cout<<*(it) <<" "; 57 | } 58 | vector v2 = {6,7,8,9,10}; 59 | for (auto it = v2.begin() ; it != v2.end() ; it++) 60 | { 61 | cout<<*(it) <<" "; 62 | } 63 | 64 | 65 | v1.swap(v2); 66 | return 0; 67 | } -------------------------------------------------------------------------------- /19. STL/vector/vector_pair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | vector> v; 7 | v.push_back({1, 2}); 8 | v.push_back({3, 4}); 9 | v.push_back({5, 6}); 10 | v.push_back({7, 8}); 11 | v.push_back({9, 10}); 12 | v.push_back({19, 20}); 13 | cout << "Value at index 0 , First Value: " << v[5].first << endl; 14 | cout << "Value at index 0 , Second Value: " << v[5].second << endl; 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /19. STL/vector/vector_push_back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | vector v; 6 | // v.push_back(1); 7 | // v.push_back(2); 8 | // v.push_back(3); 9 | // v.push_back(4); 10 | // v.push_back(5); 11 | // v.push_back(6); 12 | // v.push_back(7); 13 | for (int i = 0; i < 1000; ++i) { 14 | v.push_back(rand() * 12); 15 | } 16 | 17 | for (int i = 0; i < v.size(); i++) 18 | { 19 | cout< 2 | 3 | 4 | 5 | 40 | 41 | -------------------------------------------------------------------------------- /CPP/CPP.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CPP/bin/Debug/CPP.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/CPP/bin/Debug/CPP.exe -------------------------------------------------------------------------------- /CPP/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /CPP/obj/Debug/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/CPP/obj/Debug/main.o -------------------------------------------------------------------------------- /CppProperties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Mingw64", 5 | "includePath": [ 6 | "D:/PS/CPP/**" 7 | ], 8 | "defines": [], 9 | "compilerPath": "C:/MinGW/bin/g++.exe", 10 | "cStandard": "c11", 11 | "cppStandard": "c++17" 12 | } 13 | ], 14 | "version": 4 15 | } 16 | -------------------------------------------------------------------------------- /DSA CPP/Array/array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int a[] = {1,2,3,4,5,6}; 7 | for(auto x:a){ 8 | if (x==4){ 9 | break; 10 | cout< 2 | using namespace std; 3 | 4 | int ArmStrong(){ 5 | int n,d,sum = 0 ; 6 | cout<<"Enter the Number to Check the ArmStrong: "; 7 | cin>>n; 8 | int m = n; 9 | while (n > 0) 10 | { 11 | d = n % 10; 12 | n = n / 10; 13 | sum = sum + ( d * d * d); 14 | } 15 | if(m==sum){ 16 | cout<<"ArmStrong: "< 2 | using namespace std; 3 | 4 | int PalindRome(){ 5 | int n,rev=0,r; 6 | cout<<"Enter the Number to Check the Plaindrome: "; 7 | cin>>n; 8 | int m = n; 9 | while (n > 0) 10 | { 11 | r = n % 10; 12 | n = n / 10; 13 | rev = (rev * 10) + r; 14 | } 15 | if(rev == m){ 16 | cout<<"Palindrome: "< 2 | using namespace std; 3 | int main(){ 4 | int a,b; 5 | cout<<"Enter the Values to add a & b : "; 6 | cin>>a>>b; 7 | cout<< a + b; 8 | } 9 | int plandrom() 10 | { 11 | int n; 12 | cout<<"Enter the number "; 13 | cin<0) 17 | r=n%10; 18 | n=n/10; 19 | rev=(rev*10)+r; 20 | } 21 | if(rev=m){ 22 | cout<<"number is plandrom"; 23 | } 24 | else{ 25 | cout<<"number is not plandrom"; 26 | } 27 | int main(){ 28 | int plandrom() 29 | return 0; 30 | } 31 | 32 | 33 | 34 | } -------------------------------------------------------------------------------- /Final Term Exam Preperation/Function/built_in.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | float n = 20.2; 6 | // Built in Functions 7 | cout<<"Value Done of N: "< 2 | // #include 3 | // using namespace std; 4 | 5 | // int main(){ 6 | // cout< 13 | using namespace std; 14 | // #include 15 | #include 16 | int main () 17 | { 18 | cout< 2 | using namespace std; 3 | 4 | int isPrime(int num){ 5 | for (int i = 2; i <= num/2; i++) 6 | { 7 | if(i % 2 == 0){ 8 | cout<>num; 18 | int re = isPrime(num); 19 | if(re == 2 ){ 20 | cout<<"Its Prime"; 21 | } 22 | else{ 23 | cout<<"It's composite"; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Final Term Exam Preperation/Function/userdefined.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int func(int a = 20, int b= 20){ 4 | // cout< 2 | // using namespace std; 3 | 4 | // int a_1(int n){ 5 | // cout<<"Here Value of n is : "< 26 | using namespace std; 27 | 28 | int a_1(int n){ 29 | cout<<"Here Value of n is : "< 2 | using namespace std; 3 | 4 | struct students 5 | { 6 | string name[5]={"Abdullah","Omer","Hamza","Ali","Talha"}; 7 | int roll[5] = {1,2,3,4,5}; 8 | int marks[5][5] = {{989, 947, 977 , 923, 917}, 9 | {989, 947, 977 , 923, 917}, 10 | {989, 947, 977 , 923, 917}, 11 | {989, 947, 977 , 923, 917}, 12 | {989, 947, 977 , 923, 917}}; 13 | string sub[1][5] = { 14 | {"Physic","Math","Chemistry","Statistics","CN"}, 15 | }; 16 | 17 | }; 18 | 19 | 20 | union price 21 | { 22 | int dollar; 23 | char pound; 24 | float euro; 25 | }; 26 | 27 | 28 | int main(){ 29 | students st; 30 | int roll; 31 | cout<<"Enter the Roll No to Search the Result: "; 32 | cin>>roll; 33 | for (int i = 0; i <4; i++) 34 | { 35 | if (roll == st.roll[i]) 36 | { 37 | cout<<"==================\n\n"; 38 | cout<<"Name of Student: "< 2 | using namespace std; 3 | 4 | void Coffie(int brain){ 5 | if (brain == 1){ 6 | cout<<"Keep Coding "; 7 | } 8 | else{ 9 | cout<<"Order Coffe"; 10 | } 11 | } 12 | 13 | int main(){ 14 | int brain; 15 | cout<<"Enter the Brain Energy False(0) & True(1): "; 16 | cin>>brain; 17 | Coffie(brain); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Final Term Exam Preperation/brain.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/Final Term Exam Preperation/brain.exe -------------------------------------------------------------------------------- /Final Term Exam Preperation/def.py: -------------------------------------------------------------------------------- 1 | def is_even(n): 2 | if n % 2 == 0 : 3 | return True 4 | else: 5 | return False 6 | n = is_even(20) 7 | print(n) -------------------------------------------------------------------------------- /Final Term Exam Preperation/diabates.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 6, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "ename": "ModuleNotFoundError", 10 | "evalue": "No module named 'torch'", 11 | "output_type": "error", 12 | "traceback": [ 13 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 14 | "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", 15 | "Cell \u001b[1;32mIn[6], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m# Import necessary libraries\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtorch\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtorch\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mnn\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mnn\u001b[39;00m\n\u001b[0;32m 4\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtorch\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39moptim\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39moptim\u001b[39;00m\n", 16 | "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'torch'" 17 | ] 18 | } 19 | ], 20 | "source": [ 21 | "# Import necessary libraries\n", 22 | "import torch\n", 23 | "import torch.nn as nn\n", 24 | "import torch.optim as optim\n", 25 | "import matplotlib.pyplot as plt\n", 26 | "from sklearn.model_selection import train_test_split\n", 27 | "from sklearn.datasets import load_diabetes\n", 28 | "from sklearn.preprocessing import StandardScaler\n", 29 | "\n", 30 | "# Load the diabetes dataset\n", 31 | "diabetes = load_diabetes()\n", 32 | "X = diabetes.data\n", 33 | "y = diabetes.target\n", 34 | "\n", 35 | "# Normalize the dataset\n", 36 | "scaler = StandardScaler()\n", 37 | "X = scaler.fit_transform(X)\n", 38 | "\n", 39 | "# Split the dataset into training and testing sets\n", 40 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", 41 | "\n", 42 | "# Define the Swin Transformer model\n", 43 | "class SwinTransformer(nn.Module):\n", 44 | " def __init__(self):\n", 45 | " super(SwinTransformer, self).__init__()\n", 46 | " self.transformer = nn.TransformerEncoderLayer(d_model=10, nhead=5)\n", 47 | " self.fc = nn.Linear(10, 1)\n", 48 | "\n", 49 | " def forward(self, x):\n", 50 | " x = self.transformer(x)\n", 51 | " x = self.fc(x)\n", 52 | " return x\n", 53 | "\n", 54 | "# Train the model\n", 55 | "model = SwinTransformer()\n", 56 | "criterion = nn.MSELoss()\n", 57 | "optimizer = optim.Adam(model.parameters(), lr=0.001)\n", 58 | "\n", 59 | "train_loss = []\n", 60 | "test_loss = []\n", 61 | "for epoch in range(100):\n", 62 | " # Training\n", 63 | " running_loss = 0.0\n", 64 | " model.train()\n", 65 | " optimizer.zero_grad()\n", 66 | " outputs = model(torch.tensor(X_train, dtype=torch.float32))\n", 67 | " loss = criterion(outputs, torch.tensor(y_train, dtype=torch.float32).unsqueeze(1))\n", 68 | " loss.backward()\n", 69 | " optimizer.step()\n", 70 | " running_loss += loss.item()\n", 71 | " train_loss.append(running_loss)\n", 72 | "\n", 73 | " # Testing\n", 74 | " with torch.no_grad():\n", 75 | " model.eval()\n", 76 | " outputs = model(torch.tensor(X_test, dtype=torch.float32))\n", 77 | " loss = criterion(outputs, torch.tensor(y_test, dtype=torch.float32).unsqueeze(1))\n", 78 | " test_loss.append(loss.item())\n", 79 | "\n", 80 | " # Print the training and testing loss for each epoch\n", 81 | " print('Epoch [{}/{}], Train Loss: {:.4f}, Test Loss: {:.4f}'\n", 82 | " .format(epoch + 1, 100, running_loss, loss.item()))\n", 83 | "\n", 84 | "# Plot the accuracy on a graph\n", 85 | "plt.plot(train_loss, label='Training Loss')\n", 86 | "plt.plot(test_loss, label='Testing Loss')\n", 87 | "plt.legend()\n", 88 | "plt.show()\n" 89 | ] 90 | } 91 | ], 92 | "metadata": { 93 | "kernelspec": { 94 | "display_name": "Python 3", 95 | "language": "python", 96 | "name": "python3" 97 | }, 98 | "language_info": { 99 | "codemirror_mode": { 100 | "name": "ipython", 101 | "version": 3 102 | }, 103 | "file_extension": ".py", 104 | "mimetype": "text/x-python", 105 | "name": "python", 106 | "nbconvert_exporter": "python", 107 | "pygments_lexer": "ipython3", 108 | "version": "3.11.2" 109 | }, 110 | "orig_nbformat": 4 111 | }, 112 | "nbformat": 4, 113 | "nbformat_minor": 2 114 | } 115 | -------------------------------------------------------------------------------- /Final Term Exam Preperation/diabates.py: -------------------------------------------------------------------------------- 1 | # Import the necessary libraries 2 | import pandas as pd 3 | from sklearn.linear_model import LogisticRegression 4 | from sklearn.model_selection import train_test_split 5 | from sklearn.metrics import accuracy_score 6 | import matplotlib.pyplot as plt 7 | 8 | # Load the dataset 9 | data = pd.read_csv('diabetes.csv') 10 | 11 | # Split the dataset into features and target 12 | X = data.drop('Outcome', axis=1) 13 | y = data['Outcome'] 14 | 15 | # Split the dataset into training and testing sets 16 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) 17 | 18 | # Create the logistic regression model 19 | lr = LogisticRegression() 20 | 21 | # Train the model 22 | lr.fit(X_train, y_train) 23 | 24 | # Evaluate the model 25 | y_pred = lr.predict(X_test) 26 | accuracy = accuracy_score(y_test, y_pred) 27 | print('Accuracy:', accuracy) 28 | 29 | # Plot the confusion matrix 30 | from sklearn.metrics import plot_confusion_matrix 31 | plot_confusion_matrix(lr, X_test, y_test) 32 | plt.title('Confusion Matrix') 33 | plt.show() 34 | 35 | # Plot the ROC curve 36 | from sklearn.metrics import plot_roc_curve 37 | plot_roc_curve(lr, X_test, y_test) 38 | plt.title('ROC Curve') 39 | plt.show() 40 | -------------------------------------------------------------------------------- /Final Term Exam Preperation/even.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void is_even(int n ){ 5 | if(n% 2 == 0 ){ 6 | cout << "Even"; 7 | } 8 | else{ 9 | cout<<"Odd"; 10 | } 11 | } 12 | int main(){ 13 | is_even(3); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Final Term Exam Preperation/even.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/Final Term Exam Preperation/even.exe -------------------------------------------------------------------------------- /Final Term Exam Preperation/file_handling.ipynb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/Final Term Exam Preperation/file_handling.ipynb -------------------------------------------------------------------------------- /Final Term Exam Preperation/filename.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/Final Term Exam Preperation/filename.csv -------------------------------------------------------------------------------- /Final Term Exam Preperation/func.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // int is_even(int num) { 4 | // return num % 2 == 0; 5 | // } 6 | 7 | int check_array(int arr[]) { 8 | for (int i = 0; i <=5; i++) { 9 | if (arr[i] % 2 == 0 ) { 10 | cout << arr[i] << " is even" << endl; 11 | } else { 12 | cout << arr[i] << " is odd" <\n", 107 | "\n", 120 | "\n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | "
NoNameAgeClassSectionPhone numberlocation
Class
1211Abdullah2012Ghouri300300003multan
122ali1212Ghouri300300003multan
123omer1312Ghouri300300003multan
\n", 176 | "" 177 | ], 178 | "text/plain": [ 179 | " No Name Age Class Section Phone number location\n", 180 | "Class \n", 181 | "12 11 Abdullah 20 12 Ghouri 300300003 multan\n", 182 | "12 2 ali 12 12 Ghouri 300300003 multan\n", 183 | "12 3 omer 13 12 Ghouri 300300003 multan" 184 | ] 185 | }, 186 | "execution_count": 5, 187 | "metadata": {}, 188 | "output_type": "execute_result" 189 | } 190 | ], 191 | "source": [ 192 | "d.set_index(\"No\", inplace=True , drop=False)\n", 193 | "d.set_index(\"Section\", inplace=True , drop=False)\n", 194 | "d.set_index(\"Class\", inplace=True , drop=False)\n", 195 | "d" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 6, 201 | "id": "1426fce8", 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "# import pandas\n", 206 | "# df2 = pandas.read_json(\"supermarkets.json\")\n", 207 | "# print(df2)" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 7, 213 | "id": "815ed6f7", 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "data": { 218 | "text/plain": [ 219 | "['.ipynb_checkpoints',\n", 220 | " 'Adobe Photoshop 2020.lnk',\n", 221 | " 'desktop.ini',\n", 222 | " 'ecommerce website.txt',\n", 223 | " 'Internet Download Manager.lnk',\n", 224 | " 'Jupyter notebook',\n", 225 | " 'pandas.csv',\n", 226 | " 'pandas.ipynb',\n", 227 | " 'pandas.txt',\n", 228 | " 'Untitled.ipynb',\n", 229 | " 'Zoom.lnk']" 230 | ] 231 | }, 232 | "execution_count": 7, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "import pandas\n", 239 | "from pandas import *\n", 240 | "import os\n", 241 | "os.listdir()" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": 8, 247 | "id": "e67798b0", 248 | "metadata": {}, 249 | "outputs": [], 250 | "source": [ 251 | "pandas.read_csv?" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "id": "0fc69b6b", 258 | "metadata": {}, 259 | "outputs": [], 260 | "source": [ 261 | "import array\n", 262 | "from array import *\n", 263 | "arr = array(\"i\",[])\n", 264 | "user = int(input(\"Enter the length of the array \"))\n", 265 | "for i in range(user):\n", 266 | " value = int(input(\"Enter the values \"))\n", 267 | " arr.append(value)\n", 268 | " \n", 269 | "print(arr)\n", 270 | "\n", 271 | "# in order to defined the indexes\n", 272 | "x = int(input(\"Enter the value to find out the index of the value \"))\n", 273 | "k = 0\n", 274 | "for e in arr:\n", 275 | " if e == x:\n", 276 | " print(k)\n", 277 | " k +=1" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": null, 283 | "id": "984c059f", 284 | "metadata": {}, 285 | "outputs": [], 286 | "source": [ 287 | "import pandas\n", 288 | "df = pandas.to_csv(\"pandas.csv\")\n", 289 | "print(df)\n", 290 | "\n" 291 | ] 292 | }, 293 | { 294 | "cell_type": "code", 295 | "execution_count": null, 296 | "id": "8fd1346b", 297 | "metadata": {}, 298 | "outputs": [], 299 | "source": [] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": null, 304 | "id": "013e401e", 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "id": "a54038b8", 313 | "metadata": {}, 314 | "outputs": [], 315 | "source": [] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": null, 320 | "id": "d3e625be", 321 | "metadata": {}, 322 | "outputs": [], 323 | "source": [] 324 | } 325 | ], 326 | "metadata": { 327 | "kernelspec": { 328 | "display_name": "Python 3 (ipykernel)", 329 | "language": "python", 330 | "name": "python3" 331 | }, 332 | "language_info": { 333 | "codemirror_mode": { 334 | "name": "ipython", 335 | "version": 3 336 | }, 337 | "file_extension": ".py", 338 | "mimetype": "text/x-python", 339 | "name": "python", 340 | "nbconvert_exporter": "python", 341 | "pygments_lexer": "ipython3", 342 | "version": "3.9.7" 343 | } 344 | }, 345 | "nbformat": 4, 346 | "nbformat_minor": 5 347 | } 348 | -------------------------------------------------------------------------------- /Final Term Exam Preperation/power.py: -------------------------------------------------------------------------------- 1 | def generate_power(exponent): 2 | def power(base): 3 | return base ** exponent 4 | return power 5 | x = generate_power(2) 6 | print(x(3)) -------------------------------------------------------------------------------- /Final Term Exam Preperation/prime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int arr[] = {12,43,88,69,17,36}; 6 | // int n; 7 | // cout<<"Enter the Number to Check Prime or composite: "; 8 | // cin>>n; 9 | int count = 0; 10 | 11 | for (int i = 0; i < arr[i] ; i++) 12 | { 13 | for (int j = 0; j < 4; j++) 14 | { 15 | if (arr[i] % i == 0 ) 16 | { 17 | cout<<"Prime Values are : "<< i < 2 | using namespace std; 3 | 4 | int BinarySearch(int arr[]){ 5 | for (int i = 0; i <=8; i++) 6 | { 7 | cout<>key; 13 | while (l<=h) 14 | { 15 | mid = (l+h)/2; 16 | if (key == arr[mid]){ 17 | cout< 2 | using namespace std; 3 | 4 | // Armstrong: 5 | // if we separate the digits of number and then by taking the cube of each digit, combine them togeter. 6 | // if the sum equal to the number which we takin then it is called the armstrong number 7 | 8 | 9 | int main(){ 10 | int a,sum=0,re; 11 | cout<<"Enter the Number to Check: "; 12 | cin>>a; 13 | int n = a; 14 | while (a > 0) 15 | { 16 | re = a % 10; 17 | a = a / 10; 18 | sum = sum + (re * re * re); 19 | } 20 | 21 | if (n == sum ){ 22 | cout<<"Number is Amstrong"; 23 | } 24 | else{ 25 | cout<<"Number is not Armstrong"; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Object Oriented Programming/OOP_Examples/BankAccount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class BankAccount 5 | { 6 | private: 7 | double balance; 8 | 9 | public: 10 | void intial_Balance(double i_balance) 11 | { 12 | balance = i_balance; 13 | } 14 | 15 | void deposit(double amount) 16 | { 17 | if (amount > 0) 18 | { 19 | balance += amount; 20 | } 21 | } 22 | 23 | void withdraw(double amount) 24 | { 25 | if (amount > 0 && amount <= balance) 26 | { 27 | balance -= amount; 28 | } 29 | } 30 | 31 | double get_balance() 32 | { 33 | return balance; 34 | } 35 | }; 36 | 37 | int main() 38 | { 39 | BankAccount ali; 40 | ali.intial_Balance(500); 41 | ali.deposit(500); 42 | ali.withdraw(200); 43 | 44 | cout << "Current balance: " << ali.get_balance() << endl; 45 | cout<<"\n\n==============\n\n"; 46 | BankAccount hamza; 47 | hamza.intial_Balance(5500); 48 | hamza.deposit(300); 49 | hamza.withdraw(2200); 50 | 51 | cout << "Current balance: " << hamza.get_balance() << endl; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Object Oriented Programming/OOP_Examples/car.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Car { 6 | private: 7 | string make; 8 | string model; 9 | int year; 10 | 11 | public: 12 | 13 | void car(string a_make, string a_model, int a_year){ 14 | make = a_make; 15 | model = a_model; 16 | year = a_year; 17 | } 18 | string get_make() { 19 | return make; 20 | } 21 | 22 | string get_model() { 23 | return model; 24 | } 25 | 26 | int get_year() { 27 | return year; 28 | } 29 | }; 30 | 31 | int main() { 32 | Car myCar; 33 | myCar.car("Toyota", "Camry", 2022); 34 | 35 | cout << "Make: " << myCar.get_make() << endl; 36 | cout << "Model: " << myCar.get_model() << endl; 37 | cout << "Year: " << myCar.get_year() << endl; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Object Oriented Programming/OOP_Examples/inheritance.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FLotfiGit/CPP-Complete-Course/cb97c0f30f0e56f8314f7d934ae375401db5b584/Object Oriented Programming/OOP_Examples/inheritance.cpp -------------------------------------------------------------------------------- /Object Oriented Programming/OOP_Examples/person.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Person 6 | { 7 | private: 8 | string __name; 9 | int __age; 10 | 11 | public: 12 | // Person(const string& person_name, int person_age) : name(person_name), age(person_age) {} 13 | void Personal(string name, int age) 14 | { 15 | __name = name; 16 | __age = age; 17 | } 18 | 19 | string get_name() 20 | { 21 | return __name; 22 | } 23 | 24 | int get_age() 25 | { 26 | return __age; 27 | } 28 | }; 29 | 30 | int main() 31 | { 32 | Person Ali; 33 | Ali.Personal("Ali", 20); 34 | 35 | cout<< "Name: " << Ali.get_name() << endl; 36 | cout << "Age: " << Ali.get_age() << endl; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Object Oriented Programming/OOP_Examples/rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Rectangle { 4 | private: 5 | double length; 6 | double width; 7 | 8 | public: 9 | 10 | void rectangle(double a_length, double a_widht){ 11 | length = a_length; 12 | width = a_widht; 13 | } 14 | double calculate_area() { 15 | return length * width; 16 | } 17 | 18 | double calculate_perimeter() { 19 | return 2 * (length + width); 20 | } 21 | }; 22 | 23 | int main() { 24 | Rectangle myRectangle; 25 | myRectangle.rectangle(5.0, 3.0); 26 | 27 | cout << "Area: " << myRectangle.calculate_area() << endl; 28 | cout << "Perimeter: " << myRectangle.calculate_perimeter() << endl; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Object Oriented Programming/OOP_Examples/student.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Student { 5 | private: 6 | string _name; 7 | int _age; 8 | 9 | public: 10 | void student(string a_name , int a_age){ 11 | _name = a_name; 12 | _age = a_age; 13 | } 14 | string get_name() { 15 | return _name; 16 | } 17 | 18 | int get_age() { 19 | return _age; 20 | } 21 | }; 22 | 23 | int main() { 24 | Student mySt; 25 | mySt.student("Alice", 20); 26 | 27 | cout << "Name: " << mySt.get_name() << endl; 28 | cout << "Age: " << mySt.get_age() << endl; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Object Oriented Programming/Principles/polymor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class person { 5 | public: 6 | void show() { 7 | cout << "in base class" << endl; 8 | } 9 | }; 10 | 11 | class person2 : public person { // Use 'public' for inheritance 12 | public: 13 | int b = 20; 14 | // void show() { 15 | // cout << "In derived class" << endl; 16 | // } 17 | }; 18 | 19 | int main() { 20 | person2 p; 21 | p.show(); // Calls the show method of the derived class 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Object Oriented Programming/Principles/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class calculator{ 5 | public: 6 | calculator(){ 7 | cout<<"=============Calculator==========="; 8 | cout<<"============ Version 2.2==========\n"; 9 | cout<<"Use the Button \n\t add,subtract,multiply,divide"; 10 | } 11 | int add(int a, int b){ 12 | return a + b; 13 | } 14 | 15 | int subtract(int a , int b){ 16 | return a - b; 17 | } 18 | 19 | int multiply(int a, int b){ 20 | return a * b; 21 | } 22 | float divide(float a ,float b){ 23 | if (b == 0 ){ 24 | cout<<"Denominator Can't be Zero"; 25 | } 26 | else{ 27 | return a / b; 28 | } 29 | } 30 | }; 31 | 32 | int main() 33 | { 34 | calculator cal; 35 | int ad = cal.add(2,2); 36 | int sub = cal.subtract(5,2); 37 | int mul = cal.multiply(4,4); 38 | float dic = cal.divide(5,2); 39 | 40 | 41 | cout<<"\nValue of add: "< 2 | using namespace std; 3 | 4 | void showMenu() 5 | { 6 | cout << "1. Check Balance" << endl; 7 | cout << "2. Deposit Amount" << endl; 8 | cout << "3. Withdraw Amount" << endl; 9 | cout << "4. Exit Atm" << endl; 10 | }; 11 | int main() 12 | { 13 | int option; 14 | double balance = 1500; 15 | do 16 | { 17 | showMenu(); 18 | cout << "Choose Option: "; 19 | cin >> option; 20 | system("cls"); 21 | switch (option) 22 | { 23 | case 1: 24 | cout << "Your Current Balance is: " << balance << "$" << endl; 25 | break; 26 | 27 | case 2: 28 | cout << "Enter the Balance: "; 29 | double depositAmount; 30 | cin >> depositAmount; 31 | balance += depositAmount; 32 | break; 33 | 34 | case 3: 35 | cout << "Enter the Amount to WithDraw: "; 36 | double withdrawAmount; 37 | cin>>withdrawAmount; 38 | if (withdrawAmount <= balance) 39 | { 40 | balance -= withdrawAmount; 41 | } 42 | else 43 | { 44 | cout << "Not Enough Money To Deposit"; 45 | } 46 | break; 47 | } 48 | } while (option != 4); 49 | 50 | return 0; 51 | }; 52 | -------------------------------------------------------------------------------- /Projects/snake_game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // #include 5 | #include 6 | #include 7 | 8 | #define MAXSNAKESIZE 100 9 | 10 | using namespace std; 11 | 12 | HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); 13 | COORD CursorPosition; 14 | 15 | void gotoxy(int x, int y){ 16 | CursorPosition.X = x; 17 | CursorPosition.Y = y; 18 | SetConsoleCursorPosition(console, CursorPosition); 19 | } 20 | 21 | class Point{ 22 | private: 23 | int x; 24 | int y; 25 | public: 26 | Point(){ 27 | x = y = 10; 28 | } 29 | Point(int x, int y){ 30 | this -> x = x; 31 | this -> y = y; 32 | } 33 | void SetPoint(int x, int y){ 34 | this -> x = x; 35 | this -> y = y; 36 | } 37 | int GetX(){ 38 | return x; 39 | } 40 | int GetY(){ 41 | return y; 42 | } 43 | void MoveUp(){ 44 | y--; 45 | } 46 | void MoveDown(){ 47 | y++; 48 | } 49 | void MoveLeft(){ 50 | x--; 51 | } 52 | void MoveRight(){ 53 | x++; 54 | } 55 | void Draw(){ 56 | gotoxy(x,y); 57 | cout<<"*"; 58 | } 59 | void Erase(){ 60 | gotoxy(x,y); 61 | cout<<" "; 62 | } 63 | void CopyPos(Point * p){ 64 | p->x = x; 65 | p->y = y; 66 | } 67 | void Debug(){ 68 | cout<<"("<0; i--){ 108 | cell[i-1]->CopyPos(cell[i]); 109 | } 110 | 111 | // turning snake's head 112 | switch(dir){ 113 | case 'w': 114 | cell[0]->MoveUp(); 115 | break; 116 | case 's': 117 | cell[0]->MoveDown(); 118 | break; 119 | case 'a': 120 | cell[0]->MoveLeft(); 121 | break; 122 | case 'd': 123 | cell[0]->MoveRight(); 124 | break; 125 | } 126 | 127 | // Collision with fruit 128 | if( fruit.GetX() == cell[0]->GetX() && fruit.GetY() == cell[0]->GetY()){ 129 | AddCell(0,0); 130 | fruit.SetPoint(rand()%50, rand()%25); 131 | } 132 | 133 | //drawing snake 134 | for(int i=0; iDraw(); 136 | fruit.Draw(); 137 | 138 | //Debug(); 139 | 140 | Sleep(100); 141 | } 142 | void Debug(){ 143 | for( int i=0; iDebug(); 145 | } 146 | } 147 | }; 148 | 149 | int main(){ 150 | //random no generation 151 | srand( (unsigned)time(NULL)); 152 | 153 | // Testing snake 154 | Snake snake; 155 | char op = 'l'; 156 | do{ 157 | if(kbhit()){ 158 | op = getch(); 159 | } 160 | switch(op){ 161 | case 'w': 162 | case 'W': 163 | snake.TurnUp(); 164 | break; 165 | 166 | case 's': 167 | case 'S': 168 | snake.TurnDown(); 169 | break; 170 | 171 | case 'a': 172 | case 'A': 173 | snake.TurnLeft(); 174 | break; 175 | 176 | case 'd': 177 | case 'D': 178 | snake.TurnRight(); 179 | break; 180 | } 181 | snake.Move(); 182 | }while(op != 'e'); 183 | 184 | return 0; 185 | } 186 | 187 | // THE END 188 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C++ Complete Course 2 | This repository contains a complete course for learning C++ programming language from zero to advance level. The course is designed for individuals who are new to programming or have limited experience in C++. 3 | 4 | # Course Outline 5 | The course is divided into several sections that cover the following topics: 6 | 7 |
    8 |
  • Introduction to C++
  • 9 |
  • Variables and Data Types
  • 10 |
  • Control Structures (if-else, loops, etc.)
  • 11 |
  • Functions
  • 12 |
  • Arrays and Strings
  • 13 |
  • Pointers and References
  • 14 |
  • OOP Concepts (classes, objects, inheritance, polymorphism, etc.)
  • 15 |
  • File Input/Output
  • 16 |
  • Exception Handling
  • 17 |
  • Standard Template Library (STL)
  • 18 | 19 |
20 | 21 | # Prerequisites 22 | Before starting the course, it is recommended that you have a basic understanding of computer programming concepts and familiarity with any programming language. 23 | 24 | 25 | # Course Format 26 | The course includes a mix of video tutorials and written exercises. The videos provide a detailed explanation of the concepts, while the exercises allow you to practice and reinforce your understanding of the material. 27 | 28 | # Requirements 29 |
    30 |
  • A computer with an internet connection
  • 31 |
  • A text editor (e.g. Visual Studio Code, Sublime Text, etc.)
  • 32 |
  • A compiler (e.g. GCC, Visual Studio, etc.)
  • 33 |
34 | 35 | # How to Use the Repository 36 |
43 | 44 | # Contributions 45 | 46 | Contributions to the course are welcome. If you find any errors or have suggestions for improvements, please submit a pull request or open an issue. 47 | 48 | # Disclaimer 49 | This course is provided as-is and does not guarantee a certain level of expertise in C++ programming. It is up to the individual to make the most of the material provided and practice regularly. 50 | -------------------------------------------------------------------------------- /strings/class_strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | 7 | // string str = "Hello World"; 8 | 9 | // getline(cin,str); 10 | // cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // cout<<"Hello World"; 7 | // char x ='A'; // character we can store only one char in char type. 8 | // char y[] ="Hello World" ;// in order to store the strings, we need to declare the array in char type 9 | // in order to store the string we use double quotes 10 | // Details ['H','e','l','l','o','w','o','r','l','d','\o' > this is a string terminator] 11 | // Details ['H','e','l','l','o','w','o','r','l','d','\o' > this is a string terminator] 12 | // cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | // taking input from user using the get and getline method 7 | // char i[20] ; 8 | // cin.get(i,20); 9 | // cout<<"Here is your Character " << i < 2 | using namespace std; 3 | 4 | int main(){ 5 | char s[20]; 6 | cout<<"Enter the your name "; 7 | cin>>s; 8 | // cin.get(s,20); 9 | // cin.getline(s,20) 10 | cout<<"Wellcome "<< s ; 11 | }; 12 | -------------------------------------------------------------------------------- /strings/string_concatenation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | // char s1[20]="Hello "; 7 | // char s2[20]="World!"; 8 | // cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | char s1[20] = ""; 7 | char s2[20]="World!"; 8 | cout< 2 | #include 3 | using namespace std; 4 | int main(){ 5 | // int arr[] = {10,20,30,40,50}; 6 | // Every int stores 4 bytes in the local memory 7 | // As the length of the arry is 5 and it's is multiplied by 4 it beomes 20 8 | // cout<<"size of the array is"< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | // char s1[20] = "Hello World"; 7 | // cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string test; 8 | test = "I am Q the omnipot3nt"; 9 | char ch = test[5]; // ch is 'Q' 10 | test[18] = 'e'; // we correct misspelling of omnipotent 11 | cout << test << endl; 12 | cout << "ch = " << ch << endl; 13 | return 0; 14 | } 15 | --------------------------------------------------------------------------------