oms
20-04-2005, 07:47 PM
منذ عدة أيام قام شخص ( مسحت الرسالة بالغلط ) بإعطائي برنامج لكي أحله إياه :
وقمت بحله ولكن ؟؟؟؟؟ إلى أين أرسله ؟؟؟؟؟
وها هو البرنامج :
بسم الله الرحمن الرحيم
Write a c# sharp program that determines whether a word or sentence is a palindrome .(a palindrome reads backwards the same way as forwards, for example:
'Able was I ere I saw Elba'.)Space are considered as significant.
Notes:
The problem statement gives little information about designing the program, so we definitely need to do some thinking and planning before trying to write code .
First of all we need an algorithm to test whether a string is a palindrome. This turns out to be easy:
Make a copy of the string
Reverse the order of the characters
Compare the reversed copy with the original to see if they are the same
Now that we know that it's possible to check for a palindrome ,the next step is to consider the overall sequence of events that should take place when the program runs. This gives:
Input string to test
Make a copy
Do the reverse
Check the reverse copy against the original
Display answer
Next we want to determine what methods are required and allocate behavior to them .We could bundle everything into a single method but that would violate our cohesion guidelines . Instead, we identify the following methods:
String GetInput() Get the input string to be tested
Void TestForPalindrome(string s) Check if s is a palindrome
Bool check(string s1,string s2) Is s2 the reverse of s1?
String Reverse(string s) Return thr reverse of the argument string
We now have all the pieces ready to write the program.
However, the answer to the proplem is to convert all the characters in the input string to lower case before testing to see if it a palindrome .
المطلوب جزاكم الله خير:
شرح السؤال بالعربي.
كتابة البرنامج بلغة السي شارب.
توضيح وظيفة عمل كل دالة بمثال .
أتمنى إن استطعت أن تساعدني أن تكون الإجابة قبل يوم الثلاثاء
حيث أنه آخر موعد لتسليم الإجابات
ولك وافر الشكر موصول بالدعاء.
بسم الله الرحمن الرحيم
أعتذر أخوي جداً عن التأخير (وقت لا ينفع الندم) ولكن والله يا أخي ما وجدت وقت إلا الآن
وقد أنهيت لك مشروعك ( يمكن ما في فائدة الآن ) ولكن عملت اللي علي
أولاً : بالنسبة للشرح :
قم بكتابة برنامج بواسطة لغة السي شارب لإيجاد الـ palindrome وهي عبارة عن جملة يمكنك قرائتها من العكس بحيث تصبح صحيح مثال ذلك كلمة ( ليل ) فإذا قرأتها من اليسار إلى اليمين أو من اليمين إلى اليسار تبقى نفسها . ومثالأ آخر في الإنجليزية Able was I ere I saw Elba كما موجود في السؤال .
السؤال لا يمنحك الكثير من المعلومات لذلك يجب عليك أن تفكر بخطط وطرق لكتابة البرنامج .
أولاً نحتاج لخوارزمية لكي نعرف أن الكلمة تقرأ بالعكس (palindrome ) وهذا سهل كالتالي :
إنتبه الآن سأكتب خوارزمية :
قم بكتابة الجملة
قم بعكس الجملة
قارن بين الكلمة السابقة والكلمة الحالية
وانظر هل هي متساوية ؟
والآن يمكننا كتابة الخوارزمية السابقة بكود كالتالي :
أدخل النص في متغير Test .
قم بأخذ نسخة إحتياطية منها .
قم بتنفيذ عملية العكس .
قم بمقارنة الجملة الناتجة مع المتغير Test .
أظهر النتيجة .
والآن يمكننا الخروج من السؤال السابق بالدوال التالية :
String GetInput() لأخذ النص المراد فحصه .
Void TestForPalindrome(string s) لفحص النص هل هو قابل للعكس ؟ .
Bool check(string s1,string s2) إذا كانا متساوين .
String Reverse(string s) إرجاع عكس الكلمة .
والآن كل الدوال التي تفيدنا في البرنامج موجودة ولنبدأ في ترجمة البرنامج إلى كود :
using System;
public class Class1
{
public static void Main()
{
Palindrome p1 = new Palindrome();
p1.TestForPalindrome();
}
}
public class Palindrome
{
public void TestForPalindrome()
{
string Word = GetInput() ;
string Test_Word = Reverse(Word) ;
bool Bool_Test = Check(Word,Test_Word);
if ( Bool_Test )
Console.WriteLine("The Text Is Palindrome .");
else
Console.WriteLine("The Text Is Not Palindrome .");
}
public string GetInput()
{
string Test = "" ;
Console.Write("Enter The Statement For Test Palindrome : ");
Test = Console.ReadLine();
return Test ;
}
public bool Check(string s1,string s2)
{
if ( s1 == s2 )
return true ;
else
return false ;
}
public string Reverse(string s)
{
string Rev_Text = "" ;
for ( int i= s.Length -1 ; i>=0 ; i-- )
Rev_Text += s[i] ;
Console.Write("reverse Text Is : {0}\n\n",Rev_Text);
return Rev_Text ;
}
}
وقمت بحله ولكن ؟؟؟؟؟ إلى أين أرسله ؟؟؟؟؟
وها هو البرنامج :
بسم الله الرحمن الرحيم
Write a c# sharp program that determines whether a word or sentence is a palindrome .(a palindrome reads backwards the same way as forwards, for example:
'Able was I ere I saw Elba'.)Space are considered as significant.
Notes:
The problem statement gives little information about designing the program, so we definitely need to do some thinking and planning before trying to write code .
First of all we need an algorithm to test whether a string is a palindrome. This turns out to be easy:
Make a copy of the string
Reverse the order of the characters
Compare the reversed copy with the original to see if they are the same
Now that we know that it's possible to check for a palindrome ,the next step is to consider the overall sequence of events that should take place when the program runs. This gives:
Input string to test
Make a copy
Do the reverse
Check the reverse copy against the original
Display answer
Next we want to determine what methods are required and allocate behavior to them .We could bundle everything into a single method but that would violate our cohesion guidelines . Instead, we identify the following methods:
String GetInput() Get the input string to be tested
Void TestForPalindrome(string s) Check if s is a palindrome
Bool check(string s1,string s2) Is s2 the reverse of s1?
String Reverse(string s) Return thr reverse of the argument string
We now have all the pieces ready to write the program.
However, the answer to the proplem is to convert all the characters in the input string to lower case before testing to see if it a palindrome .
المطلوب جزاكم الله خير:
شرح السؤال بالعربي.
كتابة البرنامج بلغة السي شارب.
توضيح وظيفة عمل كل دالة بمثال .
أتمنى إن استطعت أن تساعدني أن تكون الإجابة قبل يوم الثلاثاء
حيث أنه آخر موعد لتسليم الإجابات
ولك وافر الشكر موصول بالدعاء.
بسم الله الرحمن الرحيم
أعتذر أخوي جداً عن التأخير (وقت لا ينفع الندم) ولكن والله يا أخي ما وجدت وقت إلا الآن
وقد أنهيت لك مشروعك ( يمكن ما في فائدة الآن ) ولكن عملت اللي علي
أولاً : بالنسبة للشرح :
قم بكتابة برنامج بواسطة لغة السي شارب لإيجاد الـ palindrome وهي عبارة عن جملة يمكنك قرائتها من العكس بحيث تصبح صحيح مثال ذلك كلمة ( ليل ) فإذا قرأتها من اليسار إلى اليمين أو من اليمين إلى اليسار تبقى نفسها . ومثالأ آخر في الإنجليزية Able was I ere I saw Elba كما موجود في السؤال .
السؤال لا يمنحك الكثير من المعلومات لذلك يجب عليك أن تفكر بخطط وطرق لكتابة البرنامج .
أولاً نحتاج لخوارزمية لكي نعرف أن الكلمة تقرأ بالعكس (palindrome ) وهذا سهل كالتالي :
إنتبه الآن سأكتب خوارزمية :
قم بكتابة الجملة
قم بعكس الجملة
قارن بين الكلمة السابقة والكلمة الحالية
وانظر هل هي متساوية ؟
والآن يمكننا كتابة الخوارزمية السابقة بكود كالتالي :
أدخل النص في متغير Test .
قم بأخذ نسخة إحتياطية منها .
قم بتنفيذ عملية العكس .
قم بمقارنة الجملة الناتجة مع المتغير Test .
أظهر النتيجة .
والآن يمكننا الخروج من السؤال السابق بالدوال التالية :
String GetInput() لأخذ النص المراد فحصه .
Void TestForPalindrome(string s) لفحص النص هل هو قابل للعكس ؟ .
Bool check(string s1,string s2) إذا كانا متساوين .
String Reverse(string s) إرجاع عكس الكلمة .
والآن كل الدوال التي تفيدنا في البرنامج موجودة ولنبدأ في ترجمة البرنامج إلى كود :
using System;
public class Class1
{
public static void Main()
{
Palindrome p1 = new Palindrome();
p1.TestForPalindrome();
}
}
public class Palindrome
{
public void TestForPalindrome()
{
string Word = GetInput() ;
string Test_Word = Reverse(Word) ;
bool Bool_Test = Check(Word,Test_Word);
if ( Bool_Test )
Console.WriteLine("The Text Is Palindrome .");
else
Console.WriteLine("The Text Is Not Palindrome .");
}
public string GetInput()
{
string Test = "" ;
Console.Write("Enter The Statement For Test Palindrome : ");
Test = Console.ReadLine();
return Test ;
}
public bool Check(string s1,string s2)
{
if ( s1 == s2 )
return true ;
else
return false ;
}
public string Reverse(string s)
{
string Rev_Text = "" ;
for ( int i= s.Length -1 ; i>=0 ; i-- )
Rev_Text += s[i] ;
Console.Write("reverse Text Is : {0}\n\n",Rev_Text);
return Rev_Text ;
}
}