Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KUMARASHUTOSH #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions C++/Question-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

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]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
for (int j = i+1; j < n; j++) {
if (arr[i]>arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
Expand All @@ -16,8 +16,8 @@ void bubbleSort(int arr[], int n) {
int main() {
int arr[] = { 64, 34, 25, 12, 22, 11, 90 };
int n = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, n);
std::cout << "Sorted array: ";
bubbleSort(arr, n);
for (int i = 0; i < n; i++) {
std::cout << arr[i] << " ";
}
Expand Down
Binary file added C++/Question-1.exe
Binary file not shown.
24 changes: 12 additions & 12 deletions C++/Question-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <string>

double usdToEur(double amount) {
return amount * 0.8;
return amount * 0.84375;
}

double eurToUsd(double amount) {
return amount * 1.2;
return amount * 1.185;
}

int main() {
Expand All @@ -20,15 +20,15 @@ int main() {
std::cout << "Enter currency (USD/EUR): ";
std::cin >> currency;

if (currency == "USD") {
double convertedAmount = usdToEur(amount);
std::cout << "Amount in EUR: " << convertedAmount << std::endl;
} else if (currency == "EUR") {
double convertedAmount = usdToEur(amount);
std::cout << "Amount in USD: " << convertedAmount << std::endl;
} else {
std::cout << "Invalid currency." << std::endl;
}


if (currency == "USD") {
double convertedAmount = usdToEur(amount);
std::cout << "Amount in EUR: " << convertedAmount << std::endl;
} else if (currency == "EUR") {
double convertedAmount = eurToUsd(amount); // Corrected function call
std::cout << "Amount in USD: " << convertedAmount << std::endl;
} else {
std::cout << "Invalid currency." << std::endl;
}
return 0;
}
Binary file added C++/Question-2.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions C++/Question-3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ void guessNumber() {
std::cout << "Guess the number (between 1 and 100): ";
std::cin >> guess;

if (guess > number) {
if (guess <= number) {
std::cout << "Too low! Try again." << std::endl;
} else if (guess <= number) {
} else if (guess < number) {
std::cout << "Too high! Try again." << std::endl;
} else {
std::cout << "Congratulations! You guessed the number." << std::endl;
Expand Down
Binary file added C++/Question-3.exe
Binary file not shown.
56 changes: 37 additions & 19 deletions C++/Question-4.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
// Password should have atleast 8 characters
// Password must have atleast one lowercase character, one uppercase character and a special character

#include <iostream>
#include <string>

bool checkPassword(std::string password) {
return password.length() >= 8;
}

int main() {
std::string password;

std::cout << "Enter a password: ";
std::getline(std::cin, password);

if (checkPassword(password)) {
std::cout << "Password is valid." << std::endl;
} else {
std::cout << "Password is too short." << std::endl;
}
#include <iostream>
using namespace std;
int main()
{
int low_case=0, up_case=0, digit=0, special=0;
string pass;
cout<<"Enter Password"<<endl;

cin>>pass;
int l=pass.length(),i;

for(i=0;i<l;i++)
{
if(islower(pass[i]))
low_case=1;
if(isupper(pass[i]))
up_case=1;
if(isdigit(pass[i]))
digit=1;
if(!isalpha(pass[i]) && !isdigit(pass[i]))
special=1;
}

if(low_case && up_case && digit && special && l>=8)
cout<<"strong password."<<endl;
else if(!up_case)
cout<<"please include upper case letter"<<endl;
else if(!low_case)
cout<<" please include lower case"<<endl;
else if(!digit)
cout<<"please include digits"<<endl;
else if(!special)
cout<<"please include special characters"<<endl;
else
cout<<"too short password"<<endl;

return 0;
}
return 0;
}
Binary file added C++/Question-4.exe
Binary file not shown.
15 changes: 10 additions & 5 deletions C++/Question-5.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#include <iostream>

using namespace std;
// Function to calculate the factorial of a number
int factorial(int n) {
if(n<0){
return -1;
}
if(n==0||n==1)
return 1;

return n * factorial(n - 1);
}

int main() {
int number;

std::cout << "Enter a number: ";
std::cin >> number;

cout << "Enter a number: ";
cin >> number;
int result = factorial(number);

std::cout << "The factorial of " << number << " is " << result << std::endl;
cout << "The factorial of " << number << " is " << result << endl;

return 0;
}
Binary file added C++/Question-5.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions C++/tempCodeRunnerFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Password should have atleast 8 characters
// Password must have atleast one lowercase character, one uppercase character and a special character