Created
December 30, 2019 08:18
-
-
Save shahzaintariq/07031ab211983605074de82c6535e119 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.5.11+commit.c082d0b4.js&optimize=false&gist=
This file contains 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
pragma solidity ^0.5.11; | |
contract class{ | |
struct bank { | |
string name; | |
uint age; | |
bool ispaid; | |
} | |
bank hbl; | |
function addData(string memory name,uint age,bool ispaid) public returns(string memory){ | |
hbl = bank(name,age,ispaid); | |
} | |
function getdata() public view returns(string memory,uint,bool){ | |
return (hbl.name,hbl.age,hbl.ispaid); | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract piaic{ | |
mapping(string => string) studentRecords; | |
function sdetMappingData(string memory key,string memory value ) public { | |
studentRecords[key] = value; | |
} | |
function showdata(string memory key) public view returns(string memory){ | |
return studentRecords[key]; | |
} | |
} |
This file contains 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
pragma solidity >=0.4.22 <0.6.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
constructor(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public view returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract student{ | |
enum class {onsite,online} | |
enum gender {male,female} | |
struct studentData{ | |
string name; | |
uint rollNum; | |
bool hasDegree; | |
gender myGender; | |
class myClass; | |
} | |
mapping(uint => studentData) students; | |
address payable private myAddress = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
function setAddress(address payable add) public { | |
myAddress = add; | |
} | |
function getbalane() public view returns(uint){ | |
return myAddress.balance; | |
} | |
function getAddress() public view returns(address){ | |
return myAddress; | |
} | |
function enroll(string memory yourName, uint RollNum, bool yourDegree, gender yourgender, class yourclass ) public payable returns(string memory){ | |
require(msg.value >= 2 ether); | |
myAddress.transfer(msg.value); | |
studentData memory ssdata = studentData(yourName,RollNum,yourDegree,yourgender,yourclass); | |
students[RollNum] = ssdata; | |
} | |
function getStudentsData(uint RollNum)public view returns(string memory,uint,bool,gender,class){ | |
return (students[RollNum].name,students[RollNum].rollNum,students[RollNum].hasDegree,students[RollNum].myGender,students[RollNum].myClass); | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract student{ | |
enum class {onsite,online} | |
event generateVoucher(uint rollNum,string name); | |
struct studentData{ | |
string name; | |
uint rollNum; | |
class myClass; | |
} | |
mapping(uint => studentData) students; | |
uint numberOfstudents; | |
address payable private myAddress = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
function setAddress(address payable add) public { | |
myAddress = add; | |
} | |
function getbalane() public view returns(uint){ | |
return myAddress.balance; | |
} | |
function getAddress() public view returns(address){ | |
return myAddress; | |
} | |
modifier onlyOnsite(class classes ){ | |
if(classes == class.onsite){ | |
_; | |
} | |
} | |
function enroll(string memory yourName, uint RollNum,class myClass) onlyOnsite(class.onsite) public payable returns(string memory){ | |
require(msg.value >= 2 ether); | |
myAddress.transfer(msg.value); | |
//studentData memory ssdata = | |
emit generateVoucher(RollNum,yourName); | |
students[RollNum] = studentData(yourName,RollNum,myClass); | |
} | |
function eventAslogging() | |
function getStudentsData(uint RollNum)public view returns(string memory,uint,class){ | |
return ( | |
students[RollNum].name, | |
students[RollNum].rollNum, | |
students[RollNum].myClass | |
); | |
} | |
} |
This file contains 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
pragma solidity ^0.5.0; | |
contract Rule3{ | |
//value type on storage | |
uint a = 20; | |
uint[2] public stateAr = [uint(1),2]; | |
mapping (int =>string) public stateS; | |
function doSomething(uint _a, uint _b) public { | |
//value type on memory | |
uint b = 20; | |
uint[2] memory localAr = stateAr; | |
localAr[0] = 6; | |
mapping (int =>string) storage strings = stateS; | |
} | |
function doSomething1(uint _a, uint _b) public pure returns(uint,uint,uint,uint) { | |
uint[2] memory localAr1 = [uint(3),4]; | |
uint[2] memory localAr2 = localAr1;//by reference copy | |
localAr2[0] = 5; | |
return (localAr1[0],localAr1[1],localAr2[0],localAr2[1]); | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract helloWorld { | |
function HelloWorld () public returns(string memory) { | |
string memory greeting = "helloWorld"; | |
return greeting; | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract learning{ | |
struct studentData{ | |
string name; | |
uint age; | |
uint class; | |
string grade; | |
} | |
mapping(uint => studentData) students; | |
function addStudentData(string memory name, uint age, uint class, string memory grade,uint rollno) public { | |
studentData memory addstudent = studentData(name,age,class,grade); | |
students[rollno] = addstudent; | |
} | |
function getStudentData(uint rollno)public view returns(string memory, uint,uint,string memory){ | |
return (students[rollno].name,students[rollno].age,students[rollno].class,students[rollno].grade); | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract Mymapping{ | |
enum gender{male,female} | |
struct Student{ | |
string name; | |
gender Mygender; | |
} | |
mapping(uint => Student) Students; | |
function addStudent(uint rollno, string memory name) public { | |
Student memory newstudent = Student(name, gender.male); | |
Students[rollno] = newstudent; | |
} | |
function getstudent(uint rollno)public view returns(string memory){ | |
return Students[rollno].name; | |
} | |
} |
This file contains 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
pragma solidity 0.5.11; | |
contract numberguess{ | |
uint8 public loserCounter; | |
uint8 public winnerCounter; | |
string public lastWinnerName; | |
uint8[3] numArr; | |
function YourNumber(uint8 _num1, uint8 _num2,uint8 _num3)public{ | |
numArr[0] = _num1; | |
numArr[1] = _num2; | |
numArr[2] = _num3; | |
} | |
function guess(uint8 _yournum,string memory _yourname) public returns(bool){ | |
for(uint8 i=0; i<numArr.length; i++){ | |
if(numArr[i] == _yournum){ | |
lastWinnerName = _yourname; | |
winnerCounter++; | |
return true; | |
} | |
} | |
loserCounter++; | |
return false; | |
} | |
function totalGuess() public view returns(uint){ | |
uint8 guess = loserCounter + winnerCounter; | |
return guess; | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract student{ | |
enum class {onsite,online} | |
enum gender {male,female} | |
struct studentData{ | |
string name; | |
uint rollNum; | |
bool hasDegree; | |
gender myGender; | |
class myClass; | |
} | |
mapping(uint => studentData) students; | |
uint numberOfstudents; | |
address payable private myAddress = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
function setAddress(address payable add) public { | |
myAddress = add; | |
} | |
function getbalane() public view returns(uint){ | |
return myAddress.balance; | |
} | |
function getAddress() public view returns(address){ | |
return myAddress; | |
} | |
function enroll(string memory yourName, uint RollNum, bool yourDegree, gender yourgender, class yourclass ) public payable returns(string memory){ | |
require(msg.value >= 2 ether); | |
myAddress.transfer(msg.value); | |
studentData memory ssdata = studentData(yourName,RollNum,yourDegree,yourgender,yourclass); | |
students[RollNum] = ssdata; | |
numberOfstudents++; | |
} | |
function getStudentsData(uint RollNum)public view returns(string memory,uint,bool,gender,class,uint){ | |
return ( | |
students[RollNum].name, | |
students[RollNum].rollNum, | |
students[RollNum].hasDegree, | |
students[RollNum].myGender, | |
students[RollNum].myClass, | |
numberOfstudents | |
); | |
} | |
} |
This file contains 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
pragma solidity ^0.5.11; | |
contract piaic{ | |
mapping(uint => uint) studentRecords; | |
uint tempno = 123; | |
uint rollno; | |
function sdetMappingData() public { | |
rollno = studentRecords[i]; | |
} | |
function showdata() public view returns(uint){ | |
return rollno; | |
} | |
function getRollNo()public{ | |
for(uint i=0; i<10; i++){ | |
uint rollno = tempno + i; | |
rollno = studentRecords[i]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment