From f4330e53e00932bd923fd5543c32b486a938bbdc Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Tue, 6 Feb 2024 18:06:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=BB=20Add=20excercise=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/excercises/buckets.cc | 19 +++++++++++++++ src/excercises/calculator.cc | 36 ++++++++++++++++++++++++++++ src/excercises/constants.cc | 11 +++++++++ src/excercises/hello_world.cc | 8 +++++++ src/excercises/order_of_operators.cc | 14 +++++++++++ src/excercises/outputting.cc | 24 +++++++++++++++++++ 6 files changed, 112 insertions(+) create mode 100644 src/excercises/buckets.cc create mode 100644 src/excercises/calculator.cc create mode 100644 src/excercises/constants.cc create mode 100644 src/excercises/hello_world.cc create mode 100644 src/excercises/order_of_operators.cc create mode 100644 src/excercises/outputting.cc diff --git a/src/excercises/buckets.cc b/src/excercises/buckets.cc new file mode 100644 index 0000000..4b8ca93 --- /dev/null +++ b/src/excercises/buckets.cc @@ -0,0 +1,19 @@ + +# include + +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; +} diff --git a/src/excercises/calculator.cc b/src/excercises/calculator.cc new file mode 100644 index 0000000..c269749 --- /dev/null +++ b/src/excercises/calculator.cc @@ -0,0 +1,36 @@ +#include + +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; +} diff --git a/src/excercises/constants.cc b/src/excercises/constants.cc new file mode 100644 index 0000000..04758e6 --- /dev/null +++ b/src/excercises/constants.cc @@ -0,0 +1,11 @@ + +# include + +using namespace std; + +int main() { + + const double pi = 3.14; + cout << pi; + return 0; +} diff --git a/src/excercises/hello_world.cc b/src/excercises/hello_world.cc new file mode 100644 index 0000000..5e70bda --- /dev/null +++ b/src/excercises/hello_world.cc @@ -0,0 +1,8 @@ +// Your first program + +#include + +int main(int argc, char *argv[]) { + std::cout << "Hello World!"; + return 0; +} diff --git a/src/excercises/order_of_operators.cc b/src/excercises/order_of_operators.cc new file mode 100644 index 0000000..495b645 --- /dev/null +++ b/src/excercises/order_of_operators.cc @@ -0,0 +1,14 @@ + +# include + +using namespace std; + +int main() { + + double x = 10; + double y = 5; + double z = (x + 10) / (3 * y); + cout << z; + + return 0; +} diff --git a/src/excercises/outputting.cc b/src/excercises/outputting.cc new file mode 100644 index 0000000..6ed4d55 --- /dev/null +++ b/src/excercises/outputting.cc @@ -0,0 +1,24 @@ + +#include +#include + +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; +}