-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.txt
38 lines (30 loc) · 1.12 KB
/
student.txt
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
// SPDX-License-Identifier: Bhide License
pragma solidity ^0.8.0;
contract StudentRegistry {
struct Student {
string name;
uint256 age;
}
Student[] private students;
// Define an event to log the received Ether value
event ReceivedEther(address indexed sender, uint256 value);
receive() external payable {
// This function can receive Ether, but it doesn't do anything in this example.
// Log the received Ether value
emit ReceivedEther(msg.sender, msg.value);
}
fallback() external payable {
// Fallback function to receive Ether
emit ReceivedEther(msg.sender, msg.value);
}
function addStudent(string memory name, uint256 age) public {
students.push(Student(name, age));
}
function getStudent(uint256 index) public view returns (string memory, uint256) {
require(index < students.length, "Student not found");
return (students[index].name, students[index].age);
}
function getStudentCount() public view returns (uint256) {
return students.length;
}
}