-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolidityInterface.sol
96 lines (77 loc) · 1.86 KB
/
SolidityInterface.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
interface ArithOpeartion
{
//skeleton of a smart contract
function firstDigit(uint _value) external;
function secondDigit(uint _value) external;
function executeAction() external;
function getResult() external view returns(uint);
}
contract Addition is ArithOpeartion
{
uint public digit1;
uint public digit2;
uint public result;
function firstDigit(uint _value) public
{
digit1=_value;
}
function secondDigit(uint _value) public
{
digit2=_value;
}
function executeAction() public
{
result = digit1 + digit2;
}
function getResult() public view returns(uint)
{
return result;
}
}
contract Subtraction is ArithOpeartion
{
uint public number1;
uint public number2;
uint public subvalue;
function firstDigit(uint _value) public
{
number1=_value;
}
function secondDigit(uint _value) public
{
number2=_value;
}
function executeAction() public
{
if(number1>number2)
subvalue= number1 - number2;
else
subvalue = number2 - number1;
}
function getResult() public view returns(uint)
{
return subvalue;
}
}
contract ExecuteArithOpeartion
{
ArithOpeartion arith;
function executeTask(uint action, uint _value1, uint _value2) public returns (uint)
{
if(action==1)
{
arith= new Addition();
}
else if(action==2)
{
arith= new Subtraction();
}
// execute
arith.firstDigit(_value1);
arith.secondDigit(_value2);
arith.executeAction();
return arith.getResult();
}
}