๐ช 2023. 05. 08. Monday_ ์๋๋ ค๋ป์ณ ๐ช
โ
์๋ ํ์ธ์!๐
๋ชจ๋ ํจ๊ป 4๊ฐ์ ๋์ ํ๋์ ๋ฉ์ง ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ ๊ทธ๋ ๊น์ง ํ์ดํ
ํฉ์๋ค !๐๐๐
โ
* ์ด ๊ณณ์์๋ ๋น์ผ์ ๋ฐฐ์ด ๋ด์ฉ์ ๋ณต์ตํ๋ ์ฉ๋๋ก ๊ธ์ ์์ฑํ๋ ค๊ณ ํฉ๋๋ค.
โ
* ์ค๋์ '~~~๊ตฌ์กฐ์ฒด ๋ณต์ต ' ํด๋ณด๊ฒ ์ต๋๋ค.
โ
โ
โ
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;
//์์ ~!~
contract struct {
//์ด๋ฆ, ๋ฒํธ, ์๋
์์ผ์ ๋ด์ student ๋ผ๋ ๊ตฌ์กฐ์ฒด๋ฅผ ์ ์ธ
struct student {
string name;
uint num;
uint birth;
}
// ์ ๋ชฉ, ๋ฒํธ ๋ ์ง๋ฅผ ๋ด์ class๋ผ๋ ๊ตฌ์กฐ์ฒด ์ ์ธ
struct class {
string title;
uint num;
uint date;
}
//studentํ ๋ณ์ s์ classํ ๋ณ์ c ์ ์ธ
student s;
class c;
```
```
//s์ ๊ฐ์ ๋ถ์ฌํ๋ ํจ์ setS
function setS(string memory _name, uint _num, uint _birth) public {
s = student(_name, _num, _birth);
}
//c์ ๊ฐ์ ๋ถ์ฌํ๋ ํจ์ setC
function setC(string memory _title, uint _num, uint _date) public {
c = class(_title, _num, _date);
}
```
```
//๋ณ์ s์ ๊ฐ์ ๋ฐํํ๋ ํจ์ getS
function getS() public view returns(student memory) {
return s;
}
// ๊ฐ์ ๋ฐํํ๋ ํจ์ getC
function getC() public view returns(class memory) {
return c;
}
โ
//์์ ์ฝ๋์ ์ด์ด์ ๋ณต์ต ~
//studentํ ๋ณ์๋ค์ด ๋ค์ด๊ฐ๋ array students ์ ์ธ
student[] students;
//classํ ๋ณ์๋ค์ด ๋ค์ด๊ฐ๋ array classes ์ ์ธ
class[] classes;
//students์ student ๊ตฌ์กฐ์ฒด๋ฅผ ๋ฃ๋ pushStudent ํจ์
function pushStudent(string memory _name, uint _num, uint _birth) public{
students.push(student(_name, _number, _birth));
}
//classes์ class ๊ตฌ์กฐ์ฒด๋ฅผ ๋ฃ๋ pushClass ํจ์
function pushClass(string memory _title, uint _num, uint _date) {
classes.push(class(_title,_num,_date));
}
}
โ
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;
//์์
contract struct {
//์ซ์ํ ๋ณ์ a, ๋ฌธ์ํ ๋ณ์ b, bytes2ํ ๋ณ์ c๋ฅผ ๋ด์ ๊ตฌ์กฐ์ฒด D ์ ์ธ
struct D {
uint a;
string b;
bytes2 c; //์ ์ ์ ์ธ
}
//Dํ ๋ณ์ dd ์ ์ธ
D dd;
//dd์ ๊ฐ์ ๋ถ์ฌํ๋ setDDํจ์
dd = DD(_a,_b,_c);
//Dํ ๋ณ์๋ค์ด ๋ค์ด๊ฐ๋ array Ds ์ ์ธ
D[] Ds;
//Ds์ ์๋ก์ด Dํ ๋ณ์๋ฅผ ๋ฃ๋ pushD ํจ์
function pushD(uint _a, string memory _b, bytes2 _c) public {
Ds.push(D(_a,_b,_c));
}
}
//Ds array์ n๋ฒ์งธ ์์๋ฅผ ๋ฐํ๋ฐ๋ getNํจ์
//Dํ ๋ฆฌํด
function getN(uint _n) public view returns(D memory) {
return Ds[_n-1];
}
โ
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;
//์์
contract struct {
///๊ตฌ์กฐ์ฒด ์ ์ธ///
//memeber๋ผ๋ ๊ตฌ์กฐ์ฒด๋ฅผ ์ ์ธ
//์ซ์ํ ๋ณ์ number, ๋ฌธ์ํ ๋ณ์ name, bytes2ํ ๋ณ์ password
struct member {
uint number;
string memory name;
bytes2 password;
}
//memberํ ๋ณ์ Michael์ ์ ์ธํ์ธ์.
member Michael;
//Michael์ ๊ฐ์ ๋ถ์ฌํ๋ setM ํจ์
function setM(uint _number, string memory _name, bytes2 _password) public {
Michael = member(_number, _name, _password);
}
///๋ฐฐ์ด ์ ์ธ///
//memberํ ๋ณ์๋ค์ด ๋ค์ด๊ฐ๋ members ์ ์ธ.
member[] members;
//members์ ์๋ก์ด member ๋ณ์๋ฅผ ๋ฃ๋ pushMember ํจ์
function pushMember(uint _number, string memory _name, bytes2 _password) {
members.pop(member(_number, _name, _password));
}
}
โ
โ
โ โ โ
์ฆ ๊ฒ ๋ค.