Created
February 27, 2023 17:13
-
-
Save ArslanKathia/bdbbacb8d17c7cf936a43422b5bcebcd to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Sample{ | |
address public owner; | |
uint256 serialNumber; | |
struct Student{ | |
uint rollNo; | |
string name; | |
string dept; | |
} | |
mapping(address => Student) public students; | |
constructor(){ | |
owner = msg.sender; | |
} | |
modifier isOwner(){ | |
require(owner == msg.sender,"Owner permission is not allowed"); | |
_; | |
} | |
function setSerialNumber(uint256 _serialnumber) external isOwner{ | |
serialNumber = _serialnumber; | |
} | |
function getSerialNumber() public view isOwner returns(uint256){ | |
return serialNumber; | |
} | |
function addStudent(uint _rollNo,string memory _name,string memory _dept) | |
public | |
{ | |
students[msg.sender] = Student(_rollNo,_name,_dept); | |
} | |
function getStudent(address _address) public isOwner view returns(Student memory){ | |
return students[_address]; | |
} | |
function Factorial(uint _number) public pure returns(uint){ | |
uint fact = 1; | |
for(uint i=0;i<=_number;i++){ | |
if(_number>0){ | |
fact = fact * _number; | |
_number--; | |
} | |
} | |
return fact; | |
} | |
//string comparing... | |
function compare(string memory str1,string memory str2) | |
public pure returns(bool) | |
{ | |
if(bytes(str1).length!=bytes(str2).length){ | |
return false; | |
} | |
return keccak256(abi.encodePacked(str1)) == keccak256(abi.encodePacked(str2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment