-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bcff20
commit c18c6fc
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//SPDX-License-Identifier:UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
contract Bank_1{ | ||
|
||
uint16 balance = 0; | ||
address public account; | ||
|
||
constructor(){ | ||
account = msg.sender; | ||
} | ||
|
||
|
||
function checkBalance() public view returns (uint16){ | ||
return balance; | ||
} | ||
|
||
function deposit(uint16 amt) public payable { | ||
require(amt > 0,"you cant deposit 0"); | ||
balance += amt; | ||
} | ||
|
||
function withdraw(uint16 amt) public payable { | ||
require(balance >= amt,"balace is not enough"); | ||
balance -= amt; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//SPDX-License-Identifier:UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
contract Student_1{ | ||
|
||
struct Student{ | ||
uint16 id; | ||
string name; | ||
} | ||
|
||
Student[] public studentData; | ||
|
||
function addStudent(string memory name,uint16 id) public{ | ||
for(uint8 i=0;i<studentData.length;i++){ | ||
if(studentData[i].id == id){ | ||
revert("id already exists"); | ||
} | ||
} | ||
studentData.push(Student(id,name)); | ||
} | ||
|
||
function getAll() public view returns (Student[] memory){ | ||
require(studentData.length > 0,"studentdata is empty"); | ||
return studentData; | ||
} | ||
|
||
function getLength() public view returns (uint256){ | ||
return studentData.length; | ||
} | ||
|
||
function getIndex(uint16 idx) public view returns (Student memory){ | ||
require(idx < studentData.length,"index out of bound"); | ||
return studentData[idx]; | ||
} | ||
|
||
} |