Skip to content
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
1 change: 1 addition & 0 deletions lec0-gameover/GameOver2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// GameOver2.cpp
#include <iostream>

using namespace std;

int main()
Expand Down
7 changes: 7 additions & 0 deletions lec0-gameover/Game_Over_22021212.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>
using namespace std;

int main(){
cout << "Game Over !" << endl;
return 0;
}
1 change: 0 additions & 1 deletion lec1-simplecalculator/SimpleCalculator_0_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ int main()
{
int num1, num2;
char op;

cin >> num1 >> op >> num2;
switch (op)
{
Expand Down
113 changes: 113 additions & 0 deletions lec1-simplecalculator/SimpleCalculator_0_2_22021212.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//simple_calculator.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include <math.h>

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