The basis for education in the last millennium was “reading, writing, and arithmetic;” now it is reading, writing, and computing. Learning to program is an essential part of the education of every student, not just in the sciences and engineering, but in the arts, social sciences, and humanities, as well. Beyond direct applications, it is the first step in understanding the nature of computer science’s undeniable impact on the modern world. 

This course covers the first half of our book Computer Science: An Interdisciplinary Approach (the second half is covered in our Coursera course Computer Science: Algorithms, Theory, and Machines). 

Our intent is to teach programming to those who need or want to learn it, in a scientific context. 

You can enroll here:

Computer Science: Programming with a Purpose Week 3 Quiz Answers - Coursera!

Coursera Computer Science: Programming with a Purpose Week 4 Quiz Answers!

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
Standard drawing (StdDraw)
Standard output (Stdout)

Question 5) Consider the following program

public class Q45
   public static void main(String [ ] args)
      while (! Empty ())
        int x = Int () ;
        if (!StdIn . isEmpty ()) x +- 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

Answer: 8

Post a Comment

Previous Post Next Post