From 0c60334656210a5a3364b54d303de6f76bc5b93e Mon Sep 17 00:00:00 2001 From: Le Vu Viet Anh Date: Sat, 4 Feb 2023 21:39:25 +0700 Subject: [PATCH 1/4] Create Game_Over_22021212.cpp --- lec0-gameover/GameOver2.cpp | 1 + lec0-gameover/Game_Over_22021212.cpp | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 lec0-gameover/Game_Over_22021212.cpp diff --git a/lec0-gameover/GameOver2.cpp b/lec0-gameover/GameOver2.cpp index 5d3b307..a49dd40 100644 --- a/lec0-gameover/GameOver2.cpp +++ b/lec0-gameover/GameOver2.cpp @@ -1,5 +1,6 @@ // GameOver2.cpp #include + using namespace std; int main() diff --git a/lec0-gameover/Game_Over_22021212.cpp b/lec0-gameover/Game_Over_22021212.cpp new file mode 100644 index 0000000..63be9bc --- /dev/null +++ b/lec0-gameover/Game_Over_22021212.cpp @@ -0,0 +1,7 @@ +#include +using namespace std; + + int main(){ + cout << "Game Over !" << endl; + return 0; + } From 25ffc548fa34c4249c11f4fcfe77814b4d6bab59 Mon Sep 17 00:00:00 2001 From: Le Vu Viet Anh Date: Sun, 5 Feb 2023 16:46:40 +0700 Subject: [PATCH 2/4] Create SimpleCalculator_0_2_22021212.cpp --- .../SimpleCalculator_0_1.cpp | 4 +- .../SimpleCalculator_0_2_22021212.cpp | 113 ++++++++++++++++++ 2 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 lec1-simplecalculator/SimpleCalculator_0_2_22021212.cpp diff --git a/lec1-simplecalculator/SimpleCalculator_0_1.cpp b/lec1-simplecalculator/SimpleCalculator_0_1.cpp index 108a681..4b6a84a 100755 --- a/lec1-simplecalculator/SimpleCalculator_0_1.cpp +++ b/lec1-simplecalculator/SimpleCalculator_0_1.cpp @@ -1,12 +1,12 @@ #include - +#include using namespace std; int main() { int num1, num2; char op; - + cout << 1.7*pow(10,308) + 100000000 << endl; cin >> num1 >> op >> num2; switch (op) { diff --git a/lec1-simplecalculator/SimpleCalculator_0_2_22021212.cpp b/lec1-simplecalculator/SimpleCalculator_0_2_22021212.cpp new file mode 100644 index 0000000..4a7bffe --- /dev/null +++ b/lec1-simplecalculator/SimpleCalculator_0_2_22021212.cpp @@ -0,0 +1,113 @@ +//simple_calculator.cpp +#include +#include +#include +#include + +using namespace std; + +double arithmetic(double &num1,double &num2, char &op); +double arithmetic(string &func,double &num); + +int main(int argc, char* argv[]) +{ + double num1, num2, result; + char op; + if(argc == 3){ // Xu ly ham luong giac va can bac 2 + string func = argv[1]; + double num = atof(argv[2]); + cout << arithmetic(func,num) << endl; + }else{ // Xu ly tinh toan thong thuong + num1 = atof(argv[1]); + op = argv[2][0]; + num2 = atof(argv[3]); + cout << arithmetic(num1, num2, op) << endl; + } + return 0; +} + +double arithmetic(double &num1,double &num2, char &op) +{ double result; + switch (op) + { + case '+': + result = num1 + num2; + break; + case '-': + result = num1 - num2; + break; + case 'x': + result = num1 * num2; + break; + case '/': + if (num2 == 0) + { + cout << "Invalid divisor" << endl; + exit(1); + } + else + result = num1 / num2; + break; + case '%': + if (num2 == 0) + { + cout << "Invalid divisor" << endl; + exit(1); + } + else if (num1-(int)num1 == 0 && num2 - (int)num2 == 0){ + result = (int)num1 % (int)num2; + break; + } + else{ + cout << "Invalid number (float numbers aren't allowed with this operator)" << endl; + exit(1); + } + default: + cout << "Invalid operator" << endl; + exit(1); + } + if(abs(result) > 1e6){ + cout << "Result exceeded limit" << endl; + }else{ + return result; + } + return 0; +} + +double arithmetic(string &func,double &num){ + if(abs(num) > 1e6){ + cout << "Input exceed limit" << endl; + return 0; + } + + if(func.compare("cos") == 0){ + return cos(num); + }else if(func.compare("sin") == 0){ + return sin(num); + }else if(func.compare("tan") == 0 || func.compare("tg") == 0){ + if(abs(cos(num)) < 1e-9){ + cout << "Invalid input" << endl; + }else + return tan(num); + }else if(func.compare("cot") == 0 || func.compare("cotg") == 0){ + if(abs(sin(num)) < 1e-9){ + cout << "Invalid input" << endl; + }else + return 1/tan(num); + }else if(func.compare("sqrt") == 0 ){ + if(num < 0){ + cout << "Invalid input square root function" << endl; + return 0; + }else{ + return sqrt(num); + } + } + else{ + cout << "Invalid Function" << endl; + } + return 0; +} + + + +//Modified by 22021212_LeVuVietAnh From fde7e256328c2ed024b4237c1567de7de3da6da8 Mon Sep 17 00:00:00 2001 From: Le Vu Viet Anh Date: Sun, 5 Feb 2023 16:49:17 +0700 Subject: [PATCH 3/4] redo --- lec1-simplecalculator/SimpleCalculator_0_1.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lec1-simplecalculator/SimpleCalculator_0_1.cpp b/lec1-simplecalculator/SimpleCalculator_0_1.cpp index 4b6a84a..cad62d2 100755 --- a/lec1-simplecalculator/SimpleCalculator_0_1.cpp +++ b/lec1-simplecalculator/SimpleCalculator_0_1.cpp @@ -6,7 +6,6 @@ int main() { int num1, num2; char op; - cout << 1.7*pow(10,308) + 100000000 << endl; cin >> num1 >> op >> num2; switch (op) { From a5a0407cc3a8a6a945e3c333d7c51de5c9fddee0 Mon Sep 17 00:00:00 2001 From: VietAnhLeVu <86595845+VietAnhLeVu@users.noreply.github.com> Date: Sun, 5 Feb 2023 16:57:02 +0700 Subject: [PATCH 4/4] Update SimpleCalculator_0_1.cpp --- lec1-simplecalculator/SimpleCalculator_0_1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lec1-simplecalculator/SimpleCalculator_0_1.cpp b/lec1-simplecalculator/SimpleCalculator_0_1.cpp index cad62d2..b94678d 100755 --- a/lec1-simplecalculator/SimpleCalculator_0_1.cpp +++ b/lec1-simplecalculator/SimpleCalculator_0_1.cpp @@ -1,5 +1,5 @@ #include -#include + using namespace std; int main()