├── Calculator.cpp ├── README.md ├── Student_Management_System.cpp ├── Tic-Toe-Go.cpp ├── chatboat.cpp ├── file_encryption.cpp ├── guess_the_number.cpp └── password_generater.cpp /Calculator.cpp: -------------------------------------------------------------------------------- 1 | #include "bits/stdc++.h" 2 | using namespace std; 3 | 4 | // Function to calculate the factorial of a number 5 | unsigned int factorial(int num) { 6 | int result = 1; 7 | for (int i = num; i > 0; i--) { 8 | result *= i; 9 | } 10 | return result; 11 | } 12 | 13 | // Function to validate if the input is a number 14 | bool isNumber(double& num) { 15 | cin >> num; 16 | if (cin.fail()) { 17 | cin.clear(); // Clear the error flag 18 | cin.ignore(numeric_limits::max(), '\n'); // Ignore the rest of the input 19 | return false; 20 | } 21 | return true; 22 | } 23 | 24 | int main() { 25 | double firstNumber, secondNumber, result, memory = 0; 26 | char operation; 27 | char choice[10]; 28 | set validOperations = {'+', '-', '/', '*', '^', '!'}; 29 | cout << "+ to add, - to subtract, * to multiply, / to divide, ^ to power, ! to factorial\n\n"; 30 | 31 | start: // THE BEGINNING 32 | 33 | // Input the first number with validation 34 | cout << "Enter the first number: "; 35 | while (!isNumber(firstNumber)) { 36 | cout << "Invalid input. Please enter a number: "; 37 | } 38 | 39 | reused: // 40 | 41 | // Input the operator 42 | cout << "Enter the operator: "; 43 | cin >> operation; 44 | if (validOperations.find(operation) == validOperations.end()) { 45 | cout << "Invalid input\n"; 46 | goto end; 47 | } 48 | 49 | // Perform the operation based on the input operator 50 | if (operation == '!') { 51 | result = factorial(static_cast(firstNumber)); 52 | } else { 53 | // Input the second number with validation 54 | cout << "Enter the second number: "; 55 | while (!isNumber(secondNumber)) { 56 | cout << "Invalid input. Please enter a number: "; 57 | } 58 | if (operation == '+') result = firstNumber + secondNumber; 59 | if (operation == '-') result = firstNumber - secondNumber; 60 | if (operation == '*') result = firstNumber * secondNumber; 61 | if (operation == '/') result = firstNumber / secondNumber; 62 | if (operation == '^') result = pow(firstNumber, secondNumber); 63 | } 64 | 65 | // Output the result 66 | cout << "=" << result << endl; 67 | 68 | // Memory operations 69 | cout << "\nType 'mi' to insert the number into memory, or 'mc' to clear memory\n"; 70 | cin >> choice; 71 | 72 | if (!strcmp(choice, "mi")) memory = result; // Insert into memory 73 | else if (!strcmp(choice, "mc")) memory = 0; // Clear memory 74 | else cout << "command unknown, program will go on\n"; // Default case 75 | 76 | // Loop control options 77 | cout << "\nType 'restart' to start again from the beginning, 'reuse' to use the result, \n'mr' to reuse the number in the memory, or 'quit' to quit: "; 78 | cin >> choice; // Input the choice for the next step 79 | 80 | if (!strcmp(choice, "restart")) goto start; // Restart from the beginning 81 | if (!strcmp(choice, "reuse")) { 82 | firstNumber = result; 83 | cout << firstNumber << endl; 84 | goto reused; // Start with the result 85 | } 86 | if (!strcmp(choice, "mr")) { 87 | firstNumber = memory; 88 | cout << firstNumber << endl; 89 | goto reused; // Start with the memory 90 | } 91 | if (!strcmp(choice, "quit")) goto end; // Quit the program 92 | 93 | goto start; // Restart if none of the above options were chosen 94 | 95 | end: // To quit the program 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cpp_project -------------------------------------------------------------------------------- /Student_Management_System.cpp: -------------------------------------------------------------------------------- 1 | #include"bits/stdc++.h" 2 | #include 3 | using namespace std; 4 | 5 | void generateOtp(){ 6 | char otp[5],c; 7 | int i; 8 | srand((unsigned)time(NULL)); 9 | for(i=0;i<4;) { 10 | c=rand()%127; 11 | if(isalnum(c)){ 12 | otp[i]=c; 13 | i++; 14 | } 15 | } 16 | otp[i]='\0'; 17 | printf("%s", otp); 18 | 19 | } 20 | 21 | bool stafflogin(); 22 | int input(){ 23 | cout<<"Enter 1 for Staff login: "<>key; 27 | return key; 28 | //if(key==1) stafflogin(); 29 | 30 | } 31 | bool stafflogin(){ 32 | bool flag=false; 33 | string s,pass; 34 | cout<<"Enter User Id: "<>s; 36 | if(s=="pprl735757@gmail.com"){ 37 | cout<<"Enter password"<>pass; 39 | if(pass=="Rocky@7061"){ 40 | flag=true; 41 | } 42 | else{ 43 | cout<<"Wrong Password !"<>name; 73 | cout<<"Enter Student's Marks. "<>marks; 75 | cout<<"Enter Student's Gender "<>gender; 77 | Node *new_node=new Node; 78 | new_node->roll_no=roll; 79 | new_node->student_name=name; 80 | new_node->student_marks=marks; 81 | new_node->student_gender=gender; 82 | new_node->next_add=NULL; 83 | if(head==NULL) head=new_node; 84 | else { 85 | Node *ptr=head; 86 | while(ptr->next_add!=NULL){ 87 | ptr=ptr->next_add; 88 | } 89 | ptr->next_add=new_node; 90 | } 91 | 92 | cout<>n; 102 | Node *ptr=head; 103 | while(ptr!=NULL){ 104 | if(n==ptr->roll_no){ 105 | cout<<"Roll no: "<roll_no<student_name<student_marks<student_gender<next_add; 112 | } 113 | if(found==false) cout<<"! Data note Found.."<roll_no){ 127 | found=true; 128 | } 129 | ptr=ptr->next_add; 130 | } 131 | 132 | } 133 | return found; 134 | 135 | } 136 | void count(){ 137 | int c=0; 138 | Node *ptr=head; 139 | while (ptr!=NULL) 140 | { 141 | c++; 142 | ptr=ptr->next_add; 143 | } 144 | if(c>0) cout<<"total No. of Student's are : "<>n; 155 | Node *ptr=head; 156 | while(ptr!=NULL){ 157 | if(n==ptr->roll_no){ 158 | cout<<"Enter Student's Roll no. "<>ptr->roll_no; 160 | cout<<"Enter Student's Name "<>ptr->student_name; 162 | cout<<"Enter Student's Updated Marks. "<>ptr->student_marks; 164 | cout<<"Enter Student's Gender "<>ptr->student_gender; 166 | cout<<"Record updated successfully...."<next_add; 170 | } 171 | if(found==false) cout<<"!! Data note Found.."<>n; 182 | bool found= false; 183 | if(n==head->roll_no){ 184 | Node *ptr=head; 185 | head=head->next_add; 186 | cout<<"Record Deleted Successfully..."<next_add; 194 | while(ptr!=NULL){ 195 | if(n==ptr->roll_no) { 196 | pre->next_add=ptr->next_add; 197 | found=true; 198 | cout<<"Record Deleted Successfully..."<next_add; 205 | } 206 | } 207 | if(found==false) cout<<"!! Roll no. note Found.."<student_name<roll_no<student_marks<student_gender<next_add; 223 | } 224 | 225 | 226 | } 227 | 228 | } 229 | 230 | 231 | 232 | 233 | }; 234 | 235 | int main(){ 236 | generateOtp(); 237 | int dis=178; 238 | char x=dis; 239 | cout<>your_choice; 259 | switch (your_choice) 260 | { 261 | case 1: 262 | system("cls"); 263 | cout<<"Enter Student's Roll no. "<>roll; 265 | if(students.check(roll)) cout<<"Already exits"< 2 | 3 | using namespace std; 4 | 5 | // Array to store the current state of the board 6 | char board[9] = {'0', '1', '2', '3', '4', '5', '6', '7', '8'}; 7 | 8 | // Function to check the winner of the game 9 | int checkWin() { 10 | // Check rows for a win 11 | if (board[0] == board[1] && board[1] == board[2]) { 12 | return board[0] == 'X' ? 1 : 2; 13 | } 14 | if (board[3] == board[4] && board[4] == board[5]) { 15 | return board[3] == 'X' ? 1 : 2; 16 | } 17 | if (board[6] == board[7] && board[7] == board[8]) { 18 | return board[6] == 'X' ? 1 : 2; 19 | } 20 | 21 | // Check columns for a win 22 | if (board[0] == board[3] && board[3] == board[6]) { 23 | return board[0] == 'X' ? 1 : 2; 24 | } 25 | if (board[1] == board[4] && board[4] == board[7]) { 26 | return board[1] == 'X' ? 1 : 2; 27 | } 28 | if (board[2] == board[5] && board[5] == board[8]) { 29 | return board[2] == 'X' ? 1 : 2; 30 | } 31 | 32 | // Check diagonals for a win 33 | if (board[0] == board[4] && board[4] == board[8]) { 34 | return board[0] == 'X' ? 1 : 2; 35 | } 36 | if (board[2] == board[4] && board[4] == board[6]) { 37 | return board[2] == 'X' ? 1 : 2; 38 | } 39 | 40 | // No winner yet 41 | return 0; 42 | } 43 | 44 | // Function to mark the board with the player's symbol 45 | void markBoard(int player, int box) { 46 | if (player == 1) { 47 | board[box] = 'X'; 48 | } else { 49 | board[box] = 'O'; 50 | } 51 | } 52 | 53 | // Function to display the current state of the board 54 | void displayBoard() { 55 | for (int i = 0; i < 9; i++) { 56 | cout << board[i] << "\t"; 57 | if (i == 2 || i == 5 || i == 8) { 58 | cout << "\n"; 59 | } 60 | } 61 | } 62 | 63 | // Function to check if a box is already taken 64 | bool isBoxTaken(int box) { 65 | return board[box] == 'X' || board[box] == 'O'; 66 | } 67 | 68 | int main() { 69 | int player1 = 1, player2 = 2; 70 | int box, result = 0, isGameOver = 0; 71 | 72 | for (int i = 1; i < 5; i++) { 73 | // Player 1's turn 74 | cout << "\nPlayer " << player1 << ", enter the box number: "; 75 | cin >> box; 76 | 77 | // Check if the box is already taken 78 | while (isBoxTaken(box)) { 79 | cout << "Box already taken. Please enter another box number: "; 80 | cin >> box; 81 | } 82 | 83 | markBoard(player1, box); 84 | displayBoard(); 85 | 86 | // Check if Player 1 wins 87 | result = checkWin(); 88 | if (result == 1) { 89 | cout << "\nCongratulations! Player " << player1 << " has won.\n"; 90 | isGameOver = 1; 91 | break; 92 | } else if (result == 2) { 93 | cout << "\nCongratulations! Player " << player2 << " has won.\n"; 94 | isGameOver = 1; 95 | break; 96 | } 97 | 98 | // Player 2's turn 99 | cout << "\nPlayer " << player2 << ", enter the box number: "; 100 | cin >> box; 101 | 102 | // Check if the box is already taken 103 | while (isBoxTaken(box)) { 104 | cout << "Box already taken. Please enter another box number: "; 105 | cin >> box; 106 | } 107 | 108 | markBoard(player2, box); 109 | displayBoard(); 110 | 111 | // Check if Player 2 wins 112 | result = checkWin(); 113 | if (result == 1) { 114 | cout << "\nCongratulations! Player " << player1 << " has won.\n"; 115 | isGameOver = 1; 116 | break; 117 | } else if (result == 2) { 118 | cout << "\nCongratulations! Player " << player2 << " has won.\n"; 119 | isGameOver = 1; 120 | break; 121 | } 122 | } 123 | 124 | // Check if the game is a draw 125 | if (isGameOver == 0) { 126 | cout << "\nSorry, the game is a draw.\n"; 127 | } 128 | 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /chatboat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class Chatbot { 6 | private: 7 | std::unordered_map responses; 8 | 9 | public: 10 | // Constructor to initialize the chatbot with some predefined responses 11 | Chatbot() { 12 | responses["hello"] = "Hello! How can I assist you today?"; 13 | responses["hi"] = "Hi there! What can I do for you?"; 14 | responses["how are you?"] = "I'm just a bot, but I'm functioning as expected!"; 15 | responses["bye"] = "Goodbye! Have a great day!"; 16 | responses["your name?"] = "I am a simple chatbot created to assist you."; 17 | responses["thank you"] = "You're welcome! If you have more questions, feel free to ask."; 18 | } 19 | 20 | // Method to get a response based on user input 21 | std::string getResponse(const std::string& input) { 22 | std::string lowerInput = toLower(input); 23 | if (responses.find(lowerInput) != responses.end()) { 24 | return responses[lowerInput]; 25 | } else { 26 | return "I'm sorry, I don't understand that. Can you please rephrase?"; 27 | } 28 | } 29 | 30 | private: 31 | // Helper function to convert string to lowercase 32 | std::string toLower(const std::string& str) { 33 | std::string result = str; 34 | for (char& c : result) { 35 | c = tolower(c); 36 | } 37 | return result; 38 | } 39 | }; 40 | 41 | int main() { 42 | Chatbot chatbot; 43 | std::string userInput; 44 | 45 | std::cout << "Chatbot: Hello! I am your assistant. Type 'bye' to exit." << std::endl; 46 | 47 | // Chat loop 48 | while (true) { 49 | std::cout << "You: "; 50 | std::getline(std::cin, userInput); 51 | 52 | // Exit condition 53 | if (userInput == "bye") { 54 | std::cout << "Chatbot: " << chatbot.getResponse(userInput) << std::endl; 55 | break; 56 | } 57 | 58 | // Get and display the chatbot's response 59 | std::cout << "Chatbot: " << chatbot.getResponse(userInput) << std::endl; 60 | } 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /file_encryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void encryptFile(const std::string& filename, const std::string& password) 6 | { 7 | std::ifstream inputFile(filename, std::ios::binary); 8 | std::ofstream outputFile(filename + ".encrypted", std::ios::binary); 9 | 10 | if (!inputFile) 11 | { 12 | std::cerr << "Error opening the input file." << std::endl; 13 | return; 14 | } 15 | 16 | char ch; 17 | int passwordIndex = 0; 18 | while (inputFile.get(ch)) 19 | { 20 | ch ^= password[passwordIndex]; 21 | outputFile.put(ch); 22 | 23 | passwordIndex = (passwordIndex + 1) % password.size(); 24 | } 25 | 26 | inputFile.close(); 27 | outputFile.close(); 28 | 29 | std::cout << "File encrypted successfully." << std::endl; 30 | } 31 | 32 | void decryptFile(const std::string& filename, const std::string& password) 33 | { 34 | std::ifstream inputFile(filename, std::ios::binary); 35 | std::ofstream outputFile(filename.substr(0, filename.size() - 10), std::ios::binary); 36 | 37 | if (!inputFile) 38 | { 39 | std::cerr << "Error opening the input file." << std::endl; 40 | return; 41 | } 42 | 43 | char ch; 44 | int passwordIndex = 0; 45 | while (inputFile.get(ch)) 46 | { 47 | ch ^= password[passwordIndex]; 48 | outputFile.put(ch); 49 | 50 | passwordIndex = (passwordIndex + 1) % password.size(); 51 | } 52 | 53 | inputFile.close(); 54 | outputFile.close(); 55 | 56 | std::cout << "File decrypted successfully." << std::endl; 57 | } 58 | 59 | int main() 60 | { 61 | std::string filename; 62 | std::string password; 63 | 64 | std::cout << "Enter the filename: "; 65 | std::getline(std::cin, filename); 66 | 67 | std::cout << "Enter password: "; 68 | std::getline(std::cin, password); 69 | 70 | std::cout << "Select operation (1: Encrypt, 2: Decrypt): "; 71 | int operation; 72 | std::cin >> operation; 73 | std::cin.ignore(); 74 | 75 | if (operation == 1) 76 | { 77 | encryptFile(filename, password); 78 | } 79 | else if (operation == 2) 80 | { 81 | decryptFile(filename + ".encrypted", password); 82 | } 83 | else 84 | { 85 | std::cout << "Invalid choice. Exiting the program." << std::endl; 86 | return 0; 87 | } 88 | 89 | return 0; 90 | } -------------------------------------------------------------------------------- /guess_the_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class GuessTheNumber { 6 | private: 7 | int numberToGuess; // The number that the player has to guess 8 | int maxAttempts; // Maximum number of attempts allowed 9 | int attempts; // Number of attempts made by the player 10 | 11 | public: 12 | // Constructor to initialize the game 13 | GuessTheNumber(int maxAttempts = 5) { 14 | this->maxAttempts = maxAttempts; 15 | this->attempts = 0; 16 | // Seed the random number generator and generate a random number between 1 and 100 17 | srand(static_cast(time(0))); 18 | numberToGuess = rand() % 100 + 1; 19 | } 20 | 21 | // Method to play the game 22 | void play() { 23 | int guess; 24 | std::cout << "Welcome to the Guess the Number Game!\n"; 25 | std::cout << "I have selected a number between 1 and 100. Can you guess it?\n"; 26 | 27 | // Loop until the player runs out of attempts or guesses the number 28 | while (attempts < maxAttempts) { 29 | std::cout << "Attempt " << (attempts + 1) << " of " << maxAttempts << ": Enter your guess: "; 30 | std::cin >> guess; 31 | 32 | // Increase the attempt counter 33 | attempts++; 34 | 35 | // Check if the guess is correct, too high, or too low 36 | if (guess == numberToGuess) { 37 | std::cout << "Congratulations! You've guessed the correct number in " << attempts << " attempts.\n"; 38 | return; 39 | } else if (guess < numberToGuess) { 40 | std::cout << "Too low! Try again.\n"; 41 | } else { 42 | std::cout << "Too high! Try again.\n"; 43 | } 44 | } 45 | 46 | // If the player runs out of attempts 47 | std::cout << "Sorry, you've used all " << maxAttempts << " attempts. The correct number was " << numberToGuess << ".\n"; 48 | } 49 | }; 50 | 51 | int main() { 52 | // Create an instance of the game and start it 53 | GuessTheNumber game; 54 | game.play(); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /password_generater.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | class PasswordGenerator { 8 | private: 9 | int length; 10 | std::string characters; 11 | 12 | public: 13 | // Constructor to initialize the password length and available characters 14 | PasswordGenerator(int len) { 15 | length = len; 16 | characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;:,.<>?"; 17 | } 18 | 19 | // Method to generate the password 20 | std::string generatePassword() { 21 | std::string password = ""; 22 | srand(time(0)); // Seed for random number generator 23 | 24 | for (int i = 0; i < length; i++) { 25 | int index = rand() % characters.length(); 26 | password += characters[index]; 27 | } 28 | 29 | return password; 30 | } 31 | }; 32 | 33 | int main() { 34 | int passwordLength; 35 | 36 | std::cout << "Enter the desired password length: "; 37 | std::cin >> passwordLength; 38 | 39 | // Create an instance of PasswordGenerator 40 | PasswordGenerator passwordGen(passwordLength); 41 | 42 | // Generate and display the password 43 | std::string password = passwordGen.generatePassword(); 44 | std::cout << "Generated Password: " << password << std::endl; 45 | 46 | return 0; 47 | } 48 | --------------------------------------------------------------------------------