Create a Smart Contract to Manage Multiple Instructors in Blockchain

Question: How can you create a smart contract to store data of multiple instructors in blockchain and retrieve their details based on account address?

Answer: To create a smart contract that allows you to store data of multiple instructors in blockchain and retrieve their details based on their account address, you need to follow the instructions provided. Below is a detailed explanation of the steps to achieve this objective.

Objective:

Create a smart contract that allows you to store data of multiple instructors, along with retrieving the data associated with them based on their account address. To accomplish this objective, you should follow the provided instructions:

Instructions:

1. Store the details of multiple instructors in blockchain using struct and mapping. Include the following information about the instructor: First_name, Last_name, Office_number, Phone_number, and domain (e.g., Computer Science, Mathematics, Physics). 2. Assign a predefined status of "Active/non-active" to each instructor. 3. Use the account address of the instructor as the primary key for mapping. 4. Allow only the owner of the smart contract to add instructors to the blockchain and determine their Active status. 5. Keep track of the total number of instructors added. 6. Create a getter function that returns the details of the instructors from a specific address. 7. Develop a getter function to return the number of instructors. Only the owner should have access to this function. 8. Design a function that returns the addresses of all the instructors. If a non-owner attempts to access this function, the smart contract should be destroyed; otherwise, it should return the address. By following these instructions, you can successfully create a smart contract to manage multiple instructors in blockchain.

Question: How can you write a function to count the number of vowels in a given string and deal with uppercase vowels?

Answer: For writing a function to count the number of vowels in a given string and handle uppercase vowels, you can follow the provided guidelines. Here's a step-by-step explanation:

Problem Statement:

Write a function that counts the number of vowels in the string "adieu ouija louie". If the string contains any uppercase vowel, pause the smart contract. If the string contains a lowercase vowel, return the number of vowels found. To solve this problem, you can create a function in your smart contract that utilizes a for loop to iterate through the characters of the input string and count the vowels. Here's an example of how the function can be implemented: ```solidity function countVowels(string memory s) public view returns(uint) { uint count = 0; for (uint i = 0; i < bytes(s).length; i++) { bytes1 letter = bytes(s)[i]; if (letter >= 65 && letter <= 90) { // Uppercase vowel found, pause the smart contract pause(); } else if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') { count++; } } return count; } ``` This function will count the number of lowercase vowels in the given string "adieu ouija louie" and pause the smart contract if an uppercase vowel is encountered. By following this approach, you can effectively handle the counting of vowels in the string.

Question: How can you calculate the electricity bill based on the number of units consumed with different rates for each tier?

Answer: To calculate the electricity bill based on the number of units consumed with different rates for each tier, you can create a function in your smart contract that follows the specified criteria. Here's a detailed explanation:

Problem Statement:

Write a function that calculates the electricity bill based on the number of units consumed with the following criteria: - First 100 units: no charge - Next 100 units: Rs 5 per unit - After 200 units: Rs 10 per unit The function should return the total amount of the electricity bill. To solve this problem, you can define a function in your smart contract that accepts the number of units consumed as input and calculates the total bill amount based on the given criteria. Here's an example of how the function can be implemented: ```solidity function calculateBill(uint units) public pure returns(uint) { uint billAmount; if (units <= 100) { billAmount = 0; } else if (units <= 200) { billAmount = (units - 100) * 5; } else { billAmount = 500 + ((units - 200) * 10); } return billAmount; } ``` By utilizing this function, you can accurately calculate the electricity bill based on the number of units consumed and the corresponding rates for each tier. Implementing this logic in your smart contract will enable you to provide a seamless solution for calculating electricity bills.