งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

204111: Introduction to Computer & Programming

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "204111: Introduction to Computer & Programming"— ใบสำเนางานนำเสนอ:

1 204111: Introduction to Computer & Programming
April 4, 2017 204111: Introduction to Computer & Programming Lecture 1: Introduction Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand Kitsana Waiyamai : Introduction to programming

2 Computer & Program Computers Program
April 4, 2017 Computer & Program Computers Devices for performing computations at high speeds with great accuracy A machine that can be programmed to manipulate symbols. Can quickly store and retrieve large amounts of data. Physical components are known as "hardware". Hardware components: CPU, Memory, Mouse, Keyboard, etc. Program A set of instructions for a computer to follow, written in specific programming language Kitsana Waiyamai : Introduction to programming

3 Computer Components CPU (Central Processing Unit)
Primary storage (memory) Secondary storage (disks, tapes etc.) Input devices (mouse, keyboard etc.) Output devices (screen, printer, plotter, etc.)

4 Computer Components HD CPU Output Devices Input Devices
Secondary Memory CPU Main Memory Input Devices HD

5 Computer Systems Hardware (HW)
April 4, 2017 Computer Systems Hardware (HW) Actual physical machines (equipment) that make up the computer Software (SW) Programs written for a specific application are often called softwares. Kitsana Waiyamai : Introduction to programming

6 Computer Languages Computer languages categories: Machine language
April 4, 2017 Computer Languages Computer languages categories: Machine language Binary Code Assembly language High-Level Language Uses English-like language Machine independent Portable Examples: Pascal, C, C++, Java, Fortran, . . . Computer can execute only the machine language Kitsana Waiyamai : Introduction to programming

7 High-Level Languages Procedural Language Object-Oriented Language
Fortran Cobol Basic C Pascal Object-Oriented Language C++ Functional Language Lisp Logic Language Prolog

8 The translation Process
Compiler Executable Program Source Program

9 รู้จักกับคอมพิวเตอร์
คอมพิวเตอร์ (Computer) คือ เครื่องคำนวณอิเล็กทรอนิกส์ที่สามารถทำงานคำนวณผลและเปรียบเทียบค่าตามชุดคำสั่งด้วยความเร็วสูงอย่างต่อเนื่องและอัตโนมัติ การที่เครื่องคอมพิวเตอร์จะทำงานได้ จำเป็นจะต้องมีชุดคำสั่งกำกับ เพื่อให้คอมพิวเตอร์ทำงานได้ผลตามที่ต้องการ

10 คอมพิวเตอร์ในงานด้านต่างๆ
การจัดการงานทั่วไป การทำเอกสาร การนำเสนอผลงาน การสื่อสาร โทรศัพท์มือถือ โทรคมนาคม ความบันเทิง ดนตรี ภาพยนตร์ Graphic เกมส์ การคำนวณทางคณิตศาสตร์ เครื่องคิดเลข การคำนวณทางวิทยาศาสตร์ การจำลองสถานการณ์ (simulation) การแก้ไขปัญหาทางวิทยาศาสตร์ (scientific problem solving) การควบคุมธุรกรรม ATM การจัดการประมวลผลบัญชีลูกค้า

11 ส่วนประกอบของคอมพิวเตอร์
ระบบคอมพิวเตอร์ ประกอบด้วย 2 ส่วนหลัก ได้แก่ ฮาร์ดแวร์ Hardware : Microprocessor , Monitor, Hard disk , Keyboard , Mouse , Printer , etc ซอฟต์แวร์ Software : Window XP , Linux Microsoft word, Internet Explorer, Adobe Photoshop, Ragnarok Online

12 Computer Components HD CPU Output Devices Input Devices
Secondary Memory CPU Main Memory Input Devices HD

13 Microprocessor เป็นเหมือนส่วนสมองหลักของเครื่องคอมพิวเตอร์
ทำหน้าที่ประมวลผลทางคณิตศาสตร์ (บวก ลบ คูณ หาร) และทางตรรกศาสตร์ ( and or not) Intel / AMD

14 Memory เป็นที่เก็บข้อมูลในเครื่องคอมพิวเตอร์ ก่อนที่จะนำข้อมูลนั้นมาประมวลผลใน microprocessor หน่วยความจำในเครื่องคอมพิวเตอร์แบ่งออกเป็น 2 ประเภท หน่วยความจำหลัก (Main Memory) หน่วยความจำสำรอง (Secondary Memory)

