Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
תיכון ברנקו וייס בית שמש חוגג 01שנות מצוינות חינוכית סמל מוסד 1 6 0 4 3 2 מבחן מתכונת מס 1יסודות מדעי המחשב מרץ 1111 א .משך הבחינה :שלוש שעות. ב .מבנה השאלון ומפתח הערכה :בשאלון זה שלושה פרקים. פרק ראשון -בפרק זה חמש שאלות. ועליך לענות על כולן. פרק שני ( 51 )5X11נקודות בפרק זה שלוש שאלות.ועליך לענות על שתיים. ( 01 )1X15נקודות פרק שלישי -בפרק זה שתי שאלות. ועליך לענות על אחת. ( 11 )1X11נקודות סה"כ 111 -נקודות ג .חומר עזר מותר בשימוש :כל חומר עזר (פרט למחשב או התקן שניתן לתכנות) ד .הוראות מיוחדות :כתבו את התכניות בשפת JAVA טלפון: 15 Golan St. Po.B Beit -Shemesh רח' הגולן ,51ת.ד 155.בית-שמש פקסFax: 02-9990691 : Tel: 02-9992419/20 Email: [email protected] דוא"ל: תיכון ברנקו וייס בית שמש חוגג 01שנות מצוינות חינוכית סמל מוסד 1 6 0 4 3 2 פרק ראשון ( 05נקודות) ענו על חמש השאלות ( 1-0לכל שאלה – 15נקודות) שאלה 1 לפניך אלגוריתם: .1 .2 .3 .4 א. קלוט מספר ראשון קלוט מספר שני אם (שני המספרים זוגיים) .3.1הדפס את סכומם אחרת .1.1אם (שני המספרים אי-זוגיים) .1.1.1הדפס את הפרשם .4.4אחרת .1.2.1הדפס את שני הערכים עקבו בעזרת טבלת מעקב עבור הקלט של14 : פלט תנאי תנאי 3 4.1 לא כן 21 22 מספר 1 שורה מספר 4 22 1 14 22 2 14 22 3 14 22 1.1 14 22 1.2.1 עבור כל זוג של נתוני הקלט המצויינים למטה ,יש לרשום את הפלט שמתקבל .נמקו ב. מספר ראשון מספר שני -1 -4 31 11 כי אחד זוגי והשני אי זוגי ולכן מתבצע תנאי 4.4 -4 -9 כי שניהם זוגיים ומתבצע תנאי 1.3 24 טלפון: 15 Golan St. Po.B Beit -Shemesh רח' הגולן ,51ת.ד 155.בית-שמש פקסFax: 02-9990691 : Tel: 02-9992419/20 Email: [email protected] דוא"ל: תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג 1 6 0 4 3 2 סמל מוסד 4 שאלה . ספרות1 כתבו תכנית שקולטת מספר דו סיפרתי והופכת אותו למספר סימטרי (פלינדרום) בן 2552 המספר יהפוך ל,25 לדוגמא אם נקלט המספר import java.util.*; public class pal { static Scanner in = new Scanner(System.in); public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("enter number");// request the user to enter the number int num=in.nextInt();// read the number int units = num%10;// calculate the units digit int tens = num/10;// calcaulte the tens digit num = num*100+units*10+tens;// configure the palindrom number System.out.println("pal number "+num);// print the pali number } } 3 שאלה :נתון קטע התכנית הבא for (int i=0; i<(n/5); i++) System.out.println(i*5); ) (מסומן באדום בטבלה. עקבו בעזרת טבלת מעקב,n = 12 מה יהיה פלט קטע התכנית עבור הערך.א (12/5)=2 פלט i<(n/5) i 0 אמת 0 1 אמת 2 2 שקר אין ? מה מבצע קטע התכנית.ב ( לא כוללn/5) מאפס עד2 הדפסת כפולות של . יתקבל פלט זהה לפלט שקיבלת בסעיף א ? הסבירוn עבור אילו ערכים נוספים של.ג 2 ( בתנאי סיום הלולאה הואn/5) בגלל שערך הביטוי.9>n< 15 עבור כל static bool IsEqual (int[]m1, int[]m2) // . הפעולה מקבלת שני מערכים חד מימדיים המכילים מספרים שלמים:טענת כניסה // . או 'שקר' אחרת, הפעולה מחזירה 'אמת' אם שני המערכים זהים:טענת יציאה 4 שאלה :נתונה כותרת הפעולה הבאה .כתבו את גוף הפעולה static bool IsEqual (int[]m1, int[]m2) { // arrays length are equal? if (m1.length != m2.length) return(false);// no!, so the arrays are not the same. // here they are with the same length // check value in each entry for(int i=1; i<m1.length; i++) if (m1[i] != m2[i]) return (false);// we found an entry with different value //return false. // here they have the same value in each entry. so they are equal return(true); } 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון תיכון ברנקו וייס בית שמש חוגג 01שנות מצוינות חינוכית סמל מוסד 1 6 0 4 3 2 שאלה0 נתון מערך חד-ממדי בגודל 30המכיל מספרים שלמים. כתבו קטע תוכנית המדפיס את מיקומי האיברים השווים לאיבר העוקב להם. ;]int[] arr = new int[30 ..... )for (int i= 0; i<29; i++ { )]if (arr[i] == arr[i+1 ;)System.out.println("index "+i } טלפון: 15 Golan St. Po.B Beit -Shemesh רח' הגולן ,51ת.ד 155.בית-שמש פקסFax: 02-9990691 : Tel: 02-9992419/20 Email: [email protected] דוא"ל: תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג סמל מוסד 1 6 0 4 3 2 ) נקודות35( פרק שני ) נקודות10 – (לכל שאלה6-8 ענו על שתי שאלות מתוך 6 שאלה ושמספר הספרות בו זהה4 מספר נקרא מספר משלים כאשר הוא משלים מספר שלם למספר הבנוי רק מספרות .למספר אותו הוא משלים )99-25=74 (כי51 הוא22 מספר משלים של: דוגמאות )999-308=691 (כי141 הוא303 מספר משלים של )9-9=0 (כי0 הוא4 מספר משלים של .כתבו פעולה המקבלת מספר ומחזירה את המספר המשלים שלו .א מעדכנת כל איבר במערך למספר המשלים שלו ומציגה, מספרים שלמים20 כתבו תוכנית הקולטת למערך ' יש להיעזר בפעולה מסעיף א.מערך זה כפלט .ב import java.util.*; public class comp { static Scanner in = new Scanner(System.in); static int comp (int num) // input: integer number // output: the compliment number of the input { // first calculate the number of digits in the input number int nDigits = 0;// store the number of igits int num999; // store the 999 number' the the same number of digits as num int tNum = num; // temporray var to store the original number if (tNum == 0)// extream cae: num equals zero, return 9 return(9); while(tNum>0)// we did not reach zero, so continue { tNum = tNum /10; // calculate the number by 10 and nDigits++; // add the new digit } // here we know the number of digits in the original number // configure the number with the same number of digits but with '9's num999 =(int)(Math.pow(10, nDigits)); num999--; return(num999-num); } public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = new int[20]; System.out.println("enter numbers");// read in the array for (int i = 0; i<arr.length; i++) arr[i] = in.nextInt(); // replace each array entry with the compliment number for (int i = 0; i<arr.length; i++) arr[i] = comp(arr[i]); // print the new array for (int i = 0; i<arr.length; i++) System.out.print(" "+ arr[i] ); } 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג 1 6 0 4 3 2 } סמל מוסד 7 שאלה המשתתפים. משתתפים יכול להציע מספר לא מוגבל של מחירים לכל פריט100-במכרז פומבי "שלם כך וברח" כל אחד מ . הזוכה בפריט הוא זה שהצעתו הגבוהה ביותר.לא יודעים על הצעות של אחרים . פריטים שונים123 הוצגו למכרז מספר פריט ומחיר שהמשתתף מוכן, כל הצעה כוללת מספר משתתף.כתבו תוכנית אשר קולטת הצעות של משתתפים . בתור מספר משתתף444 הקלט מסתיים כאשר ייקלט מספר.לשלם עבור פריט זה :על התוכנית להדפיס עבור כל פריט שנמכר את מספרו של המשתתף הזוכה ואת המחיר שהציע .להדפיס רשימת פריטים שעבורם לא הוצגה אף הצעה import java.util.*; public class q7 { static Scanner in = new Scanner(System.in); public static void main(String[] args) { int N= 127;//maxumun number of items int[] person = new int[N]; // array of persons double[] price =new double[N];// array of prices int curPerson; // current person read from input int itemNum=1 ; // item number read from input double curPrice=0.0 ;// current price read from input // loop to initialize the person array and price array for (int i=0; i<N; i++) { person[i] = 0; price[i] = 0.0; } // read in the first line System.out.println(";)"הצעה הכנס curPerson = in.nextInt();// read the person if (curPerson!=999)// check it is not the end of list { itemNum = in.nextInt();// read in the item curPrice = in.nextDouble();// read the price } // here we have the first line (person, item, price // while loop until end of list while (curPerson!=999) { // check if the line we just read has higher price then already stored if(curPrice > price[itemNum-1] ) {// yes' this is higher price/ save it in the item entry price[itemNum-1]= curPrice; person[itemNum-1]= curPerson; } // read in the next line System.out.println(";)"הצעה הכנס curPerson = in.nextInt(); if (curPerson!=999) { itemNum = in.nextInt(); curPrice = in.nextDouble(); } 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג 1 6 0 4 3 2 סמל מוסד } // here the price and person arrays are updated // scan the arrays and print all the entries with prices for (int i=0; i<N; i++) { if (person[i] != 0) System.out.println("" מוצר+(i+1)+" " משתתף+person[i]+" מחיר "+price[i]); } // scan the arrays and print all the entries without prices System.out.println(";)"מחיר הצעות ללא מוצרים for (int i=0; i<N; i++) { if (person[i]== 0) System.out.println((i+1)); } } } 8 שאלה .קלטו סידרת מספרים חיוביים ושלמים עד לקבלת מספר שלילי או אפס אם המספר הראשון שנקלט שווה למספר האחרון שנקלט יש להדפיס את הסכום המצטבר של כל המספרים בסדרה שערכם ,גדול מהמספר הראשון ."אחרת יש להדפיס את ההודעה "חוסר התאמה בין הראשון לאחרון .הניחו שנקלט לפחות מספר אחד חיובי האם דרוש מערך לפתרון הבעיה? נמקו.א כתבו קטע תוכנית לביצוע המשימה.ב import java.util.*; public class q8 { static Scanner in = new Scanner(System.in); public static void main(String[] args) { System.out.println("enter numbers"); int firstNum = in.nextInt();// this is the first number int num = firstNum;// num is for the current number read from input int lastNum = firstNum; // this is the last number int sum=0;// this is the summery // we assume that first and last numbers are same' so we need to calculate // the summery while (num > 0) // while loop until zero or negativ number { if (num>firstNum) // currst number greater then the first? sum = sum+num;// yes! add to the summery lastNum = num;// save as last number num = in.nextInt();// read the next from input }; if (lastNum == firstNum)// are the first and last the same? // yes! print the summery System.out.println("sum is "+sum); // the first and last are different, print error msg else System.out.println(" ;)"חוסר התאמה בין הראשון לאחרון } } 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג 1 6 0 4 3 2 סמל מוסד ) נקודות45( פרק שלישי ) נקודות45( 9-15 ענו על שאלה אחת מתוך 9 שאלה . מקומות200 בכל אולם יש.1 - ל1 ממוספרים בין, אולמות1 בבית קולנוע . אף פעם לא מתבטל שם הסרט ובהפסקה מחלקים לכל ילד משולש פיצה וטרופית, נועד לסרטי ילדים1 אולם מספר . והצופים מועברים לאולמות האחרים, לא מתקיים הסרט, צופים10 - אם יש פחות מ-ביתר האולמות סיום קליטת הנתונים לערב יהיה. ואת כמות הכרטיסים בהם הוא מעוניין, מציין את מספר האולם,אדם המגיע לקופה .הקשת מספר אולם שלילי : מעוניינת לקבל בכל ערב את המידע הבא,הנהלת הקולנוע .מספרי האולמות בהם לא תיערך הקרנה . וכמה צופים ניתן להעביר אליהם,מספרי האולמות בהם יש מקומות פנויים ובארגז טרופית יש, משולשים3 (בפיצה יש.מספר ארגזי טרופית ומספר פיצות יש להזמין עבור אולם הילדים .) טרופיות20 . ותארו את תפקידיהם, הגדירו את טיפוסיהם,בחרו במשתנים עיקריים .משימה תיפתר באמצעות פעולה- כך שכל תת,משימות-בצעו פירוק של הבעיה לתת .ב-כתבו תכנית (פעולה ראשית ופעולות נוספות) ליישום האלגוריתם המתואר בסעיפים א .א .ב .ג import java.util.*; public class q9 { static Scanner in = new Scanner(System.in); static int[] fillTheaters( int[]arr ) //input: array of empty theaters // output: each entry has the number of tickets for relevant theater { int curTheater;// current theater read from input int nTickets;// current number of tickets read from input for(int i=0;i<6;i++)// initialize the array arr[i] = 0; // request next ticket order System.out.println("enter theater and no. of tickets"); curTheater = in.nextInt();// read in the theater number nTickets = in.nextInt();// read in the no. of tickets requestes while(curTheater>0) // while more orders { if (arr[curTheater-1] >= 200) // if theeater is full, send error msg System.out.println("theateris full"); else // it is not full arr[curTheater-1] += nTickets;// add no. of tickets System.out.println("enter theater and no. of tickets"); curTheater = in.nextInt(); nTickets = in.nextInt(); } return(arr);// return the theater arry } static void avilSeats(int[]arr) // input: the theater array // output: print number of avilable seats for each theater 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג 1 6 0 4 3 2 { סמל מוסד int avil;// avilable seats in each theater for (int i=0;i<6;i++) { if(arr[i] < 200)// if not full { avil = 200 - arr[i]; // calculate avilable placase and print System.out.println("theater["+(i+1)+"] has "+avil+" avilable places"); } } } static void kidsOrder(int ntickets) // input: number of tickets requested for first theater // output; print the number of pizza and Tropit boxes needed fro the kids { int nPizza; //number of pizza to order int nBox; // number of Tropit boxes to order nPizza = ntickets/8+1; nBox = ntickets/20+1; System.out.println(" order "+nPizza+" Pizza and "+nBox+" box of Tropit"); } static void nearEmpty(int[]arr) // input: the theater array // output: print index of theater with less then 10 tickets. do not check // the first theater { for (int i=1;i<6;i++) { if(arr[i] < 10) System.out.println("theater["+(i+1)+"] has lower then 10 places"); } } public static void main(String[] args) { int[] theater = new int[6]; theater = fillTheaters(theater); avilSeats(theater); nearEmpty(theater); if (theater[0]>0) kidsOrder(theater[0]); } } 15 שאלה .ניתן להיעזר במערכים כדי לשמור מספרים שלמים גדולים במיוחד .כל תא במערך יכיל ספרה אחת של המספר הגדול המייצגים שני מספרים גדולים (כל איבר במערך מציין ספרה במספר100 כתבו פעולה שתקלוט שני מערכים בגודל . על הפעולה לחשב ולהחזיר את מערך הסכום שלהם.)הגדול : דוגמא 321121334 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון תיכון ברנקו וייס בית שמש שנות מצוינות חינוכית01 חוגג 1 6 0 4 3 2 סמל מוסד 0 3 2 1 1 2 3 3 4 3 4 333121334 3 3 3 1 2 1 3 : סכום שני המספרים 4 2 0 1 0 2 5 public class q10 { static int[] arrSum (int [] a, int [] b) { int [] arr = new int[101]; int carry=0; int i; for (i=0;i>101; i++) arr[i] = 0; for (i=0;i<101; i++) { arr[i]= a[i]+ b[i]+ carry; carry = 0; if(arr[i]>9) { arr[i]=arr[i]%10; carry = 1; } } return(arr); } public static void main(String[] args) { int[] a =new int[100]; int[] b =new int[100]; int[] c = new int[101]; // here read in the values to a and b //... c = arrSum(a,b); for (int i=0;i<101;i++) System.out.print(" "+c[i]); } } 15 Golan St. Po.B Beit -Shemesh שמש- בית155.ד. ת,51 רח' הגולן Fax: 02-9990691 :פקס Tel: 02-9992419/20 Email: [email protected] :דוא"ל :טלפון 5 3