This page contains questions and answers for the first quiz in CS100: Principles of Computer Science, a course based on the book The Most Comples Machine.
The answers given here are sample answers only. There is always some variation in the answers that would receive full credit. The Notes contain any extra comments I happen to have; they are not parts of the answers.
Question 1: What is meant by the fetch-and-execute cycle?
Answer:The fetch-and-execute cycle is the basic process by which the CPU executes a program. The CPU "fetches"--that is, reads--an instruction from memory and then executes that instruction. It does this over and over again.
Note: After the CPU fetches and executes an instruction from some location in memory, it automatically goes on the next instruction for the next fetch-and-execute cycle. It does this unless executing the instruction tells it to go to a different location instead. An instruction that sends the CPU to a different location for the next instruction is called a jump instruction.
Question 2: What is meant by machine language?
Answer: Machine language consists of instructions for a computer encoded as binary numbers. Each type of computer has its own machine language. A computer can execute machine language programs directly. Programs written in other languages must be translated into machine language before they can be executed.
Note: The term "machine language" is a technical term with a specific definition. Certainly, the term might have been used to mean "a language used by machines," and then it might include, say, ASCII code. However, that's not the way it is. "Machine language" refers to the program instructions that a given computer can execute directly. When dealing with vocabulary in a technical field, you have to understand that definitions are somewhat arbitrary and that a common term might be used with a less-than-obvious meaning.
Question 3:Explain briefly how a picture can be represented by a binary number.
Answer: A picture can be made up of pixels. Each pixel is a little square of color. The color of that square can be encoded as a binary number. For example, 0 might be used to represent white and 1 might be used to represent black. The codes for all the individual pixels can then be strung together to give a single binary number that represents the entire picture.
Note: If the pixels can have more than two colors, then you will need more than one bit for each pixel. For example, with 8 bits per pixel, you can represent 256 different colors.
Question 4: One of the exercises on Lab 0 asked you to "Make a file--not just a window!--" with certain specified contents. What is the essential difference between a file and a window?
Answer: The essential difference is that a file is permanent. That is, a file is a collection of information that has been stored in the computer's permanent memory (such as on the computer's hard disk). It can be re-opened later and will stay around until someone explicitly throws it away. On the other hand, the contents of a window are temporary. They will disappear when you close the window, unless you have saved them into a file.
Note: It might be that a window shows the same information that is in some file, but it is only a copy. When you change the contents of a window, you don't automatically change the file; you have to explicitely save the changes. A window can be a way of viewing the contents of a file. (By the way, one example of this is a directory window that lets you view the contents of a folder. A folder is just a special kind of file that can contain a list of files and other folders.)
Question 5: Suppose that each person in a class is assigned a 3-letter code, where each letter in the code can be any of the 26 letters of the alphabet. How many different possible codes are there? Why?
Answer: There are 26 rasied to the 3-rd power different codes. This is because there are 3 possible positions and you have 26 different choices of what to put in each position. Thats a total of 26 times 26 times 26 choices.
Note: Although most people got this question right, it was not clear whether anyone understood exactly why the 26's should be multiplied together. You have to think about what happens as you write down a code. There are 26 choices for the first character. Then for each of those choices, there are 26 choices for the second character. If the first character was A, for example, then there are 26 ways of adding a second character: AA, AB, AC, ..., AZ. There are another 26 two-character codes that start with B: BA, BB, ..., BZ. And anotehr 26 that begin with C, and so on. That's a total of 26 times 26 different two-letter codes. When you add the third letter, you get 26 three-letter codes for each of the 26-times-26 two-letter codes. So again the total is multiplied by 26.