34
ASST. PROF. DR. CENK BUDAYAN Introductory Computer Sciences YILDIZ TECHNICAL UNIVERSITY

Introductory Computer Sciences

  • Upload
    ramiro

  • View
    78

  • Download
    0

Embed Size (px)

DESCRIPTION

YILDIZ TECHNICAL UNIVERSITY. Introductory Computer Sciences. ASST . PROF. DR. cenk budayan. Email : [email protected] ve YARBİS http://www.yarbis.yildiz.edu.tr/budayan Office Hours: Monday 14:00 – 16:00 Wednesday 15:00-17:00 Office : 1-064. How we communicate with the computer. - PowerPoint PPT Presentation

Citation preview

Page 1: Introductory Computer Sciences

ASST. PROF. DR. CENK BUDAYAN

Introductory Computer Sciences

YILDIZ TECHNICAL UNIVERSITY

Page 2: Introductory Computer Sciences

Email: [email protected] ve YARBİS

http://www.yarbis.yildiz.edu.tr/budayanOffice Hours:

Monday 14:00 – 16:00Wednesday 15:00-17:00

Office: 1-064

Page 3: Introductory Computer Sciences

How we communicate with the computer

Machine Language (Lowest Level) 00010001111010111100011111000111111

Symbolic Language Low Level Programming Languages: It is close to

the machine language. It converts to the machine language by using a small program, therefore it is faster than the high level programming languages (assembly).

High Level Programming Languages: It consists of instructions to which people can relate, such as Click, If, and Do. (Visual Basic, C, C++, Java)

Page 4: Introductory Computer Sciences

High Level Programming Languages

Language DescriptionVisual Basic, C#

Popular programming languages for building windows and web applications. Use a graphical user interface

C, C++ Powerful advanced programming languages that emphasize flexibility and fast running times. C++ is also object oriented.

Java Flexible and powerful programming language that runs on many different computer systems. Often used to teach object-oriented programming

Python Simple, yet powerful programming language used for graphics and small applications

PHP Programming language used for creating interactive Web sites

JavaScript Scripting language used in Web applications that provides rich used interfaces for Web Browsers.

Page 5: Introductory Computer Sciences

Object oriented programming

Is an industry standard model for designing and coding programs.

When designing applications, designers use real-world objects to express patterns, called classes in software.

For example, a student registration application: Students and transcripts as possible classes

Classes contain attributes, expressed as variables. For example, student class can have attributes such as

Student ID, name, surname

Page 6: Introductory Computer Sciences

Graphical User Interface (GUI)

User Friendly. Simplified interaction with the computer.Not simplified the task of programming.Require on-screen elements such as windows, dialog

boxes, buttons and menus. Uses mouse for interaction.No longer does the user respond to a program – now the

program responds to a user.

Page 7: Introductory Computer Sciences

Visual Basic

Visual Basic (VB) is one of the programming environment which can be used for performing many purposes easily.

In the early 1960s, two mathematics professors at Dartmouth College developed a programming language called BASIC to provide their students with an easily learned language that could tackle complicated programming projects. As the popularity of BASIC grew, refinements were introduced that permitted structured programming, which increased the reliability of programs. Visual Basic 1.0 is a graphical version of BASIC developed in 1991 by the Microsoft Corporation to allow easy, visual-oriented development of Windows applications.

Page 8: Introductory Computer Sciences

Visual Basic

VB is not only limited with programming, but also it can be used for developing programs in MS Office (Excel, Word, Powerpoint and Outlook Express) via Visual Basic Application(VBA).

VBScript used for developing Web applications is one of the subsets of VB.

VB can be used for programming for many different objects. It varies for a small program to a web application which can be used by the entire world.

As you can understand, VB is a simple however a powerful language.

Page 9: Introductory Computer Sciences

Installation of Visual Basic

http://www.visualstudio.com/en-us/downloads/

Page 10: Introductory Computer Sciences

Programming

Programming: creating a sequence of instructions to enable the computer to do something.

Program: is a set of instructions a computer follows in order to perform a specific task.

A program can consist of one or two command lines or can consist of million command lines.

For example; Windows operating system is written with millions of command lines, on the other a tax program can be formed of two command lines.

Page 11: Introductory Computer Sciences

Program

Computers are designed to follow instructions.

These instructions are called an algorithm. An algorithm is a set of well-defined steps for performing a task or solving a problem.

These steps should be sequentially ordered.The computers can only follow the

instructions and they do not evaluate these instructions and examine whether these instructions are logic or not.

Page 12: Introductory Computer Sciences

Procedure

Input Process

Output

Page 13: Introductory Computer Sciences

Performing a task on the computer

1. The first step in writing instructions to carry out a task is to determine what the output should be —that is, exactly what the task should produce.

2. The second step is to identify the data, or input, necessary to obtain the output.

3. The last step is to determine how to process the input to obtain the desired output – that is, to determine what formulas or ways of doing things should be used to obtain the output.

Page 14: Introductory Computer Sciences

Example

How fast is a car moving if it travels 50 miles in 2 hours The type of the answer requested. (speed) The information needed to obtain the answer.

(distance and time) The procedure required to obtain the answer by using

the available information. (distance / time)

Page 15: Introductory Computer Sciences

Example

Finding the tax for a product. (tax: 18% of the price of the product)

TaxPrice of the product

Price* 0,18

Page 16: Introductory Computer Sciences

Program planning

Software Development Cycle Analyze: Define the problem Design: Plan the solution to the problem. Design the interface: Select objects (text boxes,

buttons etc.)

Page 17: Introductory Computer Sciences

Program planning

Code: Translate the algorithm into a programming

language.

Test and correct: Locate and remove any errors in the

program.

Complete the documentation: Organize all the

material that describes the program.

Page 18: Introductory Computer Sciences

Example

Calculate the gas mileage which is the number of miles traveled divided by the number of gallons of gas used.

Therefore, your program needs to compute the number of miles traveled since the last fill-up, and the number of gallons used during this period.

Let’s suppose that you always fill up the gas tank. Therefore, the amount of gas that you put in the car is the amount used since the last fill-up.

Page 19: Introductory Computer Sciences

Example

To compute the number of miles you need to subtract the odometer reading at the last time you filled up the tank from the odometer reading at this filling time. This means that you need to have saved the odometer reading from the last time you filled up.

Suppose you have done so by writing the odometer reading and storing it in your glove compartment.

Therefore, the inputs to your procedure are: The current odometer reading The amount of gas pumped

Page 20: Introductory Computer Sciences

First Solution

1. Read odometer value.2. Subtract previous odometer value from the current odometer value to obtain the number of miles traveled.3. Divide by the number of gallons of gas pumped to determine the mileage

Page 21: Introductory Computer Sciences

Second Solution

1. Read the current odometer value.2. Write the odometer value obtained in step 1 on a piece of paper3. Retrieve the previous value from the glove compartment.4. Store the paper from step 2 in the glove compartment.5. Subtract the value obtained in step 3 from the value obtained in step 1.6. Fill the tank.7. Read the number of gallons pumped.8. Divide the number obtained in step 5 by the number obtained in step 7.9. Display the number obtained in step 8 as the mileage.10. Stop.

Page 22: Introductory Computer Sciences

Third Solution

1. Read the current odometer value.2. Write the odometer value obtained in step 1 on a piece of paper.3. Is this the first time for this procedure?

(a) If the answer is yes,(i) Store the paper from step 2 in the glove

compartment.(ii) Stop.

(b) If the answer is no, retrieve the previous value from the glove compartment.4. Store the paper from step 2 in the glove compartment.5. Subtract the value obtained in step 3(b) from the value obtained in step 1.6. Fill up the tank.7. Read the number of gallons pumped.8. Divide the number obtained in step 5 by the number obtained in step 7.9. Display the number obtained in step 8 as the mileage.10. Stop.

Page 23: Introductory Computer Sciences

Fourth Solution

1. Read the current odometer value.2. Write the odometer value obtained in step 1 on a piece of paper.3. Is there a previous odometer reading in the glove compartment?

(a) If the answer is no,(i) Store the paper from step 2 in the glove compartment.(ii) Stop.(b) If the answer is yes, retrieve the previous value from the

glove compartment.4. Store the paper from step 2 in the glove compartment.5. Subtract the value obtained in step 3(b) from the value obtained in step 1.6. Fill up the tank.7. Read the number of gallons pumped.8. Divide the number obtained in step 5 by the number obtained in step 7.9. Display the number obtained in step 8 as the mileage.10. Stop.

Page 24: Introductory Computer Sciences

Programming tools

Pseudocode: Uses English-like phrases with some Visual Basic terms to outline the task.

Flowcharts: Graphically depict the logical steps to carry out a task and show how the steps relate to each other.

Hierarchy charts: Show how the different parts of a program relate to each other.

Page 25: Introductory Computer Sciences

Programming tools

You decide to mail a letter, however you must decide how much postage to put on the envelope. One rule of thumb is to use one stamp for every five sheets of paper. Suppose a friend asks you to determine the number of stamps to place on an envelope.

Page 26: Introductory Computer Sciences

FlowchartSymbol Name Meaning

Flowline Used to connect symbols and indicate the flow of logic

Terminal Used to represent the beginning or the end of a task

Input/Output

Used for input and output operations, such as reading and displaying. The

data to be read or displayed are described inside.

ProcessUsed for arithmetic and data manipulation operations. The

instructions are listed inside the symbol.

DecisionUsed for any logic or comparison

operations. Unlike the other symbols, the decision symbol has one entry and

two exits.

Connector Used to join different flowlines

Annotation Used to provide additional information about another flowchart symbol

Page 27: Introductory Computer Sciences

Flowchart

Page 28: Introductory Computer Sciences

Pseudocode

Pseudocode is an abbreviated plain English version of actual computer code

The geometric symbols used in flowcharts are replaced by English-like statements that outline the process. As a result, pseudocode looks more like computer code than does a flowchart.

Pseudocode allows the programmer to focus on the steps required to solve a problem rather than on how to use the computer language.

The programmer can describe the algorithm in Visual Basic- like form without being restricted by the rules of Visual Basic.

Page 29: Introductory Computer Sciences

Pseudocode

Read sheets number (input)Set the number of stamps to Sheets (sheets/5)

(process)Round the number of stamps up to the next whole

number (process)Display the number of stamps(output)

AdvantagesIt is compact and probably will not extend for many pages as flowcharts commonly do. Also, the plan looks like the code to be written and so is preferred by many programmers.

Page 30: Introductory Computer Sciences

Hierarchy Chart

shows the overall program structure. depict the organization of a program but omit the specific

processing logic. describe what each part, or module, of the program does and

they show how the modules relate to each other. The details on how the modules work, however, are omitted. The chart is read from top to bottom and from left to right.

Each module may be subdivided into a succession of submodules that branch out under it.

The main benefit of hierarchy charts is in the initial planning of a program. We break down the major parts of a program so we can see what must be done in general. From this point, we can then refine each module into more detailed plans using flowcharts or pseudocode. This process is called the divide-and-conquer method.

Page 31: Introductory Computer Sciences

Hierarchical Chart

Postage stamp

program

Read sheets

Calculate stamps

Set stamps= sheets / 5

Round stamps up

to next whole

number

Display stamps

Page 32: Introductory Computer Sciences

Decision Structure

Page 33: Introductory Computer Sciences

Repetition Structure

Page 34: Introductory Computer Sciences

Homework

Calculate and report the average grade for a class.

Output: Average gradesInput: Student gradesProcess: Find the sum of the grades, count

the number of students, calculate the average grade = sum of grades / number of students

Draw the flowchart of this program.