Computer Science: Programming with a Purpose Week 4 Quiz Answer

Computer Science Programming with a Purpose Week 4 Quiz Answer

Computer Science: Programming with a Purpose Week 4 Quiz Answer


In this article i am gone to share Coursera Course Computer Science: Programming with a Purpose Week 4 | Input and Output Quiz Answer with you..


Input and Output



Question 1)
Which one of the following is an abstraction for providing input to a program while it is running?
  • Command-line arguments
  • Standard output
  • Standard input
  • System type conversion
  • Compiler arguments



Question 2)
Which of the following tasks could be implemented as a filter using only a constant amount of memory (e.g., a couple of int or double variables and no arrays)? Mark all that apply.

For each, the input comes from standard input and consists of n real numbers between 0.0 and 1.0.

  • Print the average of the n numbers
  • Print the n numbers in increasing order
  • Print the sum of the squares of the n numbers
  • Print the median of the n numbers n
  • Print the n numbers in uniformly random order
  • Print the maximum and minimum values of the n numbers
  • Print the percentage of numbers greater than the average of the n numbers

 

Question 3)
Which of the following are advantages of using standard input (Stdln) instead of command-line arguments? Mark all that apply.
  • There is no need to format the data
  • The StdIn library is built in to Java
  • We can input strings, not just numbers
  • Conversion to primitive types is explicitly handled
  • There is no artificial limit on the amount of data we can input to a program 
  • We can provide new values while the program is executing



Question 4)
Which of the following mechanisms enable us to write programs having no artificial limit on the amount of data they can handle? Mark all that apply.
  • Command-line arguments
  • Piping
  • Standard drawing (StdDraw)
  • Standard output (Stdout)
  • Arrays



Question 5)
Consider the following program

public class Q45
{
   public static void main(String [ ] args)
     {
      while (!StdIn.is Empty ())
       {
        int x = StdIn.read Int () ;
        if (!StdIn . isEmpty ()) x +- StdIn.read Int () ;
       }
       StdOut.print (x + " ");
     }
     StdOut.println ();
}


Suppose that the standard input stream consists of a sequence of eight 15, separated by whitespace. Give the value printed when this command is issued:

java Q45 <input.txt | java Q45 | java Q45


  • 8








Post a Comment

0 Comments