-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudData.sol
37 lines (30 loc) · 1.59 KB
/
StudData.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
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0;
contract Student_management{
struct Student{
int stud_id;
string Name;
string Department;
}
Student[] Students;
function add_stud(int stud_id, string memory Name, string memory Department) public{
Student memory stud = Student(stud_id, Name, Department);
Students.push(stud);
}
function getStudent(int stud_id) public view returns(string memory, string memory){
for(uint i = 0; i < Students.length; i++){
Student memory stud = Students[i];
if(stud.stud_id == stud_id){
return(stud.Name, stud.Department);
}
}
return("Name Not Found", "Department Not Found");
}
function getStudentsCount() public view returns (uint256) {
return Students.length;
}
//Fallback Function
fallback() external {
add_stud( 0,"Unknown", "CSE");
}
}