mohamed hosny43@yahoo [email protected] 0107155035 flowcharting a flowchart is a...

22
1 Mohamed_hosny43@yahoo.com 0107155035

Upload: vuonganh

Post on 17-May-2018

215 views

Category:

Documents


2 download

TRANSCRIPT

1 [email protected]

0107155035

2 [email protected]

0107155035

Information system

An information system is the combination of technology(computers) and people that enable an organization to collect data, store them, and transform them into information Data

Data are raw facts that are collected and stored by the information system (numbers, letters, images, sound clips, or video clips) Information

Is the output data processing (example the level of sugar in the blood) Computer Operations

1. Input data (reading data)

2. Store data in internal memory

3. Perform arithmetic operation on data

4. Compare two values and select one of two alternative actions

5. Repeat a group of actions any number of times 6. Output the results of processing

Programming

is a form of problem solving which aim is to develop a step by step process(logic) to solve the problem. The step by step logic is referred to as Algorithm Programming Languages

like BASIC enable people to write programs in English-like languages that a BASIC interpreter or BASIC compiler can change into the machine language that the computer can understand

3 [email protected]

0107155035

Visual Basic has an advantage over other languages in that Visual Basic projects can be interpreted during the design and testing process, but can then be compiled into an executable program when all the errors have been removed.

high-level languages Program

Programming languages to write letters in English, but different rules change from one language to Other

machine language

which is entirely composed of zeroes and ones

Interpreter

When a program is interpreted, the high-level language statements are converted into equivalent machine-language statements one at a time as the program is executed. The nice thing about interpreting a program is that, if the program encounters a statement with an error, the interpretation process stops and an error message is displayed so the user can correct it. On the other hand, executing an interpreted program is slower than executing a compiled program since each statement has to be converted to binary each time it is encountered in the program even if it When a high-level language is compiled, the entire program is translated into machine language before any attempt to execute it. Compilation has an advantage over interpretation in that a compiled program will run faster than an interpreted program once all errors have been found and corrected. Note that, errors are more difficult to find during compilation than during interpretation

Sum = 0 Counter = 0

1001100101010101

4 [email protected]

0107155035

Questions:

Q1. Define an information system.? Q2. What is the difference between data and information? Q3. How you can convert data into information? Q4. Mention the main operations that all computers can perform. Q5. What is the difference between high level languages and machine language? Q6. What is the difference between compiler and interpreter?

steps for problem solving as follows

1. Define the problem 2. Assemble known quantities and assign variable names 3. Discard unimportant data. 4. Establish relationships and express them as equations. 5. Determine the proper algorithm by arranging the equations in correct sequence. Example

A school has 1000 students of whom 48 percent are boys. The school gave a party which 70 percent of the students attended. If 60 percent of those attending were boys, how many girls attended the party? Solution

1. The question is: “How many girls attended the party?” 2. Let x = the total number of students attending the party Let y =

the number of boys attending the party Let z = the number of girls attending the party

3. The given fact that 48 percent of the students are boys has no effect on the problem and may be discarded.

4. The relationships stated are: a. 70 percent of the students attended ( x ) b. 60 percent of those attending were boys ( y ) c. This implies that the difference between x and y represents the

number of girls attending (z). So, we express these relationships as the following equations:

a. x = 1000 * 0.70 b. y = x * 0.60 c. z = x – y

5. Since the variable x must be known to find the variable y and both x and y must be known in order to find z, the equations must be solved in the given order.

5 [email protected]

0107155035

Flowcharting

A flowchart is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem.

Note that the 5 basic flowcharting symbols are

1 -Terminal block

2-Input / Output

3- Process block

4- Decision block

5- Flow lines.

ADVANTAGES OF USING FLOWCHARTS

1. Communication 2. Effective analysis 3. Proper documentation 4. Efficient coding 5. Proper debugging 6. Efficient program maintenance

LIMITATIONS OF USING FLOWCHARTS

1. Complex logic 2. Alterations and modifications 3. The essentials of what is done can easily be lost in the technical details of how it is

done.

6 [email protected]

0107155035

4. The difficulty of coping

Pseudocode

Pseudocode is statements written in abbreviated form to show the steps required to solv Pseudocode means "false code". That means that it is not the programming language e a specific problem

Components

1. Words

2. Clauses

3. Statements

