بسم الله الرحمن الرحيم
هذه المسابقة هى من اقتراح عضو فى المنتدى بعمل مسابقة للمبتدئين ...
هذه المسابقة تشترط معرفتك الجيده لـ OOP فى C++
هذا السؤال يركز على Class عامة ....
انا سأطرح عليكم اول مسأله و الفائز طبعا من يحقق افضل و اسرع و اصغر حل ...
الجوائز : أكيد التأهل الى المسابقة المتقدمة ......
المسابقة أيضا من 10 مسائل ....
و ستعرض الاسئلة تسلسليا
السؤال الأول :-
Safe Array
Weakness of C++ that it doesn't automatically check array indexes to see if they are in bounds> (this makes array operations faster but less safe>) we can a class to create a safe array that checks the index of all array accesses>
write a class called safearay that uses an int array of fixed size (call it LIMIT) as its only data member> There will be two member functions> The first - putel()- , takes an index number and an int value as arguments and inserts the int value into the array at the index.
The second, -getel()-, takes an index number as an argument and returns the int value of the element with that index.
example:
safearay sa1; //define a safearay object
int temp=12345; //define an int value
sa1.putel(7,temp); //insert the value of temp into array at index 7
temp.getel(7); //obtain value from array at index 7
both functions should check the index argument to make sure it is not less than 0 or greater then LIMIT - 1. You can use this array without fear of writing over other parts of memory.
أتمنى ان يعجبكم السؤال ......
والسؤال الثانى فى ان نجعلها مثل built-in array اى باستخدام Operator Overloading
(operator [] )
فى انتظار حلولكم
ملاحظة لمستخدمى Java و C# الرجاء عمل Jagged Array
طبعا لاتوجد مثل هذه المشكلة فى Java او C# لذا الرجاء عمل شيئ تقريبى لها ...
واتمنى من المتسابق ان يرفق الحل
