🍻 Add excercise files
This commit is contained in:
parent
f90ca8d2ce
commit
f4330e53e0
6 changed files with 112 additions and 0 deletions
19
src/excercises/buckets.cc
Normal file
19
src/excercises/buckets.cc
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
# include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
|
||||
int c = a;
|
||||
a = b;
|
||||
b = c;
|
||||
|
||||
cout << "A: " << a;
|
||||
cout << "B: " << b;
|
||||
|
||||
return 0;
|
||||
}
|
36
src/excercises/calculator.cc
Normal file
36
src/excercises/calculator.cc
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
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:
|
||||
cout << "Operator '" << op << "' is not valid";
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
11
src/excercises/constants.cc
Normal file
11
src/excercises/constants.cc
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
# include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
const double pi = 3.14;
|
||||
cout << pi;
|
||||
return 0;
|
||||
}
|
8
src/excercises/hello_world.cc
Normal file
8
src/excercises/hello_world.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Your first program
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::cout << "Hello World!";
|
||||
return 0;
|
||||
}
|
14
src/excercises/order_of_operators.cc
Normal file
14
src/excercises/order_of_operators.cc
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
# include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
double x = 10;
|
||||
double y = 5;
|
||||
double z = (x + 10) / (3 * y);
|
||||
cout << z;
|
||||
|
||||
return 0;
|
||||
}
|
24
src/excercises/outputting.cc
Normal file
24
src/excercises/outputting.cc
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
double sale = 95000;
|
||||
cout << "Sale: $" << sale << endl;
|
||||
|
||||
const double stateTaxRate = .04;
|
||||
double stateTax = sale * stateTaxRate;
|
||||
cout << "State tax: $" << stateTax << endl;
|
||||
|
||||
const double countyTaxRate = .02;
|
||||
double countyTax = sale * countyTax;
|
||||
cout << "County tax: $" << countyTax << endl;
|
||||
|
||||
double totalTax = stateTax + countyTax;
|
||||
cout << "Total tax: $" << totalTax;
|
||||
|
||||
return 0;
|
||||
}
|
Reference in a new issue