└── подсчет калорий в еде /подсчет калорий в еде: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // Generated with Spectral Syntax 3 | 4 | contract CalorieCounter { 5 | // Mapping to store the calorie values of different food items 6 | mapping(string => uint) public foodCalories; 7 | 8 | // Function to add a new food item with its calorie value 9 | function addFoodItem(string memory foodName, uint calories) public onlyOwner { 10 | foodCalories[foodName] = calories; 11 | } 12 | 13 | // Function to get the calorie value of a specific food item 14 | function getCalories(string memory foodName) public view returns (uint) { 15 | return foodCalories[foodName]; 16 | } 17 | 18 | // Modifier to restrict function to contract owner 19 | modifier onlyOwner() { 20 | require(msg.sender == owner, "Only contract owner can add food items"); 21 | _; 22 | } 23 | 24 | // Contract owner 25 | address public owner; 26 | 27 | // Constructor 28 | constructor() { 29 | owner = msg.sender; 30 | } 31 | } 32 | --------------------------------------------------------------------------------