Download presentation
Presentation is loading. Please wait.
1
פתרון תרגילי כיתה בקלפים
2
תחלק 5 קלפים ותחשב את הסכום של כל הקלפים class Program { static void Main(string[] args) { Deck hafisa = new Deck(); // Card me; int sum_me = 0, i; for (i = 0; i < 5; i++) // { me = hafisa.dealCard(); sum_me += me.getValue(); } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }
3
תחלק 5 קלפים ותחשב את הסכום של כל הקלפים class Program { static void Main(string[] args) { Deck hafisa = new Deck(); // Card me; int sum_me = 0, i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) // { me = hafisa.dealCard(); my_hand.addCard(me); sum_me += me.getValue(); } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }
4
פתרון נוסף static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int sum_me = 0, i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) // { me = my_hand.getCard(i);//first get card sum_me += me.getValue();//now add it to the sum } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }
5
פתרון נוסף static void Main(string[] args) { Deck hafisa = new Deck(); // Card me; int sum_me = 0, i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) // { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) // { sum_me += my_hand.getCard(i).getValue();//What??? } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }
6
תוסיף קלף חדש לסוף הHAND של 5 קלפים static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } me = hafisa.dealCard(); my_hand.addCard(me);//where did it go??? for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); }
7
פתרון יותר טוב (עם פונקציה) class Program { static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); me = hafisa.dealCard(); my_hand.addCard(me);//where did it go??? Print(my_hand); }
8
פתרון יותר טוב (עם פונקציה) static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } me = hafisa.dealCard(); my_hand.addCard(me);//where did it go??? for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); }
9
תוריד את הקלף הראשון מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); my_hand.removeCard(0); Print(my_hand); }
10
פתרון נוסף static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); me = my_hand.getCard(0); my_hand.removeCard(me); Print(my_hand); }
11
תוריד את הקלף הראשון מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); my_hand.removeCard(0); Print(my_hand); }
12
תוריד את הקלף האחרון מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); int temp = my_hand.getCardCount(); me = my_hand.getCard(temp - 1); my_hand.removeCard(me); Print(my_hand); }
13
פתרון נוסף static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); my_hand.removeCard(my_hand.getCardCount()-1); Print(my_hand); }
14
תוריד כל קלף שני (זוגי) מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 10; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); for (i = 0; i < my_hand.getCardCount(); i++) { if (i % 2 == 0) // mod 2 means it is even my_hand.removeCard(i); } Print(my_hand); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.