1-If hours worked is greater than 150 Then Calculate Overtime Pay = (Hours Worked – 150) * 1.5 * (Pay Rate) Calculate Gross Pay = 150 * (Pay Rate) + Overtime Pay Else 2-Calculate Gross Pay = (Pay Rate) * (Hours Worked) Calculate TAX = 0.20 * (Gross Pay)

Rules and Constraints

1. The data names of variables being used to solve the problem should describe what the variable represents

2. All statements should be written in a way that is easy to understand

Program Logic Structures

1-Sequence

In pseudo coding, statements are done in sequential fashion unless one of the statements contains an instruction that interrupts the normal sequential flow 2- Selection

In this case an IF statement is presented There can be only two outcomes as a result of the IF statement being processed. One as a result of the tested condition being TRUE and the other as being FALSE. Therefore the IF-THEN-ELSE - The tested condition can be greater than(>), less than,(<) equal to(=), greater or equal to(>=), less than or equal to(<=),or not equal to . The result of testing the condition must be TRUE or FALSE For example M = 25N = 12If ( M >= N ) Then Statement 1 Else Statement 2

7 [email protected]

0107155035

End If Statement 3 3-Iterations

This statement implies that a certain activity or action will be performed repetitively a certain number of times or until a certain condition is met

1- Initialize the sum: Sum = 0 2- Initialize the number of terms N: N = 0 3- Increment the number of terms N 4- Add the new term to Sum: Sum = Sum + N

End If6- Stop Processing Advantages and disadvantages of Pseudocode

Some of advantages of pseudocode are :

1. It is simple because it uses English-like statements. 2. No special symbols are used. 3. No specific syntax is used. 4. It is very easy to translate its statements to that for high level languages

on a one-for-one basis The main disadvantages of pseudocode is that :

1. It can be quite lengthy for complex problems

5- If (N = 100 ) Then Go to step 6 Else Perform steps 3 through step 4 until N = 100

Iterations

8 [email protected]

0107155035

Draw flowchart to represent the process of reading two numbers, dividing them, and then displaying the result

Write a pseudocode to represent the process of reading two numbers, dividing them, and then displaying the result.

1. Input (Read) the first number “number1”.

2. Input (Read) the second number “number2”.

3. IF the value of number2 = zero Then

Print “Division is impossible because number2 is zero”

Go to step 4

ELSE

result = number1 / number2

Print number1, number2, and result

END IF

4. Stop processing.

9 [email protected]

0107155035

Draw a flowchart to find the largest of three numbers A, B, and C.

Write a pseudocode to find the largest of three numbers A, B, and C .

1. Input (Read) the values of three numbers A, B, C 2. IF the value of A > that of B Then

Go to step 3 ELSE

Go to step 4 END IF

3. IF the value of A > that of C Then Print “The maximum value is that of A” Go to step 5

ELSE Print “The maximum value is that of C” Go to step 5

END IF 4. IF the value of B > that of C Then

Print “The maximum value is that of B” Go to step 5

ELSE Print “The maximum value is that of C”

5. Stop processing

10 [email protected]

0107155035

END IF

Draw a flowchart to find the sum of first 100 natural numbers. This means that we want to find sum where sum is given by: Sum = 1 + 2 + 3 + …………………………………+ 99 + 100.

Write a pseudocode to find the sum of first 100 natural numbers. This means that we want to find sum where sum is given by: Sum = 1 + 2 + 3 + …………………………………+ 99 + 100

1. Initialize the Sum: Sum = 0

2. Initialize the term number N, which is the term itself: N = 0

3. Increment the term number: N = N + 1

4. Add the new term to Sum: Sum = Sum + N

5. IF N= 100 Then Go to step 6

Else Perform steps 3 through 4 until N is equal to 100

END IF

11 [email protected]

0107155035

6. Print an output line showing the sum of the first 100 terms of the series

7. Stop processing

Draw a flowchart to find the sum of the first 25 odd natural numbers. This means that we want to find sum where sum is given by: Sum = 1 + 3+ 5 + ………………………………… here we add 25 odd natural numbers

12 [email protected]

0107155035

Write a pseudocode to find the sum of the first 25 odd natural numbers. This means that we want to find sum where sum is given by: Sum = 1 + 3+ 5 + ………………………………… here we add 25 odd natural numbers

1. Initialize the Sum: Sum = 0

2. Initialize the number of terms N, and the first term T: N = 0 T = 1

3. Add the new term to Sum: Sum = Sum + T

4. Increment the number of terms by 1, and the term value by 2: N = N + 1

T = T + 2 5. IF N = 25 Then

Go to step 6 Else Perform steps 3 through 4 until T is less than 0.01 END IF

6. Print an output line showing the sum of the first 25 odd terms of the series 7. Stop processing

T=1+++T=0

13 [email protected]

0107155035

Draw a flowchart to read the age of Hany and Hesham, then it prints the name of the elder

Write a pseudocode to read the age of Hany and Hesham, then it prints the name of the elder 1- Input Hany is age and Hesham is age 2- If Hany is age Hesham is age Then Print “Hany is elder” Else If Hany is age = Hesham is age Then

Print “Both is equal” Else Print “Hesham is elder” End If End If 3- Stop processing

14 [email protected]

0107155035

Draw a flowchart that reads a temperature in Fahrenheit degrees and convert it into Celsius degrees, using the formula

Write a pseudocode that reads a temperature in Fahrenheit degrees and convert it into Celsius degrees, using the formula

1- Initialize Celsius Degree “C”: C = 0 2- Input (Read) Fahrenheit Degree “F” 3- C = 5/9 * (F – 32) 4- Print the value of C

15 [email protected]

0107155035

Print “the radius should be positive”

5- Stop processingDraw a flowchart that reads the radius of a sphere “r”, then it calculates its volume “V” and surface area “A” using formulas

If the read radius is negative, the flowchart should print a

warning message then terminates

16 [email protected]

0107155035

Draw a flowchart that reads the radius of a sphere “r”, then it calculates its volume “V” and surface area “A” using formulas

If the read radius is negative, the flowchart should print a

warning message then terminates

1- Initialize Volume “V”: V = 0 2- Initialize Area “A”: A = 0 2- Input (Read) Radius “r” 3- If r < 0 Then Print “the radius should be positive” Else V = (4 / 3) * (22 / 7) * (r ^ 3) A = 4 * (22 / 7) * (r ^ 2) Print “The Volume of Ball is V” Print “The Area of Ball is A” End If 5- Stop Processing

Object Oriented Programming (OOP)

In the OOP model, programs are no longer procedural. They do not follow a sequential logic. You, as the programmer, do not take control and determine the sequence of execution. Instead, the user can press keys and click various buttons and boxes in a window. Each user action can cause an event to occur, which triggers a basic procedure (function or program) that you have written Object

is something that exists. We deal with objects in our daily life. In real world objects can be parts of other objects. Property

as a characteristic or attribute of an object. ObjectName.Property = ValueMyPen.Color =Blue Method

17 [email protected]

0107155035

as a predefined actions provided with an object. ObjectName.Method()Event

as an action that may be caused by the user, such as a click, drag, or key press Classes

a prototype or blueprint for an object that includes the specifications for its properties and methods. (Encapsulation)

as an OOP feature that specifies that all methods and properties of a class be coded within the class. The class can hide or show the properties and methods as (Inheritance)is reusability, which is a big advantage of OOP over traditional programming. When you create a new class, you can then use that class in multiple projects

Fill in the spaces using the following words :Encapsulation)- class- method-property- event- object-inheritance(

1. Clicking the Mouse inside a Window is considered…………. 2. The width of the Window is considered……………………….. 3. Pressing a key from the keyboard inside the Window is considered…………. 4. Properties that the son takes from his father is considered……… 5. Going to school is considered…………………………………… 6. Amount of water in a lake is considered………………………… 7. Circuit diagram of your cassette is considered………………….. 8. …………is considered hiding for information in a Class

1- event 2- properties 3- event 4- inheritance

5- methods 6- properties 7- class 8- encapsulation

Put ( ) in front of the right sentence and (×) in front of the wrong

sentence:

1- The Class is constructed out of Object . (…..) 2- The Computer is considered an Object that is consisting of many Objects. (…..) 3- The color of a pen is a “Method”. (…..) 4- Making cassette on is considered “Event”. (…..) 5- The shape of an Object is determined by its properties. (…..) 6- Object has Properties, Methods, and Events. (…..) 7- Object is constructed out of a Class. (…..)

18 [email protected]

0107155035

8- Encapsulation is used to hide information of the Class. (…..) 9- Derived Class inherits from the Base Class properties only. (…..) 10- Encapsulation is used to protect the information of the Class.(…..)

- -

- - -

-

-

-

-

-

Fill the following table

MeansMnemonic

is something that exists. We deal with objects in our daily life. In real world objects can be parts of other

objects. object

as a characteristic or attribute of an object. properties

as a predefined actions provided with an object. methods

as an action that may be caused by the user, such as a click, drag, or key press events

a prototype or blueprint for an object that includes the specifications for its properties and methods

class

In the OOP model, programs are no longer procedural. They do not follow a sequential logic. You, as the programmer, do not take control and determine the sequence of execution. Instead, the user can press

keys and click various buttons and boxes in a window. Each user action can cause an event to occur, which triggers a basic procedure (function

or program) that you have written

)oop(

as an OOP feature that specifies that all methods and properties of a class be coded within the class. The

class can hide or show the properties and methods as encapsulation

is reusability, which is a big advantage of OOP over traditional programming. When you create a new

class, you can then use that class in multiple projects inheritance

19 [email protected]

0107155035

( IDE )Integrated Development Environment

The Visual Studio Environment is where you create and test your projects. The development environment is called the Integrated Development Environment (IDE).

VB Projects

Editor / Compiler / Debugger / Object browser / Help

Open program VB.Net

StartAll ProgramVisual Basic2005The New Project Dialog

In the New Project dialog, select Visual Basic and Windows in the Project Types , then select Windows Application in the Templates box. In addition to that you have to give your project a name on this dialog box The IDE main window

The Visual Studio toolbars contain buttons that are shortcuts for :Toolbarmenu commands. The standard toolbar is shown

makes The Form Designer is where you design a form that :Form Designeryour user interface

names The Solution Explorer window holds the files :Solution Explorer for the files included in your project and a list of the classes it references

Properties window: We use the Properties Window to set the properties of objects in your

a form The Toolbox contains the tools you use to place controls on :Toolbox

:

F5

v.b.net 2005FileSave all

The Windows Form Control

When you create a Windows Application new project, the IDE will automatically create a "Windows Form" for you as you have seen in the previous chapter. Practically, you will use this form to hold the other controls Button

It was mentioned in the previous chapter that the Button control's primary function is to react to a click of the user and perform a task associated with that button. In other words, it executes a preprogrammed function when the event of clicking The button happens

20 [email protected]

0107155035

)Property( )Hint(

Image Gets or sets the image that is displayed

on a Button control

ImageAlign Gets or sets the alignment of the image on

the Button control

TextAlign Gets or sets the alignment of the text on

the Button control

Visible Gets or sets a value indicating whether

the control is displayed

VisibleButton1.Visible=False Button1.Visible=True

: Visible:ButtonTrueFalse.:Button1.Visible=False

Button1.Enabled:True

False.Button1.Enabled=FalseButton1.Enabled=True

Label

The Label control is a rectangular area that can be filled with text. The following Table provides a list of commonly used properties for

21 [email protected]

0107155035

Empty String("")

We set this Label's Text property equal to the empty string at design time so that when the application starts running, Events

As we discussed before, when the user clicks the mouse button, Click event is generated. You can write a code that is executed when the event of clicking the button is detected. This code is called event handler

Intell Sense

IntelliSense list of the controls by using the "Me" keyword. When you type "Me" followed by a period, a list pops up showing the objects, properties, and methods for the form. As you start to type the control name, the selected position in the list changes until the unique item appears , then as soon as the correct name appears, type the next character(space, period, or Enter key)

Textbox

The TextBox is a data entry control. It provides an area for the user to type while the program executes. This information can then be used by the application's code as it executes.

22 [email protected]

0107155035

"CharacterCasting"

property will automatically change whatever the

user types to either uppercase or lowercase.

"MaxLength"

property controls the maximum number of characters

the user can type.

"ReadOnly"

property prevents the user from typing into the TextBox,

when it is set to True

"PasswordChar"

property lets you set a character

"TextLength"

property is used during run time to see how many

characters exist in the TextBox

MsgBox

MsgBox statement stands for “Message Box statement”. It is an alternative way to the label control for displaying information to the user

Button1.Text = "Cairo"

Button1.ForeColor = Color. Red

Button1.BackColor = Color. Yellow

MsgBox("Egypt")

Label5. Text Align=Center

Button1.Visible=True

Button1.Visible=False

Button1.Enabled=True

Button1.Enabled=False

CapitalTextBox1.Text=Me. TextBox2.Text.ToUpper( )

SmallTextBox2.Text=Me. TextBox1.Text.ToLower( )

/