פרטים נוספים בסילבוס של הקורס

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Variables in C Amir Haider Lecturer.
C Programming Course Overview
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
C Language Brief history In 1972, Dennis Ritchie designed C and it was used on PDP-11 mini- computers In 1974, Unix was rewritten in C C++ and C Advantages.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Variables and constants Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
C Programming Lecture 4 : Variables , Data Types
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
C Programming Laboratory I. Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return.
CSCI 130 Chapter 3. Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Data types Data types Basic types
C Programming Course Overview
LESSON 3 IO, Variables and Operators
C Short Overview Lembit Jürimägi.
Introduction to C Programming Language
مبانی کامپیوتر و برنامه سازی
CMSC 104, Section 4 Richard Chang
Introduction to C Programming
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Introduction to CS Your First C Programs
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Introduction to C Programming
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
UMBC CMSC 104 – Section 01, Fall 2016
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Variables in C Declaring , Naming, and Using Variables.
C programming Language
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Module 2 Variables, Data Types and Arithmetic
Building Blocks of C Programming Language
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
INTRODUCTION TO C.
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

פרטים נוספים בסילבוס של הקורס מבוא לתכנות ב-C מרצה : עמי ברלר כתובת: ami@cs.bgu.ac.il בחינה 70% - עבודות 30% 5-6 עבודות במשך הקורס חובה: להגיש כל העבודות לפחות 56 בבחינה פרטים נוספים בסילבוס של הקורס חובה להסתכל על הודעות נא לא להעתיק !! Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

מבנה מערכת מחשב CPU Internal Memory Output Input Mouse Keyboard Microphone Detectors Monitor Speakers Motors Hard Disk CD / DVD Tape DiskOnKey External Memory Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

מבנה הזיכרון הפנימי ROM – Read Only Memory Random Access Memory-RAM נמחק עם כיבוי המחשב מחובר קרוב למעבד תוכן הניתן לשינוי מהיר מאחסן את תוכנית המחשב והמידע הנחוץ לעבודה הרגעית של המעבד מבצע קשר עם המעבד בקצב של מיליוני פעמים בשנייה.  ROM – Read Only Memory לא נמחק עם כיבוי המחשב כולל תכניות ונתונים שהם הכרחיים להפעלת המחשב לא ניתן לשינוי אלא ע"י תוכניות מיוחדות Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

יחדה זיכרון - BYTE BYTE היא היחידה של מידע דיגיטלי היא כוללת 8 BITS binary digit)) עם ערכים 0 – 1 Byte יכול לייצג 256 ( 28 ) ערכים שונים : 0 – 255 ASCII (American Standard Code for Information Interchange) Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

אלגורתים הגדרה לא פורמלית - אלגוריתם הוא דרך שיטתית (כלומר כזו שצעדיה מוגדרים היטב) לביצועה של משימה מסוימת במספר סופי של צעדים. מקור המלה בשמו של המתמטיקאי הפרסי בן המאה התשיעית, אבו ג'עפר מוחמד אל חואריזמי. תהליך חישובי (סדרה של הוראות, מוגדר היטב )ההוראות מובנות וניתנות לביצוע(, שמקבל כקלט ערך או קבוצת ערכים, ונותן כפלט ערך או קבוצה של ערכים כ-"פונקציה" של הקלט. דוגמאות : להכין עוגה, לדבר בטלפון, להזמין פיצה וכו' Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תהליך לפתרון בעית תכנות להבין את הגדרת הבעיה להכליל ולפרק את הגדרת הבעיה לפתח אלגורים לפתרון הבעיה לכתוב את הקוד המתאים לבדוק ולשנות בהתאם Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

אלגוריתם סידרת פעולות מוגדרת (דטרמיניסטית) לביצוע המובילה לפתרון הבעיה תכונות לאלגוריתם על-פי :Knuth סופיות (עצירה) מוגדרות (כל פעולה צריכה להיות מובנת למבצע באופן חד משמעי) קלט (אפס או יותר) פלט (לפחות אחד) אפקטיביות. אלגוריתם טוב נקבע לפי הקריטריונים הבאים: נכונות: נבדק ע"י עצירה ופלט רצוי יעילות: לפי זמן הריצה של האלגוריתם ו/או כמות זיכרון שנדרשה. Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תרשים זרימה – הוראות המוגדרים כבלוקים הסתעפות קלט/פלט התחלה סיום פעולה לביצוע הערות: פעולה לביצוע הינה פעולה שחייבת להיות ברת ביצוע במחשב. במידה ופעולה זו לא ניתנת לביצוע בפעולה אחת, ניתן לשרטט תרשים זרימה נפרד המתאר כיצד מבוצעת הפעולה. קלט או פלט יכול להיות מקלדת מסך או קובץ. כל הבלוקים למעט התחלה וסיום יכולים להופיע מספר בלתי מוגבל של פעמים. בלוק התחלה וסיום חייבים להופיע בדיוק פעם אחת בלבד. בלוק ההסתעפות חייב להכיל שאלה שהתשובה עליה היא אמת (כן) או שקר (לא) (אין אולי). Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

דוגמא לבעיה: GCD Greatest Common Divisor תאור הבעיה: מציאת מחלק המשותף המכסימלי של שני מספרים שלמים חיוביים. דוגמאות: 48: {1, 2, 3, 4, 6, 8, 12, 16, 24} 18: {1, 2, 3, 6, 9} 49: {1, 7} למספרים 48 ו-18 יש מחלק מכסימלי משותף 6. למספרים 49 ו-18 אין מחלק משותף מלבד 1. פורמלית: קלט: שני מספרים שלמים, חיוביים פלט: GCD(m,n) Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

איך מוצאים GCD? פתרון נאיבי קלט: m, n I=min(m,n) אם I מחלק את m ואת n החזר את I ועבור ל-6 I  I-1 חזור ל - 3 עצור הנחות קלט: m, n שלמים חיוביים הנחת פלט: א. האלגוריתם יעצור (למה?) ב. בעצירה, I מחזיק את המחלק משותף מכסימלי -> נכונות קודם לתאר את הרעיון במילים התאור הוא סופי קלט m,n חיוביים שלמים אין התיחסות לערכים ספציפיים של m,n (עובד לכל הערכים האפשריים) האם זה עוצר? מדוע? כן – כי יש מחלק משותף ולא נפספס אותו (דיון) האם זה נכון? מדוע? כן – כי שנעצור I מחלק משותף ואין אחר גדול ממנו (דיון) אפשר להחליף את 2 ב: I = min(m,n) Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

הצגת האלגוריתם כתרשים זרימה Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

מציאת מינימום של שני מספרים Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

GCD על פי אוקילידס קלט: m,n r  m % n אם r=0 החזיר n וסיים. m  n חזור ל- 2 להסביר % דוגמת הרצה N M 30 48 18 30 12 18 6 12 ואם נחליף את m,n? בדיקת 5 התכונות נראה כי אלגוריתם זה יצטרך לבצע פחות "סיבובים" לפני שימצא את התשובה מאשר האלגוריתם הנאיבי Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

הצצה לתכנית מחשב בשפה C #include <stdio.h> void main(){ int a,b,r; scanf("%d%d",&a,&b); r = b; while(r != 0){ r= a%b; if(r == 0) printf("---%d\n",b); a = b; b = r; }; } Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

אבני יסוד של תכנית ? ? יום רביעי 05 דצמבר 2018 Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תהליך לפתרון בעית תכנות להבין את הגדרת הבעיה להכליל ולפרק את הגדרת הבעיה לפתח אלגורים לפתרון הבעיה לכתוב את הקוד המתאים לבדוק ולשנות בהתאם Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

אבני יסוד של תכנית ? ? יום רביעי 05 דצמבר 2018 Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תהליך כתיבת תוכנית כאשר רוצים לכתוב תכנית בשפה עילית כלשהי שתבצע אלגוריתם עובדים לפי סדר העבודה הבא:  הקלדת התכנית בeditor יצירת Source Code File קובץ מקור (סיומת C) קומפילציה – בדיקת קובץ המקור ויצירת Object Code File קישור תהליך שילוב הקובץ בשפת מכונה עם כל הקבצים הנוספים הדרושים לתכנית כגון ספריות וכיוב. יצירת קובץ הרצה עם סיום Exe/ הרצת התכנית Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תהליך כתיבת תוכנית Editor Algorithm File.c Linker Object input שגיאות קומפילציה Compiler Object Linker Executable input output Run time errors Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

למה ללמוד C C זו שפה יחסית קטנה וכך קלה לתכנות. Unix נכתב בשפת C C מאפשרת למתכנת גישה לתוך הקרביים של המחשב (רמת ה bit). C זו שפה מודולארית וכך היא קלה להבנה וחסכונית C מהווה את הבסיס לשפת ++C Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תכנית ראשונה ב- C /* HelloWorld – An example program */ #include <stdio.h> // Here place // for future // study void main(void) { printf(“Hello, world!\n”); } Comments are good Preprocessor directive Includes C standard library main() means “start here” Brackets define code blocks Note that all C statements end with a semicolon (;). Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

דוגמא מבנה תכנית main () { . } יום רביעי 05 דצמבר 2018 Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

void main() מגדיר פונקציה מיוחדת main. נותן הוראה לקומפיילר איפה מתחילה הרצת התכנית. כל תכנית בשפת C כוללת פנקציה main. Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

printf() היא פונקציה הקיימת בתוך השפה C הפונקציה מדפיסה את הטקסט שקיים בתוך הסוגריים בצורה מיוחדת שנראה בהמשך. Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

#include <stdio.h> הקובץ מכיל מידע לגבי הפונקציות printf , scanf ואחרות שנראה בהמשך הקורס. Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

מזהים (Identifiers) יום רביעי 05 דצמבר 2018 Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

חוקים להגדרת מזהים ב-C המזהה מורכב מרצף של אותיות, ספרות והתו '_' ( underscore ) i CSE_8a a_very_long_name_that_isnt_very_useful fahrenheit רצף זה אינו יכול להתחיל בספרה. 8a_CSE is not valid! 2. אורך המזהה אינו מוגבל. לפחות 31 התווים הראשונים נחשבים עבור הקומפיילר של שפת C. 3. בשפת C קיימות מילים שמורות ( keywords ) כגון : if , else , int . אין לתת למזהים שמות מקבוצה זו . 4. בשפת C קיימת הבחנה בין אותיות קטנות לגדולות ולכן המזהים : SIZE , Size , SiZe ... הינם שונים אחד מהשני . Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

שמות ע"י מזהים משתנים - Variables מילות שמורו - Reserved Words פונקציות - Functions קבועים - Constants מבנים - Structures סוגי משתנים - Type of variables Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

מילות שמורות auto do goto signed unsigned break double if sizeof void case else int static volatile char enum long struct while const extern register switch continue float return typedef default for short union Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

משתנים (Variables) יום רביעי 05 דצמבר 2018 Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

משתנים ב-C משתנה הוא מקום בזיכרון. גודל המקום תלוי בסוג המשתנה. לפני השימוש של משתנה צריך להצהיר עליו. ההצהרה על משתנה כוללת קודם את סוג המשתנה ואחרי זה את שם המשתנה לפי חוקי המזהים ב-C. ניתן להצהיר על כמה משתנים באותו סוג ביחד כאשר מפרידים בינהם ע"י פסיק ( , ). Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

דוגמאות של הצהרה על משתנים int i; char c; float f1, f2; unsigned int ui ; double t1,t2,t3; Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

סוגי משתנים ב-C char – a single byte character ‘A’. short int (or just short) – an integer number, usually 2 bytes (rarely used) 15 . int - an integer number – usually 4 bytes 12345. long int (or just long) – an integer number, 4 or 8 bytes (rarely used) 123456. float – a single precision real number – usually 4 bytes 0.0012. double – a double precision real number – usually 8 bytes 0.00000012. long double - a double precision real number – usually 8 bytes (rarely used) 0.00000000012. Signed vs. unsigned Department of Computer Science-BGU יום רביעי 05 דצמבר 2018

תחום סוגי משתנים טיפוס מספר בתים תחום המספרים unsigned char 1 0 – 255 short 2 +32767 -32768 unsign short 65535+ 0 long, int 4 +2147483647 -2147483648 unsigned long,unsigned int 4294967295+ 0 float (7 ספרות דיוק) 3.4e+38 3.4e-38 double (15 ספרות דיוק) 8 1.7e+308 -1.7e+308 long double (19 ספרות דיוק) 10 8 3.4e+4932 - 3.4e4932 Department of Computer Science-BGU יום רביעי 05 דצמבר 2018