Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. a. Write a line of code that asks the user the meaning of life, only accepts

ID: 3751747 • Letter: 5

Question

5. a. Write a line of code that asks the user the meaning of life, only accepts numeric input, and saves the answer in variable D1 b. Write a line of code that asks the user how the weather is like that day, only accepts string input, and saves the answer in variable D2. c. Using the menu command, write a line of code that asks the user (via GUlI) whether they are hearing "Yanny" or "Laurel", and saves the selection in variable D3. Write a line of code that shows the variable D3 and its value, without using fprintf. Write a line of code that shows the value of D2, without using fprintf. Write a line of code using fprintf, that forms output based on user's previous inputs from parts a and b of question 4: "It was a rainy evening when I heard that the Answer to the Ultimate Question of Life, The Universe, and Everything turned out to be 42." 12 inches is 1 foot. Convert 340 inches to feet by calculation, print the result using fprintf. Use eight characters in the output, six of them should be after the decimal mark. d. e. f. g. h. 100 centimeters is 1 meter. Convert 505 centimeters to meters by calculation, print the result using fprintf. Use three characters in the output, two of them should be after the decimal mark. Create the variable named D4 following result: "The imaginary part is 12 and the real part is 5.". DO NOT hard code the i. 5+12i. Using fprintf, write a line of code that prints the 5 and 12 in the code to be displayed. Generate the following matrix without typing in each individual element. Utilize the colon operator linspace, and other built-in MATLAB functions. 1 14 7 15 3 28 7 26 5 42 7 37 7 56 7 48

Explanation / Answer

As no language is mentioned in question 5, I am assuming it be MATLAB as Menu command for multiple choice is used in MATLAB

a)

D1= input ('Meaning of life?')

b)

D2=input('How the weather is today?','s')

c)

D3 = menu('Whar your are hearing?','Yanny','Laurel')

d)
As we need to output both variable and text without using fprintf, we need to use disp with sprintf

sprintf will give the exact format to display

disp(sprintf('D3 = %s', D3))

e)
Here we need to display only the value, we will use disp function

disp(D2)

f)

fprintf('It was a %s evening when I heard that the answer of the Ultimate Question of Life, The Universe, amd Everything turned out to be %d',D2,D1)

g)
%f gives the formatting to 6 decimal places

fprintf('340 inches = %f feet',340/12)

h)
If we need output till 2 decimal places we need to use %.2f formatting
fprintf('505 centimers = %.2f meters',505/100)

i)

D4='5+12i'
fprintf('The imaginary part is %s and the real part is %s', D4(1:1),D4(3:4))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote