Scripting and Programming Foundations PRHO

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the initial step a programmer typically takes when using an existing programming library?

  • Discard the library and rewrite its functionality from scratch.
  • Write the library's functions to tailor them to the project.
  • Modify the library's functions to optimize performance.
  • Include the library in the project to access its functionalities. (correct)

What common characteristic do functions within a programming library typically share?

  • Every function performs the identical computation for redundancy.
  • Functions all relate to the same purpose, providing different facets of a solution. (correct)
  • Each function fixes bugs in the other functions to ensure stability.
  • Each function competes with the other to efficiently utilize resources.

What is a primary benefit of utilizing a programming library in software development?

  • The code has already been compiled, allowing a deeper level of customization.
  • The code can be used across programming languages, ensuring broad compatibility.
  • The code has not been tested, ensuring a fresh and innovative approach.
  • The code has already been tested, reducing the risk of bugs. (correct)

Which of the following languages is known for being dynamically typed?

<p>Python (D)</p> Signup and view all the answers

Which language is least aligned with object-oriented design principles?

<p>C (B)</p> Signup and view all the answers

A programming language allows a developer to define items like 'Person,' 'Teacher,' and 'Student,' each having unique data and behaviors. Which term best describes this?

<p>Object-oriented (D)</p> Signup and view all the answers

A programmer seeks a language that will instruct the compiler to report an error if an attempt is made to assign a string value to an integer variable. Which type of language is most suitable for this purpose?

<p>Statically typed (C)</p> Signup and view all the answers

A language uses tags around text to indicate how that text should be formatted. Which characteristic describes a language having such tags?

<p>Markup (B)</p> Signup and view all the answers

Which of the following is a fundamental attribute of a compiled language?

<p>Converts to machine language before running (B)</p> Signup and view all the answers

Which of the following is a defining characteristic of an interpreted language?

<p>Runs easily on different kinds of machines (D)</p> Signup and view all the answers

What is a key advantage of interpreted programs?

<p>They can be modified at run time. (B)</p> Signup and view all the answers

Which characteristic specifically describes a markup language?

<p>Tags surround text to describe desired formatting. (B)</p> Signup and view all the answers

Which characteristic specifically describes interpreted languages?

<p>They can be run one statement at a time. (A)</p> Signup and view all the answers

A car drove 200 miles using 10 gallons of fuel. Which operation should be used to compute the miles per gallon, which is 20?

<p>Division (C)</p> Signup and view all the answers

Which operator should be used to determine if a number is evenly divisible by 5?

<p>% (A)</p> Signup and view all the answers

A variable should hold a person's height in meters. Which data type should the variable be?

<p>Float (C)</p> Signup and view all the answers

A variable should hold the names of all past U.S. presidents. Which data type should the variable be?

<p>String array (D)</p> Signup and view all the answers

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?

<p>Constant integer secondsPerMinute (D)</p> Signup and view all the answers

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?

<p>Constant integer minAge (D)</p> Signup and view all the answers

Given integer x = 3 and integer y = 5, what is the value of the expression (x / 2.0) + y?

<p>6.5 (B)</p> Signup and view all the answers

Given float x = 10.2 and float y = 1.0, what is the value of the expression x / y?

<p>10.2 (A)</p> Signup and view all the answers

What kind of operator is the == in the expression i == 20?

<p>Equality (D)</p> Signup and view all the answers

What is the purpose of parentheses () in a programming expression?

<p>To group expressions (D)</p> Signup and view all the answers

Given float x = 3.0, which expression evaluates to 2.0?

<p>$x/2 + 0.5/2 + .25$ (A)</p> Signup and view all the answers

Flashcards

Programming Library

A collection of functions, procedures, data, and documentation that can be used by programmers to add functionality to their programs.

Library function relationship

Functions in a programming library relate to a specific, shared purpose.

Advantage of using a library

A key advantage is that the code within it has already been tested, making it more reliable.

Dynamically typed language

A language where the type of a variable is checked during run-time.

Signup and view all the flashcards

Non-Object Oriented Language?

A language that is not built on object-oriented design principles.

Signup and view all the flashcards

Object-Oriented Programming

A characteristic of a language that supports creating items like people, or teachers, with internal data and operations.

Signup and view all the flashcards

Statically typed languages

Languages where the compiler reports an error if an integer variable is assigned with a string.

Signup and view all the flashcards

Markup Language

A language that uses tags around text to indicate how that text should be formatted.

Signup and view all the flashcards

Compiled Language

A language that converts to machine language before running.

Signup and view all the flashcards

Interpreted Language

Needs to be interpreted, and runs easily on different kinds of machines.

Signup and view all the flashcards

Advantage of Interpreted Programs

They can be modified at run time, offering greater flexibility.

Signup and view all the flashcards

Markup Language Defined

Tags surround text to describe desired formatting.

Signup and view all the flashcards

Interpreted Languages Defined

They can be run one statement at a time, unlike compiled languages.

Signup and view all the flashcards

Interpreted Languages Defined Again

Can run on any machine having the right interpreter.

Signup and view all the flashcards

Compute Miles Per Gallon

An operation used to find how many miles you can drive per gallon of fuel.

Signup and view all the flashcards

Modulus Operator (%)

The operator that will determine if a number is evenly divisible.

Signup and view all the flashcards

Represent a person's height in meters

It's a floating point data type.

Signup and view all the flashcards

Hold the names of all past US presidents

It's a string data type.

Signup and view all the flashcards

Declare num of seconds in a minute

constant integer secondsPerMinute

Signup and view all the flashcards

Declare min age

constant integer minAge

Signup and view all the flashcards

What kind of operator is ==

The equality (==) operator.

Signup and view all the flashcards

What is the role of parentheses?

To group expressions

Signup and view all the flashcards

Represent an age range

An expression representing age from 18 to 24, inclusive, must be (x >= 18) and (x <= 24).

Signup and view all the flashcards

Data Type for Length?

Float

Signup and view all the flashcards

Input for hours to minutes

The function takes hours and minutes as the input to the function.

Signup and view all the flashcards

Study Notes

Programming Libraries

  • The first step a programmer takes when using an existing programming library is to include the library.
  • Functions within a programming library typically relate to the same general purpose.
  • A key advantage of using a programming library is that the code has already undergone testing.

Dynamically Typed Languages

  • Python is an example of a dynamically typed language.

Object-Oriented Programming

  • C is a language not built on object-oriented design principles.
  • Object-oriented languages allow programmers to create items with internal data and operations, such as persons, teachers and students.
  • When a programmer requires a compiler to report an error on assigning a string to an integer variable, a statically typed language should be used.

Markup Languages

  • Markup languages use tags around text to specify formatting.

Compiled Languages

  • A characteristic of a compiled language is its conversion to machine language before running.

Interpreted Languages

  • A characteristic of an interpreted language is that it runs easily on different kinds of machines.
  • Interpreted programs have the advantage of being modifiable at run time.
  • Interpreted languages are specifically described as being able to run one statement at a time.
  • Interpreted languages can run on any machine that has the correct interpreter.

Mathematical Operations

  • To calculate miles per gallon, divide the miles driven by the gallons of fuel used (200 miles / 10 gallons = 20 mpg).
  • The "%" operator is used to determine if a number is evenly divisible by another number.

Data Types

  • A variable holding a person's height in meters should be a Float data type.
  • A variable should hold the names of past U.S. presidents as a String array data type.

Declaring Variables

  • To store the number of seconds in a minute for calculations, it should be declared as a constant integer named secondsPerMinute.
  • To store the minimum age to run for U.S. president (35), it should be declared as a constant integer minAge.

Expressions

  • The expression (x / 2.0) + y, given integer x = 3 and integer y = 5, evaluates to 6.5.
  • The expression x / y, given float x = 10.2 and float y = 1.0, evaluates to 10.2.
  • The "==" in the expression i == 20 is an equality operator.
  • Parentheses in a programming expression are used to group expressions.
  • Given float x = 3.0, the expression x / 2 + 0.5 / 2 + .25 evaluates to 2.0.
  • The expression (x >= 18) and (x <= 24) represents all values of x when x is an age ranging from 18 to 24 years old.
  • Float data type is used for items that are measured in length.
  • The data type that should be used to keep track of how many planes are in a hangar is Integer.

