Question 5 (1 point)
userGuess ← 0, secretNumber ← 5
PRINT “Enter a number between 1 and 10”
READ userGuess
WHILE (userGuess < 1 OR userGuess > 10)
PRINTLINE “That is not between 1 and 10. Try again.”
READ userGuess
ENDWHILE
IF (userGuess == secretNum) THEN
PRINTLINE “That’s right! ”, userGuess, “ is the secret!”
ELSE
PRINTLINE userGuess, “ is not the secret!”
ENDIF
What is the first WHILE loop being used for?
Question 5 options:
|
Input validation |
|
|
Random number generation |
|
|
Comparison between userGuess and secretNum |
|
|
Nothing |
Question 6 (1 point)
CREATE userChoice ← 0
PRINT “Choose a number to see the multiplication table.”
READ userChoice
FOR (multiplier ← 1, multiplier < 12, multiplier ← multiplier
+ 1)
PRINTLINE userChoice, “ * “, multiplier, “ = “, (multiplier *
userChoice)
ENDFOR
Why was a FOR loop used for this example?
Question 6 options:
|
Number of loop iterations was known |
|
|
Number of loop iterations was random |
|
|
A WHILE loop would not work in this example. |
|
|
A DO...WHILE loop would not work in this example. |
Question 7 (1 point)
CREATE operation ← “”, number ← 0
WHILE (operation NOT EQUAL ”Q”)
PRINT (“Enter an operation: A, S, M, D, Q”)
READ operation
SWITCH (operation)
CASE ‘A’
DO
PRINT (“Number to add (0 to quit):”)
READ number
total += number
PRINTLINE total
WHILE (number <> 0)
BREAK
CASE ‘D’
DO
PRINT (“Number to divide (0 to quit):”)
READ number
total /= number
PRINTLINE total
WHILE (number <> 0)
BREAK
DEFAULT
PRINTLINE (“Invalid choice!”)
END WHILE
What mathematical operation would be called if a user enters 'A'?
Question 7 options:
|
Subtraction |
|
|
Addition |
|
|
Division |
|
|
Multiplication |
Question 8 (1 point)
CREATE sum ← 0, value ← 0, count ← 0
PRINT “Enter an integer (0 to quit)”
READ value
WHILE(value != 0)
count ← count + 1
sum ← sum + value
PRINTLINE “The sum so far is “ + sum.”
PRINT “Enter another integer (0 to quit)”
READ value
ENDWHILE
IF (count == 0) THEN
PRINTLINE “No values were entered.”
ELSE
PRINTLINE “The sum of all values is “ + sum
PRINTLINE “The average of all values is “ + sum/count
ENDIF
What is 0 being used as for the WHILE loop?
Question 8 options:
|
Sentinel Newspaper |
|
|
Sentinel value |
|
|
Sequential value |
|
|
Serial value |
Question 9 (1 point)
METHOD MAIN ()
BEGIN
CREATE result ← SUM(arguments:
1,10)
PRINT("Sum from 1 to 10 is:”,
result)
result ← SUM(arguments:
20,30)
PRINT("Sum from 20 to 30 is:”,
result)
result ← SUM(arguments:
35,45)
PRINT("Sum from 35 to 45 is:”,
result)
END MAIN ()
METHOD SUM(parameters: num1, num2)
BEGIN
CREATE sum ← 0
FOR (i ← num1, i <= num2, i
← i+1 )
sum ← sum +
i
ENDFOR
RETURN sum
END SUM
This METHOD is used to:
Question 9 options:
|
Sum values between the two parameters sent to it. |
|
|
Subtract the second value from the first value. |
|
|
Multiply values sent to it. |
|
|
Divide the first value by the second value. |
Question 10 (1 point)
METHOD MAIN ()
BEGIN
CREATE i ← 5
CREATE j ← 2
CREATE k ← max(i, j)
PRINT("The maximum of ", i , " and ” , j ,"
is ", k)
END MAIN ()
METHOD MAX(parameters: num1, num2)
BEGIN
CREATE result
if (num1 > num2)
result ← num1
else
result ← num2
RETURN result
END MAX
What would this method call return?
CREATE num1 = MAX(42,20)
Question 10 options:
|
42 |
|
|
22 |
|
|
62 |
|
|
20 |
Answer:
5) The correct answer is A)input validation
The first while will validate the userGuess input. The UserGuess
value should be between 1 and 10.
6)The correct answer is A) Number of loop iterations was
known
We know that the loop iterations and we used for loop there.
7)The correct answer is B)Addition
For Case A, The addition operation is performed. First, it will ask
for user input and adds the number to the total.
8)The correct answer is D)Serial Value
Zero in while loop used as the serial value to continue to loop
until the value becomes Zero.
9)The correct answer is A)Sum Values between the two
parameters sent to it
The Sum Method will do Addition operation inside the Method. It
will add the two parameters sent.
10)The correct answer is A)42
In the Max Method, an if condition will be checked whether num1 is
greater than num2. If this condition is satisfied then the result
will be assigned value of num1. Max (42,20) satisfies if condition
and num1 will be assigned to result and result will be printed
which is 42.
Let me know in case if you have any doubts. Thanks and all the best.
Question 5 (1 point) userGuess ← 0, secretNumber ← 5 PRINT “Enter a number between 1...
#include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
in python 3.0 please
Question 3 (1 point) What is the value of result after the following code snippet? num1 = 20 num2 = 10 num3 = 2 result = num1 // num2 / num3 print(result) The code has an error 01.0 0 0.0 0 0.25
// Group Names: // Date: // Program Description: // Import required packages //--> // Declare class (SwitchDoLab) //--> { // Declare the main method //--> { // Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3. //--> //--> //--> // Create an integer variable named choice to store user's option. //--> // Create a Scanner object // Create...
Please select the output: main declare X as integer, Y as integer set x=1 set y=2 call sub(x, y) write x write y End program Subprogram sub( integer Num1 as ref, Integer Mum2 as reference) declare x as integer set Num1 = 3 set Num2 = 4 set x= 5 write x end subprogram Please select one: 5/42, 5/34, 5/32, 5/24 What is the output of this...
Assignment • No variables declared after you start writing code, must be declared at the top. • Reuse all the variables from the first half in the second half, do not make up new variable names. • You code must be properly formatted. • You must use the code provided and variables names provided and not add any more variables to your code. • No for(int I = 0; … no declaring variables except at top of code. • You...
Question 21 The loop condition can be a complex condition involving several operators. True OR False Question 22 final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; if(num3-5 >= 2*LIMIT) { System.out.println ("apple"); } else { System.out.println ("orange"); } System.out.println("grape"); What prints? A. Apple B. Orange C. Grape D. apple grape E. orange grape F. Nothing. Question 23 When we use a while loop, we always know in advance how many...
I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> 4.2 Output: The first 20 Fibonacci numbers, which are...
SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){ int num1,num2; cout << "Enter two numbers "<< endl; cout << "First :"; cin >> num1; cout << "Second :"; cin >>num2; int result=num1+num2; cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result; ...
Give answer according to fill in the blanks. 1.Define a class called Fraction . This class is used to represent a ratio of two integers.Include mutator methods that allow the user to set the numerator and the denominator. Also include a method that returns the value of numerator divided by denominator as a double . Include an additional method that outputs the value of the fraction reduced to lowest terms (e.g., instead of outputting 20/60, the method should output 1/3)....