-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-Interface2.sol
More file actions
68 lines (54 loc) · 2.02 KB
/
15-Interface2.sol
File metadata and controls
68 lines (54 loc) · 2.02 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IRegistration {
struct Person {
string name;
string surname;
uint no;
}
function getCount() external view returns (uint);
function getPerson(uint _no) external view returns (Person memory);
function registerPerson(string memory _name, string memory _surname, uint _no) external;
}
contract RegisterStudent is IRegistration {
uint studentCount;
mapping(uint => Person) students;
function getCount() external view override returns (uint) {
return studentCount;
}
function registerPerson(string memory _name, string memory _surname, uint _no) external override {
students[_no] = Person({name:_name, surname:_surname, no:_no });
studentCount++;
}
function getPerson(uint _no) external view override returns (Person memory) {
Person memory student = students[_no];
return student;
}
}
contract RegisterTeacher is IRegistration {
uint teacherCount;
mapping(uint => Person) teachers;
function getCount() external view override returns (uint) {
return teacherCount;
}
function registerPerson(string memory _name, string memory _surname, uint _no) external override {
teachers[_no] = Person({name:_name, surname:_surname, no:_no });
teacherCount++;
}
function getPerson(uint _no) external view override returns (Person memory) {
Person memory student = teachers[_no];
return student;
}
}
contract RegistrationFactory {
IRegistration regIt;
function register(address contractAddr, string memory _name, string memory _surname, uint _no) public {
regIt = IRegistration(contractAddr);
regIt.registerPerson(_name, _surname, _no);
}
function getByNo(address contractAddr, uint _no) public returns (IRegistration.Person memory) {
regIt = IRegistration(contractAddr);
IRegistration.Person memory person = regIt.getPerson(_no);
return person;
}
}