Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @custom:oz-upgrades-unsafe-allow
- // @custom:dev-run-script ./contracts/3_student.sol
- // SPDX-License-Identifier: Unlicensed
- pragma solidity >=0.8.0;
- contract Student {
- struct StudentInfo {
- uint256 prn;
- string name;
- string class;
- string department;
- }
- uint256 private prnCounter;
- mapping(uint256 => StudentInfo) private studentMap;
- event StudentAdded(uint256 prn, string name, string class, string department);
- event StudentDeleted(uint256 prn);
- function addStudent(
- string memory name,
- string memory class,
- string memory department
- ) public {
- prnCounter += 1;
- studentMap[prnCounter] = StudentInfo(prnCounter, name, class, department);
- emit StudentAdded(prnCounter, name, class, department);
- }
- function getStudent(uint256 _id) public view returns (StudentInfo memory) {
- require(studentMap[_id].prn != 0, "Student not found");
- return studentMap[_id];
- }
- function totalStudents() public view returns (uint256) {
- return prnCounter;
- }
- function deleteStudent(uint256 _prn) public {
- require(studentMap[_prn].prn != 0, "Student not found");
- delete studentMap[_prn];
- emit StudentDeleted(_prn);
- }
- fallback() external {
- addStudent("Unknown", "FE", "CSE");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement