Skip to content

Commit

Permalink
Added Blockchain assignements
Browse files Browse the repository at this point in the history
  • Loading branch information
samirankulkarni authored Nov 6, 2024
1 parent 5bcff20 commit c18c6fc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
27 changes: 27 additions & 0 deletions BT-1.sol
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;
}
}
36 changes: 36 additions & 0 deletions BT-2.sol
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];
}

}

0 comments on commit c18c6fc

Please sign in to comment.