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

Thegreatbahman patch 6 #922

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
26 changes: 26 additions & 0 deletions C++/CharacterIsCowl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
using namespace std;

int main() {
char c;
bool isLowercaseVowel, isUppercaseVowel;

cout << "Enter an alphabet: ";
cin >> c;

// evaluates to 1 (true) if c is a lowercase vowel
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

// evaluates to 1 (true) if c is an uppercase vowel
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

// show error message if c is not an alphabet
if (!isalpha(c))
printf("Error! Non-alphabetic character.");
else if (isLowercaseVowel || isUppercaseVowel)
cout << c << " is a vowel.";
else
cout << c << " is a consonant.";

return 0;
}
21 changes: 21 additions & 0 deletions C++/findRemainder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
using namespace std;

int main()
{
int divisor, dividend, quotient, remainder;

cout << "Enter dividend: ";
cin >> dividend;

cout << "Enter divisor: ";
cin >> divisor;

quotient = dividend / divisor;
remainder = dividend % divisor;

cout << "Quotient = " << quotient << endl;
cout << "Remainder = " << remainder;

return 0;
}
8 changes: 8 additions & 0 deletions C++/helloworld.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Your First C++ Program

#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
}
40 changes: 40 additions & 0 deletions C++/simpleCalci.ccp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# include <iostream>
using namespace std;

int main() {

char op;
float num1, num2;

cout << "Enter operator: +, -, *, /: ";
cin >> op;

cout << "Enter two operands: ";
cin >> num1 >> num2;

switch(op) {

case '+':
cout << num1 << " + " << num2 << " = " << num1 + num2;
break;

case '-':
cout << num1 << " - " << num2 << " = " << num1 - num2;
break;

case '*':
cout << num1 << " * " << num2 << " = " << num1 * num2;
break;

case '/':
cout << num1 << " / " << num2 << " = " << num1 / num2;
break;

default:
// If the operator is other than +, -, * or /, error message is shown
cout << "Error! operator is not correct";
break;
}

return 0;
}
19 changes: 19 additions & 0 deletions C++/swap2numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;

int main()
{
int a = 5, b = 10, temp;

cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;

temp = a;
a = b;
b = temp;

cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;

return 0;
}
35 changes: 35 additions & 0 deletions rootsOfQuadratic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <cmath>
using namespace std;

int main() {

float a, b, c, x1, x2, discriminant, realPart, imaginaryPart;
cout << "Enter coefficients a, b and c: ";
cin >> a >> b >> c;
discriminant = b*b - 4*a*c;

if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}

else if (discriminant == 0) {
cout << "Roots are real and same." << endl;
x1 = -b/(2*a);
cout << "x1 = x2 =" << x1 << endl;
}

else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
}

return 0;
}