Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22026555 #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# advprogram
22026555 - Lê Công Hoàng K67J
6 changes: 6 additions & 0 deletions lec0-gameover/GameOver_22026555.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
int main()
{
std::cout << "Game Over !" << std::endl;
return 0;
}
140 changes: 140 additions & 0 deletions lec1-simplecalculator/UpdateSimpleCalc_22026555.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include <bits/stdc++.h>
using namespace std;

int arithmetic(double num1, double num2, char op);
double sothuc(string op, double num);
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;
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 = atof(argv[3]);
cout << arithmetic(num1, num2, op) << endl;
return 0;
}
else if (argc == 3)
{
string n = argv[1];
int k = n.length();
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 number"; exit(1);
}
}
double num;
num = atof(argv[2]);
cout<< sothuc(n, num);
}
else {
cout<< "Invalid operator";
exit(1);
}
}

int arithmetic(double num1, double num2, char op)
{
switch (op)
{
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
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 sothuc(string op, double num)
{
if (op == "sin")
{
return sin(num);
}
else if (op == "cos")
{
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);}
}
75 changes: 75 additions & 0 deletions lec2-guessit/UpdatedGuessIt_22026555.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <bits/stdc++.h>
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;
}
}