1 / 35

הוראת פעולות במציאות החדשה

הוראת פעולות במציאות החדשה. מגיש: בונימוביץ' לביא. מעבר בין תכנות פרוצדורלית לתמ"ע. הבעיה הגדולה היא:. גישה שונה לתכנות. גישה פרוצדורלית. לזהות נתונים ופעולות. להגדיר מבני נתונים ופעולות. לממש פעולות. בעזרת הפעולות לממש את התרגיל. גישה מונחית עצמים. לזהות עצמים. להגדיר התנהגות עצמים.

gay
Download Presentation

הוראת פעולות במציאות החדשה

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. הוראת פעולות במציאות החדשה מגיש: בונימוביץ' לביא

  2. מעבר בין תכנות פרוצדורלית לתמ"ע הבעיה הגדולה היא: גישה שונה לתכנות

  3. גישה פרוצדורלית • לזהות נתונים ופעולות • להגדיר מבני נתונים ופעולות • לממש פעולות • בעזרת הפעולות לממש את התרגיל

  4. גישה מונחית עצמים • לזהות עצמים • להגדיר התנהגות עצמים • להגדיר תכונות ולממש פעולות • בעזרת המחלקות שנבנו לממש את הפתרון

  5. תכנית הלימודים "פרק 6: טיפוסים ומבוא למבני-נתונים (10 שעות) מטרות הפרק • להכיר את המושג 'טיפוס נתונים' • להכיר את מושג המחלקה הבסיסי • לבנות מבנים מורכבים פירוט התכנים המושג טיפוס: הצהרת טיפוס, המחלקה כמגדירה טיפוס. מבני נתונים מורכבים: מערכים, מחלקות בעלות תכונות פומביות בלבד, הגדרת מחלקה, תכונות של מחלקה, גישה ישירה לתכונה של מחלקה, קליטת ערך לתכונה..."

  6. כיצד לשרוד? כיצד לעבור בחינת בגרות כיצד לא לקלקל את הקונצפט של תמ"ע

  7. דוגמא לפתרון בשתי גישות תרגיל 10, תשס"ג לקראת תחרות ארצית במדעי המחשב, נערכה בחינת מיון ל- 1750 תלמידים.לתחרות הארצית יתקבלו תלמידים שציוניהם בבחינת המיון גבוה מהציון הממוצע של כל הנבחנים בבחינה זו. פתח אלגוריתם שיקלוט לכל מועמד רשומה הכוללת את הנתונים האלה: שם, כתובת, מספר תעודת זהות, שפת התכנות המועדפת עליו (פסקל או C) וציון בבחינת המיון. האלגוריתם יציג כפלט שתי רשימות המכילות את שמות התלמידים שיתקבלו לתחרות הארצית, כתובותיהם ומספרי תעודות הזהות שלהם. הרשימה הראשונה תכלול את פרטי התלמידים ששפת התכנות שלהם היא פסקל, והרשימה השנייה תכלול את פרטי התלמידים ששפת התכנות שלהם היא C.

  8. פתרון תמ"ע, מחלקה Student (פתרון של ראמי גבאלי) classStudent { privatestring name; privatestring address; privateint id; privateint grade; privatestring proglang; public Student(string name, string address, int grade, string proglang, int id) { this.name = name; this.address = address; this.grade = grade; this.proglang = proglang; this.id = id; } publicstring GetName(){returnthis.name;} publicstring GetAddress(){returnthis.address;} publicint GetGrade(){returnthis.grade;} publicint GetID(){returnthis.id;} publicstring GetProgLang(){returnthis.proglang;}

  9. פתרון תמ"ע, מחלקה Student (פתרון של ראמי גבאלי) publicvoid SetAddress(string address) { this.address = address; } publicvoid SetGrade(int grade) { this.grade = grade; } publicvoid SetProgLang(string proglang) { this.proglang = proglang; } publicvoid Print() { Console.WriteLine("Name : {0}", this.name); Console.WriteLine("Address : {0}", this.address); Console.WriteLine("Id :{0} ", this.id); Console.WriteLine("-------------------------------"); } }

  10. פתרון תמ"ע, מחלקה Contest(פתרון של ראמי גבאלי) classContest { privateStudent[] arr; privateint counter; publicContest () { arr = newStudent[1750]; counter = 0; } publicvoid AddStudent(string name, string address, int grade, string proglang, int id) { arr[counter++] = newStudent(name, address, grade, proglang, id); } publicvoid AddStudent(Student s) { arr[counter++] = newStudent(s.GetName(), s.GetAddress(), s.GetGrade(), s.GetProgLang(), s.GetID()); }

  11. פתרון תמ"ע, מחלקה Contest(פתרון של ראמי גבאלי) publicdouble GetAverage() { int sum = 0; double avg; for (int i = 0; i < this.counter; i++) sum += arr[i].GetGrade(); avg = (double)sum / this.counter; return avg; } publicvoid print(double avg, string proglang) { for (int i = 0; i < this.counter; i++) if (this.arr[i].GetGrade() > avg && this.arr[i].GetProgLang() == proglang) this.arr[i].print(); } }

  12. פתרון תמ"ע, מחלקה Program (פתרון של ראמי גבאלי) classProgram { staticvoid Main(string[] args) { Contest all = newContest (); for (int i = 0; i < 1750; i++) { Console.WriteLine("Enter Name"); string name = Console.ReadLine(); Console.WriteLine("Enter Address"); string address = Console.ReadLine(); Console.WriteLine("Enter Grade"); int grade = int.Parse(Console.ReadLine()); Console.WriteLine("Enter C or Pascal"); string proglang = Console.ReadLine(); Console.WriteLine("Enter Id"); int id = int.Parse(Console.ReadLine()); all.AddStudent(name, address, grade, proglang, id); } double avg = all.GetAverage(); all.Print(avg, ”C"); all.Print(avg, ”Pascal"); } }

  13. יתרונות/חסרונות של פתרון תמ"ע חסרונות • דורש זמן רב (הרבה קוד) • זיהוי עצמים (OOD) מהווה משימה קשה מדי יתרונות • מלמד גישה תמ"ע נכונה: חלוקה למחלקות, כימוס

  14. פתרון פרוצדורלי (פתרון של ראמי גבאלי) class Student { public string name; public string address; public int id; public string proglang; public int grade; } class Program { static void InputData(Student[] arr) //קליטת פרטי תלמידים למערך { for (int i = 0; i < arr.Length; i++) { arr[i]=new Student(); Console.WriteLine("Enter Name, Address, Id num ,Language,Grade from Student "); arr[i].name = Console.ReadLine(); arr[i].address = Console.ReadLine(); arr[i].id = int.Parse(Console.ReadLine()); arr[i].proglang = Console.ReadLine(); arr[i].grade = int.Parse(Console.ReadLine()); } }

  15. פתרון פרוצדורלי (פתרון של ראמי גבאלי) static double Average(Student[] arr) //חישוב ממוצע הציונים { int sum = 0; double avg; for (int i = 0; i < arr.Length; i++) sum += arr[i].grade; avg = (double)sum / arr.Length; return avg; } static void Print(Student[] arr, double avg, string language) הדפסת שתי הרשימות // { for(int i=0; i<arr.Length; i++) if (arr[i].grade > avg && arr[i].proglang == language) { Console.WriteLine("Name : {0}", arr[i].name); Console.WriteLine("Address: {0}", arr[i].address); Console.WriteLine("Id Num : {0}", arr[i].id); Console.WriteLine("---------------------------------"); } }

  16. פתרון פרוצדורלי (פתרון של ראמי גבאלי) static void Main(string[] args) { Student[] arr = new Student [1750]; double avg; InputData(arr); avg = Average(arr); Print(arr, avg, "Pascal"); Print(arr, avg, "C"); } }

  17. יתרונות/חסרונות של פתרון פרוצדורלי חסרונות • כל התכונות public (סותר עקרון כימוס) • הפעולות הן סטטיות ואינן קשורות לעצמים יתרונות • פתרון מצומצם • מוכר למורים מבחינת תהליך ההוראה

  18. האם יש דרך ביניים ? בהמשך...

  19. סוגי בעיות במבחן בגרות • מעקב, מציאת טעויות • כתיבת תכניות קטנות (1-5) • התכניות ללא סיפור מעשה: דורשות לבצע משהו על מערך, לכתוב פעולה המוגדרת מראש, אינן דורשות עיבוד נתונים רב שלבי • דורשות בניית מבנה נתונים • בעיות עם סיפור מעשה עשיר, רב עצמים

  20. השאלה הגדולה כיצד ללמד פתרון משימות בעייתיות במסגרת פרדיגמת תכנות מונחית עצמים?

  21. התחלת הוראת פעולות • הגישה המסורתית: מחלקה יחידה שמכילה פעולות סטטיות, הסיבה העיקרית לשימוש בפעולות היא הורדת רמת מורכבות האלגוריתם. • הגישה "עצמים תחילה": מתחילים ישר מעצמים, שומרים על עקרון הכימוס, הסיבה העיקרית לשימוש בעצמים היא שהעולם סביבנו מורכב מעצמים, אנו מעוניינים בפונקציות שעצמים נושאים.

  22. כיצד אני התחלתי class Program { static void Main(string[] args) { int i, n; Console.WriteLine("Enter number"); n = int.Parse(Console.ReadLine()); for (i = 1; i <= n; i++) { PrintStars(i); } } // prints the row of n stars static void PrintStars(int n) { int i; for (i = 1; i <= n; i++) Console.Write("*"); Console.WriteLine(); } }

  23. המשך הוראת פעולות, היעד הסופי הגישה "המסורתית" • הפעולות נשארות סטטיות • מלמדים את המחלקות בדומה לרשומה: כל התכונות הן public, ללא פעולות פנימיות, ללא שיטה בונה הגישה "עצמים תחילה" • מתקדמים בבניית מחלקות תוך שמירה על עקרון הכימוס • העיצוב הוא רק באמצעות המחלקות • ניתן להסביר את פעולות המחלקה, עבודה עם מספר מחלקות

  24. כיצד אני רואה את ההמשך • התחלתי בפעולות סטטיות • ממשיך בפעולות סטטיות בכל המשימות שלא דורשות שימוש ברשומה • להתחיל להסביר שימוש במחלקות: או במחרוזת, או Random • בסיום הקורס להתחיל להסביר בניית מחלקות: תכונות פנימיות, פעולות פנימיות, פעולה בונה, get ו-set • המטרה היא להגיע לפתרון בעיות ברמה של 9-10 • לא בטוח שיש צורך להגיע להסבר פעולות מחלקה • הוראת שימוש במחלקת שרות

  25. תרגיל Taharut, פתרון "הגיוני", מחלקה Student class Student { private string name; private string address; private int id; private int grade; private string progLang;// "C" or "Pascal" public Student(string name, string address, int grade, string proglang, int id) { this.name = name; this.address = address; this.grade = grade; this.progLang = proglang; this.id = id; } public int GetGrade(){return this.grade;} public string GetProgLang(){return this.progLang;} public void print() { Console.WriteLine("Name : {0}", this.name); Console.WriteLine("Address : {0}", this.address); Console.WriteLine("Id :{0} ", this.id); } }

  26. תרגיל Taharut, פתרון "הגיוני", מחלקה Program class Program { static void Main(string[] args) { Student[] arr = new Student[1750]; double avg; InputData(arr); avg = Average(arr); Print(arr, avg, "Pascal"); Print(arr, avg, "C"); } static void InputData(Student[] arr) { for (int i = 0; i < arr.Length; i++) { Console.WriteLine("Enter Name, Address, Id num ,Language,Grade from Student "); string name = Console.ReadLine(); string address = Console.ReadLine(); int id = int.Parse(Console.ReadLine()); string lang = Console.ReadLine(); int grade = int.Parse(Console.ReadLine()); arr[i] = new Student(name, address, grade, lang, id); } }

  27. תרגיל Taharut, פתרון "הגיוני", מחלקה Program // returns the average grade static double Average(Student[] arr) { int sum = 0; double avg; for (int i = 0; i < arr.Length; i++) sum += arr[i].GetGrade(); avg = (double)sum / arr.Length; return avg; } // prints the student data static void Print(Student[] arr, double avg, string lang) { for(int i=0; i<arr.Length; i++) if (arr[i].GetGrade() > avg && arr[i].GetProgLang() == lang) arr[i].print(); } }

  28. הנחיות לפתרון תרגילי בגרות בגישה תמ"ע • לא חובה להגיע לעיצוב מונחה עצמים מושלם • יש לממש רק את הפעולות הנחוצות. אין צורך בהעמסת שיטה בונה, חשוב לבדוק אם יש צורך בשיטות get ו-set. • מותר להגדיר חלק מן הפעולות כסטטיות במחלקה "הראשית" • הדגש הוא על השימוש הנכון במחלקה שנבנתה בתכנית

  29. פתרון תרגיל Yarid, מחלקה Bazaar class Bazaar { private int numParticipant; private int numTicketsLottery; private int numTicketsFree; private int numTicketsShow; private int numTicketsBuffet; public Bazaar() { this.numParticipant = 0; this.numTicketsBuffet = 0; this.numTicketsLottery = 0; this.numTicketsFree = 0; this.numTicketsShow = 0; } public void UpdateTickets(int lottery, int buffet, int show) { this.numTicketsFree += lottery; this.numTicketsBuffet += buffet; this.numTicketsShow += show; if (lottery > 10) this.numTicketsFree++; }

  30. פתרון תרגיל Yarid, מחלקה Bazaar // increments the number of participants by 1 public void IncParticipant() { this.numParticipant++; } // prints the all bazaar statistics public void Print() { Console.WriteLine("Participants : {0}", this.numParticipant); Console.WriteLine("Lottery tickets: {0}", this.numTicketsLottery); Console.WriteLine("Free tickets : {0}", this.numTicketsFree); Console.WriteLine("Show tickets : {0}", this.numTicketsShow); Console.WriteLine("Buffet tickets : {0}", this.numTicketsBuffet); } }

  31. פתרון תרגיל Yarid, מחלקה Program class Program { static void Main(string[] args) { int lottary, show, buffet; Bazaar bazaar = new Bazaar(); Console.WriteLine("Enter the lottery tickets number"); lottary = int.Parse(Console.ReadLine()); while (lottary != -1) { Console.WriteLine("Enter the show tickets number"); show = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the buffet tickets number"); buffet = int.Parse(Console.ReadLine()); bazaar.IncParticipant(); bazaar.UpdateTickets(lottary, buffet, show); Console.WriteLine("Enter the lottery tickets number"); lottary = int.Parse(Console.ReadLine()); } bazaar.Print(); } }

  32. פתרון תרגיל Bakbukim, מחלקה Class public class Class { private int bottles; private int batteries; public Class() { this.batteries = 0; this.bottles = 0; } // adds the bottles to the total bootles amount public void AddBottles(int bottles) { this.bottles += bottles; } // adds the batteries to the total batteries amount public void AddBatteries(int batteries) { this.batteries += batteries; } // returns the total points amount public int TotalPoints() { return this.bottles * 3 + this.batteries * 7; } }

  33. פתרון תרגיל Bakbukim, מחלקה Program class Program { static void Main(string[] args) { int bottles, batteries, classNum; Class class1 = new Class(); Class class2 = new Class(); int points1, points2; for (int i = 1; i <= 3; i++) { Console.WriteLine("Enter the class number"); classNum = int.Parse(Console.ReadLine()); Console.WriteLine("Enter bottles number"); bottles = int.Parse(Console.ReadLine()); Console.WriteLine("Enter batteries number"); batteries = int.Parse(Console.ReadLine()); if (classNum == 1){ class1.AddBatteries(batteries); class1.AddBottles(bottles); } else { class2.AddBatteries(batteries); class2.AddBottles(bottles); } }

  34. פתרון תרגיל Bakbukim, מחלקה Program points1 = class1.TotalPoints(); points2 = class2.TotalPoints(); if (points1 > points2) Console.WriteLine("The first won"); else if (points1 < points2) Console.WriteLine("The second won"); else Console.WriteLine("Teko"); } }

  35. בהצלחה!

More Related