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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Simple Calculator

This is a buggy application that will be used for Lab5 of 'Introduction to Open Source Software Development.'

- Fork the project.
- Create a topic branch from master.
- The branch name must be your student id. (e.g. 201624000)
- Make some commits to improve the project.
- Fix the well-knwon bugs.
- Remove object and binary files.
- Add .gitignore file
- Push this branch to your GitHub project.
- Open a Pull Request on GitHub.
- The Pull Request must be submitted to master branch of Classroom-IOSSD/SimpleCalculator!
- Capture the Pull Request and upload it to PLMS.

Binary file added calc
Binary file not shown.
29 changes: 20 additions & 9 deletions calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,39 @@ int main(){
FILE *fp = NULL;
int operand1, operand2;
char operator = ' ';
int result, line = 0;

int line = 0;
double result;
double (*funcp)(int, int);
double (*funcp2)(double, double);
fp = fopen("read.txt","r");
if(fp!=NULL){
fscanf(fp, "%d", &line);

for(int i=0; i<line; i++) {
for(int i=0; i<line-1; i++) {
fscanf(fp, "%d %c %d",&operand1, &operator, &operand2);
switch(operator) {
case '+':
result = add(operand1, operator);
result = add(operand1, operand2);
funcp = add;
funcp(operand1, operand2);
break;
case '-':
result = minus(operand1, operator);
result = minus(operand1, operand2);
funcp = minus;
funcp(operand1, operand2);
break;
case '*':
result = mul(operand1, operator);
result = mul(operand1, operand2);
funcp = mul;
funcp(operand1, operand2);
break;
case '/':
result = div(operand1, operator);
result = div((double)operand1, (double)operand2);
funcp2 = div;
funcp2(operand1, operand2);
break;
}
printf("%d %c %d = %d\n",
}
printf("%d %c %d = %lf\n",
operand1, operator, operand2, result);
}
}
Expand Down
Binary file added calc.o
Binary file not shown.
10 changes: 5 additions & 5 deletions operators.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "operators.h"

int add(int op1, int op2) {
double add(int op1, int op2) {
return op1+op2;
}
int minus(int op1, int op2) {
double minus(int op1, int op2) {
return op1-op2;
}
int mul(int op1, int op2) {
double mul(int op1, int op2) {
return op1*op2;
}

int div(int op1, int op2) {
return op1%op2;
double div(double op1, double op2) {
return op1/op2;
}

8 changes: 4 additions & 4 deletions operators.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int add(int op1, int op2);
int mul(int op1, int op2);
int div(int op1, int op2);
int minus(int op1, int op2);
double add(int op1, int op2);
double mul(int op1, int op2);
double div(double op1, double op2);
double minus(int op1, int op2);
Binary file added operators.o
Binary file not shown.