15 หน่วยความจำหลัก เก็บชุดคำสั่งและข้อมูลต่างๆ
ไมโครโปรเซสเซอร์จะอ่านข้อมูลจากหน่วยความจำชนิดนี้เป็นหลัก RAM (Random Access Memory) สามารถเขียนหรืออ่านข้อมูลได้ เก็บข้อมูลไม่ถาวร ข้อมูลจะสูญหายหากขาดไฟเลี้ยง ROM (Read Only Memory) อ่านข้อมูลได้อย่างเดียว เก็บข้อมูลได้ถาวร แม้ว่าจะไม่มีไฟเลี้ยง RAM

16 Secondary Memory ความจุสูงขึ้นกว่าหน่วยความจำหลัก
แต่ความเร็วในการถ่ายเทข้อมูลน้อยกว่า Hard disk Floppy disk Zip drive Thumb drive CD-ROM Thumb Drive

17 Data Representation ข้อมูลในคอมพิวเตอร์จะถูกเก็บอยู่ในรูปของ bit
bit = binary digit (เลขฐานสอง) มีค่าเป็น 0 หรือ 1 (ตามสถานะของไฟฟ้า) byte = 8 bits ข้อมูล 1 byte ในเครื่องคอมพิวเตอร์อาจจะมีความหมายแทนข้อมูลได้หลากหลายประเภท ตัวอย่างเช่น ข้อมูล 1 byte เก็บค่าดังนี้ ข้อมูลดังกล่าวอาจจะแทนอักขระ ‘a’ หรือแทนตัวเลข 97 ก็ได้ ขึ้นอยู่กับโปรแกรมคอมพิวเตอร์ ว่าจะตีค่า 1 byte นั้นเป็นอะไร

18 I/O Devices เป็นอุปกรณ์ที่ทำหน้าที่ติดต่อสื่อสารระหว่างคอมพิวเตอร์กับโลกภายนอก Keyboard Mouse Monitor Printer Speaker

19 Computer Components HD CPU Output Devices Input Devices
Secondary Memory CPU Main Memory Input Devices HD

20 การทำงานของเครื่องคอมพิวเตอร์
ชุดคำสั่งและข้อมูลจะถูกเก็บอยู่ในหน่วยความจำ CPU (microprocessor)ดึงข้อมูลและชุดคำสั่งมาจาก หน่วยความจำ อุปกรณ์อินพุต (Keyboard , Mouse , etc.) CPU ประมวลผลข้อมูล CPU นำข้อมูลผลลัพธ์ที่ถูกประมวลผลแล้วไปยัง อุปกรณ์เอาท์พุต (Monitor , Printer , etc.)

21 โปรแกรมคอมพิวเตอร์ เราไม่สามารถทำงานต่างๆได้ โดยอาศัยเพียงแต่เครื่องคอมพิวเตอร์อย่างเดียว เครื่องคอมพิวเตอร์สามารถทำงานได้รวดเร็ว แต่ไม่สามารถที่จะตัดสินใจหรือแก้ปัญหาใดๆได้ด้วยลำพัง มนุษย์จะต้องเป็นผู้กำหนดและสั่งการคอมพิวเตอร์ให้ทำงานให้ได้อย่างที่มนุษย์ต้องการ โปรแกรมคอมพิวเตอร์ หมายถึง ชุดลำดับของคำสั่งที่กำหนดให้คอมพิวเตอร์ทำการประมวลผลข้อมูลเพื่อให้แก้ปัญหา และทำงานได้อย่างที่ต้องการ Programming = Designing and writing a computer program.

22 ชนิดของภาษาในการเขียนโปรแกรม
There are 3 kind of programming languages Machine language (0’s and 1’s) Assembly language (mov, and, or, etc…) High-level language (nearly like human word) Computer itself understands only Machine language.

23 The translation Process
Compiler /Interpreter Executable Program Source Program

24 Language translator Hello World! _ …… Machine language
Interpreter / Compiler …… main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp movl $0, %eax subl %eax, %esp pushl $.LC0 …….. …. …… Assembler class MainClass { public static void Main(string[] args) Console.WriteLine("Hello World!"); } Machine Machine language High-level language Assembly language Hello World! _

25 Interpreter Read high-level language , translate , and then execute one command at a time. Inter- preter a b c …. writeln(‘a’); writeln(‘b’); writeln(‘c’); Source

26 Compiler Read all program at a time.
Translate into executable file (machine language) library Compiler Linker …. writeln(‘a’); writeln(‘b’); writeln(‘c’); object file Source a b c …. ..... Exe file

27 ขั้นตอนในการเขียนโปรแกรม
วิเคราะห์ปัญหา (Analysis) ระบุปัญหาที่ต้องการจะแก้ไข แบ่งปัญหานั้นออกเป็นปัญหาย่อยๆ ค้นหาแนวคิดและวิธีการที่จะแก้ปัญหานั้นๆ พัฒนาโปรแกรม (Implementation) เขียนโปรแกรมด้วยภาษาคอมพิวเตอร์ โดยอาศัยแนวคิดการแก้ปัญหาที่คิดไว้ก่อนหน้า Compile โปรแกรมที่เขียนขึ้นให้เป็นภาษาที่เครื่องอ่านได้ ตรวจสอบและแก้ไขจุดผิดพลาด (Testing & Debugging) ทดลองรันโปรแกรมและตรวจสอบการทำงาน หากโปรแกรมทำงานไม่ถูกต้อง หาจุดผิดให้พบ แก้ไขจุดผิดพลาดและทดลองใหม่ จนกว่าโปรแกรมจะทำงานได้ถูกต้อง

28 Analysis Example : Circle area problem Input Process Output
circle radius (รัศมี) Process calculate circle area Output Circle area

29 Analysis Pseudo-code (รหัสเทียม) Example
ใช้คำที่มีความหมาย คนอ่านแล้วเข้าใจ ขั้นตอนการทำงานเป็นแบบคอมพิวเตอร์ Example Program Circle Begin read circle radius area = Pi * radius * radius write circle area End.

30 Test & Debug Compile โปรแกรมที่เขียนขึ้นแล้วทดลองรัน ตรวจสอบผลการทำงาน
แก้ไขข้อผิดพลาด (bugs)

31 Implement เขียนโปรแกรมโดยใช้ภาษา Assembly หรือภาษาระดับสูง
เราสามารถใช้แนวคิดเดียวกัน เขียนโปรแกรมได้หลายภาษา Example class MainClass { public static void Main(string[] args) const double pi = ; int radius; double area; radius = int.Parse(Console.ReadLine()); area = pi*radius*radius; Console.WriteLine(area); } #define PI f void main() { int radius; float area; scanf(“%d”,&radius); area = PI * radius * radius; printf(“%f”,area); }

32 Test & Debug There are 2 kinds of bugs Syntax bug Semantic bug
class MainClass { public static void Main(string[] args) const double pi = ; int radius; double area; radius = int.Parse(Console.ReadLine()); area = pi * raddius * radius; Console.WriteLine(area); } class MainClass { public static void Main(string[] args) const double pi = ; int radius; double area; radius = int.Parse(Console.ReadLine()); area = pi * radius; Console.WriteLine(area); } Syntax bug Semantic bug

33 Programming Languages
The computer really only knows its own machine language or assembly language. Any high level languages would have be translated into machine language. An assembler translates an assembly language program into machine language. A compiler translates a high-level language into machine language. A source program is written in a high-level programming language. (.cs, .pas, .c) An executable program is the machine language version of a source program. (.exe)

34 Why C# ? provides a teaching language that highlights concepts common to all computer languages

35 C# Program สุนัข class C# is an object-oriented programming language.
Everything must be in some class. A program is a set of class declarations. โฮ่ง แดง ด่าง ขาว สุนัข class

36 A simple C# Program

37 Output

38 C# Program: What did you see?
Grouping using { } Statement ending with ; Various keywords: using, namespace, class, public, static, void "Hello World!"

39 C# Program: class declaration
class MainClass { public static void Main(string[] args) const double pi = ; int radius; double area; radius = int.Parse(Console.ReadLine()); area = pi*radius*radius; Console.WriteLine(area); } Class name Member declarations Data member Method (or functions) In the beginning of the class, we usually use only one method: Main --- which is where our program starts.

