Question

In: Computer Science

Flow control is one of the main building blocks that determines how a program should run....

Flow control is one of the main building blocks that determines how a program should run.
Ghana Cocoa Growing Company wishes to compare the impart of two newly acquired
fertilizers on cocoa. They will do this by applying the same quantity of the two fertilizers on
two similar but different cocoa plant under the same conditions (humidity, sunlight, soil
moisture etc.). They will then choose the fertilizer whose crop produces the best harvest
(highest quantity per square feet). As a programmer,
a. Suggest a flow control method that would be used to do the comparison and explain
the reason why you chose it.
b. Write a flow control statement that would do the comparison in “a” above. (5
marks)
c. The Ghana Statistical Services (GSS) is interested in your statement in “b” above but
it is of the view that it is too specific. They want you to modify it by creating a
function that takes four arguments i.e. (the names of the two fertilizer and their
individual yields). The function should return the name of the fertilizer with the
greatest yield.

Solutions

Expert Solution

a) The flow control method that will be most suitable for this case will be if flow control statement.

The reason why I choose is because the aim of the program is to get the most worthy fertilizer for crops , and so good fertilizer produces more yield.

Here the if flow control method can be used to compare the harvest produced by the two fertilizers and return the fertilizer name which produced more yield.

b)Let us first initialize the variables:

fertilzer1="name_of_fertilizer_1" //it will be a string

harvest1="yield generated by fertilizer1" //It will be an integer value

fertilzer2="name_of_fertilizer_2" //it will be a string

harvest2="yield generated by fertilizer2" //It will be an integer value

Now the if condition:

if(harvest1>harvest2)

then print the variable fertilizer1

else

print the variable fertilizer2

c)The method looks like this:

char function_name(fertilizer1,fertilizer2,harvest1,harvest2){

if(harvest1>harvest2){

return fertilizer1;}

else{

return fertilizer2;}

}

In this function it accepts four parameters and using the comparison of values of harvest, the required and best fertilizer name is returned.

Hope this helps!!!


Related Solutions

Show a general formula for the building blocks of protein and illustrate how these building blocks...
Show a general formula for the building blocks of protein and illustrate how these building blocks are connected to form protein.
Describe (and elaborate) how skills as one of the Building Blocks of Competencies might be reflected...
Describe (and elaborate) how skills as one of the Building Blocks of Competencies might be reflected in the 5 specific themes of: values, cognition, interpersonal behaviors, valuing diversity, and change orientation?
Write a paper on one of the four building blocks of financial ratios on
Write a paper on one of the four building blocks of financial ratios on Profit margin rate, Gross Profit Margin rate, Return on assets ratio (ROA), Return on equity (ROE), and Basic earnings per share? How each of the ratios is calculated and used to analyze financial statements? And also apply these ratios on A recently filed set of financial statements for Walmart Inc. ?  
What determines the inflation rate in the long run? How might inflation in the long run...
What determines the inflation rate in the long run? How might inflation in the long run be related to fiscal policy? What is seigniorage?
This program must have 9 functions: •main() Controls the flow of the program (calls the other...
This program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers, returns the modulo of the first...
What are the “building blocks” of proteins, nucleic acids, and lipids? How do they play a...
What are the “building blocks” of proteins, nucleic acids, and lipids? How do they play a key role in biophysical modeling on the molecular scale? In other words, why do we focus on these building blocks?
3. Write a Java program that loads a gallery.xml file, determines the number of photos (should...
3. Write a Java program that loads a gallery.xml file, determines the number of photos (should be only 3) in it and prints out the number of photos in the gallery.
Briefly explain how the two key building blocks of behavioural finance are incompatible with the notion...
Briefly explain how the two key building blocks of behavioural finance are incompatible with the notion of efficient capital markets. Clearly explain the following terms: Cognitive psychology Heuristics Cognitive Dissonance According to Hong and Stein (1999) large firms are less prone to mispricing when there is divergence of opinion. Briefly explain this statement.
[____________________________] regulation (control) determines how the primary RNA transcript is spliced or otherwise processed
[____________________________] regulation (control) determines how the primary RNA transcript is spliced or otherwise processed
One of the main objectives of management is to control the financial operations of the business...
One of the main objectives of management is to control the financial operations of the business to ensure shareholders wealth is maximized. Imagine you are given the job of the Chief Financial Comptroller/ Financial Accountant of a financial institution of your choice: Based on the financial institution of your choice identify no less than three aspects of a framework you need to use to effectively control the financial operations of the financial institution. Develop clear and cogent arguments of each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT