diff --git a/Projects/C++ Projects/Basic/A Login and Registration System/LoginAndRegistration.cpp b/Projects/C++ Projects/Basic/A Login and Registration System/LoginAndRegistration.cpp index 199a14f..9e53e2e 100644 --- a/Projects/C++ Projects/Basic/A Login and Registration System/LoginAndRegistration.cpp +++ b/Projects/C++ Projects/Basic/A Login and Registration System/LoginAndRegistration.cpp @@ -1,57 +1,83 @@ -// Autor : Nemonet TYP +// Autor : OM ROY // Title: A Login and Registration System Programmed in C++ // PROJECT FOR C/C++ PROGRAMMING TUTORIAL - #include #include -#include -#include -#include -#include -#include +#include #include -#include "login.cpp" +#include using namespace std; - -int main() +bool checkCaptcha(string& captcha, string& user_captcha) { - login userLogin; - string userChoice; - cout << "\t\t\t_____________________________________________\n\n\n"; - cout << "\t\t\t Welcome to the NEMO 2023 Login! \n\n"; - cout << "\t\t\t_________ Menu __________\n\n"; - cout << "\t | Press 1 to LOGIN |" << endl; - cout << "\t | Press 2 to REGISTER |" << endl; - cout << "\t | Press 3 if you forgot PASSWORD |" << endl; - cout << "\t | Press 4 to EXIT |" << endl; - cout << "\n\t\t\t Please Enter your choice: "; - cin >> userChoice; - cout << endl; - if (userChoice == "1") - { - userLogin.Login(); - main(); - } - else if (userChoice == "2") - { - userLogin.Registration(); - main(); - } - else if (userChoice == "3") - { - userLogin.ForgotPassword(); - main(); - } - else if (userChoice == "4") - { - cout << "\t\t\t Goodbye! \n\n"; - } + return captcha.compare(user_captcha) == 0; +} +string generateCaptcha(int n) +{ + time_t t; + srand((unsigned)time(&t)); + const char* chrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + string captcha = ""; + while (n--) + captcha.push_back(chrs[rand() % 62]); + return captcha; +} +void registeruser() { + string u, p; + cout << "Enter username: "; + cin >> u; + cout << "Enter password: "; + cin >> p; + ofstream outfile("users.txt", ios::app); + outfile << u << " " << p<< endl; + outfile.close(); + cout << "Registration successful!" << endl; +} +bool login() { + string u, p, su, sp;//su:-storedusername,sp:-storedpassword + cout << "Enter username: "; + cin >> u; + cout << "Enter password: "; + cin >> p; + string captcha = generateCaptcha(9); + cout << captcha; + string usr_captcha; + cout << "Enter above CAPTCHA: "; + cin >> usr_captcha; + if (checkCaptcha(captcha, usr_captcha)) + printf("\nCAPTCHA Matched\n"); else - { - system("cls"); - cout << "\t\t\t Please select from the options above\n"; - main(); + printf("\nCAPTCHA Not Matched\n"); + ifstream infile("users.txt"); + while (infile >> su >>sp) { + if (su == u && sp == p) { + infile.close(); + return true; + } } + infile.close(); + return false; } + +int main() { + int c; + cout << "Enter your choice(1.Registration,2.Login): "; + cin >> c; + if (c == 1) { + registeruser(); + } + else if (c == 2) { + if (login()) { + cout << "Login successful!" << endl; + } + else { + cout << "Login failed!" << endl; + } + } + else { + cout << "Invalid !" << endl; + } + return 0; +} + diff --git a/Projects/C++ Projects/Basic/A Login and Registration System/login.cpp b/Projects/C++ Projects/Basic/A Login and Registration System/login.cpp index 123d9cb..793c0fc 100644 --- a/Projects/C++ Projects/Basic/A Login and Registration System/login.cpp +++ b/Projects/C++ Projects/Basic/A Login and Registration System/login.cpp @@ -1,23 +1,60 @@ -// Autor : Nemonet TYP +// Autor : Om Roy // Title: A Login and Registration System Programmed in C++ // PROJECT FOR C/C++ PROGRAMMING TUTORIAL #include #include -#include -#include +#include +#include #include -#include -#include #include +#include #include "login.h" using namespace std; -void login::Login() -{ - string count; - string username, password, id, recordPass, recordSecurity; +namespace { + + // Helper function to hash strings + int hashString(const string& str) { + hash mystdhash; + return mystdhash(str); + } + + // Helper function to read user data from the file + bool readUserDataFromFile(const string& filename, unordered_map>& usersData) { + ifstream input(filename); + if (!input) return false; + + string id, pass, security; + while (input >> id >> pass >> security) { + usersData[id] = { stoi(pass), stoi(security) }; + } + + return true; + } + + // Helper function to write user data to the file + void writeUserDataToFile(const string& filename, const unordered_map>& usersData) { + ofstream output(filename, ios::trunc); + for (const auto& user : usersData) { + output << user.first << ' ' << user.second.first << ' ' << user.second.second << endl; + } + } + + // Helper function to delete a specific user by ID + void deleteUserData(const string& filename, const string& userId) { + unordered_map> usersData; + readUserDataFromFile(filename, usersData); + + usersData.erase(userId); + writeUserDataToFile(filename, usersData); + } + +} // Anonymous namespace + +void login::Login() { + string username, password; system("cls"); cout << "\n\t\t\t Please enter the username and password: " << endl; cout << "\t\t\t USERNAME: "; @@ -25,27 +62,19 @@ void login::Login() cout << "\t\t\t PASSWORD: "; cin >> password; - string loginHash = password; - hash mystdhash; - int loginHashPassword = mystdhash(loginHash); - - ifstream input("data.txt"); - - while (input >> id >> recordPass >> recordSecurity) - { - if (id == username && stoi(recordPass) == loginHashPassword) - { - count = "1"; - system("cls"); - } + int loginHashPassword = hashString(password); + unordered_map> usersData; + if (!readUserDataFromFile("data.txt", usersData)) { + cout << "\n Error reading data file\n"; + return; } - input.close(); - if (count == "1") - { + + if (usersData.find(username) != usersData.end() && usersData[username].first == loginHashPassword) { + system("cls"); cout << username << "\nLogin successful!\n"; + string choice = "1"; - while (choice != "2") - { + while (choice != "2") { cout << "\t\t\t_____________________________________________\n\n\n"; cout << "\t\t\t Welcome to the NEMO 2023 Login! \n\n"; cout << "\t\t\t_______ Currently Logged In: " << username << " ________\n\n"; @@ -56,33 +85,27 @@ void login::Login() cin >> choice; cout << endl; - if (choice == "1") - { + if (choice == "1") { system("cls"); DrunkGame(); } - else if (choice == "2") - { + else if (choice == "2") { system("cls"); cout << "Logging out" << endl; } - else - { + else { system("cls"); cout << "Choice invalid, try again"; } } - } - else - { + } else { system("cls"); cout << "\n Username or password is incorrect, please try again or register\n"; } } -void login::Registration() -{ - string regUser, regPassword, regId, regPass, securityQuestion, regSecure, regCount; +void login::Registration() { + string regUser, regPassword, securityQuestion; system("cls"); cout << "\n\t\t\t Enter Username: "; cin >> regUser; @@ -92,255 +115,126 @@ void login::Registration() cin.ignore(); getline(cin, securityQuestion); - string hashing = regPassword; - hash mystdhash; - int hashPassword = mystdhash(hashing); + int regPassHash = hashString(regPassword); + int securityHash = hashString(securityQuestion); - string secureHashing = securityQuestion; - hash mystdhash2; - int securityHash = mystdhash2(secureHashing); + unordered_map> usersData; + if (!readUserDataFromFile("data.txt", usersData)) { + cout << "\n Error reading data file\n"; + return; + } - ifstream input("data.txt"); - input.seekg(0, ios::end); + if (usersData.find(regUser) != usersData.end()) { + string decision; + cout << "\n\tUsername already taken.\n"; + cout << "\t\tEnter 1 to enter a new one\n"; + cout << "\t\tEnter 2 to go back to the menu\n"; + cout << "\n\t\tEnter choice: "; + cin >> decision; + + if (decision == "1") { + Registration(); + } else if (decision == "2") { + system("cls"); + cout << "\tReturning to menu\n"; + return; + } else { + system("cls"); + cout << "\tInvalid Entry, returning to menu." << endl; + return; + } + } - if (input.tellg() == 0) - { - ofstream f1("data.txt", ios::app); - f1 << regUser << ' ' << hashPassword << ' ' << securityHash << endl; + usersData[regUser] = { regPassHash, securityHash }; + writeUserDataToFile("data.txt", usersData); + + system("cls"); + cout << "\n\t\t\t Registration successful!\n"; +} + +void login::ForgotPassword() { + string user; + system("cls"); + cout << "\n\t\t\tPress 1 to enter USERNAME\n"; + cout << "\t\t\tPress 2 to go back to MENU\n"; + cout << "\n\t\t\tEnter choice: "; + cin >> user; + + if (user == "1") { + string username, userSecurity, newPassword; system("cls"); - cout << "\n\t\t\t Registration successful!\n"; - return; - } - else - { - ifstream input("data.txt"); - while (input >> regId >> regPass >> regSecure) - { - if (regUser == regId) - { - string decision; - cout << "\n\t\tUsername already taken.\n"; - cout << "\t\tEnter 1 to enter a new one\n"; - cout << "\t\tEnter 2 to go back to the menu\n"; - cout << "\n\t\tEnter choice: "; - cin >> decision; - - if (decision == "1") - { - Registration(); - } - else if (decision == "2") - { - system("cls"); - cout << "\tReturning to menu\n"; - return; - } - else - { - system("cls"); - cout << "\tInvalid Entry, returning to menu." << endl; - return; - } - } - else - { - regCount = "1"; - } + cout << "\n\t\tEnter USERNAME: "; + cin >> username; + unordered_map> usersData; + if (!readUserDataFromFile("data.txt", usersData)) { + cout << "\n Error reading data file\n"; + return; } - if (regCount == "1") - { - ofstream f1("data.txt", ios::app); - f1 << regUser << ' ' << hashPassword << ' ' << securityHash << endl; - system("cls"); - cout << "\n\t\t\t Registration successful!\n"; + + if (usersData.find(username) == usersData.end()) { + cout << "\t\tUser not found\n"; return; } + + cout << "\n\t\tUser found\n\t\tSecurity Question: What was your favorite childhood movie?: "; + cin.ignore(); + getline(cin, userSecurity); + + int securityHash = hashString(userSecurity); + if (usersData[username].second == securityHash) { + system("cls"); + cout << "\t\tSecurity Question correct\n"; + cout << "\n\t\tEnter new PASSWORD: "; + cin >> newPassword; + + int newPassHash = hashString(newPassword); + usersData[username] = { newPassHash, usersData[username].second }; + writeUserDataToFile("data.txt", usersData); + + cout << "\t\t\t Your password has been updated!\n"; + } else { + system("cls"); + cout << "\t\tSecurity Question incorrect\n"; + } + } else if (user == "2") { + system("cls"); + cout << "\tReturning to MENU\n"; + } else { + system("cls"); + cout << "\tChoice invalid... Try again\n"; + ForgotPassword(); } } -void login::DrunkGame() -{ +void login::DrunkGame() { srand(time(0)); const int size = 60; cout << "Enter a letter to begin \n "; char x; cin >> x; int position = size / 2; - while (true) - { + while (true) { cout << "|START|"; - for (int i = 0; i < size; i++) - { + for (int i = 0; i < size; i++) { if (i == position) cout << x; else cout << " "; } cout << "|END|" << endl; + int move = rand() % 3 - 1; position = position + move; - if (position < 1) - { + + if (position < 1) { cout << "Guess you were too drunk to make it to the end..." << endl; break; } - if (position > size - 1) - { + if (position > size - 1) { cout << "You might be drunk, but you made it to the end!" << endl; break; } - for (int sleep = 0; sleep < 1000000; ++sleep) - ; } system("pause"); system("cls"); } - -void login::ForgotPassword() -{ - string forgotChoice, count, secondCount; - system("cls"); - cout << "\n\t\t\tPress 1 to enter USERNAME\n"; - cout << "\t\t\tPress 2 to go back to MENU\n"; - cout << "\n\t\t\tEnter choice: "; - cin >> forgotChoice; - - if (forgotChoice == "1") - { - string user, userSecurity, forgotId, forgotPass, forgotSecurity; - int newHashPassword, forgotSecHash; - system("cls"); - cout << "\n\t\tEnter USERNAME: "; - cin >> user; - cout << endl; - - ifstream input("data.txt"); - while (input >> forgotId >> forgotPass >> forgotSecurity) - { - if (user == forgotId) - { - cout << "\n\t\tUser found\n\t\tSecurity Question: What was your favorite childhood movie?: "; - cin.ignore(); - getline(cin, userSecurity); - cout << endl; - - string hashing = userSecurity; - hash mystdhash; - forgotSecHash = mystdhash(hashing); - - if (stoi(forgotSecurity) == forgotSecHash) - { - system("cls"); - string newPass; - cout << "\t\tSecurity Question correct\n"; - cout << "\n\t\tEnter new PASSWORD: "; - cin >> newPass; - - string newPassHash = newPass; - hash mystdhash2; - newHashPassword = mystdhash2(newPassHash); - - count = "1"; - break; - } - else - { - string incorrectChoice; - system("cls"); - cout << "\t\tSecurity Question incorrect\n"; - cout << "\t\tPress 1 to Re-Enter\n\t\tPress 2 to return to MENU\n"; - cout << "\n\t\tEnter choice: "; - cin >> incorrectChoice; - - if (incorrectChoice == "1") - { - ForgotPassword(); - } - if (incorrectChoice == "2") - { - system("cls"); - cout << "\tReturning to MENU\n"; - return; - } - else - { - system("cls"); - cout << "\tInvalid answer... Returning to menu\n"; - return; - } - } - } - else - { - string newChoice; - system("cls"); - cout << "\t\tUser not found\n"; - cout << "\t\tPress 1 to Re-Enter USERNAME\n\t\tPress 2 to return to MENU\n"; - cout << "\n\t\tEnter choice: "; - cin >> newChoice; - if (newChoice == "1") - { - ForgotPassword(); - } - else if (newChoice == "2") - { - system("cls"); - cout << "\tReturning to MENU\n"; - return; - } - else - { - system("cls"); - cout << "\tChoice invalid... Returning to MENU\n"; - return; - } - } - } - input.close(); - if (count == "1") - { - DeleteLine(user); - secondCount = "1"; - } - if (secondCount == "1") - { - ofstream f1("data.txt", ios::app); - f1 << user << ' ' << newHashPassword << ' ' << forgotSecHash << endl; - system("cls"); - cout << "\t\t\t Your password has been updated!\n"; - return; - } - } - else if (forgotChoice == "2") - { - system("cls"); - cout << "\tReturning to MENU\n"; - return; - } - else - { - system("cls"); - cout << "\tChoice invalid... Try again\n"; - ForgotPassword(); - } -} - -void login::DeleteLine(string userDelete) -{ - string line; - ifstream myFile; - myFile.open("data.txt"); - ofstream temp; - temp.open("temp.txt"); - while (getline(myFile, line)) - { - if (line.substr(0, userDelete.size()) != userDelete) - { - temp << line << endl; - } - } - myFile.close(); - temp.close(); - remove("data.txt"); - rename("temp.txt", "data.txt"); -} diff --git a/Projects/C++ Projects/Basic/AIO Calculator/AIO calculator.cpp b/Projects/C++ Projects/Basic/AIO Calculator/AIO calculator.cpp index c8e494d..73f37f9 100644 --- a/Projects/C++ Projects/Basic/AIO Calculator/AIO calculator.cpp +++ b/Projects/C++ Projects/Basic/AIO Calculator/AIO calculator.cpp @@ -1,148 +1,139 @@ #include +#include // For pow() function using namespace std; -//addition -long double add(long double num1, long double num2) -{ - long double result; - { - result = num1 + num2; - } - return result; +// Addition +long double add(long double num1, long double num2) { + return num1 + num2; } -//subtraction -long double sub(long double num1a, long double num2a) -{ - long double resulta; - { - resulta = num1a - num2a; - } - return resulta; + +// Subtraction +long double sub(long double num1, long double num2) { + return num1 - num2; } -//multiplication -long double mltp(long double num1b, long double num2b) -{ - long double resultb; - { - resultb = num1b * num2b; - } - return resultb; + +// Multiplication +long double multiply(long double num1, long double num2) { + return num1 * num2; } -//division -long double dv(long double num1c, long double num2c) -{ - long double resultc; - { - resultc = num1c / num2c; + +// Division (with zero check) +long double divide(long double num1, long double num2) { + if (num2 == 0) { + cout << "Error: Division by zero is undefined.\n"; + return 0; } - return resultc; + return num1 / num2; } -//exponent -long double power(long double base, long double exponent) -{ - long double resultd = 1; - for(long double i = 0; i < exponent; i++) - { - resultd = base * resultd; - } - return resultd; + +// Exponentiation using pow() +long double power(long double base, long double exponent) { + return pow(base, exponent); +} + +// Conversion functions +long double celsiusToFahrenheit(long double celsius) { + return (celsius * 1.8) + 32; } -int panel; -long double a; -long double b; +long double fahrenheitToCelsius(long double fahrenheit) { + return (fahrenheit - 32) * 5 / 9; +} -void ctrl_panel() -{ - cout << "Control Panel\n\nOperators: \n\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Exponent\n6.Multiplication Table\n7.Celcius to Farenheit\n8.Farenheit to Celcius\n\n0.Back\n"; - cin >> panel; - switch(panel) - { - case 0: - return; - break; - case 1: - cout << "Addition\n\nFirst Number: \n"; - cin >> a; - cout << "Second Number: \n"; - cin >> b; - cout << add(a, b) << endl << endl; - break; - case 2: - cout << "Subtraction\n\nFirst Number: \n"; - cin >> a; - cout << "Second Number: \n"; - cin >> b; - cout << sub(a, b) << endl << endl; - break; - case 3: - cout << "Multiplication\n\nFirst Number: \n"; - cin >> a; - cout << "Second Number: \n"; - cin >> b; - cout << mltp(a, b) << endl << endl; - break; - case 4: - cout << "Division\n\nFirst Number: \n"; - cin >> a; - cout << "Second Number: \n"; - cin >> b; - cout << dv(a, b) << endl << endl; - break; - case 5: - cout << "Exponent\n\nBase: \n"; - cin >> a; - cout << "Power: \n"; - cin >> b; - cout << power(a, b) << endl << endl; - break; - case 7: - cout << "Celcius to Farenheit\n\nTemperature: \n"; - cin >> a; - cout << a * 1.8 + 32 << "℉" << endl << endl; - break; - case 8: - cout << "Farenheit to Celcius\n\nTemperature: \n"; - cin >> a; - cout << (a - 32) * 5/9 << "℃" << endl << endl; - break; - case 6: - cout << "Multiplication table\n\nPlease select a number you want to show the table of: \n"; - int num; - cin >> num; - int num2 = 0; - cout << "Range: \n"; - int range; - cin >> range; - - for(int i = 0; i < range; i++) - { - num2++; - cout << num << " x " << num2 << " = " << num * num2 << endl << endl; - } - break; - } +// Display multiplication table +void multiplicationTable() { + int num, range; + cout << "Enter the number for multiplication table: "; + cin >> num; + cout << "Enter the range: "; + cin >> range; + + for (int i = 1; i <= range; i++) { + cout << num << " x " << i << " = " << num * i << endl; + } } -int main() -{ +// Control panel function +void controlPanel() { int choice; - do - { - cout << "Welcone to NemoNet Calculator\n\n1.Enter\n0.Quit\n\n"; - cout << " contact NemoNet on: \n\nGitHub\n"; + + do { + cout << "\nControl Panel\n"; + cout << "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n"; + cout << "5. Exponentiation\n6. Multiplication Table\n"; + cout << "7. Celsius to Fahrenheit\n8. Fahrenheit to Celsius\n"; + cout << "0. Exit\n\nEnter your choice: "; cin >> choice; - - switch(choice) - { + + long double a, b; + + switch (choice) { case 1: - ctrl_panel(); + cout << "Enter two numbers: "; + cin >> a >> b; + cout << "Result: " << add(a, b) << endl; + break; + case 2: + cout << "Enter two numbers: "; + cin >> a >> b; + cout << "Result: " << sub(a, b) << endl; + break; + case 3: + cout << "Enter two numbers: "; + cin >> a >> b; + cout << "Result: " << multiply(a, b) << endl; + break; + case 4: + cout << "Enter two numbers: "; + cin >> a >> b; + cout << "Result: " << divide(a, b) << endl; + break; + case 5: + cout << "Enter base and exponent: "; + cin >> a >> b; + cout << "Result: " << power(a, b) << endl; + break; + case 6: + multiplicationTable(); + break; + case 7: + cout << "Enter temperature in Celsius: "; + cin >> a; + cout << "Fahrenheit: " << celsiusToFahrenheit(a) << "℉" << endl; + break; + case 8: + cout << "Enter temperature in Fahrenheit: "; + cin >> a; + cout << "Celsius: " << fahrenheitToCelsius(a) << "℃" << endl; break; case 0: - return 0; + cout << "Exiting calculator. Goodbye!\n"; + return; + default: + cout << "Invalid choice. Please try again.\n"; + } + } while (choice != 0); +} + +// Main function +int main() { + int option; + + do { + cout << "\nWelcome to NemoNet Calculator\n"; + cout << "1. Start\n0. Quit\n\nEnter your choice: "; + cin >> option; + + switch (option) { + case 1: + controlPanel(); break; + case 0: + cout << "Thank you for using NemoNet Calculator!\n"; + return 0; + default: + cout << "Invalid choice. Please enter 1 to start or 0 to quit.\n"; } - } - while(choice != 0); + } while (option != 0); } diff --git a/Projects/C++ Projects/Basic/Bank Management System/Bank_management_system.cpp b/Projects/C++ Projects/Basic/Bank Management System/Bank_management_system.cpp new file mode 100644 index 0000000..f8e2a3b --- /dev/null +++ b/Projects/C++ Projects/Basic/Bank Management System/Bank_management_system.cpp @@ -0,0 +1,75 @@ +// Autor : OM ROY +// Title: Bank Management System Programmed in C++ +// PROJECT FOR C/C++ PROGRAMMING TUTORIAL + +#include +#include +#include +using namespace std; +class Bank { + string name; + double accountNumber, depositAmount, withdrawalAmount, balance, rate, timeDuration; + char accountType; +public: + void getdata(); + void saving_account(); + void current_account(); + void display(); +}; +void Bank::getdata(void) { + cout << "Enter the name of Account Holder: "; + cin.ignore(); + getline(cin, name); + cout << "Enter the Account Number: "; + cin >> accountNumber; + cout << "Enter the Deposit Amount: "; + cin >> depositAmount; + cout << "Enter the Withdrawal Amount: "; + cin >> withdrawalAmount; + balance = 0000; // Initial balance + cout << "Enter the Account Type (s for saving, c for current): "; + cin >> accountType; + cout << "Enter the Time Duration (in years): "; + cin >> timeDuration; + switch(accountType) { + case 's': + saving_account(); + break; + case 'c': + current_account(); + break; + default: + cout << "Invalid account type!" << endl; + } +} +void Bank::saving_account(void) { + rate = 7; + balance = balance + depositAmount - withdrawalAmount; + double finalBalance = balance * pow((1 + rate / 100), timeDuration); + cout << "The Balance after the compound interest: " << finalBalance << endl; + cout << "The Amount after withdrawal: " << balance << endl; + cout << "You will not get a check book." << endl; +} +void Bank::current_account(void) { + rate = 5; + balance = balance + depositAmount - withdrawalAmount; + cout << "The Balance: " << balance << endl; + if (balance >= 3000) { + cout << "The ledger balance: " << balance << endl; + } else { + cout << "The ledger balance: " << balance - 354 << " (including penalty)" << endl; + } + cout << "You will get a check book." << endl; +} +void Bank::display(void) { + cout << "The Account Holder Name: " << name << endl; + cout << "Account Number: " << accountNumber << endl; + cout << "Current Balance: " << balance << endl; +} +int main() { + Bank account; + account.getdata(); + account.display(); + return 0; +} + diff --git a/Projects/C++ Projects/Basic/Bank Management System/Bank_management_system.exe b/Projects/C++ Projects/Basic/Bank Management System/Bank_management_system.exe new file mode 100644 index 0000000..6a623e2 Binary files /dev/null and b/Projects/C++ Projects/Basic/Bank Management System/Bank_management_system.exe differ diff --git a/Projects/C++ Projects/Basic/Bank Management System/main.cpp b/Projects/C++ Projects/Basic/Bank Management System/main.cpp deleted file mode 100644 index 8b13789..0000000 --- a/Projects/C++ Projects/Basic/Bank Management System/main.cpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Projects/C++ Projects/Basic/Bank Management System/main.exe b/Projects/C++ Projects/Basic/Bank Management System/main.exe new file mode 100644 index 0000000..06aa6fd Binary files /dev/null and b/Projects/C++ Projects/Basic/Bank Management System/main.exe differ diff --git a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp index 932f14f..a83542a 100644 --- a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp +++ b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp @@ -1,196 +1,247 @@ -/*This C++ PROGRAM is developed by NemonET TYP and -special right is given to TEAM TYP for educational purpose */ -//Don't copy source code without permission - +// Autor : OM ROY +// Title: Calculate CGPA Programmed in C++ +// PROJECT FOR C/C++ PROGRAMMING TUTORIAL + + + +// #include +// #include + +// using namespace std; + +// void calculateGPA(); +// void calculateCGPA(); +// void method(); + +// int main() +// { +// system("cls"); +// int input; +// cout<<"--------------------------------------------------------------------------"<>input; +// switch(input) +// { +// case 1: +// calculateGPA(); +// break; + +// case 2: +// calculateCGPA(); +// break; +// case 3: +// method(); +// break; +// case 4: +// exit(EXIT_SUCCESS); +// break; +// default: +// cout<<"You have entered wrong input.Try again!\n"<>q; + +// float credit [q]; +// float point [q]; + +// cout<>credit[i]; +// cout<>point[i]; +// cout<<"-----------------------------------\n\n"<>inmenu; + +// switch(inmenu) +// { +// case 1: +// calculateGPA(); +// break; +// case 2: +// main(); +// break; +// case 3: +// exit(EXIT_SUCCESS); + +// default: +// cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<>l; +// cout<<"\n\n"<>semrs[i]; +// cout<<"\n"<>inmenu; + +// switch(inmenu) +// { +// case 1: +// calculateCGPA(); +// break; +// case 2: +// main(); +// break; +// case 3: +// exit(EXIT_SUCCESS); + +// default: +// cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<>inmenu; + +// switch(inmenu) +// { +// case 1: +// main(); +// break; +// case 2: +// exit(EXIT_SUCCESS); + +// default: +// cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"< -#include - +#include using namespace std; - -void calculateGPA(); -void calculateCGPA(); -void method(); - -int main() -{ - system("cls"); - int input; - cout<<"--------------------------------------------------------------------------"<>input; - switch(input) - { - case 1: - calculateGPA(); - break; - - case 2: - calculateCGPA(); - break; - case 3: - method(); - break; - case 4: - exit(EXIT_SUCCESS); - break; - default: - cout<<"You have entered wrong input.Try again!\n"<> s.name; + cout << "Enter the internal marks (out of 40):" << endl; + cin >> s.internalMarks; + cout << "Enter the internal marks (out of 50):" << endl; + cin >> s.midtermmarks; + cout << "Enter the internal marks (out of 100):" << endl; + cin >> s.termendmarks; + return s; } - -void calculateGPA() -{ - int q; - system("cls"); - cout<<"-------------- GPA Calculating -----------------"<>q; - - float credit [q]; - float point [q]; - - cout<>credit[i]; - cout<>point[i]; - cout<<"-----------------------------------\n\n"<>inmenu; - - switch(inmenu) - { - case 1: - calculateGPA(); - break; - case 2: - main(); - break; - case 3: - exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<>l; - cout<<"\n\n"<>semrs[i]; - cout<<"\n"<>inmenu; - - switch(inmenu) - { - case 1: - calculateCGPA(); - break; - case 2: - main(); - break; - case 3: - exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<(totalCgpaSum) / n; } - -void method() -{ - system("cls"); - cout<<"--------------- Method of Calculating GPA & CGPA ---------------\n\n"<>inmenu; - - switch(inmenu) - { - case 1: - main(); - break; - case 2: - exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<> n; + Subject arr[n]; + for (int i = 0; i < n; i++) { + arr[i] = subjects(); } -}; + for (int i = 0; i < n; i++) { + int c = cgpa(arr[i].internalMarks, arr[i].midtermmarks, arr[i].termendmarks); + cout << "CGPA for subject " << arr[i].name << " is: " << c << endl; + } + float totalCgpaValue = totalCgpa(arr, n); + cout << "Total CGPA for all subjects is: " << totalCgpaValue << endl; + return 0; +} \ No newline at end of file diff --git a/Projects/C++ Projects/Basic/Certificate/Largest_Number.cpp b/Projects/C++ Projects/Basic/Certificate/Largest_Number.cpp new file mode 100644 index 0000000..1662f24 --- /dev/null +++ b/Projects/C++ Projects/Basic/Certificate/Largest_Number.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +int main() { + float n1, n2, n3; + cout << "Enter the first number: "; + cin >> n1; + cout << "Enter the second number: "; + cin >> n2; + cout << "Enter the third number: "; + cin >> n3; + if (n1 >= n2 && n1 >= n3) { + cout << "The largest number is: " << n1 << endl; + } + else if (n2 >= n1 && n2 >= n3) { + cout << "The largest number is: " << n2 << endl; + } + else { + cout << "The largest number is: " << n3 << endl; + } + return 0; +} diff --git a/Projects/C++ Projects/Basic/Certificate/Largest_Number.exe b/Projects/C++ Projects/Basic/Certificate/Largest_Number.exe new file mode 100644 index 0000000..6c3666e Binary files /dev/null and b/Projects/C++ Projects/Basic/Certificate/Largest_Number.exe differ diff --git a/Projects/C++ Projects/Basic/Certificate/certificate.exe b/Projects/C++ Projects/Basic/Certificate/certificate.exe new file mode 100644 index 0000000..f4ac2e7 Binary files /dev/null and b/Projects/C++ Projects/Basic/Certificate/certificate.exe differ diff --git a/Projects/C++ Projects/Basic/Scientific Calculator/scientificcaculator.cpp b/Projects/C++ Projects/Basic/Scientific Calculator/scientificcaculator.cpp new file mode 100644 index 0000000..dcec16f --- /dev/null +++ b/Projects/C++ Projects/Basic/Scientific Calculator/scientificcaculator.cpp @@ -0,0 +1,121 @@ +#include +#include +using namespace std; +void show(){ + cout << "Scientific Calculator" << endl; + cout << "1. Addition" << endl; + cout << "2. Subtraction" << endl; + cout << "3. Multiplication" << endl; + cout << "4. Division" << endl; + cout << "5. Sine" << endl; + cout << "6. Cosine" << endl; + cout << "7. Tangent" << endl; + cout << "8. Logarithm" << endl; + cout << "9. Exponential" << endl; + cout << "10. Power" << endl; + cout << "11. Exit" << endl; +} +double add(double a, double b) { + return a + b; +} +double sub(double a, double b) { + return a - b; +} +double mul(double a, double b) { + return a * b; +} +double divide(double a, double b) { + if (b == 0) { + cout << "Invalid" << endl; + return NAN; + } + return a / b; +} +double sine(double x) { + return sin(x); +} +double cosine(double x) { + return cos(x); +} +double tangent(double x) { + return tan(x); +} +double log(double x) { + if (x <= 0) { + cout << "Invalid" << endl; + return NAN; + } + return log(x); +} +double exp(double x) { + return exp(x); +} +double pow(double base, double exponent) { + return pow(base, exponent); +} +int main() { + int c; + double num1, num2; + while (true) { + show(); + cout << "Enter your choice: "; + cin >> c; + if (c == 11) break; + switch (c) { + case 1: + cout << "Enter two numbers: "; + cin >> num1 >> num2; + cout << "Result: " << add(num1, num2) << endl; + break; + case 2: + cout << "Enter two numbers: "; + cin >> num1 >> num2; + cout << "Result: " << sub(num1, num2) << endl; + break; + case 3: + cout << "Enter two numbers: "; + cin >> num1 >> num2; + cout << "Result: " << mul(num1, num2) << endl; + break; + case 4: + cout << "Enter two numbers: "; + cin >> num1 >> num2; + cout << "Result: " << divide(num1, num2) << endl; + break; + case 5: + cout << "Enter angle in radians: "; + cin >> num1; + cout << "Result: " << sine(num1) << endl; + break; + case 6: + cout << "Enter angle in radians: "; + cin >> num1; + cout << "Result: " << cosine(num1) << endl; + break; + case 7: + cout << "Enter angle in radians: "; + cin >> num1; + cout << "Result: " << tangent(num1) << endl; + break; + case 8: + cout << "Enter a number: "; + cin >> num1; + cout << "Result: " << log(num1) << endl; + break; + case 9: + cout << "Enter a number: "; + cin >> num1; + cout << "Result: " << exp(num1) << endl; + break; + case 10: + cout << "Enter base and exponent: "; + cin >> num1 >> num2; + cout << "Result: " << pow(num1, num2) << endl; + break; + default: + cout << "Invalid choice!" << endl; + } + cout << endl; + } + return 0; +} diff --git a/Projects/C++ Projects/Basic/Scientific Calculator/scientificcaculator.exe b/Projects/C++ Projects/Basic/Scientific Calculator/scientificcaculator.exe new file mode 100644 index 0000000..4e33f32 Binary files /dev/null and b/Projects/C++ Projects/Basic/Scientific Calculator/scientificcaculator.exe differ diff --git a/Projects/C++ Projects/Basic/Stone Paper Scissor/stonepaperscissor.cpp b/Projects/C++ Projects/Basic/Stone Paper Scissor/stonepaperscissor.cpp new file mode 100644 index 0000000..c05db00 --- /dev/null +++ b/Projects/C++ Projects/Basic/Stone Paper Scissor/stonepaperscissor.cpp @@ -0,0 +1,134 @@ +// Autor : OM ROY +// Title: Stone Paper Scissor Programmed in C++ +// PROJECT FOR C/C++ PROGRAMMING TUTORIAL +//I make two different code + +// #include +// using namespace std; +// struct Game{ +// char player1; +// char player2; +// }; +// Game games(){ +// Game a; +// cout<<"Game (C= Scissor,S=Stone,P=Paper)"<>a.player1; +// cout<<"Player 2(C or S or P)"<>a.player2; +// return a; +// } +// void winner(Game a){ +// if(a.player1 =='C'&& a.player2 =='P'){ +// cout<<"Player 1 is winner"< +// using namespace std; + +// // Define struct for Game +// struct Game { +// char player1; +// char player2; +// }; + +// // Function to play a single game round and return a Game object +// Game games() { +// Game a; +// cout << "Game (C= Scissor, S= Stone, P= Paper)" << endl; +// cout << "Player 1 (C or S or P): "; +// cin >> a.player1; +// cout << "Player 2 (C or S or P): "; +// cin >> a.player2; +// return a; +// } + +// // Function to determine and print the winner +// void winner(Game a) { +// if ((a.player1 == 'C' && a.player2 == 'P') || +// (a.player1 == 'P' && a.player2 == 'S') || +// (a.player1 == 'S' && a.player2 == 'C')) { +// cout << "Player 1 is the winner!" << endl; +// } else if ((a.player1 == 'P' && a.player2 == 'C') || +// (a.player1 == 'S' && a.player2 == 'P') || +// (a.player1 == 'C' && a.player2 == 'S')) { +// cout << "Player 2 is the winner!" << endl; +// } else { +// cout << "It's a draw!" << endl; +// } +// } + +// int main() { +// cout << "Start the GAME:" << endl; + +// // Array to hold multiple games (currently set to hold 1 game) +// Game g[1]; + +// // Play one round of the game +// g[0] = games(); + +// // Determine and print the winner +// winner(g[0]); + +// return 0; +// } + +#include +using namespace std; +void win(string ans1, string ans2){ + if(ans1=="rock" and ans2 == "paper"){ + cout<<"Person with paper sign won"<>ans1; + cout<<"Enter the possibility2: "<>ans2; + win(ans1,ans2); +} \ No newline at end of file diff --git a/Projects/C++ Projects/Basic/Stone Paper Scissor/stonepaperscissor.exe b/Projects/C++ Projects/Basic/Stone Paper Scissor/stonepaperscissor.exe new file mode 100644 index 0000000..bbc9ea2 Binary files /dev/null and b/Projects/C++ Projects/Basic/Stone Paper Scissor/stonepaperscissor.exe differ diff --git a/Projects/C++ Projects/Basic/TextbasedAdventure/textbasedadventure.cpp b/Projects/C++ Projects/Basic/TextbasedAdventure/textbasedadventure.cpp new file mode 100644 index 0000000..155a42d --- /dev/null +++ b/Projects/C++ Projects/Basic/TextbasedAdventure/textbasedadventure.cpp @@ -0,0 +1,79 @@ +#include +#include +using namespace std; +void display() { + cout << "Welcome to the Text Adventure Game!" << endl; + cout << "You find yourself in a mysterious land with several rooms." << endl; + cout << "Your goal is to find the hidden treasure and escape." << endl; + cout << "Good luck!" << endl << endl; +} +int getplayer() { + int c; + cout << "Enter your choice: "; + cin >> c; + return c; +} +void room1(); +void room2(); +void room3(); +void room1() { + cout << "You are in Room 1. There are doors to Room 2 and Room 3." << endl; + cout << "1. Go to Room 2" << endl; + cout << "2. Go to Room 3" << endl; + int choice = getplayer(); + if (choice == 1) { + room2(); + } else if (choice == 2) { + room3(); + } else { + cout << "Invalid choice. Try again." << endl; + room1(); + } +} +void room2() { + cout << "You are in Room 2. There are doors to Room 1 and Room 3." << endl; + cout << "1. Go to Room 1" << endl; + cout << "2. Go to Room 3" << endl; + int choice = getplayer(); + if (choice == 1) { + room1(); + } else if (choice == 2) { + room3(); + } else { + cout << "Invalid choice. Try again." << endl; + room2(); + } +} +void room3() { + cout << "You are in Room 3. There is a door to Room 1 and a hidden treasure here!" << endl; + cout << "1. Go to Room 1" << endl; + cout << "2. Take the treasure and win the game!" << endl; + int choice = getplayer(); + if (choice == 1) { + room1(); + } else if (choice == 2) { + cout << "Congratulations! You found the hidden treasure and won the game!" << endl; + } else { + cout << "Invalid choice. Try again." << endl; + room3(); + } +} +int main() { + display(); + int m; + cout<<"Enter the room number(1,2,3):"<>m; + if(m==1){ + room1(); + } + else if(m==2){ + room2(); + } + else if(m==3){ + room3(); + } + else{ + cout<<"Invalid !"< +#include +#include +using namespace std; +class stock { +public: + string symbol; + double price; + + stock(string symbol, double price) { + this->symbol = symbol; + this->price = price; + } +}; + +int main() { + vector stocks = { + {"AAPL", 150.50}, + {"TSLA", 720.25}, + {"GOOG", 2850.00} + }; + double balance = 10000.00; + while (true) { + cout << "Current Balance: $" << balance << endl; + cout << "------- Stocks -------" << endl; + for (int i = 0; i < stocks.size(); i++) { + cout << i + 1 << ". " << stocks[i].symbol << " - $" << stocks[i].price << endl; + } + cout << endl << "1. Buy Stock" << endl; + cout << "2. Sell Stock" << endl; + cout << "3. View Portfolio" << endl; + cout << "4. Exit" << endl; + int c; + cin >> c; + if (c == 1) { + int stockIndex; + int quantity; + cout << "Enter stock number (1-" << stocks.size() << "): "; + cin >> stockIndex; + if (stockIndex <= 0 || stockIndex > stocks.size()) { + cout << "Invalid stock selection." << endl; + continue; + } + cout << "Enter quantity: "; + cin >> quantity; + if (quantity * stocks[stockIndex - 1].price > balance) { + cout << "Insufficient funds." << endl; + continue; + } + balance -= quantity * stocks[stockIndex - 1].price; + cout << "Bought " << quantity << " shares of " << stocks[stockIndex - 1].symbol << endl; + } + else if (c == 2) { + int stockIndex; + int quantity; + cout << "Enter stock number to sell (1-" << stocks.size() << "): "; + cin >> stockIndex; + if (stockIndex <= 0 || stockIndex > stocks.size()) { + cout << "Invalid stock selection." << endl; + continue; + } + cout << "Enter quantity to sell: "; + cin >> quantity; + balance += quantity * stocks[stockIndex - 1].price; + cout << "Sold " << quantity << " shares of " << stocks[stockIndex - 1].symbol << endl; + } + else if (c == 3) { + cout << "Your portfolio:" << endl; + } + else { + cout << "Invalid choice." << endl; + } + } + + cout << "Exiting application." << endl; + + return 0; +} \ No newline at end of file diff --git a/Projects/C++ Projects/Basic/stock_market/stocktrading.exe b/Projects/C++ Projects/Basic/stock_market/stocktrading.exe new file mode 100644 index 0000000..db4fb80 Binary files /dev/null and b/Projects/C++ Projects/Basic/stock_market/stocktrading.exe differ diff --git a/Projects/C++ Projects/Basic/stonepaperscissors/stonepaperscissor.cpp b/Projects/C++ Projects/Basic/stonepaperscissors/stonepaperscissor.cpp new file mode 100644 index 0000000..75e7af2 --- /dev/null +++ b/Projects/C++ Projects/Basic/stonepaperscissors/stonepaperscissor.cpp @@ -0,0 +1,129 @@ +// #include +// using namespace std; +// struct Game{ +// char player1; +// char player2; +// }; +// Game games(){ +// Game a; +// cout<<"Game (C= Scissor,S=Stone,P=Paper)"<>a.player1; +// cout<<"Player 2(C or S or P)"<>a.player2; +// return a; +// } +// void winner(Game a){ +// if(a.player1 =='C'&& a.player2 =='P'){ +// cout<<"Player 1 is winner"< +// using namespace std; + +// // Define struct for Game +// struct Game { +// char player1; +// char player2; +// }; + +// // Function to play a single game round and return a Game object +// Game games() { +// Game a; +// cout << "Game (C= Scissor, S= Stone, P= Paper)" << endl; +// cout << "Player 1 (C or S or P): "; +// cin >> a.player1; +// cout << "Player 2 (C or S or P): "; +// cin >> a.player2; +// return a; +// } + +// // Function to determine and print the winner +// void winner(Game a) { +// if ((a.player1 == 'C' && a.player2 == 'P') || +// (a.player1 == 'P' && a.player2 == 'S') || +// (a.player1 == 'S' && a.player2 == 'C')) { +// cout << "Player 1 is the winner!" << endl; +// } else if ((a.player1 == 'P' && a.player2 == 'C') || +// (a.player1 == 'S' && a.player2 == 'P') || +// (a.player1 == 'C' && a.player2 == 'S')) { +// cout << "Player 2 is the winner!" << endl; +// } else { +// cout << "It's a draw!" << endl; +// } +// } + +// int main() { +// cout << "Start the GAME:" << endl; + +// // Array to hold multiple games (currently set to hold 1 game) +// Game g[1]; + +// // Play one round of the game +// g[0] = games(); + +// // Determine and print the winner +// winner(g[0]); + +// return 0; +// } + +#include +using namespace std; +void win(string ans1, string ans2){ + if(ans1=="rock" and ans2 == "paper"){ + cout<<"Person with paper sign won"<>ans1; + cout<<"Enter the possibility2: "<>ans2; + win(ans1,ans2); +} \ No newline at end of file diff --git a/Projects/C++ Projects/Hangman/hangman.cpp b/Projects/C++ Projects/Hangman/hangman.cpp new file mode 100644 index 0000000..f0aada8 --- /dev/null +++ b/Projects/C++ Projects/Hangman/hangman.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +using namespace std; +void display(const string &word, const vector &guessed) { + for (size_t i = 0; i < word.size(); ++i) { + if (guessed[i]) { + cout << word[i]; + } + else { + cout << " _"; + } + } + cout << endl; +} +bool wordguess(const vector &guessed) { + for (bool b : guessed) { + if (!b) { + return false; + } + } + return true; +} +int main() { + vector words = { "om", "kanisha", "aditi", "harsh"}; + srand(static_cast(time(0))); + string word = words[rand() % words.size()]; + vector guessed(word.size(), false); + int remainingAttempts = 6; + cout << "Welcome to Hangman!" << endl; + while (remainingAttempts > 0 && !wordguess(guessed)) { + cout << "Current word: "; + display(word, guessed); + cout << "Remaining attempts: " << remainingAttempts << endl; + cout << "Enter a letter: "; + char guess; + cin >> guess; + bool correctguess = false; + for(size_t i = 0; i < word.size(); ++i) { + if (word[i] == guess && !guessed[i]) { + guessed[i] = true; + correctguess = true; + } + } + if(!correctguess) { + --remainingAttempts; + cout << "Incorrect guess!" << endl; + } + else { + cout << "Correct guess!" << endl; + } + } + if(wordguess(guessed)) { + cout << "Congratulations! You've guessed the word: " << word << endl; + } + else { + cout << "Sorry, you've run out of attempts. The word was: " << word << endl; + } + return 0; +}