From fec90f4e7a285b6238df77b725ab32c9190a3004 Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Fri, 3 Feb 2023 17:58:07 +0700 Subject: [PATCH 1/7] Add files via upload --- .../Simple_Caculator_22026554.cpp | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lec1-simplecalculator/Simple_Caculator_22026554.cpp diff --git a/lec1-simplecalculator/Simple_Caculator_22026554.cpp b/lec1-simplecalculator/Simple_Caculator_22026554.cpp new file mode 100644 index 0000000..71667d6 --- /dev/null +++ b/lec1-simplecalculator/Simple_Caculator_22026554.cpp @@ -0,0 +1,84 @@ +#include +using namespace std; + +double arithmetic(double num1, double num2, char op) +{ + switch (op) { + case '+': + return num1 + num2; + case '-': + return num1 - num2; + case 'x': + return num1 * num2; + case '/': + if (num2 == 0) { + cout << "Invalid divisor" << endl; + exit(1); + } + else + return num1 / num2; + case '%': + if (num2 == 0 || num2 != (int)num2 || num1 != (int)num1) { + cout << "Invalid divisor" << endl; + exit(1); + } + else{ + return (int)num1 % (int)num2; + } + default: + cout << "Invalid operator" << endl; + exit(1); + } +} + +double luonggiac(double num, string n) +{ + if (n == "cos"){ + return cos(num); + } + else if (n == "sin"){ + return sin(num); + } + else if (n == "tan"){ + return tan(num); + } + else if (n == "cot"){ + return (1/tan(num)); + } +} + +int main(int argc, char* argv[]) +{ + if(argc == 4){ + double num1, num2; + char op; + num1 = atof(argv[1]); + op = argv[2][0]; + num2 = atof(argv[3]); + cout<< arithmetic(num1, num2, op); + } + else if (argc == 3){ + string n = argv[1]; + int s = n.length(); + if (s == 3){ + if ((n != "cos") && (n != "sin") && (n != "tan" && n != "cot")){ + cout<< "Invalid operator"; + exit(1); + } + } + if (s == 4){ + if (n != "sqrt"){ + cout<< "Invalid operator"; + exit(1); + } + } + double num; + num = atof(argv[2]); + cout<< luonggiac(num, n); + } + else { + cout<< "Invalid operator"; + exit(1); + } + return 0; +} \ No newline at end of file From 48419564624063c8792fe8cbac990f4c28bc0130 Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:03:58 +0700 Subject: [PATCH 2/7] SimpleCaculator_22026554 From e7b648d6e0190789eecce958504aae2ce5262dce Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:08:55 +0700 Subject: [PATCH 3/7] Simple_Caculator_0_2_22026554 From 569d8e831152f48a9845811161317867ec63981f Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:18:58 +0700 Subject: [PATCH 4/7] Delete Simple_Caculator_22026554.cpp --- .../Simple_Caculator_22026554.cpp | 84 ------------------- 1 file changed, 84 deletions(-) delete mode 100644 lec1-simplecalculator/Simple_Caculator_22026554.cpp diff --git a/lec1-simplecalculator/Simple_Caculator_22026554.cpp b/lec1-simplecalculator/Simple_Caculator_22026554.cpp deleted file mode 100644 index 71667d6..0000000 --- a/lec1-simplecalculator/Simple_Caculator_22026554.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -using namespace std; - -double arithmetic(double num1, double num2, char op) -{ - switch (op) { - case '+': - return num1 + num2; - case '-': - return num1 - num2; - case 'x': - return num1 * num2; - case '/': - if (num2 == 0) { - cout << "Invalid divisor" << endl; - exit(1); - } - else - return num1 / num2; - case '%': - if (num2 == 0 || num2 != (int)num2 || num1 != (int)num1) { - cout << "Invalid divisor" << endl; - exit(1); - } - else{ - return (int)num1 % (int)num2; - } - default: - cout << "Invalid operator" << endl; - exit(1); - } -} - -double luonggiac(double num, string n) -{ - if (n == "cos"){ - return cos(num); - } - else if (n == "sin"){ - return sin(num); - } - else if (n == "tan"){ - return tan(num); - } - else if (n == "cot"){ - return (1/tan(num)); - } -} - -int main(int argc, char* argv[]) -{ - if(argc == 4){ - double num1, num2; - char op; - num1 = atof(argv[1]); - op = argv[2][0]; - num2 = atof(argv[3]); - cout<< arithmetic(num1, num2, op); - } - else if (argc == 3){ - string n = argv[1]; - int s = n.length(); - if (s == 3){ - if ((n != "cos") && (n != "sin") && (n != "tan" && n != "cot")){ - cout<< "Invalid operator"; - exit(1); - } - } - if (s == 4){ - if (n != "sqrt"){ - cout<< "Invalid operator"; - exit(1); - } - } - double num; - num = atof(argv[2]); - cout<< luonggiac(num, n); - } - else { - cout<< "Invalid operator"; - exit(1); - } - return 0; -} \ No newline at end of file From 84d2aa7fa09e4fcaacb968d898493f544f59ed50 Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:19:39 +0700 Subject: [PATCH 5/7] SimpleCaculator_0_2_Update_22026554 --- .../Simple_Caculator_22026554.cpp | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lec1-simplecalculator/Simple_Caculator_22026554.cpp diff --git a/lec1-simplecalculator/Simple_Caculator_22026554.cpp b/lec1-simplecalculator/Simple_Caculator_22026554.cpp new file mode 100644 index 0000000..71667d6 --- /dev/null +++ b/lec1-simplecalculator/Simple_Caculator_22026554.cpp @@ -0,0 +1,84 @@ +#include +using namespace std; + +double arithmetic(double num1, double num2, char op) +{ + switch (op) { + case '+': + return num1 + num2; + case '-': + return num1 - num2; + case 'x': + return num1 * num2; + case '/': + if (num2 == 0) { + cout << "Invalid divisor" << endl; + exit(1); + } + else + return num1 / num2; + case '%': + if (num2 == 0 || num2 != (int)num2 || num1 != (int)num1) { + cout << "Invalid divisor" << endl; + exit(1); + } + else{ + return (int)num1 % (int)num2; + } + default: + cout << "Invalid operator" << endl; + exit(1); + } +} + +double luonggiac(double num, string n) +{ + if (n == "cos"){ + return cos(num); + } + else if (n == "sin"){ + return sin(num); + } + else if (n == "tan"){ + return tan(num); + } + else if (n == "cot"){ + return (1/tan(num)); + } +} + +int main(int argc, char* argv[]) +{ + if(argc == 4){ + double num1, num2; + char op; + num1 = atof(argv[1]); + op = argv[2][0]; + num2 = atof(argv[3]); + cout<< arithmetic(num1, num2, op); + } + else if (argc == 3){ + string n = argv[1]; + int s = n.length(); + if (s == 3){ + if ((n != "cos") && (n != "sin") && (n != "tan" && n != "cot")){ + cout<< "Invalid operator"; + exit(1); + } + } + if (s == 4){ + if (n != "sqrt"){ + cout<< "Invalid operator"; + exit(1); + } + } + double num; + num = atof(argv[2]); + cout<< luonggiac(num, n); + } + else { + cout<< "Invalid operator"; + exit(1); + } + return 0; +} \ No newline at end of file From ec035d677fd4c7673c4895dc039929ea0772a17c Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:24:59 +0700 Subject: [PATCH 6/7] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 643700d..619833c 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# advprogram \ No newline at end of file +# advprogram + +Quàng Thế Anh- 22026554 From 5e4bbfd82a32cce5829025e6baf949901385843c Mon Sep 17 00:00:00 2001 From: dkozTA <124289620+dkozTA@users.noreply.github.com> Date: Sat, 4 Feb 2023 19:05:54 +0700 Subject: [PATCH 7/7] Update_SImple_Caculator_0_2 --- lec1-simplecalculator/Simple_Caculator_22026554.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lec1-simplecalculator/Simple_Caculator_22026554.cpp b/lec1-simplecalculator/Simple_Caculator_22026554.cpp index 71667d6..a3ee354 100644 --- a/lec1-simplecalculator/Simple_Caculator_22026554.cpp +++ b/lec1-simplecalculator/Simple_Caculator_22026554.cpp @@ -45,6 +45,15 @@ double luonggiac(double num, string n) else if (n == "cot"){ return (1/tan(num)); } + else if (n == "sqrt"){ + if (num > 0){ + return sqrt(num); + } + else{ + cout<< "Invalid"; + exit(1); + } + } } int main(int argc, char* argv[])