Question

In: Computer Science

What is the exact output of the following pseudocode segment? METHOD MAIN CALL myMethod (0,2) CALL...

What is the exact output of the following pseudocode segment?

METHOD MAIN

CALL myMethod (0,2)
CALL myMethod (3,5)

CALL myMethod (6,7)  

END MAIN

Answer:

METHOD myMethod(A,B)
BEGIN
    WHILE (A < B)
         PRINT(A + " ")
         A ← A + 1
    ENDWHILE
    PRINTLINE();

END MyMethod

Solutions

Expert Solution

Here is the equivalent C++ Code. Please read the code comments for more information

Give a thumbs up!!

Psuedocode

METHOD MAIN

CALL myMethod (0,2)
CALL myMethod (3,5)

CALL myMethod (6,7)  

END MAIN

END MyMethodMETHOD myMethod(A,B)
BEGIN
    WHILE (A < B)
         PRINT(A + " ")
         A ← A + 1
    ENDWHILE
    PRINTLINE();

C++ Code

#include<iostream>
using namespace std;


//my method
void myMethod(int A,int B)
{
   while(A<B)
   {
       cout<<A<<" ";
       A=A+1;
   }
   cout<<endl;
}

int main()
{
   myMethod(0,2); //myMethod runs for 0 1
   myMethod(3,5);//myMethod runs for 3 4
   myMethod(6,7);//myMethod results 6
   return 0;
}


Screenshot of output


Related Solutions

Given the following code, what is output by the method call, mystery(6 * 8)? public static...
Given the following code, what is output by the method call, mystery(6 * 8)? public static void mystery (int x[]) {     System.out.println("A"); } public static void mystery (int x) {     System.out.println("B"); } public static void mystery (String x) {     System.out.println("C"); } A B C CA CB Which of the following is true about overloaded methods? Java cannot use a method's return type to tell two overloaded methods apart. Java cannot use a method's parameters to tell two overloaded methods apart....
21. What is the output of the following segment of code if 7 is input by...
21. What is the output of the following segment of code if 7 is input by the user when asked to enter a number?____________ int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 7: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout...
For each call to the following method, indicate what console output is produced: public void mystery2(int...
For each call to the following method, indicate what console output is produced: public void mystery2(int n) { if (n <= 1) { System.out.print(n); } else { mystery2(n / 2); System.out.print(", " + n); } } mystery2(1); mystery2(4); mystery2(16); mystery2(30); mystery2(100);
pseudocode The main( ) program passes these integer values as arguments to the findMax( ) method...
pseudocode The main( ) program passes these integer values as arguments to the findMax( ) method for further processing. The main program receives one result back from findMax( ) method and displays the maximum of these three integer values. The findMax( ) method simply receives three integer values from the main program and finds the maximum of three integers and returns one value back to the caller (in this case the main application).
no need to explain 11. What is output by the following code segment? boolean isHighTemp =...
no need to explain 11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot 12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”);...
4. Rewrite the following pseudocode segment using a loop structure in the specified languages: k =...
4. Rewrite the following pseudocode segment using a loop structure in the specified languages: k = (j + 13) / 27 loop:       if k > 10 then goto out       k = k + 1       i = 3 * k - 1       goto loop out: . . . a. C++ b. Python c. Ruby Assume all variables are integer type. Discuss the relative merits of the use of these languages for this particular code.
what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back('...
what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back(' ') l = ['A', 'L', 'E', 'S', 'T', 'E'] for i in l: → if ord(i) % 3 == 0: → → dq.push_back(i) → elif ord(i) % 5 == 0: → → dq.push_front(i) → → dq.push_back(i) → elif ord(i) % 4 == 0: → → dq.push_back(i) → else: → → dq.peek_front() → → dq.push_front('X') → → dq.push_back('R') dq.push_front(dq.peek_back()) dq.pop_back() print(dq)
C++ Questions What is the output of the following pseudocode code: ages = new List Append(ages,...
C++ Questions What is the output of the following pseudocode code: ages = new List Append(ages, 55) Append(ages, 88) Append(ages, 66) Print(ages) A. 55, 66, 88 B. 55, 88, 66 C. 55, because there is no loop D. 66, because there is no loop E. None of the above. QUESTION 2 Type the list after the given operations. Each question starts with an empty list. Type the list as: 5, 7, 9 Append(list, 3) Append(list, 2) Append(list, 1) Remove(list, 3)...
What are the main ways to segment markets? Doing it internationally can be difficult. What are...
What are the main ways to segment markets? Doing it internationally can be difficult. What are the things you need to keep in mind when doing so.
assume that the following pseudocode is executed in a program module main declare x = 1...
assume that the following pseudocode is executed in a program module main declare x = 1 declare sum = 0 declare max = 5 while ( x < max) Display "x is ", x set x = x + 1 set sum = s + x end while end module after the execution of this program the final value of x is_____ and the final value of sum is_____
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT