From 7193c526ad258989a23bbfa16462f1825ac0c42d Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Wed, 1 Feb 2023 23:50:57 +0700 Subject: [PATCH 01/10] Add files via upload --- lec0-gameover/GameOver_22026555.cpp | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lec0-gameover/GameOver_22026555.cpp diff --git a/lec0-gameover/GameOver_22026555.cpp b/lec0-gameover/GameOver_22026555.cpp new file mode 100644 index 0000000..7eadb14 --- /dev/null +++ b/lec0-gameover/GameOver_22026555.cpp @@ -0,0 +1,6 @@ +#include +int main() +{ + std::cout << "Game Over !" << std::endl; + return 0; +} From 1d00e4c8086a694cf64071cbbcca9f3b8ebad721 Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Wed, 1 Feb 2023 23:52:14 +0700 Subject: [PATCH 02/10] Add files via upload --- lec0-gameover/GameOver_22026555.cpp | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lec0-gameover/GameOver_22026555.cpp diff --git a/lec0-gameover/GameOver_22026555.cpp b/lec0-gameover/GameOver_22026555.cpp new file mode 100644 index 0000000..7eadb14 --- /dev/null +++ b/lec0-gameover/GameOver_22026555.cpp @@ -0,0 +1,6 @@ +#include +int main() +{ + std::cout << "Game Over !" << std::endl; + return 0; +} From aef574bdcc0b88b6108c51125c99f9378b6c1637 Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Thu, 2 Feb 2023 00:16:26 +0700 Subject: [PATCH 03/10] Add files via upload --- .../UpdateSimpleCalc_22026555.cpp | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp diff --git a/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp b/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp new file mode 100644 index 0000000..bcb5933 --- /dev/null +++ b/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp @@ -0,0 +1,81 @@ +#include +using namespace std; + +int arithmetic(int num1, int num2, char op); +double sothuc(char op, double num); +int main(int argc, char* argv[]) +{ + if (argc == 4) + { + int num1, num2; char op; + num1 = atoi(argv[1]); + op = argv[2][0]; + num2 = atoi(argv[3]); + cout << arithmetic(num1, num2, op) << endl; + return 0; + } + else if (argc == 3) + { + double num; + char op; + num = atoi(argv[2]); + op = argv[1][0]; + cout << sothuc(op, num) << endl; + return 0; + } + else { + cout << "Invalid" << endl; + return 0; + } +} + +int arithmetic(int num1, int 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) + { + cout << "Invalid divisor" << endl; + exit(1); + } + else + return num1 % num2; + default: + cout << "Invalid operator" << endl; + exit(1); + } +} +double sothuc(char op, double num) +{ + switch (op) + { + case 'c': + return cos(num); + case 's': + if (num < 0) + { + cout << "Invalid number" << endl; + exit(1); + } + else + return sqrt(num); + default: + cout << "Invalid operator" << endl; + exit(1); + } +} From 8feda79ede511906e5bd930a59847824b64c1fe8 Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Thu, 2 Feb 2023 00:24:37 +0700 Subject: [PATCH 04/10] S1mpleCal_22026555.cpp From 17e0aeaf6033372f70876e028c075c950e82ba44 Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:12:31 +0700 Subject: [PATCH 05/10] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 643700d..627be82 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# advprogram \ No newline at end of file +# advprogram +22026555 - Lê Công Hoàng K67J From e6dc0e502a9219b7a965c21390070d84f1f77624 Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:21:01 +0700 Subject: [PATCH 06/10] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 627be82..3db12de 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# advprogram 22026555 - Lê Công Hoàng K67J From 82dbf9c460e986438ad330317d02de02ef79224a Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Thu, 2 Feb 2023 12:25:55 +0700 Subject: [PATCH 07/10] Update UpdateSimpleCalc_22026555.cpp --- .../UpdateSimpleCalc_22026555.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp b/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp index bcb5933..b20049d 100644 --- a/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp +++ b/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp @@ -7,6 +7,12 @@ int main(int argc, char* argv[]) { if (argc == 4) { + string n = argv[2]; + int k = n.length(); + if (k != 1) + { + cout << "Invalid operator" << endl; return 0; + } int num1, num2; char op; num1 = atoi(argv[1]); op = argv[2][0]; @@ -16,6 +22,26 @@ int main(int argc, char* argv[]) } else if (argc == 3) { + string n = argv[1]; + int k = n.length(); + if (k == 3) + { + if (n[0] != 'c' || n[1] != 'o' || n[2] != 's') + { + cout << "Invalid operator"; return 0; + } + } + else if (k == 4) + { + if (n[0] != 's' || n[1] != 'q' || n[2] != 'r' || n[3] != 't') + { + cout << "Invalid operator"; return 0; + } + } + else if (k > 4 || k < 3) + { + cout << "Invalid operator"; return 0; + } double num; char op; num = atoi(argv[2]); From b827c7381687ace1e05a66e1c1b6e82d7311a553 Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Fri, 3 Feb 2023 23:37:27 +0700 Subject: [PATCH 08/10] Update UpdateSimpleCalc_22026555.cpp --- .../UpdateSimpleCalc_22026555.cpp | 131 +++++++++++------- 1 file changed, 82 insertions(+), 49 deletions(-) diff --git a/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp b/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp index b20049d..b976f46 100644 --- a/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp +++ b/lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp @@ -1,8 +1,8 @@ #include using namespace std; -int arithmetic(int num1, int num2, char op); -double sothuc(char op, double num); +int arithmetic(double num1, double num2, char op); +double sothuc(string op, double num); int main(int argc, char* argv[]) { if (argc == 4) @@ -14,9 +14,25 @@ int main(int argc, char* argv[]) cout << "Invalid operator" << endl; return 0; } int num1, num2; char op; - num1 = atoi(argv[1]); + string tmp = argv[1]; + string tmpp = argv[3]; + for (int i = 0; i < tmp.length(); i++) + { + if (tmp[i] < '0' || tmp[i] > '9') + { + cout << "Invalid number"; exit(1); + } + } + for (int i = 0; i < tmpp.length(); i++) + { + if (tmpp[i] < '0' || tmpp[i] > '9') + { + cout << "Invalid number"; exit(1); + } + } + num1 = atof(argv[1]); op = argv[2][0]; - num2 = atoi(argv[3]); + num2 = atof(argv[3]); cout << arithmetic(num1, num2, op) << endl; return 0; } @@ -24,38 +40,37 @@ int main(int argc, char* argv[]) { string n = argv[1]; int k = n.length(); - if (k == 3) - { - if (n[0] != 'c' || n[1] != 'o' || n[2] != 's') - { - cout << "Invalid operator"; return 0; - } - } - else if (k == 4) - { - if (n[0] != 's' || n[1] != 'q' || n[2] != 'r' || n[3] != 't') - { - cout << "Invalid operator"; return 0; - } - } - else if (k > 4 || k < 3) + if (k == 3){ + if ((n != "cos") && (n != "sin") && (n != "tan" && n != "cot")){ + cout<< "Invalid operator"; + exit(1); + } + } + if (k == 4){ + if (n != "sqrt"){ + cout<< "Invalid operator"; + exit(1); + } + } + string tmp = argv[2]; + for (int i = 0; i < tmp.length(); i++) + { + if (tmp[i] < '0' || tmp[i] > '9') { - cout << "Invalid operator"; return 0; + cout << "Invalid number"; exit(1); } - double num; - char op; - num = atoi(argv[2]); - op = argv[1][0]; - cout << sothuc(op, num) << endl; - return 0; } - else { - cout << "Invalid" << endl; - return 0; - } + double num; + num = atof(argv[2]); + cout<< sothuc(n, num); + } + else { + cout<< "Invalid operator"; + exit(1); + } } -int arithmetic(int num1, int num2, char op) +int arithmetic(double num1, double num2, char op) { switch (op) { @@ -63,7 +78,7 @@ int arithmetic(int num1, int num2, char op) return num1 + num2; case '-': return num1 - num2; - case 'x': + case '*': return num1 * num2; case '/': if (num2 == 0) @@ -74,34 +89,52 @@ int arithmetic(int num1, int num2, char op) else return num1 / num2; case '%': - if (num2 == 0) + if (num2 == 0 || num2 != (int)num2 || num1 != (int)num1) { cout << "Invalid divisor" << endl; exit(1); } else - return num1 % num2; + return int(num1) % int(num2); default: cout << "Invalid operator" << endl; exit(1); } } -double sothuc(char op, double num) +double sothuc(string op, double num) { - switch (op) + if (op == "sin") + { + return sin(num); + } + else if (op == "cos") { - case 'c': - return cos(num); - case 's': - if (num < 0) - { - cout << "Invalid number" << endl; - exit(1); - } - else - return sqrt(num); - default: - cout << "Invalid operator" << endl; - exit(1); + return cos(num); + } + else if (op == "tan") + { + if (cos(num) == 0) + { + cout << "Invalid Number"; exit(1); + } + else return tan(num); + } + else if (op == "cot") + { + if (sin(num) == 0) + { + cout << "Invalid Number"; exit(1); + } + else return (1/tan(num)); + } + else if (op == "sqrt") + { + if (num < 0) + { + cout << "Invalid Number"; exit(1); + } + else return sqrt(num); } + else {cout << "Invalid operator" << endl; + exit(1);} } From 9af146bbcf95ceb0bfa1df30e4283b7c4dc665be Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Sat, 4 Feb 2023 01:17:06 +0700 Subject: [PATCH 09/10] GuessIt_22026555 --- lec2-guessit/UpdatedGuessIt_22026555.cpp | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lec2-guessit/UpdatedGuessIt_22026555.cpp diff --git a/lec2-guessit/UpdatedGuessIt_22026555.cpp b/lec2-guessit/UpdatedGuessIt_22026555.cpp new file mode 100644 index 0000000..18dddbb --- /dev/null +++ b/lec2-guessit/UpdatedGuessIt_22026555.cpp @@ -0,0 +1,75 @@ +#include +using namespace std; +int generateRandomNumber(); +int getPlayerGuess(); +int solandoan = 0; int tongdiem = 0; +void playGuessIt(); +void printAnswer(int number, int randomNumber); +int main() +{ + bool play_again = true; + while (play_again) + { + playGuessIt(); + cout << "One more time (y / n)?"; + char answer; + cin >> answer; + if (tolower(answer) != 'y') + { + play_again = false; + } + } + return 0; +} + +void playGuessIt() +{ + int randomNumber = generateRandomNumber(); + int number; + do { + number = getPlayerGuess(); + printAnswer(number, randomNumber); + } while (number != randomNumber); +} +int generateRandomNumber() +{ + int a; + srand (time(0)); + a = rand() % 100 + 1; + return a; +} + +int getPlayerGuess() +{ + int number; + cout << endl << "Enter your number between 1 and 100: "; + cin >> number; + while(cin.fail()) + { + cin.clear(); + cin.ignore(); + cin >> number; + } + if (number > 100 || number <= 0) + { + return number; + } + else {solandoan++; + return number;} +} + +void printAnswer(int number, int randomNumber) +{ + if (number > 100 || number <= 0) { + cout <<"Invalid number, guess again." << endl;} + else if (number > randomNumber) { + cout <<"Your number is higher." << endl; + } else if (number < randomNumber) { + cout <<"Your number is lower." << endl; + } else { + cout << "Congratulation! You win." << endl; + cout << "So lan doan cua ban la: " << solandoan << endl; + cout << "Diem cua ban la: " << 100 - solandoan << endl; + } +} + From 7729787fed750219aed9e58d4dec8650de4a5e3b Mon Sep 17 00:00:00 2001 From: cusnaruto <119999945+cusnaruto@users.noreply.github.com> Date: Mon, 6 Mar 2023 00:40:55 +0700 Subject: [PATCH 10/10] Create c-cpp.yml --- .github/workflows/c-cpp.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/c-cpp.yml diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml new file mode 100644 index 0000000..a383a52 --- /dev/null +++ b/.github/workflows/c-cpp.yml @@ -0,0 +1,23 @@ +name: C/C++ CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: configure + run: ./configure + - name: make + run: make + - name: make check + run: make check + - name: make distcheck + run: make distcheck