king saud university college of applied studies and community services csc 206 programming with...

20
King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Upload: jayson-chapman

Post on 16-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

King Saud University College of applied studies and community services

CSC 206 Programming with Basic

Lecture 1

Page 2: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Outline and Objective

• What Is A Computer Program? Software?• Problem Solving• Program Development Cycle• Flow chart

Page 3: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

What Is A Computer Program? Software?

• Program = set of instructions that a computer will follow to perform a specific task.

• Software = collection of programs.

• Two types of software:

• System software: used to manage computer hardware to enable us to execute & write application programs/software. Ex. Operating System, Compilers, …etc.

• Application Software: are meant for solving users own problems. Ex. Word processors, database management…etc.

Page 4: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

5

Program Development Cycle:

1. Analyze: Define the problem

2. Design: Plan the solution to the problem

3. Develop the Interface: Select the objects

Page 5: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Program Development Cycle:

4.Code: Translate the algorithm into a programming language.

5. Debug and Test: Locate and remove any errors in the program.

6. Complete the Documentation: Organize all the materials that describe the program

Page 6: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

The Software Development Method

1. Specify the problem requirements.

2. Analyze the problem.

3. Design the algorithm to solve the problem.

4. Implement the algorithm.

5. Test and verify the completed program.

6. Maintain and update the program.

7

Page 7: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

كتابة وخطوات المسائل حل خطواتالمسألة :البرامج : حل صياغة

المسألة اوال:اوال: عناصر وتحليل تعريف: بالتالي يتم وذلك

البرنامج • مخرجات تحديدالبرنامج • مدخالت تحديدالبرمجه • عمليات تحديد

الخوارزم: ثانيا ثانيا كتابةللمسألة . الخوارزمية الخطوات بكتابة وذلك

االنسياب: ثالثا ثالثا مخططات رسم

Page 8: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

صحيحة : • رقمين يقرأ بحيث برنامجا اكتب مثالمجموعهم يطبع ثم

الحل :•المسألة اوال:اوال: عناصر وتحليل تعريف

: بالتالي يتم وذلكالعددين : • مجموع البرنامج مخرجات zتحديدالصحيحة : • الرقمين البرنامج مدخالت x , yتحديدالجمع : • عملية البرمجه عمليات z=x+yتحديد

الخوارزم: ثانيا ثانيا كتابةرقمين 1. x yندخلالعددين 2. مجموع z=x+yنحسبالجمع 3. ناتج نطبعالنهاية4.

Page 9: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

h البدايةstart

Input x ,yx , y ادخل

z اطبعOutput z

z=x+y احسب process

النهايةend

Page 10: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

وتنفيذه : • البرنامج كتابةالبرمجه • لغات احدى بواسطة البرنامج كتابةاالله .• لغة الى البرنامج ترجمةاالخطاء .• واصالح البرنامج اختبار

Page 11: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

What is a flowchart?

• Diagram that visually represents the steps that the program performs to arrive at a solution.

• A popular logic tool used for showing an algorithm in graphical form.

• Programmer draws flowchart before coding.

Page 12: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

13

Most common flowchart symbols are:

–Flowline–Terminal–Input/Output–Processing–Decision

Page 13: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Purpose of Flowcharting:

• An aid in developing the logic of a program.• Verification that all possible conditions have

been considered in a program.• Provides means of communication with others

about the program.• A guide in coding the program.• Documentation for the program.

Page 14: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

2.5The if Selection Structure

true

false

grade >= 60 print “Passed”

Page 15: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1
Page 16: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

17

Example of Flowchart:Start

Initialize counterand sum to 0

Are there more data?

Get next grade

Increment counter

Add grade to sum

Yes

No

Average=sum/counter

Finish

Page 17: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Exercise

Write a program to process a collection of daily temperatures. Your program should count and print the number of hot days (85 or higher), the number of pleasant days (60 - 84), the number of cold days (less than 60). It should also display the category of each temperature.

18

Page 18: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Exercise

1. Specify the problem requirements

2. Analyze the problem

Input: Output:

temperature

A program is required to process daily temperatures and provide the total number of hot, pleasant, and cold days.

total number of days in each category

3. Design the algorithm to solve the problem

1. Get the temperature.

2. Determine category of that temperature and increment counter for that particular category.

3. Display categories and total number of days that fell under the category.

19

Page 19: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

>=85?

Print Hot, Cold, and Pleasant

End

Add 1 to HotYes

Add 1 to ColdYes

<=60?

No

Add 1 to Pleasant

No

Get Temp

Exercise Start

20

Page 20: King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1

Exercise

write a program that reads the number of a hours an employee works and calculate an overtime pay for employees who work more than 40 hours and then display the paycheck.

write a program that reads the name and grade of a student, and displays a note that shows wither the student passed or failed.

write a program that reads the whether temperature In F° and then display it in C°.

write a program that reads three numbers, then displays the sum, the average, and the largest of these numbers.

21