diff --git a/C++/Question-1.cpp b/C++/Question-1.cpp index 3373a60..f94ec12 100644 --- a/C++/Question-1.cpp +++ b/C++/Question-1.cpp @@ -3,8 +3,8 @@ void bubbleSort(int arr[], int n) { for (int i = 0; i < n; i++) { - for (int j = i; j < n - i - 1; j++) { - if (arr[j] < arr[j + 1]) { + for (int j = 0; j < n - i - 1; j++) { //we have to make j=i to j=0 + if (arr[j] > arr[j + 1]) { //to make ascending order less than(<) to greater than(>) int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; diff --git a/C++/Question-1.exe b/C++/Question-1.exe new file mode 100644 index 0000000..3302a1b Binary files /dev/null and b/C++/Question-1.exe differ diff --git a/C++/Question-2.cpp b/C++/Question-2.cpp index b2e8ef2..6bae6ad 100644 --- a/C++/Question-2.cpp +++ b/C++/Question-2.cpp @@ -24,7 +24,7 @@ int main() { double convertedAmount = usdToEur(amount); std::cout << "Amount in EUR: " << convertedAmount << std::endl; } else if (currency == "EUR") { - double convertedAmount = usdToEur(amount); + double convertedAmount = eurToUsd(amount);// change function name from usdtoEur to eurtoUsd std::cout << "Amount in USD: " << convertedAmount << std::endl; } else { std::cout << "Invalid currency." << std::endl; diff --git a/C++/Question-2.exe b/C++/Question-2.exe new file mode 100644 index 0000000..c578171 Binary files /dev/null and b/C++/Question-2.exe differ diff --git a/C++/Question-3.cpp b/C++/Question-3.cpp index e6116b7..df5b8c2 100644 --- a/C++/Question-3.cpp +++ b/C++/Question-3.cpp @@ -11,9 +11,9 @@ void guessNumber() { std::cout << "Guess the number (between 1 and 100): "; std::cin >> guess; - if (guess > number) { + if (guess < number) {//changed the greater than(>)to less than(<) std::cout << "Too low! Try again." << std::endl; - } else if (guess <= number) { + } else if (guess > number) { //changed the less than equal to(<=)to greater than(>) std::cout << "Too high! Try again." << std::endl; } else { std::cout << "Congratulations! You guessed the number." << std::endl; diff --git a/C++/Question-3.exe b/C++/Question-3.exe new file mode 100644 index 0000000..4a0c8a2 Binary files /dev/null and b/C++/Question-3.exe differ diff --git a/C++/Question-4.cpp b/C++/Question-4.cpp index 83db22b..948eb53 100644 --- a/C++/Question-4.cpp +++ b/C++/Question-4.cpp @@ -5,7 +5,19 @@ #include bool checkPassword(std::string password) { - return password.length() >= 8; + int count1=0,count2 = 0,count3 =0; + for(int i=0;i=65&&password[i]<=90){ //check condtion for upper case +count1++; + } + if(password[i]>=97&&password[i]<=122){//check for lower case character + count2++; + }if(password[i]>=32&&password[i]<=47||password[i]>=58&&password[i]<=64||password[i]>=91&&password[i]<=96||password[i]>=123&&password[i]<=126){ + count3++; + }//check for special character + + } + return password.length() >= 8&&count1>=1&&count2>=1&&count3>=1; } int main() { @@ -13,11 +25,15 @@ int main() { std::cout << "Enter a password: "; std::getline(std::cin, password); - + if (password.size() < 8) + { + std::cout<< "Password is too short."; //check password length condition when password is short + } + if (checkPassword(password)) { std::cout << "Password is valid." << std::endl; } else { - std::cout << "Password is too short." << std::endl; + std::cout << "invalid password" << std::endl; //check for uppercase,lowercase as well as special characters } return 0; diff --git a/C++/Question-4.exe b/C++/Question-4.exe new file mode 100644 index 0000000..e7a086d Binary files /dev/null and b/C++/Question-4.exe differ diff --git a/C++/Question-5.cpp b/C++/Question-5.cpp index 036a83c..425899e 100644 --- a/C++/Question-5.cpp +++ b/C++/Question-5.cpp @@ -2,6 +2,13 @@ // Function to calculate the factorial of a number int factorial(int n) { + + if (n == 0 || n == 1)// given base condition for recursion to terminate the function + { + + return 1; + } + return n * factorial(n - 1); } @@ -10,9 +17,12 @@ int main() { std::cout << "Enter a number: "; std::cin >> number; + if (number < 0) //given condition for negative numbers + { + std::cout << "Invalid number"; + } int result = factorial(number); - std::cout << "The factorial of " << number << " is " << result << std::endl; return 0; diff --git a/C++/Question-5.exe b/C++/Question-5.exe new file mode 100644 index 0000000..e5d7265 Binary files /dev/null and b/C++/Question-5.exe differ