Function Input

  • When a function converts hours and minutes to seconds, the input should be hours and minutes.
  • A function returning x cubed (x * x * x) requires x as the input.
  • A function calculating the weight difference (Diff) between two sample weights (S1 and S2) should output Diff.
  • For a function P(integer x) returning integer y = 2 * x, P(5) evaluates to 10
  • If Function F() "Puts "Hey" to output", after three successive calls to F() "HeyHeyHey" is displayed.
  • A valid user-defined function name can be any valid identifier.
  • A function MyFct with input x and output z returns z only.
  • The return value of a function is the Output of a function.

Control Structures

  • A "while loop" control structure should be used for accepting input numbers and adding them to a sum until a 0 is input.
  • A "do-while loop" control structure supports a game that prompts the user to enter an answer and checks if the input matches the correct answer and continues prompting the user until the answer matches the correct answer.

Pseudocode

  • Given the pseudocode:
x=3
do
 Put x to output
 Put " " to output
 x=x-1
while x > 0
  • The put to output is 3 2 1.
  • Given the code:
count = 0
while count is less than 5:
 print 'Hello'
  • "Hello" will print indefinitely.
  • In the pseudocode:
i=0
while i < 20
 Put i to output
 i=i+1
  • The loop expression is i < 20
  • In the pseudocode:
y=0
s = 100.0
while y < 10
 s = s + (s * 5.0)
 y=y+1
  • The loop variable initialization is y=0.
  • To output the minimum of x and y, the correct order of statements is: declare variable min, min = x, If y < min, set min = y, Put min to output.
  • To calculate speed in miles per hour given a start and end location and time traveled in hours, the order of the required statments is: Declare variables distMiles and speedMph, distMiles = endLocation - startLocation, speedMph = distMiles / timeHours, Put speedMph to output
  • To create a pyramid (large on bottom, small on top) on a table, the correct order of actions is: Clear table, Place largest shape, Place middle-sized shape, Place smallest shape.

Algorithms

  • The algorithm:
if x == y
 z=1
else
 z=0
  • determines whether x and y are the same.
  • The algorithm:
x = Get next input
if x == –1
 Put "Goodbye" to output
  • outputs Goodbye when user types -1.
  • Given the algorithm:
i=0
 x=0
 while i < 5
  if list[i] < 0
   x=1
  i=i+1
 Put x to output
  • An output of 1 indicates at least one integer is negative.
  • A programmer should develop an algorithm to solve a problem before writing a program to solve the problem.
  • "Insert key, turn key, open door" represents an algorithm.
  • "Shake bulb; if it rattles, replace it" represents an algorithm.
  • For an algorithm that should output "OK" if a list's numbers are all non-zero, else "Not OK", a valid test is Input 99, 0, 5. Ensure output is "Not OK."

Flowcharts

  • In the flowchart, if the input is 17, OK is printed.
  • In the flowchart, if the input is 3 5 -1, 6 10 will be printed.

Class Diagrams

  • A class diagram depicts the Employee class' name, data members, and functions.
  • System’s classes, attributes, and methods and their features, constraints, and relationships are elements that are characteristic of a class diagram.

Use Case Diagrams

  • A use case diagram provides an overview of several use cases.

Waterfall Approach

  • The design phase of a waterfall approach would create a sequence diagram that specifies the required order of events between completed program components.
  • The analysis phase of a waterfall approach defines a program's goals.
  • Testing is the phase of a waterfall approach where another person runs the program hundreds of times with different input, checking that each run yields correct output.
  • When a programmer starts writing the program in C++ using several functions, implementation phase of a waterfall approach is occurring.
  • When a company leadership determines that the system should support direct data entry as well as automated data capture of phone calls and emails, the analysis phase of the waterfall process is occurring.

Agile Approach

  • The testing phase of an agile approach would define a hypothesis to find a problem in a program.
  • The implementation phase of an agile approach creates an executable program.
  • The design phase of an agile approach creates a list of components needed to build an online auction site.
  • In an agile approach, the analysis phase is when goals are changed based on customer feedback.
  • If a programmer begins writing a second version of the program implementation phase of an agile approach , based on feedback.
  • If a colleague runs the second version of the program on numerous inputs to ensure outputs are correct, testing phase of an agile approach is being carried out.
  • The programming of the fourth version occurs during the implementation phase of an agile approach.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser