Free Essay

Pt1420 Programming Unit 10 Research & Homework

In:

Submitted By Derek777
Words 1912
Pages 8
Unit 10: Homework and Research Assignment

Definition

Decision Structure - allows a program to perform actions only under certain conditions.

Boolean expression - expressions that can be evaluated as either True or False

Iteration - is the repetition of a block of statements within a computer program.

Counter-controlled repetition structure - used when a program needs to repeatedly process one or more instructions until some condition is met, at which time the loop ends. Many programming tasks are repetitive, having little variation from one item to the next.

Condition controlled - Most programming languages have constructions for repeating a loop until some condition changes. Note that some variations place the test at the start of the loop, while others have the test at the end of the loop.

Pre – test loop - the condition gets evaluated at the beginning of the loop cycle. Therefore, the body of the loop will not get executed if the condition does not hold the very first time.

Post – Test loop - the loop condition gets evaluated at the end of the loop cycle. Therefore, the body of the loop will get executed at least once, regardless of the condition. This is a major difference between a pretest loop and a posttest loop. You may choose a posttest loop if the problem description justifies the body of the loop be executed at least once.

Repetition Sequence/ Set of statements - A repetition structure causes a statement or set of statements to execute repeatedly. Sequence – set of statements that execute in the order that they appear.

Condition controlled loop - uses a true/false condition to control the number of times that it repeats.

Sentinel value - must be unique enough that it will not be mistaken as a regular value in the list. It is a special value that marks the end of a list of values.

Function header - specifies the data type of the value that is returned from the function, the name of the function, and any parameter variables used by the function to accept arguments.

Function return value - is either "return" or "return value", where value is a variable or other information coming back from the subroutine.

Input validation - is sometimes called an error trap or an error handler. It is part of the practice of defensive programming. Thorough input validation anticipates both obvious and unobvious errors.

Error trap - some programming languages provide “error trapping,” which means that when the program attempts to do something impossible (such as divide by zero or read a file that doesn’t exist), control will be transferred to an errorhandling routine supplied by the programmer. If no error trapping were provided, the program would simply end with an error message that might puzzle the user.

“reading” a file - Unfortunately this means the server doesn't have permission to create files in your directory. There are two ways you can handle reading data from a file: you can either read one line at a time, or read the entire file into an array.

“writing data to” a file - When a file is opened for writing, it will be created if it does not already exist and it will be reset if it does, resulting in the deletion of any data already there. Using the w indicates that the file is assumed to be a text file.

Filename extension - an identifier specified as a suffix to the name by syntax, often separated from the base filename (by, e.g., a dot, a space), that indicates, e.g., the encoding (file format), the usage, of a computer file. Examples of filename extensions are .png, .jpeg, .exe, .dmg, and .txt.

Input file - are provided as arguments to a program, standard input is automatically redirected to become those input files instead of the keyboard.

Append mode - the name of a procedure for concatenating (linked) lists or arrays in some high-level programming languages.

Sequential access - means that a group of elements (such as data in a memory array or a disk file or on magnetic tape data storage) is accessed in a predetermined, ordered sequence. Sequential access is sometimes the only way of accessing the data, for example if it is on a tape. It may also be the access method of choice, for example if all that is wanted is to process a sequence of data elements in order.

Direct acess method of reading data from a computer file without reading through the file fromthe beginning as on a disk or drum. Also called: random access.
In one or two sentences, answer the given question

List and explain the syntax of a single alternative decision structure.

provides only one alternative path of execution

List and explain the syntax of a dual alternative decision structure.

is used when your program must make a choice in which there are two possible outcomes to a decision. It is used when you have an either-or situation (in other words, a decision in which the two possible outcomes are mutually exclusive). In general terms, think of it as saying something like “if condition X, then do Y, otherwise do Z”.

List and explain the syntax of a multiple alternative decision structure.

They are to be executed as a result of the condition being true or false. There are times when the program needs to choose between more than two options. There are two methods for accomplishing this task: (1) nested "if-else" statements; and (2) the "switch" statement. Allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute.

Example:

SYNTAX DISPLAY
Multiple Alternative IF Statement
Form:
IF condition1 THEN statement sequence1 ELSIF condition2 THEN statement sequence2 ... ELSIF conditionk THEN statement sequencek ELSE statement sequencen END IF;
Example:
IF N >= 0 THEN Ada.Text_IO.Put(Item=>"Positive"); ELSIF N = 0 THEN Ada.Text_IO.Put(Item=>"Zero"); ELSE Ada.Text_IO.Put(Item=>"Negative"); END IF;

What is the general syntax of a case structure?

Case {variable of type: integer or character ONLY} of {input statement- within inverted commas if of type char} : {code..} {input statement- within inverted commas if of type char} : {code..} ...
End; {End Case}
Compare the use of a NESTED DECISION structure as opposed to a CASE structure.

In an IF-THEN-ELSE statement, how does the status of the Boolean test expression affect the choice of statements to be executed?

These statements are executed if the condition is true.

When would you use a counter controlled repetition structure? when you know exactly how many times the loop should run.

When would you use a condition controlled repetition structure? This is used to execute a program when a certain condition is met. Example true/ false question.

How is a Boolean expression used to control a condition controlled loop?

One situation could be if a true/ false situation is met within the loop.

List and explain the syntax of a DO WHILE loop.

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
Syntax:
The syntax of a do...while loop in C programming language is:
-------------------------------------------------
do { statement(s); }while( condition );
Notice that the conditional expression appears at the end of the loop, so the statement(s) in the loop execute once before the condition is tested.
If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop execute again. This process repeats until the given condition becomes false.
List and explain the syntax of a DO UNTIL loop.

List and explain the syntax of a FOR-NEXT loop.
Description

Repeats a group of statements a specified number of times.
Syntax

For counter = start To end [Step step] [statements] [Exit For] [statements]
Next
The For...Next statement syntax has these parts: counter | Numeric variable used as a loop counter. The variable can't be an array element or an element of a user-defined type. | start | Initial value of counter. | end | Final value of counter. | step | Amount counter is changed each time through the loop. If not specified, step defaults to one. | statements | One or more statements between For and Next that are executed the specified number of times. |

List and explain the syntax of a WHILE loop.
A while loop statement in C programming language repeatedly executes a target statement as long as a given condition is true.
Syntax:
The syntax of a while loop in C programming language is:
-------------------------------------------------
while(condition) { statement(s); }
Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.
When the condition becomes false, program control passes to the line immediately following the loop.

What loop structures lend themselves to use as a POST-TEST loop?
Repetition Structures

How is a DO-WHILE loop incremented?
You have to explicitly write a statement that performs this action.

How is a FOR-NEXT loop incremented?
A loop counter variable is used
What loop structure will increment and control itself without having a separate counter statement?
Count- controlled while loop
What specific type of loop will always perform a task (or set of statements) at least once?
While Loop
What pair of statements will repeat as long as a condition is true?
Both the While and Do-While loops cause a statement or set of state- ments to repeat as long as a condition is true.
When using a counter variable, what three actions will the loop typically perform?
Initialization, test, increment

Compare a Module (or subroutine) and a function.

Modular programming is mostly a strategy to reduce coupling in a computer program, mostly by means of encapsulation. A function is a unit of work that does something and when you have several functions that you can group in a certain way, you put them in a module.

What Flowchart symbol and verbiage is used to call a Function?

Subroutine / Predefined Process

This shape takes two names - 'Subroutine' or 'Predefined Process'. Its called a subroutine if you use this object in flowcharting a software program. This allows you to write one subroutine and call it as often as you like from anywhere in the code.

What Flowchart symbol and verbiage is used for the termination of a Function?
Terminal / Terminator

The terminator is used to show where your flow begins or ends. Ideally, you would use words like 'Start', 'Begin', 'End' inside the terminator object to make things more obvious.

Describe the steps in detecting data type mismatch errors.
In Data type mismatches the first step is to read the input as a string, 2nd is determine whether the string can be converted, and 3rd is convert or send an error message and start over.

What is defensive programming in terms of program design?
Defensive programming is the practice of anticipating errors that can happen while a program is running.

In terms of input validation, what do we mean by the term empty input?
Means when an input operation attempts to read data, but there is not data to read.

What flowcharting symbol is used for opening and closing files?

Rectangle

What type of file can be opened and viewed in an editor such as notepad?

Text file

What happens in the processing step of file access?

Writes data to the file or reads data from the file

Similar Documents

Premium Essay

Its Making Put Something Here

...PT1420 Introduction to Programming Week-2 Lesson Plan TUE 6:00 PM to 10:30 PM Instructor: Tushar Patel (tspatel02@yahoo.com, tpatel@itt-tech.edu) CLASS: Topic: Unit 2: Software Program Design I Course Objectives Covered by This Unit CO2: Design programs by using flowcharts and pseudo code. CO3: Write programs that perform input, processing, and output. Unit Learning Outcomes LO8: Determine program input, processing, and output stages. LO9: Create the necessary flowcharts to describe a program’s structure. LO10: Use pseudocode to define a program’s structure. LO11: Formulate solution algorithms for calculations by properly following the order of operations. Key Concepts ▪ Determining input, process, and output ▪ Creating flowcharts and pseudocode ▪ Formulating algorithms Reading ▪ Gaddis, Chapter 2: “Introduction to Computers and Programming,” pages 29-55 Resources: • Data Projector • ITT Virtual Library • Text Books • Visual Studio • Lab Computers • Student Removable Hard Drive • VM Ware Player Methods: • Lecture • Group Discussion • Lab Work • Review exercise / Research Papers • Quiz Brief Lesson Overview: Today’s lecture we would be discussing the following topics. • Discuss how all programs basically consist of a three-step process: input, process, and output. Use the payroll calculation program...

Words: 895 - Pages: 4