-
Notifications
You must be signed in to change notification settings - Fork 2
/
030-entrance-exam.sol
79 lines (64 loc) · 1.8 KB
/
030-entrance-exam.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* Entrance exam into Advanced Solidity Concepts
* @author Njoh Noh Prince Junior
*/
// contract C
contract C {
uint256 private data;
uint256 public info;
// constructor --runs only once the contract is deployed
// sets the initial value of info to 10
constructor() {
info = 10;
}
// increment a given number by 1 and return the result
function increment(uint256 a) private pure returns (uint256) {
return a + 1;
}
// assign a given value to data
function updateData(uint256 a) public {
data = a;
}
// get the value stored in data
function getData() public view returns (uint256) {
return data;
}
// compute the sum between two numbers
// and it returns the sum of the two numbers
function compute(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
}
// contract D
contract D {
// creating an instance of contract C
C c = new C();
// read the data saved in info variable in contract C
function readInfo() public view returns (uint256) {
return c.info();
}
}
// contract E
// inheriting contract C using the special keyword is
contract E is C {
uint256 private result;
C private c;
// instantiate variable c to an instance of contract C
constructor() {
c = new C();
}
// run the compute function from contract C
function getComputedResult() public {
result = compute(23, 5);
}
// get the value store in result
function getResult() public view returns (uint256) {
return result;
}
// read the data saved in info variable in contract C
function readInfo() public view returns (uint256) {
return info;
}
}