Comp sci unit 1

Ace your homework & exams now with Quizwiz!

Computer basics

- collection of on and off switches - Boolean control - use bionary #s to process data - data included only info that can be input, processed, or output -represented by and combo of 0s and 1s (binary #s)

NAMING AND IDENTIFIERS: What is an identifier? What does more effective code allow? And if you choose good identifiers what does it allow for other programs?

-Descriptive name used in code -more effective code is easier to debug -if you choose good identifiers, other programs will be able to read the code easier

2. The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ? A. Boolean B. number C. string D. list

A. Reason: The status of whether a store is open can be represented using only the values true and false, so a Boolean variable is most appropriate.

Forms of data?

Alphanumeric values, images, colors, interactions, etc.

8. Consider the following code segment. (p←10) (q←20) (r←30) (s←40) (p←q) (q←r) (s←q) (r←p) What is the value of r as a result of executing the code segment? A. 10 B. 20 C. 30 D. 40

B.

1. The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ? A. Boolean B. number C. string D. list

B. Reason: A person's age is typically represented numerically, so a numeric variable is most appropriate.

Data can?

Be collected, analyzed, stored, etc.

3. A teacher is writing a code segment that will use variables to represent a student's name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment? A. A string variable named s and a Boolean variable named a B. A string variable named s and a numeric variable named n C. A string variable named studentName and a Boolean variable named isAbsent D. A string variable named studentName and a numeric variable named numAbsences

C. Reason: A student name is best represented using a string. The status of whether a student is absent can be represented using only the values true and false, so a Boolean variable is most appropriate. For both variables, using meaningful variable names helps with the readability of the code segment.

4. Consider the following code segment, which uses the variables r, s, and t. r ← 1 s ← 2 t ← 3 r ← s s ← t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment? A. 1 1 B. 1 2 C. 2 3 D. 3 2

C. Reason: Line 1 assigns 1 to r. Line 2 assigns 2 to s. Line 3 assigns 3 to t. Line 4 assigns the value of s, which is 2, to r. Line 5 assigns the value of t, which is 3, to s. Line 6 displays 2. Line 7 displays 3.

5. Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Consider the following program, which uses the variables start, end, and current. start← 1 end← 20 current ← 3 start ← current current ← current + 1 DISPLAY (start) DISPLAY (current) What is displayed as a result of executing the program? A. 1 3 B. 3 3 C. 3 4 D. 4 4

C. Reason: The code segment initially sets start to 1, end to 20, and current to 3. Next, the code segment sets start to the value of current, which is 3. Then current is increased from 3 to 4. The final values of start and current are 3 and 4, respectively.

Data is?

Collection of individual values expressed in different ways based on program

CONSTANTS AND VARIABLES: what can identifiers be?

Constants or variables

NAMING AND IDENTIFIERS: naming is ______ for programming.

Critical

Computer?

Egg timer

What is data?

Info that can be processed or interpreted by a computer

Data Types: Arrays

List of items

DATA TYPES: can the data type of a given identifier change?

NO

CONSTANTS AND VARIABLES: can values of variables change?

THEY CAN CHANGE

CONSTANTS AND VARIABLES: can values of constants change?

THEY CANNOT CHANGE

Data types: Boolean

True or false, on or off, yes or no

NAMING AND IDENTIFIERS: What is the form of abstraction used for?

Used to decrease the complexity of programs

DATA TYPES: do identifiers follow a certain rules based on their data type?

Yes

Data types: Integer

whole numbers

Data types: String

Value not made of numbers (last name= vazquez)

Computers

-tools that work info or data -do things humans do just easier -take data as an input, transform it in some way, and produce output as a result -take many forms

7. Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable? A. A simulation of flipping a fair coin B. A simulation of rolling a fair die (with sides numbered 1 through 6) C. A simulation of the temperature in a location over time D. A simulation of traffic patterns on a road

A. Reason: There are only two possible results of a coin flip, which can be stored in a Boolean variable as true or false.

6. Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. Which of the following are benefits of using well-named variables in a computer program? Select two answers. A. The program will run faster B. The program will be easier for people to read C. The program will have a greater data storage capacity D. The program will be easier to modify

B. Reason: Using well-named variables allows a person reading the program to better understand the intentions of the programmer. D. Reason: Using well-named variables allows the original programmer or another programmer to better understand what quantity a variable represents. This in turn can assist the same programmer or another programmer to know what parts of a program to modify and what side effects might occur when a given part of the program is changed in the future.


Related study sets

Principles of Finance Study Cards

View Set