Created
October 29, 2018 23:50
-
-
Save bhflm/6b58d450d2bfa9ebc2f5ce5e0835f702 to your computer and use it in GitHub Desktop.
ej 2
This file contains hidden or 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
pragma solidity ^0.4.25; | |
contract owned { | |
constructor() public { owner = msg.sender; } | |
address owner; | |
modifier onlyOwner { | |
require( | |
msg.sender == owner, | |
"Only owner can call this function." | |
); | |
_; | |
} | |
} | |
contract Ejemplo2 is owned{ | |
address owner; | |
mapping(uint256 => Alumno) alumnos; | |
struct Alumno { | |
uint256 notaIndividual; | |
uint256 notaContenido; | |
uint256 notaGrupal; | |
} | |
constructor (){ | |
owner = msg.sender; | |
} | |
function calificar(uint256 padron, uint256 notaContenido, uint256 notaGrupal, uint256 notaIndividual) public onlyOwner{ | |
alumnos[padron].notaIndividual = notaIndividual; | |
alumnos[padron].notaContenido = notaContenido; | |
alumnos[padron].notaGrupal = notaGrupal; | |
emit Calificacion(padron, notaContenido, notaGrupal, notaIndividual); | |
} | |
function obtenerNotas(uint256 padron)public view returns(uint256 notaIndividual, uint256 notaContenido, uint256 notaGrupal, uint256 notaFinal){ | |
notaIndividual = alumnos[padron].notaIndividual; | |
notaContenido = alumnos[padron].notaContenido; | |
notaGrupal = alumnos[padron].notaGrupal; | |
notaFinal = calcularNotaFinal(notaIndividual, notaContenido, notaGrupal); | |
} | |
function calcularNotaFinal(uint256 notaIndividual, uint256 notaContenido, uint256 notaGrupal)private pure returns(uint256){ | |
return ((notaContenido*70) + (notaGrupal * 20) + (notaIndividual * 10))/100; | |
} | |
event Calificacion(uint256 padron, uint256 notaContenido, uint256 notaGrupal, uint256 notaIndividual); | |
} | |
[ | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "padron", | |
"type": "uint256" | |
}, | |
{ | |
"name": "notaContenido", | |
"type": "uint256" | |
}, | |
{ | |
"name": "notaGrupal", | |
"type": "uint256" | |
}, | |
{ | |
"name": "notaIndividual", | |
"type": "uint256" | |
} | |
], | |
"name": "calificar", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "constructor" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": false, | |
"name": "padron", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": false, | |
"name": "notaContenido", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": false, | |
"name": "notaGrupal", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": false, | |
"name": "notaIndividual", | |
"type": "uint256" | |
} | |
], | |
"name": "Calificacion", | |
"type": "event" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "padron", | |
"type": "uint256" | |
} | |
], | |
"name": "obtenerNotas", | |
"outputs": [ | |
{ | |
"name": "notaIndividual", | |
"type": "uint256" | |
}, | |
{ | |
"name": "notaContenido", | |
"type": "uint256" | |
}, | |
{ | |
"name": "notaGrupal", | |
"type": "uint256" | |
}, | |
{ | |
"name": "notaFinal", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment