Docsity

Scripting and Programming Foundations, Exams of Computer Science

Toggle sidebar
bg1
Scripting and Programming Actual FINAL PREP- Foundations - C173 with C173 Pre-Assessment Practice
Questions
Which operator should be used to determine if a number is evenly divisible by 5? - correct
answer %
A car drove 200 miles using 10 gallons of fuel.
Which operation should be used to compute the miles per gallon, which is 20? - correct answer
Division
floating-point literal - correct answer a number with a fractional part, even if that fraction is 0,
as in 1.0, 0.0, or 99.573
string literal - correct answer consists of text (characters) within double quotes, as in "Go
#57!". A character includes any letter (a-z, A-Z), digit (0-9), or symbol (~, !, @, etc.).
A variable should hold a person's height in meters. - correct answer Float
A variable should hold the names of all past U.S. presidents. - correct answer String array
integer - correct answer A variable of type _______ can hold whole number values, like 1, 999,
0, or -25 (but not 3.5 or 0.001).
A program uses the number of seconds in a minute in various calculations.
How should the item that holds the number of seconds in a minute be declared? - correct
answer Constant integer secondsPerMinute
A program determines if a user's age is high enough to run for U.S. president. The minimum age
requirement is 35.
How should the item that holds the minimum age be declared? - correct answer Constant
integer minAge
Given integer x = 3 and integer y = 5.
What is the value of the expression ( x / 2.0) + y? - correct answer 6.5
Given float x = 10.2 and float y = 1.0.
What is the value of the expression x / y ? - correct answer 10.2
What kind of operator is the == in the expression i == 20? - correct answer Equality
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Partial preview of the text

Download Scripting and Programming Foundations and more Exams Computer Science in PDF only on Docsity!

Questions Which operator should be used to determine if a number is evenly divisible by 5? - correct answer % A car drove 200 miles using 10 gallons of fuel. Which operation should be used to compute the miles per gallon, which is 20? - correct answer Division floating-point literal - correct answer a number with a fractional part, even if that fraction is 0, as in 1.0, 0.0, or 99. string literal - correct answer consists of text (characters) within double quotes, as in "Go #57!". A character includes any letter (a-z, A-Z), digit (0-9), or symbol (~, !, @, etc.). A variable should hold a person's height in meters. - correct answer Float A variable should hold the names of all past U.S. presidents. - correct answer String array integer - correct answer A variable of type _______ can hold whole number values, like 1, 999, 0, or - 25 (but not 3.5 or 0.001). A program uses the number of seconds in a minute in various calculations. How should the item that holds the number of seconds in a minute be declared? - correct answer Constant integer secondsPerMinute A program determines if a user's age is high enough to run for U.S. president. The minimum age requirement is 35. How should the item that holds the minimum age be declared? - correct answer Constant integer minAge Given integer x = 3 and integer y = 5. What is the value of the expression ( x / 2.0) + y? - correct answer 6. Given float x = 10.2 and float y = 1.0. What is the value of the expression x / y? - correct answer 10. What kind of operator is the == in the expression i == 20? - correct answer Equality

Questions What is the purpose of parentheses () in a programming expression? - correct answer To group expressions Given float x = 3.0. Which expression evaluates to 2.0? - correct answer x / 2 + 0.5 /2 +. Which expression evaluates to true only when the user is within 3 years of 21 years, given a variable x containing a user's age? - correct answer ( x >= 18) and ( x <= 24) Which data type is used for items that are measured in length? - correct answer Float Which data type should be used to keep track of how many planes are in a hangar? - correct answer Integer A function should convert hours and minutes to seconds, such as converting 1 hour and 10 minutes to 4,200 seconds. What should be the input to the function? - correct answer Hours and minutes A function returns a number x cubed. For example, if x is 3, the function returns 3 * 3 * 3, or 27. What should be the input to the function? A x B x, x C x, x, x D 27 - correct answer x A function calculates the weight difference (Diff) given two sample weights (S1 and S2). What should be the output from the function? - correct answer Diff function P(integer x) returns integer y y = 2 * x What does P(5) evaluate to? - correct answer 10

Questions Which control structure should be used? - correct answer While loop Joe is building an online game. He wants to provide a riddle and have the player guess the answer. The game needs to prompt the user to enter the answer, check to see if it the input provided does not match the correct answer , and continue prompting the user until the answer entered matches the correct answer. Which control structure supports Joe's needs? - correct answer Do-while loop Psuedocode - correct answer text that resembles a program in a real programming language but is simplified to aid human understanding What is put to output by the following pseudocode? x = 3 do Put x to output Put " " to output x = x - 1 while x > 0 A 3 2 1 0 B 3 2 1 0 - 1 C 2 1 0 D 3 2 1 - correct answer 3 2 1 A programmer has developed the following code: count = 0 while count is less than 5: print 'Hello' What is the result of implementing this code? - correct answer 'Hello' will print indefinitely.

Questions What is the loop expression in the following pseudocode? i = 0 while i < 20 Put i to output i = i + 1 A i B i< C i = 0 D i = i + 1 - correct answer i< What is the loop variable initialization in the following pseudocode? y = 0 s = 100. while y < 10 s = s + (s * 5.0) y = y + 1 - correct answer y = 0 Order the steps needed to output the minimum of x and y from first (1) to last (4). Select your answers from the pull-down list. A Declare variable min B Put min to output C min = x D If y < min, set min = y - correct answer Declare variable min, min = x, If y < min, set min = y, Put min to output Order the steps needed to calculate speed in miles per hour given a start and end location and time traveled in hours from first (1) to last (4).

Questions x = Get next input if x == - 1 Put "Goodbye" to output - correct answer Outputs Goodbye when user types - 1 What does an output of 1 indicate for the following algorithm running on a five-element list of integers? i = 0 x = 0 while i < 5 if list[i] < 0 x = 1 i = i + 1 Put x to output A All integers are positive. B All integers are negative. C At least one integer is negative. D At least one integer is positive. - correct answer At least one integer is negative. When should a programmer develop an algorithm to solve a problem? - correct answer Before writing a program to solve the problem Which text represents an algorithm? A Cats and dogs have tails. B Insert key, turn key, open door. C The forecast for tomorrow is rain. D A box has balls, bats, and hats. - correct answer Insert key, turn key, open door. Which text represents an algorithm?

Questions A Shake bulb; if it rattles, replace it. B Water is wet; fire is not wet. C Staring at the sun hurts the eyes. D The max speed is 60 mph. - correct answer Shake bulb; if it rattles, replace it. An algorithm should output "OK" if a list's numbers are all non-zero, else the output is "Not OK." Which test is a valid test of the algorithm? A Input 0, 0, 0. Ensure output is "OK." B Input 5, 4, 0. Ensure output is "OK." C Input - 3, - 2, 5. Ensure output is "Not OK." D Input 99, 0, 5. Ensure output is "Not OK." - correct answer Input 99, 0, 5. Ensure output is "Not OK." What is put to output by the following flowchart, if the input is 17? - correct answer What is put to output by the following flowchart, if the input is 17? What is put to output by the following flowchart, if the input is 3 5 - 1? - correct answer What is put to output by the following flowchart, if the input is 3 5 - 1? class diagram - correct answer structural diagram that can be used to visually model the classes of a computer program, including data members and functions. Depicts the Employee class' name, data members, and functions - correct answer What is the purpose of the following class diagram? use case diagram - correct answer behavioral diagram used to visually model how a user interacts with a software program Which elements are characteristic of a class diagram? - correct answer System's classes, attributes, and methods and their features, constraints, and relationships What is the purpose of a use case diagram, such as the following diagram? - correct answer Describes how a user can interact with a program Review the following use case diagram:

