Question

In: Computer Science

4. Write a program trace for the pseudocode in Exercise • E4.6, assuming the input values...

4. Write a program trace for the pseudocode in Exercise • E4.6, assuming the input values are 4 7 –2 –5 0.

Ans.

first

value

minimum

output

• E4.6 --> This is the pseudocode

Set a Boolean variable "first" to true.
While another value has been read successfully
   If first is true
      Set the minimum to the value.
      Set first to false.
   Else if the value is less than the minimum
      Set the minimum to the value.
Print the minimum.

Solutions

Expert Solution

// PLEASE LIKE THE SOLUTION
// FEEL FREE TO DISCUSS IN COMMENT SECTION
// C++ PROGRAM

#include<bits/stdc++.h>
using namespace std;
  
// main method
int main(){
   // now create a bool variable
   bool first = true;

   // variable to store minimum
   double min;

   // while loop
   while(true){

       // read value
       double read;
       cin>>read;

       // unsuccessful read or 0
       if(!read)
           break;

       // now check if true
       if(first == true){
           min = read;
           first = false;
       }

       else{
           // check if less
           if(read<min)
               min = read;
       }
   }
   // print minimum
   cout<<"Minimum = "<<min<<endl;
   return 0;
}

// SAMPLE OUTPUT


Related Solutions

Trace the execution of the following program assuming the input stream contains the numbers 10, 3,...
Trace the execution of the following program assuming the input stream contains the numbers 10, 3, and 14.3. Use a table that shows the value of each variable at each step. Also show the output (exactly as it would be printed) // FILE: Trace.java // PURPOSE: An exercise in tracing a program and understanding // assignment statements and expressions. import java.util.Scanner; public class Trace { public static void main (String[] args) { int one, two, three; double what; Scanner scan...
Exercise 4 – Lists and input Using a function Write a program that prompts the user...
Exercise 4 – Lists and input Using a function Write a program that prompts the user to input a sequence of words. The program then displays a list of unique words (words that only occurred once, i.e. no repeated).
Write a program with two input values, Hours and Rate. The program should first calculate Gross...
Write a program with two input values, Hours and Rate. The program should first calculate Gross pay, which is your pay before deductions. The program should then calculate the following three deduction amounts: Federal Tax (20% of Gross), State Tax (5% of Gross), Social Security Tax (6.2% of Gross). Then your program should calculate Net pay, which is your Gross pay minus the three deductions. The output should be all five of the calculated values.
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Write a program which reads an input file. It should assume that all values in the...
Write a program which reads an input file. It should assume that all values in the input file are integers written in decimal. Your program should read all integers from the file and print their sum, maximum value, minimum value, and average. Use the FileClient class here (from a previous reading) as an example. You'll need to create a file to be used as input to test your program, as well. Your program should work whether the integers are separated...
Write a program that asks the user to input a set of floating-point values. When the...
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.5 pts Your code with comments A screenshot of the execution Test Case:       Enter float: 1.0...
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
Write pseudocode (3 Marks) and program structure (4 Marks) for the problem given below; In a...
Write pseudocode and program structure (4 Marks) for the problem given below; In a college, students are awarded a pass grade if their total mark is between 50-59, credit grade if the mark is between 60-69, distinction for marks between 70-79. High distinction if the mark is above or equal to 80 and fail if the mark is below 50.
In this exercise, you will test and debug a Future Value Program. The pseudocode of the...
In this exercise, you will test and debug a Future Value Program. The pseudocode of the program is as follows: Display user message WHILE user wants to continue           get monthly investment, yearly interest rate, and years           convert yearly interest rate to monthly interest rate           convert years to months           set the future value to zero           FOR each month                     add monthly investment amount to future value                     calculate interest for month                     add interest to future value          ...
In this exercise, you will test and debug a Future Value Program. The pseudocode of the...
In this exercise, you will test and debug a Future Value Program. The pseudocode of the program is as follows: Display user message WHILE user wants to continue           get monthly investment, yearly interest rate, and years           convert yearly interest rate to monthly interest rate           convert years to months           set the future value to zero           FOR each month                     add monthly investment amount to future value                     calculate interest for month                     add interest to future value          ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT