1: Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1: Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same thing. Assume that num is an integer variable that has been initialized, and that there are functions fl, f2, f3, and f4. Do not use any if or if-else statements in the actions in the switch statement, only calls to the four functions. if num < -2 || num > 4 f1 (num) else if num <= 2 if num >= 0 f2 (num) else f3 (num) end else f4 (num) end end Test your switch statement with num: a random integer from -5 to 5, and creating anonymous functions for fl-f4: fl=sin (num), f2=enum cos(num), f3= num?+2*num, f4= arctan(num). QUESTION 2: Write a script that will prompt the user for a quiz grade and error-check until the user enters a valid quiz grade. The script will then echo print the grade. For this case, valid grades are in the range from 0 to 10 in steps of 0.5. Do this by creating a vector of valid grades and then use any or all in the condition in the while loop. 1: Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same thing. Assume that num is an integer variable that has been initialized, and that there are functions fl, f2, f3, and f4. Do not use any if or if-else statements in the actions in the switch statement, only calls to the four functions. if num < -2 || num > 4 f1 (num) else if num <= 2 if num >= 0 f2 (num) else f3 (num) end else f4 (num) end end Test your switch statement with num: a random integer from -5 to 5, and creating anonymous functions for fl-f4: fl=sin (num), f2=enum cos(num), f3= num?+2*num, f4= arctan(num). QUESTION 2: Write a script that will prompt the user for a quiz grade and error-check until the user enters a valid quiz grade. The script will then echo print the grade. For this case, valid grades are in the range from 0 to 10 in steps of 0.5. Do this by creating a vector of valid grades and then use any or all in the condition in the while loop.
Expert Answer:
Related Book For
Fundamentals of Electric Circuits
ISBN: 9780073301150
3rd edition
Authors: Matthew Sadiku, Charles Alexander
Posted Date:
Students also viewed these programming questions
-
Assume that children is an integer variable containing the number of children in a community, and that families is an integer variable containing the number of families in the same community. Write a...
-
If Number is an integer variable and MyString = "One potato" then the following statement is valid: Number = Length_Of(MyString) True or False
-
Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same thing. Assume that num is an integer variable that has been initialized, and that there are...
-
Nisha has completed her MBA and has joined a company which was going to raise fund from long term sources such as Debt and Equity. Nisha was asked by her manager to prepare a report on which could be...
-
The following tables list the ages, heights (in inches), and weights (in pounds) of the players on the 2009 roster for the National Hockey League teams Boston Bruins and Edmonton Oilers. a. Compare...
-
(a) Determine the currents l1, l2, and l3 in Fig. 19-50. Assume the internal resistance of each battery is r = 1.0. (b) What is the terminal voltage of the 6.0-V battery? 12.0 V 8.012 12 10 12.0 V 15...
-
For a given data set containing 18 points, the assumptions of the linear model are satisfied. The following values are computed: b1 = 5.58 and sb = 4.42. Perform a test of the hypothesis H0 : 1 = 0...
-
The following transactions occurred during 2014. Assume that depreciation of 10% per year is charged on all machinery and 5% per year on buildings, on a straight-line basis, with no estimated...
-
For this question, use the two-period New Keynesian model discussed in Topic 2 (weeks 7-11). The central bank minimises the following loss function 1 L = - 2 ( y Ye) + 10 (p = p), 2 K (4) using the...
-
Two mining companies, Red and Blue, bid for the right to drill a field. The possible bids are $ 15 Million, $ 25 Million, $ 35 Million, $ 45 Million and $ 50 Million. The winner is the company with...
-
Goldmine purchased a piece of land and a building for RM20 million. Apart from the purchase price. Goldmine has incurred the following expenditures in relation to the purchase of land and building:...
-
A taxpayer needs help identifying and understanding their Adjusted Gross Income ( AGI ) for the tax year of 2 0 2 3 . Filing status: Single Their total income consists of the following: Wages $ 2 0 ,...
-
Kingsport Containers Company makes a single product that is subject to wide seasonal variations in demand. The company uses a job - order costing system and computes plantwide predetermined overhead...
-
For the last few years, you have been running StoreWell, a company supplying refrigerants to storage and logistics clients. Given the market shifts during COVID-19. you decide to divert some of your...
-
Lincolnshire Lumber sells boards for many uses including wood floors. For floors, the boards are sold to local installers or do - it - yourself homeowners. The boards go through up to four processes,...
-
The City of Piglet reported property tax revenues in 2020 in the amount of $10 million. The deferred inflow-property taxes reported in the General Fund's balance sheet was $300,000 on December 31,...
-
How much less is a perpetuity of $2,000 worth than an annuity due of the same amount for 30 payments (in $ dollars)? Assume an interest rate of 10%. $
-
Record the following selected transactions for March in a two-column journal, identifying each entry by letter: (a) Received $10,000 from Shirley Knowles, owner. (b) Purchased equipment for $35,000,...
-
Determine Vx in the circuit of Fig. 10.62 using any method of your choice. , 312 10
-
Repeat prob. 7.65 using PSpice. In Problem 7.65 If the input pulse in Fig. 7.130(a) is applied to the circuit in Fig. 7.130(b), determine the response i(t). e, (V) 542 10 20 211 1 (s)
-
Given that Determine: (a) [z] (b) [y] (c) [h] (d) [T] 0.06S-0.4 0.2 2 [g] =
-
Under what conditions can WTO members not use MFN when dealing with one another?
-
What does most favored nation (MFN) mean?
-
How do the various forms of economic integration differ?
Study smarter with the SolutionInn App