├── .gitignore ├── 07_array ├── five.dSYM │ └── Contents │ │ ├── Resources │ │ ├── DWARF │ │ │ └── five │ │ └── Relocations │ │ │ └── aarch64 │ │ │ └── five.yml │ │ └── Info.plist ├── two.cpp ├── one.cpp ├── three.cpp ├── four.cpp └── five.cpp ├── 02_primitives ├── modifier.cpp ├── myString.cpp ├── casting.cpp ├── data.cpp └── userInput.cpp ├── 05_loops ├── task_two.cpp ├── task_three.cpp ├── task_one.cpp ├── task_five.cpp ├── task_six.cpp ├── task_four.cpp └── task.md ├── 06_function ├── myFunTwo.cpp ├── myFunFour.cpp ├── myFunThree.cpp └── myFunction.cpp ├── 04_conditionals ├── taskOne.cpp ├── taskTwo.cpp ├── taskThree.cpp ├── taskFour.cpp └── tasks.md ├── 03_operators ├── assign.cpp ├── relation.cpp ├── logical.cpp ├── arth.cpp └── tasks.md ├── 01_varconst └── main.cpp ├── .github └── dependabot.yml ├── .devcontainer ├── Dockerfile ├── devcontainer.json └── reinstall-cmake.sh ├── test └── hello.cpp ├── 08_oop ├── defaultCons.cpp ├── parametCons.cpp ├── myFriend.cpp ├── consDeligation.cpp ├── myClass.cpp ├── encp.cpp ├── abstr.cpp ├── copyCons.cpp ├── getterSetter.cpp └── inheritance.cpp ├── challenge1.md ├── readme.md ├── challenge3.md ├── challenge4.md ├── challenge2.md └── 09_stl ├── stl_emp_manage.cpp └── stl_store.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /07_array/five.dSYM/Contents/Resources/DWARF/five: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiteshchoudhary/chai-aur-cpp/HEAD/07_array/five.dSYM/Contents/Resources/DWARF/five -------------------------------------------------------------------------------- /02_primitives/modifier.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | unsigned smallTeaPack = 1200; 8 | 9 | long long largeTeaStorage = 100000000; 10 | 11 | short teaSample = 25; 12 | 13 | cout << largeTeaStorage << endl; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /02_primitives/myString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | string favoriteTea = "Lemon Tea \t"; 8 | string description = "Known as \"best\" tea"; 9 | 10 | cout << favoriteTea << description << endl; 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /05_loops/task_two.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string response; 6 | 7 | do { 8 | cout << "Do you want more tea (yes/no): "; 9 | getline(cin, response); 10 | } while (response != "no" || response != "No"); 11 | } -------------------------------------------------------------------------------- /07_array/two.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int chaiServed[7] = {50, 60, 55, 70, 65, 80, 75}; 7 | 8 | cout << "Chai cups served on Day 1: " << chaiServed[0]; 9 | cout << "Chai cups served on Day 2: " << chaiServed[1]; 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /07_array/one.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int chaiTemperature[5] = {85, 90, 88, 92, 89}; 7 | 8 | cout << "Chai temperature: "; 9 | for(int i = 0 ; i < 5 ; i++ ){ 10 | cout << chaiTemperature[i] << " degree C \n"; 11 | } 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /02_primitives/casting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | float teaPrice = 49.99; 8 | int roundedTeaPrice = (int) teaPrice; 9 | 10 | int teaQuantity = 2; 11 | int totalPrice = teaPrice * teaQuantity; 12 | 13 | cout << totalPrice << endl; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /02_primitives/data.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int teaLeaves = 50; 8 | float waterTemperature = 85.588588; 9 | double priceOfTea = 299.99; 10 | char teaGrade = 'A'; 11 | bool isTeaReady = false; 12 | 13 | cout << waterTemperature << endl; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /06_function/myFunTwo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | void pourChai(int cups){ 7 | cups = cups + 5; 8 | cout << "Poured cups: " << cups << endl; 9 | } 10 | 11 | int main(){ 12 | 13 | int cups = 2; 14 | pourChai(cups); 15 | cout << "Total cups are " << cups << endl; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /04_conditionals/taskOne.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string teaOrder; 6 | 7 | cout << "Enter your tea order"; 8 | getline(cin, teaOrder); 9 | 10 | if(teaOrder == "Green Tea"){ 11 | cout << "You have ordered Green Tea" << endl; 12 | 13 | } 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /05_loops/task_three.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int teaCups = 5; 6 | int i = 100; 7 | 8 | for( int i = 1 ; i <= teaCups ; i++){ 9 | cout << "Brewing cup " << i << " of tea..." << endl; 10 | } 11 | cout << i; 12 | cout << "Outside of loop"; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /06_function/myFunFour.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int hellooChai(){ 6 | return 10; 7 | } 8 | 9 | int main(){ 10 | 11 | //lamda 12 | auto preparedChai = [](int cups){ 13 | cout << "Preparing " << cups << " cups of tea" << endl; 14 | }; 15 | 16 | preparedChai(4); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /04_conditionals/taskTwo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int hour; 7 | 8 | cout << "Enter the current hour (0-23): "; 9 | cin >> hour; 10 | 11 | if(hour >= 8 && hour <= 18) { 12 | cout << "Tea shop is OPEN!" << endl; 13 | } else { 14 | cout << "Tea shop is CLOSED!" << endl; 15 | 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /03_operators/assign.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int teaBags; 7 | 8 | cout << "Enter the number of tea bags you have: "; 9 | cin >> teaBags; 10 | 11 | if (teaBags < 10) { 12 | // teaBags = teaBags + 5 13 | teaBags += 5; 14 | } 15 | cout << "Your total bags are: " << teaBags; 16 | 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /06_function/myFunThree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int globalChaiStock = 100; 6 | void pourChai(int &cups){ 7 | int test = 9; 8 | cups = cups + 5; 9 | 10 | cout << "Poured cups: " << cups << endl; 11 | } 12 | 13 | 14 | 15 | int main(){ 16 | 17 | int cups = 2; 18 | pourChai(cups); 19 | cout << "Total cups are " << cups << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /07_array/three.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int totalChaiServed(int chai[], int size){ 6 | int total = 0; 7 | for(int i = 0 ; i < size ; i++){ 8 | total += chai[i]; 9 | } 10 | return total; 11 | } 12 | 13 | int main(){ 14 | int chaiServed[7] = {50, 60, 55, 70, 65, 80, 75}; 15 | 16 | int total = totalChaiServed(chaiServed, 7); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /05_loops/task_one.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int teaCups; 6 | 7 | cout << "Enter the number of tea cups to server: "; 8 | cin >> teaCups; 9 | 10 | //while loop 11 | while (teaCups > 0) { 12 | teaCups--; 13 | cout << "Serving a cup of tea \n" << teaCups << " remaining" << endl; 14 | } 15 | 16 | cout << "All tea cups are served. " << endl; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /01_varconst/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int score; 8 | score = 110; 9 | 10 | const int uid = 232323; 11 | 12 | int hiteshBalance = 500; 13 | hiteshBalance = 1000; 14 | 15 | // uid = 1223; 16 | cout << "Welcome to chai with cpp 1" << endl ; 17 | 18 | 19 | cout << "Welcome to chai with cpp 2" << endl ; 20 | cout << "Welcome to chai with cpp 3" << endl ; 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /02_primitives/userInput.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | string userTea; 8 | int teaQuantity; 9 | 10 | cout << "What would you like to order in tea? \n"; 11 | getline(cin, userTea); 12 | 13 | //ask for quantity 14 | cout << "how many cups of " << userTea << "would you like to have ? "; 15 | cin >> teaQuantity; 16 | 17 | cout << teaQuantity; 18 | cout << userTea; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /03_operators/relation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int cups; 7 | 8 | cout << "Enter the number of cups you have"; 9 | cin >> cups; 10 | 11 | if (cups > 20) { 12 | cout << "You will get a GOLD badge" << endl; 13 | } else if (cups >= 10 && cups <= 20) { 14 | cout << "You will get a SILVER badge" << endl; 15 | 16 | } else { 17 | cout << "NO BADGE for you" << endl; 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /05_loops/task_five.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | 6 | string teaTypes[5] = {"Oolong tea", "Orange Tea", "Green Tea", "Black Tea", "Lemon Tea"}; 7 | 8 | for(int i = 0 ; i < 5 ; i++){ 9 | if(teaTypes[i] == "Green Tea"){ 10 | cout << "Skipping the " << teaTypes[i] << endl; 11 | continue; 12 | } 13 | 14 | cout << "Brewing " << teaTypes[i] << "..." << endl; 15 | } 16 | return 0; 17 | 18 | } -------------------------------------------------------------------------------- /05_loops/task_six.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | 6 | string teaTypes[5] = {"Oolong tea", "Orange Tea", "Green Tea", "Black Tea", "Lemon Tea"}; 7 | 8 | for(int i = 0 ; i < 5 ; i++){ 9 | cout << "Brewing " << teaTypes[i] << "..." << endl; 10 | 11 | for (int j = 1 ; j <= 3 ; j++){ 12 | cout << "Brewing " << j << " cup of " << teaTypes[i] << endl; 13 | } 14 | } 15 | 16 | return 0; 17 | 18 | } -------------------------------------------------------------------------------- /05_loops/task_four.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string response; 6 | 7 | while(true){ 8 | cout << "Do you want more tea (type 'stop' to exit)?: "; 9 | getline(cin, response); 10 | 11 | if(response == "stop"){ 12 | //exit the loop 13 | break; 14 | } 15 | cout << "Here is your another cup of tea. \n"; 16 | } 17 | cout << "No more tea will be served to you"; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for more information: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | # https://containers.dev/guide/dependabot 6 | 7 | version: 2 8 | updates: 9 | - package-ecosystem: "devcontainers" 10 | directory: "/" 11 | schedule: 12 | interval: weekly 13 | -------------------------------------------------------------------------------- /07_array/four.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int* prepareChaiOrders(int cups){ 6 | int* orders = new int[cups]; 7 | for(int i = 0; i < cups; i++){ 8 | orders[i] = (i + 1) * 10; 9 | } 10 | return orders; 11 | } 12 | 13 | int main(){ 14 | int cups = 5; 15 | int* chaiOrder = prepareChaiOrders(cups); 16 | 17 | for(int i =0; i < cups; i++){ 18 | cout << "Cups: " << i + 1 << "has " << chaiOrder[i] << " ml\n"; 19 | } 20 | 21 | delete[] chaiOrder; 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /03_operators/logical.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | bool isStudent; 7 | int cups; 8 | 9 | 10 | cout << "Are you a student (1 for yes and 0 for No) ?"; 11 | cin >> isStudent; 12 | cout << "How many cups of tea have you purchased ?"; 13 | cin >> cups; 14 | 15 | if (isStudent || cups > 15) { 16 | cout << "You are elegible for a discount " << endl; 17 | } else { 18 | cout << "You are NOT elegible for a discount " << endl; 19 | 20 | } 21 | 22 | return 0; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /07_array/five.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int chaiSales[3][7] = { 7 | {50, 60, 55, 70, 65, 80, 75}, // Shop 1 sales for 7 days 8 | {40, 55, 60, 65, 70, 75, 80}, // Shop 2 sales for 7 days 9 | {45, 50, 55, 60, 65, 70, 75} // Shop 3 sales for 7 days 10 | }; 11 | 12 | for(int i = 0; i < 3; i++){ 13 | cout << "I am at shop: " << i+1 << "\n"; 14 | for(int j = 0; j < 7; j++){ 15 | cout << chaiSales[i][j] << " cups - "; 16 | } 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /04_conditionals/taskThree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int cups; 7 | 8 | double pricePerCup = 2.5, totalPrice, discount; 9 | 10 | cout << "Enter the number of tea cups" ; 11 | cin >> cups; 12 | 13 | totalPrice = pricePerCup * cups; 14 | 15 | if(cups > 20){ 16 | discount = 0.20; 17 | }else if (cups >= 10 && cups <= 20){ 18 | discount = 0.10; 19 | } else { 20 | discount = 0; 21 | } 22 | 23 | totalPrice -= (totalPrice * discount); 24 | 25 | cout << "Total price after discount is: " << totalPrice << endl; 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /03_operators/arth.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int cups; 7 | double pricePerCup, totalPrice, discountedPrice; 8 | 9 | cout << "Enter the number of tea cups: "; 10 | cin >> cups; 11 | cout << "Enter the price per cups: "; 12 | cin >> pricePerCup; 13 | 14 | totalPrice = cups * pricePerCup; 15 | 16 | // apply 5% discount if total price is above 100 17 | 18 | if (totalPrice > 100) { 19 | discountedPrice = totalPrice - (totalPrice * 0.05); 20 | cout << "Discounted price is: " << discountedPrice << endl; 21 | } else { 22 | cout << "Total price is " << totalPrice << endl; 23 | } 24 | 25 | 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /07_array/five.dSYM/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.xcode.dsym.five 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundlePackageType 12 | dSYM 13 | CFBundleSignature 14 | ???? 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleVersion 18 | 1 19 | 20 | 21 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/devcontainers/cpp:1-debian-11 2 | 3 | ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.21.5" 4 | 5 | # Optionally install the cmake for vcpkg 6 | COPY ./reinstall-cmake.sh /tmp/ 7 | 8 | RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ 9 | chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ 10 | fi \ 11 | && rm -f /tmp/reinstall-cmake.sh 12 | 13 | # [Optional] Uncomment this section to install additional vcpkg ports. 14 | # RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " 15 | 16 | # [Optional] Uncomment this section to install additional packages. 17 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 18 | # && apt-get -y install --no-install-recommends 19 | -------------------------------------------------------------------------------- /test/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Function to create an array of chai orders 5 | int* prepareChaiOrders(int cups) { 6 | int* orders = new int[cups]; // Dynamically allocate array 7 | for (int i = 0; i < cups; i++) { 8 | orders[i] = (i + 1) * 10; // Assigning orders for each cup 9 | } 10 | return orders; // Return the pointer to the array 11 | } 12 | 13 | int main() { 14 | int cups = 5; 15 | int* chaiOrders = prepareChaiOrders(cups); // Get the array from the function 16 | 17 | // Print the orders 18 | cout << "Chai orders for " << cups << " cups:" << endl; 19 | for (int i = 0; i < cups; i++) { 20 | cout << "Cup " << i + 1 << ": " << chaiOrders[i] << " ml" << endl; 21 | } 22 | 23 | delete[] chaiOrders; // Free the allocated memory 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /08_oop/defaultCons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Chai { 7 | public: 8 | string teaName; 9 | int servings; 10 | vector ingredients; 11 | 12 | //default contructor 13 | Chai(){ 14 | teaName = "Unknow Tea"; 15 | servings = 1; 16 | ingredients = {"Water", "Tea leaves"}; 17 | cout << "constructor called" << endl; 18 | } 19 | 20 | void displayChaiDetails(){ 21 | cout << "Tea Name: " << teaName << endl; 22 | cout << "Servings: " << servings << endl; 23 | cout << "Ingredients: " ; 24 | for(string ingridient : ingredients){ 25 | cout << ingridient << " "; 26 | } 27 | cout << endl; 28 | } 29 | 30 | }; 31 | 32 | int main(){ 33 | Chai defaultChai; 34 | 35 | defaultChai.displayChaiDetails(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /06_function/myFunction.cpp: -------------------------------------------------------------------------------- 1 | // returnType functionName(parameters){ 2 | // //function body 3 | // } 4 | // void 5 | #include 6 | using namespace std; 7 | int checkTemperature(int temperature){ 8 | return temperature; 9 | } 10 | 11 | //declaration of function 12 | void serveChai(int cups); 13 | 14 | 15 | void makeChai(){ 16 | cout << "Boiling water, adding tea leaves, straining..."; 17 | } 18 | 19 | void serveChai(string teaType = "Masala Tea"){ 20 | int cups = 4; 21 | cout << "Serving " << teaType << endl; 22 | } 23 | 24 | void serveChai(int cup, int tealeaves){ 25 | 26 | } 27 | 28 | 29 | int main(){ 30 | int temp = checkTemperature(50); 31 | // cout << temp; 32 | // makeChai(); // calling a function 33 | // serveChai(3); 34 | serveChai(); 35 | return 0; 36 | } 37 | 38 | // defination of function 39 | void serveChai(int cups){ 40 | cout << "Serving " << cups << " of chai"; 41 | } 42 | -------------------------------------------------------------------------------- /08_oop/parametCons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Chai { 7 | public: 8 | string teaName; 9 | int servings; 10 | vector ingredients; 11 | 12 | //parameter contructor 13 | Chai(string name, int serve, vector ingr){ 14 | teaName = name; 15 | servings = serve; 16 | ingredients = ingr; 17 | cout << "Param constructor called" << endl; 18 | } 19 | 20 | void displayChaiDetails(){ 21 | cout << "Tea Name: " << teaName << endl; 22 | cout << "Servings: " << servings << endl; 23 | cout << "Ingredients: " ; 24 | for(string ingridient : ingredients){ 25 | cout << ingridient << " "; 26 | } 27 | cout << endl; 28 | } 29 | 30 | }; 31 | 32 | int main(){ 33 | Chai lemonTea("Lemon Tea", 2, {"Water", "lemon", "Honey"}); 34 | 35 | lemonTea.displayChaiDetails(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /04_conditionals/taskFour.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int choice; 7 | double price; 8 | 9 | cout << "Select your tea\n"; 10 | cout << "1. Green Tea\n"; 11 | cout << "2. Lemon Tea\n"; 12 | cout << "3. Oolong Tea\n"; 13 | cout << "Enter your choice in number: \n"; 14 | 15 | cin >> choice; 16 | 17 | switch(choice){ 18 | case 1: 19 | price = 2.0; 20 | cout << "You selected Green Tea. Price: "<< price << endl; 21 | break; 22 | case 2: 23 | price = 3.0; 24 | cout << "You selected Lemon Tea. Price: "<< price << endl; 25 | break; 26 | case 3: 27 | price = 4.0; 28 | cout << "You selected Oolong Tea. Price: "<< price << endl; 29 | break; 30 | default: 31 | cout << "Invalid choice" << endl; 32 | break; 33 | 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /challenge1.md: -------------------------------------------------------------------------------- 1 | # Challenges 2 | 3 | ## Challenge 1: 4 | 5 | --- 6 | 7 | Tea Information Display Write a program that declares variables to store the type of tea, its price per kilogram (float), and its rating (char). Use data types effectively and print them in a formatted output using escape sequences. 8 | 9 | > Hint: Use \n for new lines and \" to quote the tea name. 10 | 11 | ## Challenge 2: 12 | 13 | --- 14 | 15 | Modify Tea Prices Create a program where the user inputs a base price for tea. Use type casting to increase the price by 10% and display the rounded new price using explicit casting. 16 | 17 | > Hint: Use both float and int types, and demonstrate type casting. 18 | 19 | ## Challenge 3: 20 | 21 | --- 22 | 23 | Favorite Tea Input Write a program that takes the user’s favorite tea as input using getline and also asks how many cups of tea they want using cin. Display the result in a fun message. 24 | 25 | > Hint: Combine cin and getline carefully to avoid input issues. 26 | -------------------------------------------------------------------------------- /04_conditionals/tasks.md: -------------------------------------------------------------------------------- 1 | ### 1. **If Statement** 2 | 3 | ### **Challenge:** Write a program that checks if the user wants to order Green Tea. If the user types "Green Tea," the program should confirm their order. 4 | 5 | ### 2. **If-Else Statement** 6 | 7 | ### **Challenge:** Write a program that checks if a tea shop is open. If the current hour (input by the user) is between 8 AM and 6 PM, the shop is open; otherwise, it’s closed. 8 | 9 | ### 3. **Nested If-Else** 10 | 11 | ### **Challenge:** A tea shop offers discounts based on the number of tea cups ordered. Write a program that checks the number of cups ordered and applies a discount:* More than 20 cups: 20% discount 12 | * Between 10 and 20 cups: 10% discount 13 | * Less than 10 cups: No discount 14 | 15 | 16 | ### 4. **Switch Case** 17 | 18 | ### **Challenge:** Write a program that lets the user select a tea type from a menu. Use a switch statement to display the price based on the selected tea:* Green Tea: $2 19 | * Black Tea: $3 20 | * Oolong Tea: $4 21 | 22 | -------------------------------------------------------------------------------- /08_oop/myFriend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | class Chai{ 9 | private: 10 | string teaName; 11 | int servings; 12 | 13 | public: 14 | Chai(string name, int serve): teaName(name), servings(serve){} 15 | 16 | friend bool compareServings(const Chai &chai1, const Chai &chai2); 17 | 18 | void display() const { 19 | cout << "teaname: " << teaName << endl; 20 | } 21 | 22 | }; 23 | 24 | bool compareServings(const Chai &chai1, const Chai &chai2){ 25 | return chai1.servings > chai2.servings; 26 | } 27 | 28 | int main(){ 29 | Chai masalaChai("Masala Chai", 14); 30 | Chai gingerChai("Ginger Chai", 8); 31 | 32 | masalaChai.display(); 33 | gingerChai.display(); 34 | 35 | if(compareServings(masalaChai, gingerChai)){ 36 | cout << "Masal chai is having MORE servings" << endl; 37 | } else { 38 | cout << "Masal chai is having LESS servings" << endl; 39 | 40 | } 41 | 42 | 43 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Code files for C++ 2 | 3 | > Playlist url : [youtube link](https://youtube.com/playlist?list=PLu71SKxNbfoCPfgKZS8UE0MDuwiKvL8zi&si=JtyW06CizjYo7cCh) 4 | 5 | Welcome to the C++ playlist. This playlist is a collection of C++ code files that you can use to practice your C++ skills. Each code file is designed to teach a specific concept or technique, and you can use them as a starting point for your own projects. 6 | 7 | If you want to follow along with the videos, use the link mentioned above to subscribe to the playlist. 8 | 9 | ## Raising PR 10 | 11 | Please do not raise any PRs for this playlist. Learners should get the playlist exactly what was taught in the videos. 12 | 13 | ## Social 14 | 15 | - [twitter](https://twitter.com/hiteshdotcom) 16 | - [LinkedIn](https://www.linkedin.com/in/hiteshchoudhary/) 17 | 18 | ## Course link (Udemy) 19 | 20 | [One stop web development](https://hitesh.ai/udemy) 21 | 22 | ## Challenges 23 | 24 | I am trying to add challenges to the playlist. Finish these challenges and post code selfie on linkedin and twitter and share it with me. 25 | -------------------------------------------------------------------------------- /challenge3.md: -------------------------------------------------------------------------------- 1 | ### **Challenges for Students** 2 | 3 | 1. **Challenge 1: If Statement**\ 4 | Write a program that asks the user for their favorite tea. If they choose "Oolong," print a message saying, "You have excellent taste!" 5 | 6 | 2. **Challenge 2: If-Else Statement**\ 7 | Create a program that asks the user for their age. If the user is older than 18, allow them to proceed with purchasing tea; otherwise, print a message saying they are too young to purchase. 8 | 9 | 3. **Challenge 3: Nested If-Else**\ 10 | Write a program that checks the temperature of tea water input by the user: 11 | 12 | - If the temperature is above 100°C, print "Too hot!" 13 | - If the temperature is between 80°C and 100°C, print "Perfect temperature." 14 | - If the temperature is below 80°C, print "Too cold!" 15 | 16 | 4. **Challenge 4: Switch Case**\ 17 | Write a program that offers different tea brewing methods. The user selects a method (1 for Boiling, 2 for Steeping, 3 for Iced Tea), and the program prints the instructions for the selected brewing method. Use a switch statement to handle the selections. 18 | -------------------------------------------------------------------------------- /08_oop/consDeligation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Chai { 7 | public: 8 | string teaName; 9 | int servings; 10 | vector ingredients; 11 | 12 | // deligating constructor 13 | 14 | Chai(string name): Chai(name, 1, {"Water", "tea leaves"}){} 15 | 16 | // main Constructor 17 | Chai(string name, int serve, vector ingr){ 18 | teaName = name; 19 | servings = serve; 20 | ingredients = ingr; 21 | 22 | cout << "Main Constructor called!" << endl; 23 | } 24 | 25 | void displayChaiDetails(){ 26 | cout << "Tea Name: " << teaName << endl; 27 | cout << "Servings: " << servings << endl; 28 | cout << "Ingredients: " ; 29 | for(string ingridient : ingredients){ 30 | cout << ingridient << " "; 31 | } 32 | cout << endl; 33 | } 34 | }; 35 | 36 | int main(){ 37 | Chai quickChai("Quick chai"); 38 | quickChai.displayChaiDetails(); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the 2 | // README at: https://github.com/devcontainers/templates/tree/main/src/cpp 3 | { 4 | "name": "C++", 5 | "build": { 6 | "dockerfile": "Dockerfile" 7 | }, 8 | 9 | "customizations": { 10 | "vscode": { 11 | "extensions": [ 12 | "hiteshchoudharycode.chai-theme", 13 | "ms-vscode.cpptools", 14 | "ms-vscode.cmake-tools", 15 | "ms-vscode.cpptools-extension-pack" 16 | ] 17 | } 18 | } 19 | 20 | // Features to add to the dev container. More info: https://containers.dev/features. 21 | // "features": {}, 22 | 23 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 24 | // "forwardPorts": [], 25 | 26 | // Use 'postCreateCommand' to run commands after the container is created. 27 | // "postCreateCommand": "gcc -v", 28 | 29 | // Configure tool-specific properties. 30 | // "customizations": {}, 31 | 32 | // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. 33 | // "remoteUser": "root" 34 | } 35 | -------------------------------------------------------------------------------- /challenge4.md: -------------------------------------------------------------------------------- 1 | ### **Challenges for Students** 2 | 3 | 1. **Challenge 1: While Loop**\ 4 | Write a program that keeps asking the user to input the number of tea bags they have left. Stop when the number of bags is 0, and print a message that they are out of tea bags. 5 | 6 | 2. **Challenge 2: Do-While Loop**\ 7 | Write a program that asks the user if they want to add more sugar to their tea. Keep asking until they respond with "enough." Use a `do-while` loop for this. 8 | 9 | 3. **Challenge 3: For Loop**\ 10 | Create a program that prints the first 10 multiples of 2, representing the total tea bags required for making batches of tea. 11 | 12 | 4. **Challenge 4: Break and Continue**\ 13 | Write a program that checks a list of tea types and serves tea for each type, except "Herbal Tea." If "Herbal Tea" is encountered, skip it using `continue`. If "No Tea" is encountered, stop the loop using `break`. 14 | 15 | 5. **Challenge 5: Nested Loops**\ 16 | Write a program that displays a tea brewing schedule. For each day of the week (outer loop), brew 2 cups of tea for breakfast, lunch, and dinner (inner loop). 17 | -------------------------------------------------------------------------------- /challenge2.md: -------------------------------------------------------------------------------- 1 | ### **Challenges for Students** 2 | 3 | 1. **Challenge 1: Arithmetic Operators**\ 4 | Write a program that calculates the price of tea packs. A user enters the number of tea packs they want, and the price per pack. Apply a 10% tax to the total price and display the final cost. 5 | 6 | 2. **Challenge 2: Assignment Operators**\ 7 | Create a program where the user inputs the number of tea bags they have. If the number is less than 20, give them 10 extra bags using the `+=` assignment operator. Display the updated total. 8 | 9 | 3. **Challenge 3: Relational and Logical Operators**\ 10 | A tea subscription service offers a discount if the user buys more than 12 cups or if they are a member for more than a year. Write a program that checks if the user qualifies for a discount based on their input. 11 | 12 | 4. **Challenge 4: Bitwise Operators**\ 13 | Write a program that uses bitwise AND (`&`) to check which tea types are in stock. The stock is encoded in an integer (1 for Green, 2 for Black, 4 for Oolong). Allow the user to check availability by inputting the tea type (1, 2, or 4), and display a message saying whether that tea is in stock or not. 14 | -------------------------------------------------------------------------------- /05_loops/task.md: -------------------------------------------------------------------------------- 1 | # Task to learn loop in C++ 2 | 3 | ## 1. While Loop 4 | Challenge: 5 | Write a program that keeps track of tea orders. Each time a cup of tea is made, decrease the number of cups remaining. The loop should run until all cups are served. 6 | 7 | ## 2. Do-While Loop 8 | Challenge: 9 | Create a program that asks the user if they want more tea. Keep asking them until they type "no" (case-insensitive), using a do-while loop. 10 | 11 | ## 3. For Loop 12 | Challenge: 13 | Write a program that prints the brewing instructions for making 5 cups of tea. The brewing process should be printed once for each cup using a for loop. 14 | 15 | # 4. Break Keyword 16 | Challenge: 17 | Write a program that keeps serving tea until the user says they’ve had enough (input 'stop'). Use a break statement to exit the loop when the user types 'stop'. 18 | 19 | # 5. Continue Keyword 20 | Challenge: 21 | Write a program that skips brewing green tea if the user dislikes it. Use a continue statement to skip over green tea but brew other types of tea in a list. 22 | 23 | # 6. Nested Loops 24 | Challenge: 25 | Write a program that brews multiple cups of different types of tea. For each type of tea, brew 3 cups using a nested loop. -------------------------------------------------------------------------------- /08_oop/myClass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Chai { 7 | public: 8 | //data members (attributes) 9 | string teaName; // name of the tea 10 | int servings; // Number of servings 11 | vector ingredients; // list of ingredients for the tea 12 | 13 | //Member function 14 | 15 | void displayChaiDetails(){ 16 | cout << "Tea Name: " << teaName << endl; 17 | cout << "Servings: " << servings << endl; 18 | cout << "Ingredients: " ; 19 | for(string ingridient : ingredients){ 20 | cout << ingridient << " "; 21 | } 22 | cout << endl; 23 | } 24 | 25 | 26 | 27 | }; 28 | 29 | 30 | int main(){ 31 | Chai chaiOne; 32 | 33 | chaiOne.teaName = "lemon tea"; 34 | chaiOne.servings = 2; 35 | chaiOne.ingredients = {"Water", "lemon", "Honey", "tea"}; 36 | 37 | chaiOne.displayChaiDetails(); 38 | 39 | Chai chaiTwo; 40 | 41 | chaiTwo.teaName = "Masala Chai"; 42 | chaiTwo.servings = 4; 43 | chaiTwo.ingredients = {"Water", "Milk", "Tea", "Ginger", "Masala"}; 44 | 45 | chaiTwo.displayChaiDetails(); 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /08_oop/encp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class BankAccount { 6 | private: 7 | string accountNumber; 8 | double balance; 9 | 10 | public: 11 | BankAccount(string accNum, double initialBalance){ 12 | accountNumber = accNum; 13 | balance = initialBalance; 14 | } 15 | 16 | //getter 17 | double getBalance() const { 18 | return balance; 19 | } 20 | 21 | //Method to deposit money 22 | void deposit(double amount){ 23 | if(amount > 0){ 24 | balance += amount; 25 | cout << "Deposited: " << amount << endl; 26 | } else { 27 | cout << "Invalid deposit amount"; 28 | } 29 | } 30 | 31 | void withdraw(double amount) { 32 | if(amount > 0 && amount <= balance){ 33 | balance -= amount; 34 | }else { 35 | cout << "Invalid withdrawn amount" << endl; 36 | } 37 | } 38 | 39 | }; 40 | 41 | int main(){ 42 | BankAccount myAccount("1229988", 500); 43 | 44 | myAccount.getBalance(); 45 | 46 | myAccount.deposit(200); 47 | myAccount.withdraw(100); 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /08_oop/abstr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | class Tea { 8 | public: 9 | virtual void prepareIngredients() = 0; // pure virtual function 10 | virtual void brew() = 0; // pure virtual function 11 | virtual void serve() = 0; // pure virtual function 12 | 13 | void makeTea(){ 14 | prepareIngredients(); 15 | brew(); 16 | serve(); 17 | } 18 | }; 19 | 20 | //derived class 21 | 22 | class GreenTea : public Tea{ 23 | public: 24 | void prepareIngredients() override { 25 | cout << "green leaves and water is ready" << endl; 26 | } 27 | 28 | void brew() override { 29 | cout << "Green Tea brewed" << endl; 30 | } 31 | void serve() override { 32 | cout << "Green Tea Served" << endl; 33 | } 34 | }; 35 | 36 | class MasalaTea : public Tea{ 37 | public: 38 | void prepareIngredients() override { 39 | cout << "green leaves and water is ready along with masala" << endl; 40 | } 41 | 42 | void brew() override { 43 | cout << "Masala Tea brewed" << endl; 44 | } 45 | void serve() override { 46 | cout << "Masala Tea Served" << endl; 47 | } 48 | }; 49 | 50 | int main(){ 51 | 52 | GreenTea greenTea; 53 | MasalaTea masalaTea; 54 | 55 | greenTea.makeTea(); 56 | masalaTea.makeTea(); 57 | 58 | return 0; 59 | } -------------------------------------------------------------------------------- /03_operators/tasks.md: -------------------------------------------------------------------------------- 1 | ## 1. **Arithmetic Operators** 2 | 3 | ### **Challenge:** Create a program that calculates the total price of tea cups. The user inputs the number of cups they want and the price per cup. The program should calculate the total price, apply a 5% discount if the total is above a certain amount, and show the final price. 4 | 5 | > +, -, \*, /, % 6 | 7 | ### 2. **Assignment Operators** 8 | 9 | ### **Challenge:** Write a program that allows a user to input the number of tea bags they have. Assign additional bags to them based on certain conditions (e.g., if they have fewer than 10 bags, give them 5 extra). Update the original number using assignment operators. 10 | 11 | > +=, -=, \*=, /=, %= 12 | 13 | ### 3. **Relational Operators** 14 | 15 | ### **Challenge:** A tea shop offers a loyalty program. Customers who buy more than 20 cups of tea get a special "Gold" badge, and those who buy 10 to 20 cups get a "Silver" badge. Write a program to display the badge they will receive based on the number of cups they buy. 16 | 17 | > > , >=, <, <= 18 | 19 | ### 4. **Logical Operators** 20 | 21 | ### **Challenge:** Create a program that checks if a user is eligible for a tea subscription discount. The discount applies if the user is either a student or has purchased more than 15 cups. Ask the user to input their status (student or not) and their cup count. 22 | 23 | > > && and || operators 24 | 25 | ### 5. **Bitwise Operators** 26 | 27 | ### Online resources 28 | -------------------------------------------------------------------------------- /08_oop/copyCons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Chai { 7 | public: 8 | string* teaName; 9 | int servings; 10 | vector ingredients; 11 | 12 | //parameter contructor 13 | Chai(string name, int serve, vector ingr){ 14 | teaName = new string(name); 15 | servings = serve; 16 | ingredients = ingr; 17 | cout << "Param constructor called" << endl; 18 | } 19 | 20 | Chai(const Chai& other){ 21 | teaName = new string(*other.teaName); 22 | servings = other.servings; 23 | ingredients = other.ingredients; 24 | cout << "Copy constructor called" << endl; 25 | 26 | } 27 | 28 | 29 | ~Chai(){ 30 | delete teaName; 31 | cout << "Destructor called" << endl; 32 | } 33 | 34 | void displayChaiDetails(){ 35 | cout << "Tea Name: " << *teaName << endl; 36 | cout << "Servings: " << servings << endl; 37 | cout << "Ingredients: " ; 38 | for(string ingridient : ingredients){ 39 | cout << ingridient << " "; 40 | } 41 | cout << endl; 42 | } 43 | 44 | }; 45 | 46 | int main(){ 47 | Chai lemonTea("Lemon Tea", 2, {"Water", "lemon", "Honey"}); 48 | //lemonTea.displayChaiDetails(); 49 | 50 | //copy the object 51 | Chai copiedChai = lemonTea; 52 | //copiedChai.displayChaiDetails(); 53 | 54 | *lemonTea.teaName = "Modified Lemon tea"; 55 | 56 | cout << "Lemon Tea --------" << endl; 57 | lemonTea.displayChaiDetails(); 58 | cout << "Copied Tea ---------" << endl; 59 | copiedChai.displayChaiDetails(); 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /07_array/five.dSYM/Contents/Resources/Relocations/aarch64/five.yml: -------------------------------------------------------------------------------- 1 | --- 2 | triple: 'arm64-apple-darwin' 3 | binary-path: '/Users/apple/Desktop/Hindi/cpp/07_array/five' 4 | relocations: 5 | - { offset: 0x1A, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003D2C, symSize: 0x114 } 6 | - { offset: 0x3205, size: 0x8, addend: 0x0, symName: __ZStL8__ioinit, symObjAddr: 0xE37E, symBinAddr: 0x100008000, symSize: 0x0 } 7 | - { offset: 0x3510, size: 0x8, addend: 0x0, symName: __ZNSt8__detail30__integer_to_chars_is_unsignedIjEE, symObjAddr: 0x1EC, symBinAddr: 0x100003F54, symSize: 0x0 } 8 | - { offset: 0x352A, size: 0x8, addend: 0x0, symName: __ZNSt8__detail30__integer_to_chars_is_unsignedImEE, symObjAddr: 0x1ED, symBinAddr: 0x100003F55, symSize: 0x0 } 9 | - { offset: 0x3544, size: 0x8, addend: 0x0, symName: __ZNSt8__detail30__integer_to_chars_is_unsignedIyEE, symObjAddr: 0x1EE, symBinAddr: 0x100003F56, symSize: 0x0 } 10 | - { offset: 0x3552, size: 0x8, addend: 0x0, symName: __GLOBAL__sub_I_five.cpp, symObjAddr: 0x150, symBinAddr: 0x100003E7C, symSize: 0x14 } 11 | - { offset: 0x356C, size: 0x8, addend: 0x0, symName: __Z41__static_initialization_and_destruction_0v, symObjAddr: 0x114, symBinAddr: 0x100003E40, symSize: 0x3C } 12 | - { offset: 0x3574, size: 0x8, addend: 0x0, symName: __GLOBAL__sub_I_five.cpp, symObjAddr: 0x150, symBinAddr: 0x100003E7C, symSize: 0x14 } 13 | - { offset: 0x3591, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003D2C, symSize: 0x114 } 14 | - { offset: 0x3599, size: 0x8, addend: 0x0, symName: __Z41__static_initialization_and_destruction_0v, symObjAddr: 0x114, symBinAddr: 0x100003E40, symSize: 0x3C } 15 | ... 16 | -------------------------------------------------------------------------------- /08_oop/getterSetter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Chai{ 7 | private: 8 | string teaName; 9 | int servings; 10 | vector ingredients; 11 | 12 | public: 13 | Chai(){ 14 | teaName = "Unknown tea"; 15 | servings = 1; 16 | ingredients = {"Water", "tea leaves"}; 17 | } 18 | 19 | Chai(string name, int serve, vector ingr){ 20 | teaName = name; 21 | servings = serve; 22 | ingredients = ingr; 23 | } 24 | 25 | //getter 26 | string getTeaName(){ 27 | return teaName; 28 | } 29 | 30 | //setter 31 | void setTeaName(string name){ 32 | //logic 33 | teaName = name; 34 | } 35 | 36 | //getter for serving 37 | int getServings(){ 38 | return servings; 39 | } 40 | 41 | //setter for servings 42 | void setServings(int serve){ 43 | servings = serve; 44 | } 45 | 46 | //getter for ingre 47 | vector getIngredients(){ 48 | return ingredients; 49 | } 50 | 51 | //settter for ingre 52 | 53 | void setIngredients(vector ingr){ 54 | ingredients = ingr; 55 | } 56 | 57 | void displayChaiDetails(){ 58 | cout << "Tea Name: " << teaName << endl; 59 | cout << "Servings: " << servings << endl; 60 | cout << "Ingredients: " ; 61 | for(string ingridient : ingredients){ 62 | cout << ingridient << " "; 63 | } 64 | cout << endl; 65 | } 66 | 67 | }; 68 | 69 | int main(){ 70 | Chai chai; 71 | chai.setTeaName("Ginger tea"); 72 | } -------------------------------------------------------------------------------- /09_stl/stl_emp_manage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | using namespace std; 10 | 11 | struct Employee { 12 | int id; 13 | string name; 14 | double salary; 15 | }; 16 | 17 | 18 | void displayEmployee(const Employee& emp){ 19 | cout << "ID: " << emp.id << " , Name: " << emp.name << " , Salary: $" << emp.salary << endl; 20 | } 21 | 22 | int main(){ 23 | 24 | vector employees = { 25 | {101, "hitesh", 100000}, 26 | {102, "saksham", 30000}, 27 | {103, "shubham", 50000}, 28 | {104, "anirudh", 60000}, 29 | {105, "aryan", 70000}, 30 | }; 31 | 32 | sort(employees.begin(), employees.end(), [](const Employee& e1, const Employee& e2){ 33 | return e1.salary > e2.salary; 34 | }); 35 | 36 | cout << "Employees sorted by salary -> Highest to lowest \n"; 37 | for_each(employees.begin(), employees.end(), displayEmployee); 38 | 39 | vector highEarners; 40 | 41 | copy_if( 42 | employees.begin(), 43 | employees.end(), 44 | back_inserter(highEarners), 45 | [](const Employee& e){ 46 | return e.salary > 50000; 47 | }); 48 | 49 | cout << "Employees who are high earners \n"; 50 | for_each(highEarners.begin(), highEarners.end(), displayEmployee); 51 | 52 | double totalSalary = accumulate(employees.begin(), employees.end(), 0.0, [](double sum, const Employee& e){ 53 | return sum + e.salary; 54 | }); 55 | 56 | double avaerageSalary = totalSalary / employees.size(); 57 | 58 | auto highestPaid = max_element(employees.begin(), employees.end(), [](const Employee& e1, const Employee& e2){ 59 | return e1.salary < e2.salary; 60 | }); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /.devcontainer/reinstall-cmake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #------------------------------------------------------------------------------------------------------------- 3 | # Copyright (c) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. 5 | #------------------------------------------------------------------------------------------------------------- 6 | # 7 | set -e 8 | 9 | CMAKE_VERSION=${1:-"none"} 10 | 11 | if [ "${CMAKE_VERSION}" = "none" ]; then 12 | echo "No CMake version specified, skipping CMake reinstallation" 13 | exit 0 14 | fi 15 | 16 | # Cleanup temporary directory and associated files when exiting the script. 17 | cleanup() { 18 | EXIT_CODE=$? 19 | set +e 20 | if [[ -n "${TMP_DIR}" ]]; then 21 | echo "Executing cleanup of tmp files" 22 | rm -Rf "${TMP_DIR}" 23 | fi 24 | exit $EXIT_CODE 25 | } 26 | trap cleanup EXIT 27 | 28 | 29 | echo "Installing CMake..." 30 | apt-get -y purge --auto-remove cmake 31 | mkdir -p /opt/cmake 32 | 33 | architecture=$(dpkg --print-architecture) 34 | case "${architecture}" in 35 | arm64) 36 | ARCH=aarch64 ;; 37 | amd64) 38 | ARCH=x86_64 ;; 39 | *) 40 | echo "Unsupported architecture ${architecture}." 41 | exit 1 42 | ;; 43 | esac 44 | 45 | CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" 46 | CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" 47 | TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) 48 | 49 | echo "${TMP_DIR}" 50 | cd "${TMP_DIR}" 51 | 52 | curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O 53 | curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O 54 | 55 | sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" 56 | sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license 57 | 58 | ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake 59 | ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest 60 | -------------------------------------------------------------------------------- /09_stl/stl_store.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | using namespace std; 14 | 15 | struct Product { 16 | int productID; 17 | string name; 18 | string category; 19 | }; 20 | 21 | struct Order { 22 | int orderID; 23 | int ProductID; 24 | int quantity; 25 | string customerID; 26 | time_t orderDate; 27 | }; 28 | 29 | int main(){ 30 | vector products = { 31 | {101, "Laptop", "Electronics"}, 32 | {102, "SmartPhone", "Electronics"}, 33 | {103, "Coffe Maker", "Kitchen"}, 34 | {104, "Blender", "Kitchen"}, 35 | {105, "Desk lamp", "Home"}, 36 | }; 37 | 38 | deque recentCustomers = {"C001", "C002", "C003"}; 39 | 40 | recentCustomers.push_back("C004"); 41 | recentCustomers.push_front("C005"); 42 | 43 | list orderHistory; 44 | 45 | orderHistory.push_back({1, 101, 1, "C001", time(0)}); 46 | orderHistory.push_back({2, 102, 2, "C002", time(0)}); 47 | orderHistory.push_back({3, 103, 1, "C003", time(0)}); 48 | 49 | set categories; 50 | for(const auto &product: products){ 51 | categories.insert(product.category); 52 | } 53 | 54 | map productStock = { 55 | {101, 10}, 56 | {102, 20}, 57 | {103, 15}, 58 | {104, 5}, 59 | {105, 7}, 60 | }; 61 | 62 | multimap customerOrders; 63 | for(const auto &order: orderHistory){ 64 | customerOrders.insert({order.customerID, order}); 65 | } 66 | 67 | unordered_map customerData = { 68 | {"C001", "Alice"}, 69 | {"C002", "hitesh"}, 70 | {"C003", "Vidya"}, 71 | {"C004", "max"}, 72 | {"C005", "harry"}, 73 | }; 74 | 75 | unordered_set uniqueProductIDs; 76 | 77 | for(const auto &product: products){ 78 | uniqueProductIDs.insert(product.productID); 79 | } 80 | 81 | 82 | return 0; 83 | } -------------------------------------------------------------------------------- /08_oop/inheritance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // base/main/parent class 8 | class Tea { 9 | protected: 10 | string teaName; 11 | int servings; 12 | public: 13 | Tea(string name, int serve): teaName(name), servings(serve){ 14 | cout << "Tea constructor called " << teaName << endl; 15 | } 16 | 17 | virtual void brew() const { 18 | cout << "Brewing " << teaName << " with generic method" << endl; 19 | } 20 | virtual void serve() const { 21 | cout << "Serving " << servings << " cup of tea with generic method" << endl; 22 | } 23 | 24 | virtual ~Tea(){ 25 | cout << "Tea destructor called for " << teaName << endl; 26 | } 27 | 28 | 29 | }; 30 | 31 | class GreenTea: public Tea { 32 | public: 33 | GreenTea(int serve): Tea("Green Tea", serve){ 34 | cout << "Green tea constructor called" << endl; 35 | } 36 | 37 | void brew() const override { 38 | cout << "Brewing" << teaName << " by steeping green tea leaves" << endl; 39 | } 40 | 41 | ~GreenTea(){ 42 | cout << "Green tea constructor called " << endl; 43 | } 44 | }; 45 | 46 | class MasalaTea : public Tea { 47 | public: 48 | MasalaTea(int serve) : Tea("Masala Tea", serve){ 49 | cout << "MasalaTea constructor called" << endl; 50 | } 51 | 52 | void brew() const override final { 53 | cout << "Brewing" << teaName << " with spices and milk" << endl; 54 | } 55 | 56 | ~MasalaTea(){ 57 | cout << "Masala tea desctrutor called" << endl; 58 | } 59 | }; 60 | 61 | // class SpicyMasalaTea: public MasalaTea{ 62 | // public: 63 | // void brew() const override{ 64 | // cout << "Brewing" << teaName << " with spices and milk" << endl; 65 | // } 66 | // }; 67 | 68 | int main(){ 69 | 70 | Tea* tea1 = new GreenTea(2); 71 | Tea* tea2 = new MasalaTea(3); 72 | 73 | tea1->brew(); 74 | tea1->serve(); 75 | 76 | tea2->brew(); 77 | tea2->serve(); 78 | 79 | delete tea1; 80 | delete tea2; 81 | 82 | return 0; 83 | } --------------------------------------------------------------------------------