Aptos Move by Example
  • 🚀Getting Started
  • Set-Up
  • Why is Move Secure
    • Move prover
  • Move vs Solidity
    • Resources
    • Parallel Processing
    • Reentrancy attacks
    • Memory management
    • Smart contract verification
    • Compiled language
  • Basic Concepts
    • Move.toml
    • Primary data-types
    • Strings
    • Comments
    • Functions
    • Function Visibilities
    • Control flow and expressions
    • Loops
    • Error
    • Struct and its Abilities
    • Scripts
    • Operations
  • Intermediate Concepts
    • Local variables
    • Constants
    • Signer
    • Vector
    • Address
    • Uses and Aliases
    • Maps
    • Hash functions
    • References
    • Unit test
    • Generics
    • Type Arguments
    • Type Inference
  • Advanced Concepts
    • Global Storage Structure
    • Global Storage Operations
    • Phantom Type Parameters
    • Timestamps
    • Ownership
    • Move coding conventions
    • View functions
    • Aptos account
    • Aptos Coin
    • Aptos Token(Nft)
    • Object
    • Token V2
  • Applications
    • First App
    • ToDoList
    • Voting System
    • Basic Tokens
    • Storage using Generics
    • Company
    • Collection
    • Football Card
    • Staking Module
    • MultiSender Wallet
    • English Auction
    • Dutch Auction
    • Attendance Sheet
    • Polling Contract
    • Lottery Contract
  • Decentralized Finance
    • Simple Swap Protocol Contract
    • Code of Swapping Protocol
  • Hacks
    • Coming soon
  • Hands on tutorials
    • Indexer tutorials
Powered by GitBook
On this page
Edit on GitHub
  1. Applications

Attendance Sheet

module my_addrx::AttendanceSheet{
    
    use std::vector;

    struct Students has store, key, drop , copy
    {
        students: vector<Student>,
    }
    struct Student has store, key, drop , copy
    {
        age: u8,
        fName: vector<u8>,
        lName: vector<u8>,
        attendanceValue: u8,
        rollNo: u8
    }

    public fun create_student(_student: Student,_students: &mut Students): Student{
        let newStudent = Student {
        age: _student.age,
        fName: _student.fName,
        lName: _student.lName,
        attendanceValue: _student.attendanceValue,
        rollNo: _student.rollNo,
        };
        add_student(_students,newStudent);
        return newStudent
    }

    public fun add_student(_students: &mut Students,_student: Student){
        vector::push_back(&mut _students.students,_student);
    }

    public fun incrementAttendance(student : &mut Student){
        student.attendanceValue = student.attendanceValue + 1;
    }

    public fun getParticularStudent(student : &Student):&Student{
        return student
    }

    public fun getTotalNoOfStudent(student : &Students):u64{
        let totalStudent = vector::length(&student.students);
        return totalStudent
    }

    #[test]
    fun test_create_student()
    {
        let harry = Student{
            age: 31,
            fName: b"Harry",
            lName: b"Potter",
            attendanceValue: 0,
            rollNo: 1
        };
        let stud = Students{
            students : (vector[harry]),
        };
        let carry = Student{
            age: 31,
            fName: b"Carry",
            lName: b"Minati",
            attendanceValue: 0,
            rollNo: 2
        };
        let stud2 = Students{
            students : (vector[carry])
        };
        let yoyo = Student{
            age: 31,
            fName: b"Honey",
            lName: b"Singh",
            attendanceValue: 0,
            rollNo: 3
        };
        let stud3 = Students{
            students : (vector[yoyo])
        };

        let createdStud = create_student(harry,&mut stud);
        assert!(createdStud.fName == harry.fName,0);

        let createdStud2 = create_student(carry,&mut stud2);
        let createdStud3 = create_student(carry,&mut stud3);

        assert!(createdStud2.rollNo == carry.rollNo,0);

        incrementAttendance(&mut createdStud);//1
        incrementAttendance(&mut createdStud2);//2
        incrementAttendance(&mut createdStud3);//3
        incrementAttendance(&mut createdStud);//1
        incrementAttendance(&mut createdStud2);//2
        incrementAttendance(&mut createdStud);//1

        let p_stud1 = getParticularStudent(&mut createdStud);
        let p_stud2 = getParticularStudent(&mut createdStud2);
        let p_stud3 = getParticularStudent(&mut createdStud3);

        assert!(p_stud1.attendanceValue == 3,0);
        assert!(p_stud2.attendanceValue == 2,0);
        assert!(p_stud3.attendanceValue == 1,0);
        let _total = getTotalNoOfStudent(&mut stud3);
    }
}
PreviousDutch AuctionNextPolling Contract

Last updated 1 year ago