Saturday 31 October 2020

Functions with Tuples

Functions with return type using tuples:

    func BTechFYResult(stuName: String, engMarks: UInt8, CLangMarks: UInt8, maths1Marks: UInt8, maths2Marks: UInt8, phyMarks:UInt8, BEEMarks:UInt8, EDCMarks:UInt8, drawingMarks:UInt8)->(result:Bool, total:UInt16, percentage:Float, name:String)

    {

        var isFirstYear:Bool = true

        //Calculating the first year total and percentage

        let firstYearTotal:UInt16 = UInt16(engMarks) + UInt16(CLangMarks) + UInt16(maths1Marks) + UInt16(maths2Marks) + UInt16(phyMarks) + UInt16(BEEMarks) + UInt16(EDCMarks) + UInt16(drawingMarks)

        let firstYearPercentage:Float = (Float(firstYearTotal)*100)/Float(maxTotal)

        //Condition to check student is passed or failed

        if ((engMarks >= passMarks) && (CLangMarks >= passMarks) && (maths1Marks >= passMarks) && (maths2Marks >= passMarks) && (phyMarks >= passMarks) && (BEEMarks >= passMarks) && (EDCMarks >= passMarks) && (drawingMarks >= passMarks))

        {

            isFirstYear = true

        }else

        {

            isFirstYear = false

        }

        //Creating and storing the values in tuple

        var BTechFYResultSummary:(result:Bool, total:UInt16, percentage:Float, name:String) = (isFirstYear, firstYearTotal, firstYearPercentage, stuName)

        return BTechFYResultSummary

    }


No comments:

Post a Comment