Re-write the following if statement structure as a SWITCH/CASE statement in C++ and Pseudocode:
X ← 1
A ← 3
IF (a is equal to 1) THEN
x ← x + 5
ELSE IF (a is equal to 2) THEN
x ← x + 10
ELSE IF (a is equal to 3) THEN
x ← x + 15
ELSE IF (a is equal to 4) THEN
x ← x + 20
ELSE x ← x + 100
ENDIF
PRINT("x = " + x);
Pseudocode: -------------- X ← 1 A ← 3 SWITCH(A) CASE 1: x ← x + 5 BREAK CASE 2: x ← x + 10 BREAK CASE 3: x ← x + 15 BREAK CASE 4: x ← x + 20 BREAK DEFAULT: x ← x + 100 ENDSWITCH PRINT("x = " + x); ================================================ C++ code: ----------- X = 1 A = 3 switch(A){ case 1: x = x + 5; break; case 2: x = x + 10; break; case 3: x = x + 15; break; case 4: x = x + 20; break; default: x = x + 100; } cout<<"x = "<<x<<endl;
Re-write the following if statement structure as a SWITCH/CASE statement in C++ and Pseudocode: X...
in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){ sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() { int score, highest; //missing portion of the program return 0; } 1(c). Find the missing portion of the following code, so the...
1) Convert the "Switch" statement to "if/else"
2) Convert from for loop to while loop
Convert the following "switch" statement to an equivalent "if/else": switch(x) case 10: cost- 1; break; case 20: cost- 2; break; default: cost 0; 0 if (cost =-1) x = 1; else if (cost-20) x = 2; else x = 0; O if ( x = 10) cost = 1; else if (x = 2) cost-20; else cost = 0; if (case10) cost 1; else if...
re doing. A Pythagorean triple is a set of integers (a, b, c) satisfying a2+bc2. Write pseudocode (or Matlab code) that will output the number of unique Pythagorean triples that satisfy c< 200. [Unique means that you should not count (a 3, b 4, c 5) and (a 4, b 3, c 5) as two different triples, for example]. Explain why your program will work. Imagine a square n x n matrix A with diagonal elements which we believe to...
all
in pseudocode
Question 1) Warmup question: Write a function named True False() (only the function, no main is needed) that takes in a number and determines if it is evenly divisible by 5 (le, returns true or false). (15 points) Answer is in: Pseudocode CHO Java0 C+0 Page 17 Question 3) 2D Arrays The IRS has contracted you to process a 10x10 array of floating point numbers called Taxes and sum up all negative numbers in the array so...
A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized. k-G+ 13)/27 loop: if k> 10 then goto out k=k+1 i=3"k-1 goto loop I out: B) Rewrite the following code segment in C++ using the multiple-selection (switch and if-else) statements. Assume that all the variables are declared and initialized. if((k 1) || (k 2))j-2 k-1 if ((k 3) || ( ks))j - 3.k+1 if (k 4)j-4k-1...
programming simple processor Implement switch construct as specified by pseudocode(this is similar to Java switch construct) switch A case 3: B := 1 break case 5: B := 22 break case 8: C := 32 break default: C := 99 endswitch
Question 5: Consider the following C++ program. switch(x) case 1: if (x > 1) case 2: if (x > 3) case 3: cout<<"Epic Beats!" << endl; case 4: cout << "Chill Vibes" << endl; break; case 5: cout << "Sweet Jazz" << endl; break; default: cout << "Invalid input. Try again."; A. What is the output if x = 1? B. What is the output if x = 3? C. What is the output if x = 2? D. What...
R$ ( pseudocode only, I just need the English written pseudocode) Write pseudocode for a program that prints a calendar such as the following: Su M T W Th F Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Write a MIPS program to demonstrate the operation of the following switch statement. switch (S) { case 5: A = A + 1; break; case 25: A = A - 1; break; default: A = A * 2; break; } Implement and simulate your solution. Allocate .data locations for the variables S and A, and load these values into registers before performing the switch statement on the registers. Run your program several times with different values for these variables, to...
Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube root (a)1/3 of a given number a with accuracy roughly within 10-8 using x0 = a/2. Use at most 100 iterations. Explain steps by commenting on them. Use f(x) = x3 − a. Choose a = 2 + w, where w = 3 Algorithm : Newton-Raphson Iteration Input: f(x)=x3−a, x0 =a/2, tolerance 10-8, maximum number of iterations100 Output: an approximation (a)1/3 within 10-8 or...