Questions A programmer decides a program should convert U.S. units to metric units and decides to write the program in C++ using several functions. Which phase of a waterfall approach is occurring when the programmer starts writing the program? - correct answer Implementation A company has a new project it wishes to implement to track and analyze employee and customer interactions. The company leadership determines that the system should support direct data entry as well as automated data capture of phone calls and emails. Which phase of the waterfall process is occurring? - correct answer Analysis A programmer shows a program's first version to a customer. The customer provides feedback, which causes the programmer to change the goals of the program. In which phase of an agile approach are goals changed based on customer feedback? - correct answer Analysis A programmer shows a program's first version to a customer. Based on feedback, the programmer begins writing a second version of the program. In which phase of an agile approach does the writing of a second version of the program occur?

  • correct answer Implementation A programmer shows a program's first version to a customer. Based on feedback, the programmer creates a second version, and then has a colleague run the second version on numerous inputs to ensure outputs are correct. Which phase of an agile approach is that colleague carrying out? - correct answer Testing A programmer is currently programming the fourth version of a program. Each version has additional features to satisfy more customers. In which phase of an agile approach does the programming of the fourth version occur? - correct answer Implementation

Questions What does a programmer do first to use an existing programming library? - correct answer Include the library library - correct answer A set of pre-written functions that carry out common tasks, that a programmer can use to improve productivity. What relationship is common among a programming library's functions? - correct answer Functions all relate to the same purpose What is an advantage of using a programming library? - correct answer The code has already been tested. statically typed, - correct answer each variable's type must be declared and cannot change while the program runs. ("Static" means unchanging) Why are statically typed languages considered safer? - correct answer Because they report errors during compilation (like if assigning an integer with a string) why are dynamically-typed languages considered easier to use? - correct answer because when types need to change, less converting and fewer variables are required what are 3 popular examples of statically typed languages - correct answer C, C++, Java dynamically typed - correct answer a variable's type may change while a program executes, usually based on what is assigned to the variable. ("Dynamic" means changing) Which language is dynamically typed? - correct answer Python object-oriented language - correct answer supports decomposing a program into objects what four languages provide extensive object-oriented support? - correct answer C++, Java, Python, and C# Which language is not built on object-oriented design principles? - correct answer C markup language - correct answer allows a developer to describe a document's content, desired formatting, or other features what is a popular markup language - correct answer HTML (Hyper text markup language) A programmer wants a compiler to report an error if an integer variable is assigned with a string. Which kind of language should the programmer use? - correct answer Statically typed A language substantially supports a programmer creating items like person, teacher, and students. Each item has internal data and some operations.

Questions D An interpreter executes statements one at a time. - correct answer Tags surround text to describe desired formatting. Which characteristic specifically describes interpreted languages? - correct answer They can be run one statement at a time and They can run on any machine having the right interpreter. What is an editor? - correct answer A program that allows you to write code What is a compiler? - correct answer A program that produces other programs. The compiler does all the work at once and then runs the new program. We're translating the code we wrote to computer code all at once. This is often when we produce an .exe (executable) file. What is an interpreter? - correct answer runs a program's statements. A program that runs code one line at a time. Instead of converting all of the code at once it runs each line as it's needed. It interprets that specific line from your code to computer code. What is an operator and what does it do? - correct answer An operator takes two operands (values) and does something with them. It is an object capable of manipulating a value. If it is a comparison or logical operator it would compare to see if they are similar or dissimilar. If it is a mathematical operator it would perform mathematical calculations. What is an expression? - correct answer something that has a value. What is the difference in a terminal and non-terminal expression? - correct answer A terminal is a final value, while a non-terminal can be reduced further. What is proper Python grammar for making an expression? - correct answer Expression → Expression Operator Expression The Expression non-terminal that appears on the left side can be replaced by an Expression, followed by an Operator, followed by another Expression. For example, 1 + 1 is an Expression Operator Expression. What is a variable? - correct answer Simply put, its a container for storing a value. Used by programs to refer to data. It is a named item, used to hold a value. A name that refers to a value. program can store that data in _______. Each __________ has a name, a value, and a type. The value might change over time, and that's why its "_________" _________ is on the left-side of the = with the current value of the right-side expression What are the three main types of data covered? - correct answer sting, integers, Boolean string - correct answer string is a sequence of characters surrounded by quotes, either single or double example: myVar = "string data"

Questions ^^ Integers - correct answer Is a whole number value. No decimals, whole numbers only example: myVar = 33 ^^ Boolean - correct answer A true or false value. example: myVar = True What is grammar used for in programming? - correct answer In a programming language like Python, the code must match the language grammar exactly. When programming language grammar is not followed the interpreter will return a Syntax Error message. This means that the structure of the code is inconsistent with the rules of the programming language. How do you change the value of a variable with Python? - correct answer Using the = character to assign a new value x = 6 x = 9 print x # would print out 9 How to do you join multiple variables together with string data in Python? What is this called? - correct answer Using the + sign to concatenate the values What does it mean to index a string? How do you do that with Python code? - correct answer This is what we call selecting a sub-sequence of a string. You do this in Python by specifying the character you want to access by its index position. Index position begins at 0. For example, this code would print out the letter J: name = 'John' print name[0] What does it mean to slice a string? How do you do that with Python code? - correct answer Slicing is simply obtaining a subset of data from a string. You may have also heard this called string extraction. You do this in Python by specifying the index position where you want to begin and where you want to end. Everything from the starting point up until the end point will be extracted. For example, this code would print out "Jo": name = 'John' print name[0:2]

    • correct answer concatenate or add = - correct answer assignment
    • correct answer multiply
    • correct answer subtract

Questions How are compound mathematical expressions evaluated in Python? - correct answer First perform calculations within parentheses. Next work left to right and perform all multiplication and division. Finally, work left to right and perform all addition and subtraction What is the function of parentheses, (), in programming expressions? - correct answer When we are working with an expression, they group items within that expressions. Items within parentheses are evaluated first. For example: (5 + 3) * 8 = 64 because we do the addition first, then multiplication 5 + 3 * 8 = 29 because we do the multiplication first, then the addition. We also use parentheses in procedures to define the inputs to that procedure, which is a very different idea than when working within an expression.. < - correct answer less than

  • correct answer greater than <= - correct answer less than or equal to = - correct answer greater than or equal to == - correct answer comparisons equality How does the OR operator evaluate two operands? - correct answer If has a True value, the result is True and is not evaluated (so even if it would produce an error it does not matter). If has a False value, the result of the or is the value of . How does the AND operator evaluate two operands? - correct answer If has a False value, the result is False and is not evaluated (so even if it would produce an error it does not matter). If has a True value, the result of the and is the value of . How are elements in a list indexed? - correct answer List elements are assigned an index number starting with 0. What is mutation? Do lists support mutation? - correct answer This is the ability to change the value of something. Lists support mutation, allowing you to change the overall length as well as individual elements within the list.

Questions How is a for loop constructed in Python? What is its purpose? - correct answer A for loop provides a way to execute a block once for each element of a list. The syntax is this: for in : How do you select a sub-sequence of a list with Python? - correct answer You specify the index position to begin the selection and the index position by which to stop the selection. For example, the following code would print red and yellow because they are at position 0 and 1.The value of 2 tells us to stop the selection at position 2, but not to include it. myColors = ["red","yellow","blue","orange","green"] print myColors[0:2] What does the pop method do to a list in Python? - correct answer By default it removes the last element from a list. It can also be used with an index number to remove a specific element that is not in last place. For example, the following code would print red, yellow, blue, and orange because pop removed green from the end of the list. myColors = ["red","yellow","blue","orange","green"] myColors.pop() print myColors How would you remove a specific element from a list? - correct answer Using the pop method and specifying that specific element's index position. For example, the following code would print red, blue, orange, green because pop removes the color yellow. myColors = ["red","yellow","blue","orange","green"] myColors.pop(1) print myColors How do you update a list item with Python? - correct answer By specifying the element that you want to update and then assigning a new value. For example, the following code would change the second element in list, from yellow to purple. myColors = ["red","yellow","blue","orange","green"]

Questions How do you use dot notation to access an attribute of a class? - correct answer You list the individual object's name that is an instance of the class, a dot, and then the attribute name. For example myClass.color would access the color associated with the object myClass. What is instantiation? - correct answer Creating instances of a class What is abstraction? - correct answer Focus on the essential qualities of something rather than one specific example. For example, if I say a table you have an idea of what I mean even though I didn't say if it was wood/glass or big/small. This is the essential idea behind creating classes. What is encapsulation? - correct answer Surrounding something, not just to keep the contents together, but also to protect those contents. Restricts access to the inner workings of a class or any objects based on that class; this is referred to as information hiding or data hiding. What is inheritance? How does inheritance apply to working with classes? - correct answer A form of code reuse. We can create a new class, but instead of writing it from scratch, we can base it on an existing class. It would inherit some of the characteristics of the base class but could also have its own unique properties and methods that are not shared with the base class. What is polymorphism? How does polymorphism apply to working with classes? - correct answer Means many forms. It lets us automatically do the correct behavior even if what we're working with could take one of many different forms. The + is a great example. If we're adding two variables together with the plus sign, and these variables are integers, it will numerically add them. But if they are two strings it will concatenate them. With classes this allows us to work with objects created from different classes. What are the differences in a hashed search and a linear search? - correct answer A linear search goes through each entry one at a time to see if the search word matches the word you are looking for. With a large index and lots of queries this will be a very slow process. A hashed search maps those entries to a number, or keyword, and places those into buckets. This way you know which bucket to start looking at for a particular entry instead of looking through all of the entries. A hashed search is much like looking at the index in the back of a book; if you are looking for "pineapples" you don't have to start at the beginning and read each entry A-P, you can jump to the words that begin with P and start looking there. In this example the letter P would be the bucket that the entry pineapple is placed in. How are buckets used in a hash table? What effect do they have on lookup speed? - correct answer Entries in a hash table are mapped to a number, which is the position in the index where you should look for the entry. A hash table has numbered bucket slots that hold entries. The entries are organized in the buckets based on their assigned keyword number. When you run a search using a hash table the keyword assigned will be used to determine which bucket

Questions the entry should be located in and begin the search there. Because the search knows where to begin looking it is much quicker to look up items. Which storage method covered in this course ensures the fastest access to data? - correct answer A hash table, or dictionary What is an algorithm? - correct answer A well-defined sequence of steps (known as a procedure) that will always finish and produce the right results. The algorithm must finish in order for us to analyze efficiency. What is the difference in a procedure and an algorithm? - correct answer A procedure and algorithm are both a set of instructions that will be executed in order. The difference is that an algorithm must return a value. A procedure, or function, that does not return a value may not be considered an algorithm. What are circular definitions? - correct answer A definition that constantly calls itself. Because it lacks a base case it has no way to stop. It is stuck in a loop with a reference pointing to another reference that never resolves. These types of definitions are largely helpful in mathematical application. What is a recursive definition? - correct answer When a function calls itself, it is recursion. If a function is calling itself, it would be stuck in a loop forever unless we have a condition that would allow the recursion to stop. A recursive definition needs to have two parts: the recursive case and the base case. The base case must be something that you already know the answer for and not need to do anything to work it out. This is what allows us to eventually stop running the definition. The recursive case is when the function is calling itself to run again. The recursive case is defined in terms of itself, but in terms of a smaller version of itself, as progress must be made towards the base case. When would you use recursion? - correct answer To allow us to define infinitely many things using a few simple rules. A simple definition can be used to expand on something much more complex. This involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. For example, you could define ancestory = person 1 + ancestors. If you are person 1, your ancestors would be your parents, but they are not your only ancestors. Your parents have parents, but those are still your ancestors. Your grandparents had parents, and so on. A very simple definition can execute with multiple layers and a much more complex value. What three rules must a recursive algorithm obey? - correct answer It must have a base case which allows it to eventually end. It must change its state and move towards the base case. It must call itself recursively. What do we mean when we talk about the cost of an algorithm? - correct answer An algorithm's cost is related to the resources that it requires to execute. The primary way cost is