40 Basic grouping { } { curly brackets are used to group things together in C# } { they come in pairs, and { they can { be nested } } } Example:

41 Semi-colon; In C#, every statement must end in a semicolon.
Compiler uses semicolon to find where one statement ends. It does not use line breaks or any textual markers. For example, the following are the same programs (for the compiler): using System; namespace Hello { class MainClass { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } using System; namespace Hello{ class MainClass {public static void Main(string[] args) { Console.WriteLine( "Hello World!");}}}

42 Various keywords Various keywords help the C# compiler to understand our programs abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void volatile while

43 Keywords namespace - Programs are organized using “namespace.”
using - specifies external namespaces that the program uses. class - defines class. (remember that our program is one of the classes.)

44 Keywords Other keywords we are using:
void, public, static, etc. At this point, it is difficult to understand them fully. You just have to remember the patterns that we use them.

45 /* comments */ Comments are inserted into C# program by enclosing it within /* and */ , or after // Comments are ignored by the computer, but helpful to explain the program using System; class MyClass { // This is an example class, // and this is a line comment… static void Main() { /* Sometimes, we love to comment things, and anything inside thes markers are comments */ Console.WriteLine("Hello!"); // chill~ chill~~ }

46 Method Main is a method where the program for our class starts.

47 Main declaration Here is how we declare our Main function (inside our class): static void Main() { // โปรแกรมของเราจะอยู่ต่อจากนี้ … } Remark: there are 4 ways to define Main function. We use the simplest one. static void Main() {...} static void Main(string[] args) {...} static int Main() {...} static int Main(string[] args) {...}

48 Inside method Main Variable declarations Statements
public static void Main(string[] args) { const double pi = ; int radius; double area; radius = int.Parse(Console.ReadLine()); area = pi*radius*radius; Console.WriteLine(area); }

49 Variables Example: Variables are used to store “data.”
They must be declared before used. To declare them, we must specify their “types.” int radius; double area;

50 Data DATA - information that must be supplied to a program before it can produce results. Basic data types: int whole numbers double numbers with fractions bool true or false char Computer character set string - strings

51 Data Data has to be stored and referenced.
Easiest way to refer to data is to give it a symbolic name or identifier Data in a program can be classified as Constant data and Variable data.

52 Variables Variable is a container for a data value. A variable is created via a declaration where both its name and type are specified Every variable has a name, type and value.

53 Variable declaration Syntax: Examples:
<type> <name>; Examples: We can also assign its initial value. E.g., int radius; double area; int a,b,c; bool isokay; int k = 200; bool done = false;

54 Assignments Syntax: Examples: <variable> = <value>;
area = radius*radius*3.14; a = b + c + d;

55 Constants Constants can be used in programs. E.g., 5, 10.4, "Hello" are constants. There are also named constants, which are declared in the same way as variables, but with additional const keyword. Examples: const double pi = ; const string message = "Hello";

56 Statements Examples: The first two are assignments.
The third one writes the value of “area” to the screen. radius = int.Parse( Console.ReadLine() ); area = pi*radius*radius; Console.WriteLine(area);

57 Methods (again) We use various methods from various classes.
Console and int are standard classes. Console.WriteLine int.Parse Console.ReadLine

58 Example using System; namespace Hello { class MainClass
static void Main(string[] args) double price, money; int n; double leftover; Console.Write("Enter candy price: "); price = double.Parse(Console.ReadLine()); Console.Write("Enter number of candies: "); n = int.Parse(Console.ReadLine()); Console.Write("Enter your money :"); money = double.Parse(Console.ReadLine()); leftover = money - price * n; Console.WriteLine("You have {0} bahts left.", leftover); }

59 WriteLine Output formatting
Console.WriteLine("You have {0} bahts left.", leftover);

60 Identifiers Symbolic names for program elements
Program name Variable name Data Type name Etc. Rules for constructing identifiers Letters, digits, and under score (_) First character letter Can be long (63 char) Reserved words (keywords) are not allowed

61 Identifier examples Valid examples Invalid examples
score, count, total score1, count99, total09 score_1, count_99, total_99 myStudentId my_student_id Invalid examples point&score total-number 9points

62 Notes for Identifiers Identifiers are case-sensitive mystudentId


ดาวน์โหลด ppt 204111: Introduction to Computer & Programming

งานนำเสนอที่คล้ายกัน


Ads by Google