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

Team Initiators #5

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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Local: Question-4","url":"d:\\CodeQuest-2\\CODEQUEST-2\\C++\\Question-4.cpp","tests":[{"id":1714803881806,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"d:\\CodeQuest-2\\CODEQUEST-2\\C++\\Question-4.cpp","group":"local","local":true}
6 changes: 3 additions & 3 deletions C++/Question-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <iostream>

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 i = 0; i < n-1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
Expand Down
Binary file added C++/Question-1.exe
Binary file not shown.
23 changes: 15 additions & 8 deletions C++/Question-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
#include <iostream>
#include <string>

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

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

int main() {
int main()
{
double amount;
std::string currency;

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

if (currency == "USD") {
if (currency == "USD")
{
double convertedAmount = usdToEur(amount);
std::cout << "Amount in EUR: " << convertedAmount << std::endl;
} else if (currency == "EUR") {
double convertedAmount = usdToEur(amount);
}
else if (currency == "EUR")
{
double convertedAmount = eurToUsd(amount);
std::cout << "Amount in USD: " << convertedAmount << std::endl;
} else {
}
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.
42 changes: 35 additions & 7 deletions C++/Question-4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,49 @@
#include <iostream>
#include <string>

bool checkPassword(std::string password) {
return password.length() >= 8;
bool checkPassword(std::string password)
{
int flag1 = 0, flag2 = 0, flag3 = 0;
if (password.length() < 8)
{
std ::cout << "Password is too short.\n";
return 0;
}

else if (password.length() >= 8)
{
for (int i = 0; i < password.length(); i++)
{
if (password[i] >= 65 && password[i] <= 90)
flag1 = 1;
if (password[i] >= 97 && password[i] <= 122)
flag2 = 1;
if (!(password[i] >= 97 && password[i] <= 122) && !(password[i] >= 65 && password[i] <= 90) && !(password[i] >= 48 && password[i] <= 57))
flag3 = 1;
}
if (flag1 == 1 && flag2 == 1 && flag3 == 1)
return true;
else
return false;
}
else
return 0;
}

int main() {
int main()
{
std::string password;

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

if (checkPassword(password)) {
if (checkPassword(password))
{
std::cout << "Password is valid." << std::endl;
} else {
std::cout << "Password is too short." << std::endl;
}

else
{
std::cout << "Password is invalid" << std::endl;
}
return 0;
}
Binary file added C++/Question-4.exe
Binary file not shown.
18 changes: 11 additions & 7 deletions C++/Question-5.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#include <iostream>

// Function to calculate the factorial of a number
int factorial(int n) {
return n * factorial(n - 1);
int factorial(int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}

int main() {
int main()
{
int number;

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

int result = factorial(number);

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

return 0;
}
Binary file added C++/Question-5.exe
Binary file not shown.