Question

In: Computer Science

Response in Coral Code and code example in Coral Code please!!!! Respond to the following in...

Response in Coral Code and code example in Coral Code please!!!! Respond to the following in a minimum of 175 words:

It is important to program your code efficiently. Efficient code does not include duplicate code that performs the same procedure. Functions are helpful in making code modular. How can functions reduce the amount of written code and make code easier to read/follow?

Provide a code example that supports your comments.

Solutions

Expert Solution

The answer to the above problem is as follows:

When we talk about function, its a group of statements that perform a specific task and we can call this from the code itself. This is what a function does in any language or if we are dealiing with Coral Code then also, it serves the same purpose. When we define a function, we can also pass in parameters to the function which are essentially values that can be used inside the function, and this function can also return values from it, to the place where its called.

All these features of a function, allows the coder/programmer the ability to refrain from repeating the same code at multiple places, as the group of code that is being repeated can be coded inside a function, and this function can be called at all required places. As such the redundancy and duplicacy of code is removed from the programs. At the same time, it allows us to make the program modular, by grouping the statement that perform a specific task like say, compute factorial, compute fibonacci term, search element, add record or other such task into one group, thereby dividing the program into modules.

Below is an example of function that computes sum of two numbers. Now if we want to find out sum of multiple pair of two values like (5,6) ; (2,3); (11,15) etc . Then without functions we will have to write separate code for each pair. But with functions, we can simply call the function sumOfTwoNumber() and pass the two values as parameters and store the returned result.

Example of function in CORAL code-

Function sumOfTwoNumbers(float num1, float num2) returns float sum
sum = num1 + num2

Function Main() returns nothing
float resultSum
resultSum = sumOfTwoNumbers(5, 6)
Put resultSum to output

Image of CORAL Code-

The output of the above code will be 11

If this answer helps, please give an up vote and feel free to comment for any query.


Related Solutions

In Coral Code Please!!!! The assignment is to get an integer from input, and output that...
In Coral Code Please!!!! The assignment is to get an integer from input, and output that integer squared, ending with newline. (Note: This assignment is configured to have students programming directly in the zyBook. Instructors may instead require students to upload a file). Below is a program that's been nearly completed for you. Click "Run program". The output is wrong. Sometimes a program lacking input will produce wrong output (as in this case), or no output. Remember to always pre-enter...
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: What are three...
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: What are three main things to look out for in detecting cash flow manipulation?
Entrepreneurs Please respond to the following with a 250-300 word response: Analyze the characteristics of a...
Entrepreneurs Please respond to the following with a 250-300 word response: Analyze the characteristics of a successful entrepreneur (see pages 5-7 in textbook) and determine if you have what it takes to start your own business. Provide specific examples to support your response. A recent tax change will significantly lower tax rates for businesses. Consider the contributions of small businesses, as discussed on pages 27-28 in textbook, and provide your opinion on this tax modification.
Respond to the following in a minimum of 175 words, please type response: An important part...
Respond to the following in a minimum of 175 words, please type response: An important part of using statistics is being able to explain your results to decision makers. Imagine that you have conducted a two-sample test and determined that the difference was not statistically significant.   While one mean was 4.3 and the other was 3.9, the p level for the t test was p=.07. Your management team says, “Well, the difference may not be statistically significant, but the difference is...
Respond to the following in a minimum of 175 words, please type response: The standard error...
Respond to the following in a minimum of 175 words, please type response: The standard error of the estimate of the mean is represented by the equation: σ√n Discuss what this equation means, using your own words and explain why we use it. Consider how it relates to the fact that we are making assumptions about the population and not just the sample.
Please respond to ONE of the following prompts. Describe an example of how you as a...
Please respond to ONE of the following prompts. Describe an example of how you as a professional nurse have used ethical theories or ethical principles in a clinical practice setting. OR In your clinical setting, consider the many times and various ways in which you acted as a patient or family advocate. Which model did you follow in advocating for the patient: rights protection model, values-based model, or respect for persons model? Would having used a different model have changed...
Please respond to the following in a minimum of 175 words: Provide an example of how...
Please respond to the following in a minimum of 175 words: Provide an example of how an international company (such as Unilever or Mondelez International) changes its distribution channels and/or marketing messages based on country.
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: Can you explain...
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: Can you explain the advantages and disadvantages to using the T-accounts and Excel? Please make sure you explain it with examples in a way that your peers would understand.
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: Cash flow analysis...
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: Cash flow analysis is 1 of the most important processes that firms can conduct to keep the company running smoothly. For small businesses that may not be equipped to easily obtain short-term financing, cash flow analysis becomes an essential component for financial success.   Discuss the primary problem with cash flow analysis. Discuss 2 additional issues that makes cash flow analysis difficult.
Advertising and Promotion Please respond to the following with a 250-300 word response: From the second...
Advertising and Promotion Please respond to the following with a 250-300 word response: From the second e-Activity, determine the best possible way to leverage Facebook, Twitter, and other social networking sites to advertise and promote the small business of your choice. Explain your rationale. Select a small business with which you are familiar and then determine the best way for that business to stretch its advertising budget. Provide specific examples to support your response.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT