المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : برامج لمادة البرمجة المتقدمة1 (إنطلاقا من الصفر)


Executioner
01-03-2008, 02:39 PM
بسم الله الرحمن الرحيم
السلام عليكم ورحمة الله وبركاته
أما بعد:

أحببت أن أبدأ موضوعاً جديداً لبرامج مادة البرمجة المتقدمة1 من بدايته عسى لأولئك الطلاب الذين يجدون صعوبة بهذه المادة أن يستعينوا بهذه البرامج الموجودة، وينطلقوا من الصفر، حيث أن هذه البرامج كانت لمادة البرمجة من السنة الأولى وقد كان يعطى هذه المادة أستاذنا الحالي، مما يزيد في أهميتها، حيث كانت مكتوبة بلغة الـ ++C ومن ثم أعدت كتابتها بلغة الـ #C لكم.

ستجدون كثيرا من البرامج التي قد أخذناها هذه السنة (وهي هامة)، وأريد إلى أن أنوه إلى أن هناك عدة صفحات.

ملاحظات:
أرجو أن تنشروها لكي تصل للذين يريدونها.
أنا إن شاء الله جاهز لأي استفسار يوجد في هذه البرامج.
أرجو إطلاعي على الأخطاء في حال ورودها، وعلى النصائح والملاحظات.
ولمزيد من الإستفسارات في حال لم أرد عليها عليكم بمراسلة الأساتذة (أبو عمر أو Golden man أو Bl@ck angel ..... إلخ) .
لا تنسوني من صالح الدعاء الدعاء الدعاء الدعاء (من صمصومة قلبكم).

Executioner
01-03-2008, 02:40 PM
1- برنامج إخراج رسالة ترحيب للمستخدم:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome in C#.");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:41 PM
2- برنامج لجمع وطرح وضرب وقسمة عددين:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x=0, y=0;

Console.Write("Enter the value of the first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the value of the second number: ");
y = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("x+ y= " + (x + y));
Console.WriteLine("x- y= " + (x - y));
Console.WriteLine("x* y= " + (x * y));
if (y != 0)
Console.WriteLine("x/ y= " + (x / y));
else
Console.WriteLine("Error divide by zero.");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:42 PM
3- برنامج يطبع لنا قيمة محرف مدخل بالآسكي:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the char: ");
int ch = Console.Read();
Console.WriteLine("In ASCII: " + ch);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:42 PM
4- برنامج يتحقق لنا من المطابقة الشهيرة:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter angle by degree: ");
double Angle = Convert.ToInt32(Console.ReadLine());
Angle = (Angle*(220/70)) / 180; // convert to radian.
double result = Math.Pow(Math.Sin(Angle), 2) + Math.Pow(Math.Cos(Angle),2);
Console.WriteLine("Th result is: " + result);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:43 PM
5- برنامج ندخل له جب زاوية فيحسب لنا الزاوية بالراديان و الدرجات:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the sin of angle: ");
double Angle = Convert.ToDouble(Console.ReadLine());
double result = Math.Asin(Angle);
Console.WriteLine("Angle by radian: "+ result);
result= result*180/Math.PI;
Console.WriteLine("Angle by degree: "+ result);
/*if (Angle > 0)
Console.WriteLine("Angle by degree: " +
(Math.Floor((Math.Floor(result)/10))*10));
else
Console.WriteLine("Angle by degree: " +
(Math.Ceiling((Math.Ceiling(result) / 10)) * 10));*/
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:43 PM
6- برنامج ندخل له عددين فيطبع لنا الأكبر:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x = 0, y = 0;
Console.Write("Enter the first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second number: ");
y = Convert.ToInt32(Console.ReadLine());
if (x > y)
Console.WriteLine("The bigger is the first number: " + x);
else
Console.WriteLine("The bigger is the second number: " + y);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:44 PM
7- حل معادلة من الدرجة الأولى:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double a=0, b=0;
double x = 0;
Console.Write("Enter the value of a: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the value of b: ");
b = Convert.ToInt32(Console.ReadLine());
if (a == 0)
Console.WriteLine("The equation is wrong.");
else
{
x = -b / a;
Console.WriteLine("x= " + x);
}
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:45 PM
8- حل معادلة من الدرجة الثانية:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double a=0, b=0, c=0;
double x1= 0, x2=0;
Console.Write("Enter the value of a: ");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the value of b: ");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the value of c: ");
c = Convert.ToDouble(Console.ReadLine());
double delta = Math.Pow(b, 2) - 4 * a * c;
if (delta==0)
{
x1 = -b / (2 * a);
Console.WriteLine("x1= x2= " + x1);
}
else
if (delta > 0)
{
x1 = (-b - Math.Pow(delta, 0.5)) / (2 * a);
x2 = (-b + Math.Pow(delta, 0.5)) / (2 * a);
Console.WriteLine("x1= " + x1);
Console.WriteLine("x2= " + x2);
}
else
Console.WriteLine("The equation is wrong.");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:45 PM
9- برنامج ندخل له ثلاثة أعداد فيطبع لنا الأكبر:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x = 0, y = 0, z=0;
Console.Write("Enter the first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second number: ");
y = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the third number: ");
z = Convert.ToInt32(Console.ReadLine());
if (x >= y)
{
if (x>z)
Console.WriteLine("The bigger is the first number: " + x);
else
Console.WriteLine("The bigger is the third number: " + z);
}
else
if (y>z)
Console.WriteLine("The bigger is the second number: " + y);
else
Console.WriteLine("The bigger is the third number: " + z);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:50 PM
10- المطلوب قراءة عدد يمثل عدد الأرقام الذي سيدخل و حساب معدل هذه الأعداد:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double sum = 0;
Console.WriteLine("Enter the whole number: ");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
{
Console.Write("Enter new number: ");
sum += Convert.ToDouble(Console.ReadLine());
}
Console.WriteLine("The Avg Is: " + (sum/n));
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:51 PM
11- المطلوب إدخال مجموعة أعداد حقيقية حتى يأتي عدد سالب ثم طباعة المجموع والعدد والمعدل:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double sum = 0, n = 0, num=0;
for (; num >= 0; )
{
Console.Write("Enter new number: ");
num = Convert.ToDouble(Console.ReadLine());
if (num >= 0)
{
sum += num;
n++;
}
else
Console.WriteLine("We will exit you have enter negative value.");
}
if (n != 0)
{
Console.WriteLine("The sum is: " + sum);
Console.WriteLine("The count is: " + n);
Console.WriteLine("The average is: " + sum/n);
}
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:52 PM
12- المطلوب حساب المتوسط الحسابي للأعداد الفردية والزوجية بين 1-100:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double s1=0, s2=0, a1=0, a2=0;
for (int i = 1; i <= 100; i++)
{
if (i % 2 != 0) // or i%2==1
s1+=i;
else
s2+=i;
}
Console.WriteLine("sum1 is: " + s1);
Console.WriteLine("sum2 is: " + s2);
a1 = s1 / 50.0;
a2 = s2 / 50.0;
Console.WriteLine("average1 is: " + a1);
Console.WriteLine("average2 is: " + a2);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:53 PM
13- ندخل عدد يمثل يوم فيطبع لنا اسم هذا اليوم بطريقة(if else):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int day = 0;
Console.Write("Enter the number: ");
day = Convert.ToInt32(Console.ReadLine());
if (day == 1)
Console.WriteLine("Sturaday.");
else
if (day == 2)
Console.WriteLine("Sunday.");
else
if (day == 3)
Console.WriteLine("Monday.");
else
if (day == 4)
Console.WriteLine("Tuesday.");
else
if (day == 5)
Console.WriteLine("Wednesday.");
else
if (day == 6)
Console.WriteLine("Thursday.");
else
if (day == 7)
Console.WriteLine("Friday.");
else
Console.WriteLine("error.");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:53 PM
14- ندخل عدد يمثل يوم فيطبع لنا اسم هذا اليوم بطريقة(switch):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int day = 0;
Console.Write("Enter the number: ");
day = Convert.ToInt32(Console.ReadLine());
switch (day)
{
case 1: Console.WriteLine("Sturaday."); break;
case 2: Console.WriteLine("Sunday."); break;
case 3: Console.WriteLine("Monday."); break;
case 4: Console.WriteLine("Tuesday."); break;
case 5: Console.WriteLine("Wednesday."); break;
case 6: Console.WriteLine("Thursday."); break;
case 7: Console.WriteLine("Friday."); break;
default: Console.WriteLine("error."); break;
}
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:54 PM
15- نفس البرنامج 14 ولكن مع إمكانية تكرار هذه العملية ضمن حلقة وإمكانية المستخدم من الخروج متى شاء:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int exit = 0;
do {
Console.WriteLine("Enter 0 to exit.");
exit = Convert.ToInt32(Console.ReadLine());
if (exit != 0)
{
int day = 0;
Console.Write("Enter the number: ");
day = Convert.ToInt32(Console.ReadLine());
switch (day)
{
case 1: Console.WriteLine("Sturaday."); break;
case 2: Console.WriteLine("Sunday."); break;
case 3: Console.WriteLine("Monday."); break;
case 4: Console.WriteLine("Tuesday."); break;
case 5: Console.WriteLine("Wednesday."); break;
case 6: Console.WriteLine("Thursday."); break;
case 7: Console.WriteLine("Friday."); break;
default: Console.WriteLine("error."); break;
}
}
else
Console.WriteLine("Good By.");
} while(exit!=0);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:55 PM
16- طباعة الأحرف الكبيرة مع ترتيبها بالآسكي، ثم طباعة الأحرف الصغيرة مع ترتيبها بالآسكي:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = 65;
for (char ch = 'A'; ch <= 'Z'; ch++)
Console.WriteLine(ch + ": " + i++);
i = 97;
for (char ch = 'a'; ch <= 'z'; ch++)
Console.WriteLine(ch + ": " + i++);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:55 PM
17- إدخال محرف وإخبار المستخدم في حال كونه صغيرا أم كبيرا أو غير ذلك:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int ch = 0;
Console.Write("Enter a char: ");
ch= Console.Read();
if (ch >= 'A' && ch <= 'Z')
Console.WriteLine("Capital letter.");
else if (ch >= 'a' && ch <= 'z')
Console.WriteLine("Small letter.");
else
Console.WriteLine("Other.");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:56 PM
18- إدخال محرف فإذا كان صغيرا طبعه كبيرا والعكس صحيح، عدا ذلك يطبعه نفسه:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int ch = 0;
Console.Write("Enter a char: ");
ch= Console.Read();
if (ch >= 'A' && ch <= 'Z')
Console.WriteLine((char)(ch+32));
else if (ch >= 'a' && ch <= 'z')
Console.WriteLine((char)(ch-32));
else
Console.WriteLine((char)(ch));
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:57 PM
19- المطلوب إدخال 10 علامات وطباعة المعدل والعلامات المدخلة:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double []Marks= new double[20];
double sum = 0;
for (int i = 0; i < 10; i++)
{
Console.Write("Enter new mark " + (i+1) + ": ");
Marks[i] = Convert.ToDouble(Console.ReadLine());
sum += Marks[i];
}
Console.WriteLine("Average is: " + sum/10);
Console.WriteLine("The marks is:");
for (int i = 0; i < 10; i++)
Console.WriteLine("Mark " + (i+1) + " is: " + Marks[i]);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:57 PM
20- التحويل من نظام العد العشري إلى نظام العد الثنائي:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Dec = 0;
Console.Write("Enter the number: ");
Dec = Convert.ToInt32(Console.ReadLine());
Console.Write("The Value Is: (" + Dec + ")10 ---> (");
int []Bin= new int[100];
int size = 0;
while (Dec > 1)
{
Bin[size] = Dec % 2;
Dec = Dec / 2;
size++;
}
Bin[size] = Dec;
for (int i = size; i >= 0; i--)
Console.Write(Bin[i]);
Console.WriteLine(")2");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:58 PM
21- التحويل من نظام العد العشري إلى نظام العد الثماني:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Dec = 0;
Console.Write("Enter the number: ");
Dec = Convert.ToInt32(Console.ReadLine());
Console.Write("The Value Is: (" + Dec + ")10 ---> (");
int []Bin= new int[100];
int size = 0;
while (Dec > 7)
{
Bin[size] = Dec % 8;
Dec = Dec / 8;
size++;
}
Bin[size] = Dec;
for (int i = size; i >= 0; i--)
Console.Write(Bin[i]);
Console.WriteLine(")8");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:58 PM
22- التحويل من نظام العد العشري إلى نظام العد السداسي عشري:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Dec = 0;
Console.Write("Enter the number: ");
Dec = Convert.ToInt32(Console.ReadLine());
Console.Write("The Value Is: (" + Dec + ")10 ---> (");
int []Bin= new int[100];
int size = 0;
while (Dec > 15)
{
Bin[size] = Dec % 16;
Dec = Dec / 16;
size++;
}
Bin[size] = Dec;
for (int i = size; i >= 0; i--)
{
switch (Bin[i])
{
case 10: Console.Write("A"); break;
case 11: Console.Write("B"); break;
case 12: Console.Write("C"); break;
case 13: Console.Write("D"); break;
case 14: Console.Write("E"); break;
case 15: Console.Write("F"); break;
default: Console.Write(Bin[i]); break;
}
}
Console.WriteLine(")16");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:59 PM
23- التحويل من نظام العد العشري إلى أي نظام عد:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Dec = 0;
Console.Write("Enter the number: ");
Dec = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the system: ");
int sys = Convert.ToInt32(Console.ReadLine());

Console.Write("The Value Is: (" + Dec + ")10 ---> (");
int []Bin= new int[100];
int size = 0;
while (Dec > sys-1)
{
Bin[size] = Dec % sys;
Dec = Dec / sys;
size++;
}
Bin[size] = Dec;
for (int i = size; i >= 0; i--)
{
switch (Bin[i])
{
case 10: Console.Write("A"); break;
case 11: Console.Write("B"); break;
case 12: Console.Write("C"); break;
case 13: Console.Write("D"); break;
case 14: Console.Write("E"); break;
case 15: Console.Write("F"); break;
case 16: Console.Write("G"); break;
case 17: Console.Write("H"); break;
case 18: Console.Write("I"); break;
case 19: Console.Write("J"); break;
case 20: Console.Write("K"); break;
default: Console.Write(Bin[i]); break;
}
}
Console.WriteLine(")" + sys);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 02:59 PM
24- التحويل من نظام العد العشري إلى أي نظام عد2 بشكل مختصر:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Dec = 0;
Console.Write("Enter the number: ");
Dec = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the system: ");
int sys = Convert.ToInt32(Console.ReadLine());

Console.Write("The Value Is: (" + Dec + ")10 ---> (");
int []Bin= new int[100];
int size = 0;
while (Dec > sys-1)
{
Bin[size] = Dec % sys;
Dec = Dec / sys;
size++;
}
Bin[size] = Dec;
for (int i = size; i >= 0; i--)
{
if (Bin[i] >= 0 && Bin[i] <= 9)
Console.Write(Bin[i]);
else
Console.Write((char)(Bin[i]+55));
}
Console.WriteLine(")" + sys);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 03:00 PM
25- المطلوب إدخال اسم الطالب ثم إدخال 10 علامات له، ثم طباعة الإسم والمعدل وكل علامة على حده:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string Name="";
double[] Marks = new double[100];
double sum = 0;

Console.Write("Enter your name: ");
Name = Console.ReadLine();
for (int i = 0; i < 10; i++)
{
Console.Write("Enter new value" + (i+1) + ": ");
Marks[i] = Convert.ToDouble(Console.ReadLine());
sum += Marks[i];
}

Console.WriteLine("The name is: " + Name);
Console.WriteLine("The Avergae is: " + sum/10);
Console.WriteLine("The marks is:");
for (int i = 0; i < 10; i++)
Console.WriteLine("Mark " + (i+1) + ": " + Marks[i]);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 03:01 PM
26- طباعة طول سلسلة محرفية مدخلة من قبل المستخدم، واستخدام مفهوم المصفوفات في طباعتها:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.WriteLine("The length of it is: " + name.Length);

for (int i = 0; i < name.Length; i++)
Console.Write(name[i]);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 03:01 PM
27- المطلوب إدخال معدلات عدة طلاب (يتحدد العدد من قبل المستخدم) وفرز المعدلات تنازليا ثم طباعتها:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double []Avgs= new double[100];
double n = 0;
Console.Write("Enter the count of students: ");
n = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i < n; i++)
{
Console.Write("Enter new average " + (i+1) +": ");
Avgs[i] = Convert.ToDouble(Console.ReadLine());
}
for (int i = 0; i < n - 1; i++)
for (int j = i+1; j < n; j++)
if (Avgs[i] < Avgs[j])
{
double t = Avgs[i];
Avgs[i] = Avgs[j];
Avgs[j] = t;
}
for (int j = 0; j < n; j++)
Console.WriteLine("Average " + (j+1) + ": " + Avgs[j]);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 03:02 PM
28- المطلوب إدخال مصفوفة أعداد صحيحة ومن ثم إدخال عنصر ومعرفة كون هذا العنصر موجود أم غير موجود في هذه المصفوفة (من خلال طباعة رسالة وطباعة الـ index):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int []nums= new int[100];
Console.Write("Enter the count of numbers: ");
int size = Convert.ToInt32(Console.ReadLine());
bool found = false;
for (int i = 0; i < size; i++)
{
Console.Write("Enter new vlaue " + (i+1) + ": ");
nums[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Enter the element you want search for it: ");
int elem = Convert.ToInt32(Console.ReadLine());

for (int i = 0; !found && i < size; i++)
if (elem == nums[i])
{
Console.WriteLine("Yes, element is found. And the index is: " + i);
found = true;
}
if (found == false)
Console.WriteLine("No, element is not found.");
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 03:02 PM
29- المطلوب إدخال عناصر صحيحة ومن ثم البحث عن أكبر عنصر في هذه اللائحة، وطباعة مكانه:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int []nums= new int[100];
Console.Write("Enter the count of numbers: ");
int size = Convert.ToInt32(Console.ReadLine());
bool found = false;
for (int i = 0; i < size; i++)
{
Console.Write("Enter new vlaue " + (i+1) + ": ");
nums[i] = Convert.ToInt32(Console.ReadLine());
}
int max= nums[0], index=0;
for (int i = 1; i < size; i++)
if (nums[i] > max)
{
max = nums[i];
index = i;
}
Console.WriteLine("The number is: " + max + ", the index is: " + index);
Console.ReadKey(true);

}
}
}

Executioner
01-03-2008, 03:03 PM
30- المطلوب إدخال لائحة من العناصر وفرزها فرز تصاعدي ومن ثم تطبيق خوارزمية البحث الثنائي (بالإضافة إلى ذلك عداد لنعرف كم مرة دخل في الحلقة):

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int []numbers= new int[100];
Console.WriteLine("Enter count os numbers: ");
int size= Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
Console.Write("Enter new element: ");
numbers[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("The matrix before farez.");
for (int i = 0; i < size; i++)
Console.WriteLine("element[" + i + "]: " + numbers[i]);
for (int i=0; i<size-1; i++)
for (int j=i+1; j<size; j++)
if (numbers[i] > numbers[j])
{
int t = numbers[i];
numbers[i] = numbers[j];
numbers[j] = t;
}
Console.WriteLine("The matrix After farez.");
for (int i = 0; i < size; i++)
Console.WriteLine("element[" + i + "]: " + numbers[i]);
Console.Write("Enter the number you want to serch of it: ");
int element = Convert.ToInt32(Console.ReadLine());

int loop = 0; // count.
int High = size - 1, Low= 0, Mid= (High+Low)/2;
bool found = false;
while (!found && High >= Low)
{
Mid= (High+Low)/2;
loop++;
if (numbers[Mid] == element)
{
found = true;
Console.WriteLine("dsfsdfsd");
}
else
if (numbers[Mid] < element)
Low = Mid + 1;
else
High = Mid - 1;
}
if (!found)
Console.WriteLine("Element is not found");
else
{
Console.WriteLine("Element is found.");
Console.WriteLine("Index of found element: " + Mid);
}
Console.WriteLine("The number of the loop: " + loop);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 03:03 PM
31- المطلوب إدخال اسم n طالب و r علامة لكل طالب (بشرط عند الإدخال نكتب الاسم ومن العلامات لكل طالب) وطباعة اسم الطالب ومن ثم في السطر الثاني علاماته ومن ثم في السطر التالي معدله لكل طالب (مع فرز حسب المعدل تنازليا) هذه هي المصفوفات ثنائية البعد:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int [,]Marks= new int[100,100];
string []Names= new string[100];
int CountStudents=0, CountMarks=0; // n, r
Console.Write("Enter Count Students: ");
CountStudents = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Count Marks: ");
CountMarks = Convert.ToInt32(Console.ReadLine());
double []Avgs= new double[100];

for (int i = 0; i < CountStudents; i++)
{
Console.WriteLine("Enter new name: ");
Names[i] = Console.ReadLine();
for (int j = 0; j < CountMarks; j++)
{
Console.WriteLine("Enter new mark: ");
Marks[i,j] = Convert.ToInt32(Console.ReadLine());
Avgs[i] += Marks[i,j];
}
Avgs[i]= Avgs[i]/CountMarks;
}

for (int i=0; i<CountStudents-1; i++)
for (int j=i+1; j<CountStudents; j++)
if (Avgs[i] < Avgs[j])
{
double t1 = Avgs[i];
Avgs[i] = Avgs[j];
Avgs[j] = t1;
string t2= Names[i];
Names[i] = Names[j];
Names[j] = t2;
int t3 = 0;
for (int t = 0; t < CountMarks; t++)
{
t3= Marks[i,t];
Marks[i, t] = Marks[j, t];
Marks[j, t] = t3;
}
}

for (int i = 0; i < CountStudents; i++)
{
Console.WriteLine("The name is: " + Names[i]);
Console.Write("Marks is: " + Marks[i,0]);
for (int j = 1; j < CountMarks; j++)
Console.Write(", " + Marks[i,j]);
Console.WriteLine("");
Console.WriteLine("The Average is: " + Avgs[i]);
}
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:35 PM
32- المطلوب برنامج ندخل فيه مصفوفة أرقام صحيحة ونقوم بعد ذلك بإقحام عدد بعد أن نحدد له المكان المطلوب (خوارزمية الإقحام):

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int []a= new int[100];
Console.Write("Enter the count of matrix: ");
int size = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
Console.WriteLine("Enter new element: ");
a[i]= Convert.ToInt32(Console.ReadLine());
}

Console.Write("Enter the index: ");
int index = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the element: ");
int element = Convert.ToInt32(Console.ReadLine());
size++;
for (int i = size - 1; i > index; i--)
a[i] = a[i-1];
a[index]= element;
for (int i = 0; i < size; i++)
Console.WriteLine("element[" + i + "]: " + a[i]);

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:36 PM
33- المطلوب برنامج ندخل فيه مصفوفة أرقام صحيحة ونقوم بعد ذلك بإدخال عدد فيبحث إذا ما كان موجودا ويحذفه ويطبع رسالة في حال وجودة (مع طباعة المصفوفة) أو عدم وجوده (خوارزمية الحذف):

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int []a= new int[100];
Console.Write("Enter the count of matrix: ");
int size = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
Console.WriteLine("Enter new element: ");
a[i]= Convert.ToInt32(Console.ReadLine());
}

Console.Write("Enter the element you want to serch of it and delete it: ");
int element = Convert.ToInt32(Console.ReadLine());
int index = -1;
for (int i = 0; i < size; i++)
if (element == a[i])
{
index = i;
break;
}
if (index == -1)
Console.WriteLine("The elememt is not found");
else
{
Console.WriteLine("The elememt is found");
for (int i = index; i <= size - 1; i++)
a[i] = a[i+1];
size--;
for (int i = 0; i < size; i++)
Console.WriteLine("Element [" + i + "]: " + a[i]);
}
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:37 PM
34- المطلوب إدخال مجموعة من الأعداد مفروزة تصاعديا ومن ثم إدخال عنصر جديد نقوم بوضعه في المكان الصحيح (الفرز بالإقحام) وطباعة المصفوفة قبل وبعد ذلك:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int []a= new int[100];
Console.Write("Enter the count of matrix: ");
int size = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
Console.WriteLine("Enter new element: ");
a[i]= Convert.ToInt32(Console.ReadLine());
}

Console.Write("Enter the element you want to insert: ");
int element = Convert.ToInt32(Console.ReadLine());
int index = -1;
for (int i = 0; i < size; i++)
if (element < a[i])
{
index = i;
break;
}
size++;
if (index == -1)
index = size - 1;
for (int i = size-1; i >index; i--)
a[i] = a[i-1];
a[index] = element;
for (int i = 0; i < size; i++)
Console.WriteLine("Element [" + i + "]: " + a[i]);

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:39 PM
35- الطلوب كتابة فقط كيفية طباعة القطر الرئيسي ضمن مصفوفة والقطر الثانوي (جميع أنواع الحلول مع تحديد الأفضل):


for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i==j)
Console.WriteLine(a[i, j]);

int j = 0;
for (int i = 0; i < n; i++)
{
Console.WriteLine(a[i, j]);
j++;
}

for (int i = 0; i < n; i++)
Console.WriteLine(a[i,i]);


الطريقة الأفضل هي السفلى ثم الأعلى ثم الأعلى.
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i+j == n- 1)
Console.WriteLine(a[i,j]);

for (int i = 0; i < n; i++)
{
int j= n-i-1;
Console.WriteLine(a[i, j]);
}

for (int i = 0; i < n; i++)
Console.WriteLine(a[i,n-i-1]);



الطريقة الأفضل هي السفلى ثم الأعلى ثم الأعلى.

Executioner
01-03-2008, 04:39 PM
36- المطلوب إدخال أعداد صحيحة ضمن مصفوفة ثنائية البعد (مربعة) وطباعة سحرية إذا كانت سحرية، وإذا كانت غير سحرية طباعة ليست سحرية:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double [,]Magic= new double[100,100];
int i=0, j=0, n=0;
Console.Write("Enter the size of array: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
{
Console.WriteLine("Enter new element:");
Magic[i,j]=Convert.ToInt32(Console.ReadLine());
}
bool IsMagic = true;
double Sum1 = 0;
double Sum2 = 0;
for (i = 0; i < n; i++)
Sum1+= Magic[0,i];
i = 1;
while (IsMagic && i < n)
{
Sum2 = 0;
for (j = 0; j < n; j++)
Sum2 += Magic[i, j];
if (Sum1 != Sum2)
IsMagic = false;
i++;
}
if (IsMagic)
{
j = 0;
while (IsMagic && j < n)
{
Sum2 = 0;
for (i = 0; i < n; i++)
Sum2 += Magic[i, j];
IsMagic = Sum1==Sum2;
j++;
}
}
if (IsMagic)
{
Sum2 = 0;
for (int k = 0; k < n; k++)
Sum2 += Magic[k, k];
IsMagic = Sum2 == Sum1;
}
if (IsMagic)
Console.WriteLine("This Array Is Magic.");
else
Console.WriteLine("This Array Is Not Magic.");

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:40 PM
37- عدة توابع واستخدامها (تابع يرد القيمة الأكبر بين اثنتين، تابع يقوم بالجمع بين عددين، تابع يحسب لنا قسمة عدد على آخر، تابع يقوم بطباعة مصفوفة، تابع يجمع عناصر مصفوفة، تابع يقوم بقراءة مصفوفة):

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static int GetBig(int x, int y)
{
if (x > y)
return x;
return y;
}
static int GetSum(int x, int y)
{
return x + y;
}
static double GetDivide(int x, int y)
{
if (y != 0)
return x / y;
return 0;
}
static void PrintArray(int []a)
{
Console.WriteLine("The array is:");
for (int i = 0; i < a.Length; i++)
Console.WriteLine(a[i]);
}
static int GetSumArray(int []a)
{
int count=0;
for (int i = 0; i < a.Length; i++)
count += a[i];
return count;
}
static void ReadArray(ref int[] a)
{
Console.WriteLine("Read array:");
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine("Enter new value:");
a[i]= Convert.ToInt32(Console.ReadLine());
}
}
static void Main(string[] args)
{
int x = 7, y = 5;
Console.WriteLine("The Big Is: " + GetBig(x,y));
Console.WriteLine("The Big Is: " + GetSum(x, y));
Console.WriteLine("The Big Is: " + GetDivide(x, y));

int []a= {3,5,7,9,6,5};
PrintArray(a);
ReadArray(ref a);
Console.WriteLine("The Sum Of Array Is: " + GetSumArray(a));
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:41 PM
38- ملاحظة حول التحميل الزائد:

التحميل الزائد:
إما من خلال عدد المتحولات، مثال:

static int Name(int x1, int x2) { .. .. ...}
static int Name(int x1, int x2, int x3) { .. .. ...}
أو من خلال إختلاف الأنماط، مثال:

static float Name(int x1, int x2) { .. .. ...}
static float Name(float x1, float x2) { .. .. ...}أما حالة ما يرده التابع فهذا أمر غير صحيح لأنه لن يتمكن من التفريق بينهما، مثال:

static int Name(int x1, int x2) { .. .. ...}
static float Name(int x1, int x2) { .. .. ...}

Executioner
01-03-2008, 04:41 PM
39- المطلوب تصميم تابع لحساب عدد الكلمات في سلسلة محرفية:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static int CountWords(string str)
{
int count = 0;
if (str[0]!=' ')
count++;
for (int i = 1; i < str.Length; i++)
if (str[i] != ' ' && str[i - 1] == ' ')
count++;
return count;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine(); ;
Console.WriteLine("Count Of Words: " + CountWords(str));

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:42 PM
40- المطلوب تصميم تابع لحساب عدد تكرار حرف A في سلسلة محرفية:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static int CountA(string str)
{
int count = 0;
for (int i = 1; i < str.Length; i++)
if (str[i]=='a' || str[i]=='A')
count++;

return count;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine(); ;
Console.WriteLine("Count Of A: " + CountA(str));

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:42 PM
41- المطلوب تصميم تابع يقوم بتحويل الحرف الأول من كل كلمة إلى كبير في سلسلة محرفية ويجعل بقية الحروف صغيرة:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Change(ref string str)
{
string str1 = "";
char ch= 'v';
int count = 0;
if (str[0]>='a' && str[0]<='z')
{
ch= str[0];
ch= (char)(ch-32);
str1 += ch.ToString();
}
for (int i = 1; i < str.Length; i++)
{
if (str[i]!=' ' && str[i-1]==' ' && str[i] >= 'a' && str[i] <= 'z')
{
ch = str[i];
ch = (char)(ch - 32);
str1 += ch.ToString();
}
else
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
ch = str[i];
ch = (char)(ch + 32);
str1 += ch.ToString();
}
else
{
ch = str[i];
str1 += ch.ToString();
}
}
}
str = str1;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine();
Change(ref str);
Console.WriteLine("The string become: " + str);

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:43 PM
42- المطلوب تصميم تابع لحساب تردد كل الأحرف الكبيرة في سلسلة محرفية:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static int CountCL(string str)
{
int count = 0;
for (int i = 1; i < str.Length; i++)
if (str[i] >='A' && str[i]<='Z')
count++;
return count;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine(); ;
Console.WriteLine("Count Of Capital Letter: " + CountCL(str));

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:44 PM
43- المطلوب تصميم تابع يشفر سلسلة محرفية بتحويل كل حرف أبجدي إلى الذي يليه وكل رقم إلى الذي يلي يليه وكل رمز يبقى كما هو:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void InCode(ref string str)
{
string str1= "";
char ch= 'a';
for (int i=0; i<str.Length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z')
{
if (str[i] == 'z' || str[i] == 'Z')
{
ch = (char)(str[i] -25);
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] + 1);
str1 += ch.ToString();
}
}
else if (str[i] >= '0' && str[i] <= '9')
{
if (str[i] == '9')
{
ch = '1';
str1 += ch.ToString();
}
else if (str[i] == '8')
{
ch = '0';
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] + 2);
str1 += ch.ToString();
}
}
else
{
ch = (char)(str[i]);
str1+= ch.ToString();
}
}
str = str1;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine(); ;
InCode(ref str);
Console.WriteLine("The string become: " + str);

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:44 PM
44- المطلوب تصميم تابع يفك تشفير السلسلة السابقة:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void DeCode(ref string str)
{
string str1= "";
char ch= 'a';
for (int i=0; i<str.Length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z')
{
if (str[i] == 'a' || str[i] == 'A')
{
ch = (char)(str[i] +25);
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] - 1);
str1 += ch.ToString();
}
}
else if (str[i] >= '0' && str[i] <= '9')
{
if (str[i] == '0')
{
ch = '8';
str1 += ch.ToString();
}
else if (str[i] == '1')
{
ch = '9';
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] - 2);
str1 += ch.ToString();
}
}
else
{
ch = (char)(str[i]);
str1+= ch.ToString();
}
}
str = str1;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine(); ;
DeCode(ref str);
Console.WriteLine("The string become: " + str);

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:45 PM
45- المطلوب استخدام التابعين السابقين في برنامج واحد:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void InCode(ref string str)
{
string str1 = "";
char ch = 'a';
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z')
{
if (str[i] == 'z' || str[i] == 'Z')
{
ch = (char)(str[i] - 25);
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] + 1);
str1 += ch.ToString();
}
}
else if (str[i] >= '0' && str[i] <= '9')
{
if (str[i] == '9')
{
ch = '1';
str1 += ch.ToString();
}
else if (str[i] == '8')
{
ch = '0';
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] + 2);
str1 += ch.ToString();
}
}
else
{
ch = (char)(str[i]);
str1 += ch.ToString();
}
}
str = str1;
}
static void DeCode(ref string str)
{
string str1= "";
char ch= 'a';
for (int i=0; i<str.Length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z')
{
if (str[i] == 'a' || str[i] == 'A')
{
ch = (char)(str[i] +25);
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] - 1);
str1 += ch.ToString();
}
}
else if (str[i] >= '0' && str[i] <= '9')
{
if (str[i] == '0')
{
ch = '8';
str1 += ch.ToString();
}
else if (str[i] == '1')
{
ch = '9';
str1 += ch.ToString();
}
else
{
ch = (char)(str[i] - 2);
str1 += ch.ToString();
}
}
else
{
ch = (char)(str[i]);
str1+= ch.ToString();
}
}
str = str1;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine();

Console.WriteLine();
Console.WriteLine("The string before incoding: ");
Console.WriteLine(str);

Console.WriteLine();
InCode(ref str);
Console.WriteLine("The string after incoding: ");
Console.WriteLine(str);

Console.WriteLine();
DeCode(ref str);
Console.WriteLine("The string after dncoding: ");
Console.WriteLine(str);

Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:45 PM
46- المطلوب تصميم تابع يضع بدلا من كل مجموعة فراغات (2 أو أكثر) الحرف "A" في سلسلة محرفية:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Change(ref string str) // must ref string not string ref.
{
bool p = true;
string str1= "";
for (int i = 0; i < str.Length; i++)
{
if (str[i] == ' ')
{
if (p == true && i != str.Length - 1)
{
if (str[i + 1] == ' ')
{
p = false;
str1 += "A";
}
else
{
str1 += str[i].ToString();
}
}
}
else
{
str1 += str[i].ToString();
p = true;
}
}
str = str1;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line:");
string str= Console.ReadLine();
Change(ref str);
Console.WriteLine("Become: " + str);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:46 PM
47- المطلوب تصميم تابع يحذف كل مجموعة فراغات (2 أو أكثر) من سلسلة محرفية:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Change(ref string str) // must ref string not string ref.
{
bool p = true;
string str1= "";
for (int i = 0; i < str.Length; i++)
{
if (str[i] == ' ')
{
if (p == true && i!=str.Length-1)
{
if (str[i + 1] == ' ')
{
p = false;
//str1 += "A";
}
else
{
str1 += str[i].ToString();
}
}
}
else
{
str1 += str[i].ToString();
p = true;
}
}
str = str1;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line:");
string str= Console.ReadLine();
Change(ref str);
Console.WriteLine("Become: " + str);
Console.ReadKey(true);
}
}
}

Executioner
01-03-2008, 04:46 PM
48- التحويل من نظام العد الثنائي إلى نظام العد الست عشري:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string number;
Console.WriteLine("Enter the number: ");
number = Console.ReadLine();
int i = number.Length - 1;
string str2 = "";
while (i >= 0)
{
string str = "";
if (i / 3 >= 1)
str = number.Substring(i - 3, 4);
else
str = number.Substring(i - i % 3, i % 3 + 1);
/*if (i >= 3)
str = number.Substring(i - 3, 4);
else
if (i == 2)
str = number.Substring(i - 2, 3);
else
if (i == 1)
str = number.Substring(i - 1, 2);
else
if (i == 0)
str = number.Substring(i, 1);*/
switch (Convert.ToInt16(str))
{
case 0: str2 = str2 + '0'; break;
case 1: str2 = str2 + '1'; break;
case 10: str2 = str2 + '2'; break;
case 11: str2 = str2 + '3'; break;
case 100: str2 = str2 + '4'; break;
case 101: str2 = str2 + '5'; break;
case 110: str2 = str2 + '6'; break;
case 111: str2 = str2 + '7'; break;
case 1000: str2 = str2 + '8'; break;
case 1001: str2 = str2 + '9'; break;
case 1010: str2 = str2 + 'A'; break;
case 1011: str2 = str2 + 'B'; break;
case 1100: str2 = str2 + 'C'; break;
case 1101: str2 = str2 + 'D'; break;
case 1110: str2 = str2 + 'E'; break;
case 1111: str2 = str2 + 'F'; break;
default: break;
}
i = i - 4;
}
Console.Write("The result is: (" + number + ")2 ------> (");
for (i = str2.Length - 1; i >= 0; i--) // 5#
Console.Write(str2[i]);
Console.WriteLine(")16");
Console.Read();
}
}
}

Executioner
01-03-2008, 04:47 PM
49- التحويل من نظام العد الثنائي إلى نظام العد الثماني:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string number;
Console.WriteLine("Enter the number: ");
number = Console.ReadLine();
int i = number.Length - 1;
string str2 = "";
while (i >= 0)
{
string str = "";
if (i/2>=1)
str = number.Substring(i - 2, 3);
else
str = number.Substring(i - i%2, i%2+1);
switch (Convert.ToInt16(str))
{
case 0: str2 = str2 + '0'; break;
case 1: str2 = str2 + '1'; break;
case 10: str2 = str2 + '2'; break;
case 11: str2 = str2 + '3'; break;
case 100: str2 = str2 + '4'; break;
case 101: str2 = str2 + '5'; break;
case 110: str2 = str2 + '6'; break;
case 111: str2 = str2 + '7'; break;
default: break;
}
i = i - 3;
}
Console.Write("The result is: (" + number + ")2 -----> (");
for (i = str2.Length - 1; i >= 0; i--) // 5#
Console.Write(str2[i]);
Console.WriteLine(")8");
Console.Read();
}
}
}

Executioner
01-03-2008, 04:48 PM
السلام عليكم وحمة الله وبركاته:

بداية سلام خاص إلى أميــــ الرومانسية ـــــــر ;)

ثانيا أرجو أن تكونوا قد استفدتم من هذه البرامج.

وأرجو ممن لديه طرق أخرى أفضل من الموجودة إدراجها مع ذكر رقم البرنامج (فقط).

وأخيرا إن هذا الموضوع سيضاف إليه برامج أخرى للذين يريدون البرامج فكونوا على إطلاع.

وبعون الله إذا لحقت سيكون هناك برامج حول الكلاسات ... الوراثة ... الملفات ... معالجة الأخطاء .... وأخيرا لعبة.

وكما قلت حسب ما لحق.

والله يوفقنا ويوفقكم.

So SAD
01-03-2008, 07:43 PM
لك روح الله يوفقك
وانشالله بتلحق كل شي وبتجيب اعلى العلامات
ومن شان الكلاسات ... الوراثة ... الملفات ... معالجة الأخطاء
يا ريت تحطلنا عنها لو انو برنامج واحد لك وحدة
امرك لله وانشالله هل الشي ما بيأثر على دراستك
لانو هل البرامج يلي حطيتها كتير كتير عم تساعدني
مكشور كتير

amer-ab
01-04-2008, 06:34 AM
one 100000000000000000000000000 thank you

Executioner
01-04-2008, 06:46 AM
50- التحويل من نظام العد الثنائي إلى نظام العد العشري:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number: ");
string str = Console.ReadLine();
double sum = 0;
for (int i = str.Length-1; i>=0 ; i--)
if (str[i] == '1')
sum += Math.Pow(2,str.Length-i-1);
Console.Write("The result is: (" + str + ")2 -----> (" + sum + ")10");
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:47 AM
51- التحويل من نظام العد الثنائي إلى (8 أو 16 أو 10):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Get10(string str)
{
double sum = 0;
for (int i = str.Length - 1; i >= 0; i--)
if (str[i] == '1')
sum += Math.Pow(2, str.Length - i - 1);
Console.Write("The result is: (" + str + ")2 -----> (" + sum + ")10");
}
static void Get8(string number)
{
int i = number.Length - 1;
string str2 = "";
while (i >= 0)
{
string str = "";
if (i / 2 >= 1)
str = number.Substring(i - 2, 3);
else
str = number.Substring(i - i % 2, i % 2 + 1);
switch (Convert.ToInt16(str))
{
case 0: str2 = str2 + '0'; break;
case 1: str2 = str2 + '1'; break;
case 10: str2 = str2 + '2'; break;
case 11: str2 = str2 + '3'; break;
case 100: str2 = str2 + '4'; break;
case 101: str2 = str2 + '5'; break;
case 110: str2 = str2 + '6'; break;
case 111: str2 = str2 + '7'; break;
default: break;
}
i = i - 3;
}
Console.Write("The result is: (" + number + ")2 -----> (");
for (i = str2.Length - 1; i >= 0; i--)
Console.Write(str2[i]);
Console.WriteLine(")8");
}
static void Get16(string number)
{
int i = number.Length - 1;
string str2 = "";
while (i >= 0)
{
string str = "";
if (i / 3 >= 1)
str = number.Substring(i - 3, 4);
else
str = number.Substring(i - i % 3, i % 3 + 1);
switch (Convert.ToInt16(str))
{
case 0: str2 = str2 + '0'; break;
case 1: str2 = str2 + '1'; break;
case 10: str2 = str2 + '2'; break;
case 11: str2 = str2 + '3'; break;
case 100: str2 = str2 + '4'; break;
case 101: str2 = str2 + '5'; break;
case 110: str2 = str2 + '6'; break;
case 111: str2 = str2 + '7'; break;
case 1000: str2 = str2 + '8'; break;
case 1001: str2 = str2 + '9'; break;
case 1010: str2 = str2 + 'A'; break;
case 1011: str2 = str2 + 'B'; break;
case 1100: str2 = str2 + 'C'; break;
case 1101: str2 = str2 + 'D'; break;
case 1110: str2 = str2 + 'E'; break;
case 1111: str2 = str2 + 'F'; break;
default: break;
}
i = i - 4;
}
Console.Write("The result is: (" + number + ")2 ------> (");
for (i = str2.Length - 1; i >= 0; i--)
Console.Write(str2[i]);
Console.WriteLine(")16");
}
static void Main(string[] args)
{
Console.Write("Enter the number: ");
string str = Console.ReadLine();
int sys = 0;
do {
Console.Write("Enter the system you want convert to it: ");
sys = Convert.ToInt32(Console.ReadLine());
} while (sys != 8 && sys != 10 && sys != 16);
if (sys == 10)
Get10(str);
else if (sys == 8)
Get8(str);
else Get16(str);
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:47 AM
52- التحويل من نظام العد الثماني إلى نظام العد العشري:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Get10(string str)
{
double sum = 0;
for (int i = str.Length - 1; i >= 0; i--)
sum += (str[i]-48) * Math.Pow(8, str.Length - i - 1);
Console.Write("The result is: (" + str + ")8 -----> (" + sum + ")10");
}
static void Main(string[] args)
{
Console.Write("Enter the number: ");
string str = Console.ReadLine();
Get10(str);
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:48 AM
53- التحويل من نظام العد الست عشري إلى نظام العد العشري:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Get10(string str)
{
double sum = 0;
for (int i = str.Length - 1; i >= 0; i--)
if (str[i]>='A' || str[i]>='a')
{
if (str[i]>='a')
sum += (str[i]-55-32) * Math.Pow(16, str.Length - i - 1);
else
sum += (str[i]-55) * Math.Pow(16, str.Length - i - 1);
}
else
sum += (str[i]-48) * Math.Pow(16, str.Length - i - 1);
Console.Write("The result is: (" + str + ")16 -----> (" + sum + ")10");
}
static void Main(string[] args)
{
Console.Write("Enter the number: ");
string str = Console.ReadLine();
Get10(str);
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:48 AM
54- التحويل من أي نظام عد إلى أي نظام عد (2 أو 8 أو 10 أو 16) -----> (2 أو 8 أو 10 أو 16):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void FromAnyOneTo10(string str, int sys)
{
double sum = 0;
for (int i = str.Length - 1; i >= 0; i--)
if (str[i]>='A' || str[i]>='a')
{
if (str[i]>='a')
sum += (str[i]-55-32) * Math.Pow(sys, str.Length - i - 1);
else
sum += (str[i]-55) * Math.Pow(sys, str.Length - i - 1);
}
else
sum += (str[i]-48) * Math.Pow(sys, str.Length - i - 1);
Console.Write("The result is: (" + str + ")" + sys + " -----> (" + sum + ")10");
}
static void From10ToAnyOne(string str, int sys)
{
int Dec = Convert.ToInt32(str);
Console.Write("The result is: (" + Dec + ")10 -----> (");
int[] Bin = new int[100];
int size = 0;
while (Dec > sys - 1)
{
Bin[size] = Dec % sys;
Dec = Dec / sys;
size++;
}
Bin[size] = Dec;
for (int i = size; i >= 0; i--)
{
if (Bin[i] >= 0 && Bin[i] <= 9)
Console.Write(Bin[i]);
else
Console.Write((char)(Bin[i] + 55));
}
Console.WriteLine(")" + sys);
}
static string From2To16(string number)
{
int i = number.Length - 1;
string str2 = "";
while (i >= 0)
{
string str = "";
if (i / 3 >= 1)
str = number.Substring(i - 3, 4);
else
str = number.Substring(i - i % 3, i % 3 + 1);
switch (Convert.ToInt16(str))
{
case 0: str2 = str2 + '0'; break;
case 1: str2 = str2 + '1'; break;
case 10: str2 = str2 + '2'; break;
case 11: str2 = str2 + '3'; break;
case 100: str2 = str2 + '4'; break;
case 101: str2 = str2 + '5'; break;
case 110: str2 = str2 + '6'; break;
case 111: str2 = str2 + '7'; break;
case 1000: str2 = str2 + '8'; break;
case 1001: str2 = str2 + '9'; break;
case 1010: str2 = str2 + 'A'; break;
case 1011: str2 = str2 + 'B'; break;
case 1100: str2 = str2 + 'C'; break;
case 1101: str2 = str2 + 'D'; break;
case 1110: str2 = str2 + 'E'; break;
case 1111: str2 = str2 + 'F'; break;
default: break;
}
i = i - 4;
}
Console.Write("The result is: (" + number + ")2 ------> (");
for (i = str2.Length - 1; i >= 0; i--) // 5#
Console.Write(str2[i]);
Console.WriteLine(")16");
return str2;
}
static string From2To8(string number)
{
int i = number.Length - 1;
string str2 = "";
while (i >= 0)
{
string str = "";
if (i / 2 >= 1)
str = number.Substring(i - 2, 3);
else
str = number.Substring(i - i % 2, i % 2 + 1);
switch (Convert.ToInt16(str))
{
case 0: str2 = str2 + '0'; break;
case 1: str2 = str2 + '1'; break;
case 10: str2 = str2 + '2'; break;
case 11: str2 = str2 + '3'; break;
case 100: str2 = str2 + '4'; break;
case 101: str2 = str2 + '5'; break;
case 110: str2 = str2 + '6'; break;
case 111: str2 = str2 + '7'; break;
default: break;
}
i = i - 3;
}
Console.Write("The result is: (" + number + ")2 -----> (");
for (i = str2.Length - 1; i >= 0; i--)
Console.Write(str2[i]);
Console.WriteLine(")8");
return str2;
}
static string From16To2(string str)
{
string str1 = "";
for (int i = 0; i < str.Length; i++)
{
char ch = str[i];
switch (ch)
{
case '0': str1 += "0000"; break;
case '1': str1 += "0001"; break;
case '2': str1 += "0010"; break;
case '3': str1 += "0011"; break;
case '4': str1 += "0100"; break;
case '5': str1 += "0101"; break;
case '6': str1 += "0110"; break;
case '7': str1 += "0111"; break;
case '8': str1 += "1000"; break;
case '9': str1 += "1001"; break;
case 'A':
case 'a': str1 += "1010"; break;
case 'B':
case 'b': str1 += "1011"; break;
case 'C':
case 'c': str1 += "1100"; break;
case 'D':
case 'd': str1 += "1101"; break;
case 'E':
case 'e': str1 += "1110"; break;
case 'F':
case 'f': str1 += "1111"; break;
default: break;
}
}
Console.WriteLine("The result is: (" + str + ")16 -----> (" + str1 + ")2");
return str1;
}
static string From8To2(string str)
{
string str1 = "";
for (int i = 0; i<str.Length; i++)
{
char ch = str[i];
switch (ch)
{
case '0': str1 += "000"; break;
case '1': str1 += "001"; break;
case '2': str1 += "010"; break;
case '3': str1 += "011"; break;
case '4': str1 += "100"; break;
case '5': str1 += "101"; break;
case '6': str1 += "110"; break;
case '7': str1 += "111"; break;
default: break;
}
}
Console.WriteLine("The result is: (" + str + ")8 -----> (" + str1 + ")2");
return str1;
}
static void From8To16(string str)
{
string str1 = From8To2(str);
string str2 = From2To16(str1);
Console.Write("The result is: (" + str + ")8 -----> (");
for (int i=str2.Length-1; i>=0; i--)
Console.Write(str2[i]);
Console.WriteLine(")16");
}
static void From16To8(string str)
{
string str1 = From16To2(str);
string str2 = From2To8(str1);
Console.Write("The result is: (" + str + ")16 -----> (");
for (int i = str2.Length - 1; i >= 0; i--)
Console.Write(str2[i]);
Console.WriteLine(")8");
}
static void Main(string[] args)
{
int sys1 = 0, sys2 = 0;
do {
Console.Write("Enter sys1: ");
sys1 = Convert.ToInt32(Console.ReadLine());
} while(sys1!=2 && sys1!=8 && sys1!=10 && sys1!=16);
Console.Write("Enter the number: ");
string str = Console.ReadLine();
do {
Console.Write("Enter sys2: ");
sys2 = Convert.ToInt32(Console.ReadLine());
} while (sys2 != 2 && sys2 != 8 && sys2 != 10 && sys2 != 16 || sys2==sys1);
if (sys2 == 10)
FromAnyOneTo10(str, sys1);
else if (sys1 == 10)
From10ToAnyOne(str, sys2);
else if (sys1 == 2 && sys2 == 16)
From2To16(str);
else if (sys1 == 2 && sys2 == 8)
From2To8(str);
else if (sys1 == 16 && sys2 == 2)
From16To2(str);
else if (sys1 == 8 && sys2 == 2)
From8To2(str);
else if (sys1 == 8 && sys2 == 16)
From8To16(str);
else if (sys1 == 16 && sys2 == 8)
From16To8(str);
else Console.WriteLine("Error.");
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:49 AM
55- المطلوب إدخال سلسلة من المحارف تتضمن أقواس بداية ونهاية بحيث يكون لدينا بين كل قوسين سلاسل محرفية تمثل أعدادا بالست عشري والمطلوب حساب مجموع هذه القيم بعد تحويلها إلى نظام العد العشري:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static double Get10(string str)
{
double sum = 0;
for (int i = str.Length - 1; i >= 0; i--)
if (str[i] >= 'A' || str[i] >= 'a')
{
if (str[i] >= 'a')
sum += (str[i] - 55 - 32) * Math.Pow(16, str.Length - i - 1);
else
sum += (str[i] - 55) * Math.Pow(16, str.Length - i - 1);
}
else
sum += (str[i] - 48) * Math.Pow(16, str.Length - i - 1);
return sum;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the line: ");
string str = Console.ReadLine();
double sum=0;
for (int i = 0; i < str.Length; i++)
if (str[i] == '(')
{
string str2 = "";
i++;
while (str[i] != ')' && str[i] != '(' && i < str.Length-1)
{
char ch= (char)str[i];
str2 += ch.ToString();
i++;
}
if (i == str.Length || str[i] == '(')
i--;
if (str[i] == ')')
{
sum += Get10(str2);
}
}
Console.WriteLine("The Sum Is: " + sum);
Console.ReadKey();

}
}
}

Executioner
01-04-2008, 06:50 AM
56- المطلوب حساب عاملي عدد وعكس عاملي هذا العدد:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static int Amely(int x)
{
int sum = 1;
Console.Write("Amely " + x + "= " + x + "! = " + x);
sum *= x;
for (int i = x - 1; i >= 1; i--)
{
Console.Write(" * " + i);
sum *= i;
}
Console.WriteLine(" = " + sum);
return sum;
}
static void UnAmely(int x)
{
int val = 1;
int sum=1;
while (sum != x && sum < x)
{
sum*= val;
val++;
}
if (x == sum)
{
Console.WriteLine("this number (" + x + ") is OK." );
Console.Write(x + "= " + "1");
for (int i = 2; i < val; i++)
Console.Write(" * " + i);
}
else
Console.WriteLine("this number (" + x + ") is not OK.");
}
static void Main(string[] args)
{
UnAmely(Amely(3)+1);
Console.WriteLine();
UnAmely(Amely(6));
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:50 AM
57- طباعة عدد بالمقلوب (عوديا):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void PrintNumber(int x)
{
if (x >= 10)
{
Console.Write(x%10);
PrintNumber(x/10);
}
else
Console.Write(x);
}
static void Main(string[] args)
{
Console.WriteLine("Enter the number: ");
int num= Convert.ToInt32(Console.ReadLine());
PrintNumber(num);
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:51 AM
58- طباعة مصفوفة (عوديا):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void PrintArray(int []x, int i)
{
if (i < x.Length)
{
Console.WriteLine("Element[" + i + "]: " + x[i]);
PrintArray(x,i+1);
}
}
static void Main(string[] args)
{
int[] a = { 2,4,5,89,2,5,8,10};
PrintArray(a,0);
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:51 AM
59- قراءة مصفوفة (عوديا):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void ReadArray(ref int []x, int i)
{
if (i < x.Length)
{
Console.WriteLine("Enter new element: ");
x[i] = Convert.ToInt32(Console.ReadLine());
ReadArray(ref x,i+1);
}
}
static void PrintArray(int[] x, int i)
{
if (i < x.Length)
{
Console.WriteLine("Element[" + i + "]: " + x[i]);
PrintArray(x, i + 1);
}
}
static void Main(string[] args)
{
int[] a = new int[5];
ReadArray(ref a,0);
PrintArray(a, 0);
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:52 AM
61- صنف موظف:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Employee
{
int Id;
string FName;
string LName;
double Salary;
int Age;
public Employee()
{
Id = 0;
FName = "";
LName = "";
Salary = 0;
Age = 0;
}
public Employee(int i, string f, string l, double s, int a)
{
Id = i;
FName = f;
LName = l;
Salary = s;
Age = a;
}
public Employee(Employee e)
{
Id = e.Id;
FName = e.FName;
LName = e.LName;
Salary = e.Salary;
Age = e.Age;
}
public void Read()
{
Console.WriteLine("Enter the Id: ");
Id = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the FName: ");
Console.WriteLine("Enter the LName: ");
Console.WriteLine("Enter the Salary: ");
Salary = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the Age: ");
Age = Convert.ToInt32(Console.ReadLine());
}
public void Print()
{
Console.WriteLine("The Id Is: " + Id);
Console.WriteLine("The FName Is: " + FName);
Console.WriteLine("The LName Is: " + LName);
Console.WriteLine("The Salary Is: "+ Salary);
Console.WriteLine("The Age Is: " + Age);
}
public void ChangeId(int i)
{
Id = i;
}
public void ChangeFName(string i)
{
FName = i;
}
public void ChangeLName(string i)
{
LName = i;
}
public void ChangeSalary(double i)
{
Salary = i;
}
public void ChangeAge(int i)
{
Age = i;
}
public int GetId()
{
return Id;
}
public string GetFName()
{
return FName;
}
public string GetLName()
{
return LName;
}
public double GetSalary()
{
return Salary;
}
public int GetAge()
{
return Age;
}
~Employee()
{
Console.WriteLine("End of object.");
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter count employees: ");
int n= Convert.ToInt32(Console.ReadKey());
Employee []emps= new Employee[n];
for (int i = 0; i < n; i++)
emps[i].Read();
for (int i = 0; i < n; i++)
emps[i].Print();
Console.ReadKey(true);
}
}
}

Executioner
01-04-2008, 06:52 AM
62- صنف يمثل الوقت:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
class Time
{
int H, M, S;
public Time()
{
H = S = M = 1;
}
public Time(int h, int m, int s)
{
Set(h, m, s);
}
public Time(Time t)
{
Set(t);
}
public void SetH(int h)
{
if (h>=1 && h<=24)
H= H;
}
public void SetM(int m)
{
if (m >= 1 && m <= 60)
M= m;
}
public void SetS(int s)
{
if (s >= 1 && s <= 60)
S = s;
}
public void Set(int h, int m ,int s)
{
SetH(h);
SetM(m);
SetS(s);
}
public void Set(Time t)
{
Set(t.H, t.M, t.S);
}
public int ReadH()
{
do {
Console.WriteLine("Enter the hours between 1 - 24: ");
H= Convert.ToInt32(Console.ReadLine());
} while (!(H>=1 && H<=24));
return H;
}
public int ReadM()
{
do {
Console.WriteLine("Enter the miuntes between 1 - 60: ");
M = Convert.ToInt32(Console.ReadLine());
} while (!(M >= 1 && M <= 60));
return M;
}
public int ReadS()
{
do {
Console.WriteLine("Enter the seconds between 1 - 60: ");
S = Convert.ToInt32(Console.ReadLine());
} while (!(S >= 1 && S <= 60));
return S;
}
public void Read()
{
H = ReadH();
M = ReadM();
S = ReadS();
}
public void Print()
{
Console.WriteLine("The value of hours is: " + H);
Console.WriteLine("The value of minutes is: " + M);
Console.WriteLine("The value of seconds is: " + S);
}
~Time()
{
Console.WriteLine("End Of Object.");
}
}
static void Main(string[] args)
{
Time t = new Time();
t.Print();
t.Read();
t.Print();
Console.ReadKey();
}
}
}

Executioner
01-04-2008, 06:53 AM
64- صنف مصفوفة:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class array
{
int[] a = null;
int size;
public array()
{
a = null;
size = 0;
}
public array(int[] a1, int size1)
{
size = size1;
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = a1[i];
}
public array(int size1)
{
size = size1;
a = new int[size];
for (int i = 0; i < size; i++)
{
Console.Write("Enter new element: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void Read()
{
Console.Write("Enter the size of array: ");
size = Convert.ToInt32(Console.ReadLine());
a = new int[size]; // It is important.
for (int i = 0; i < size; i++)
{
Console.Write("Enter new element: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void Print()
{
Console.WriteLine("Size is: " + size);
for (int i = 0; i < size; i++)
Console.WriteLine("element " + (i + 1) + " is: " + a[i]);
}
public void Sort()
{
int temp = 0;
for (int i = 0; i < size - 1; i++)
{
for (int j = i + 1; j < size; j++)
{
if (a[i] > a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
}
~array()
{
Console.WriteLine("End of object.");
}
}
class Program
{
static void Main(string[] args)
{
array a1;
a1 = new array();
a1.Read();
a1.Print();
a1.Sort();
a1.Print();
Console.ReadKey(true);
}
}
}

Executioner
01-04-2008, 06:53 AM
66- وراثة دائرة من نقطة:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public class TPoint
{
int x, y;
public TPoint()
{
x = y = 1;
}
public TPoint(int x1, int y1)
{
x = x1;
y = y1;
}
public TPoint(TPoint p)
{
x = p.x;
y = p.y;
}
public void ReadPoint()
{
Console.WriteLine("Enter value x: ");
x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value y: ");
y = Convert.ToInt32(Console.ReadLine());
}
public void PrintPoint()
{
Console.WriteLine("Tha value of x is: " + x);
Console.WriteLine("Tha value of y is: " + y);
}
public void SetPoint(int x1, int y1)
{
x = x1;
y = y1;
}
public int Getx()
{
return x;
}
public int Gety()
{
return y;
}
public void GetPoint(ref int x1, ref int y1)
{
x1 = x;
y1 = y;
}
~TPoint()
{
Console.WriteLine("End of Point object.");
}
}
public class TCircle : TPoint
{
int d;
public TCircle(): base()
{
d = 1;
}
public TCircle(int x1, int y1, int d1)
: base(x1, y1)
{
d = d1;
}
public TCircle(TCircle c)
: base(c.Getx(), c.Gety())
{
d = c.d;
}
public void ReadCircle()
{
ReadPoint();
Console.WriteLine("Enter value d: ");
d = Convert.ToInt32(Console.ReadLine());
}
public void PrintCircle()
{
PrintPoint();
Console.WriteLine("Tha value of d is: " + d);
}
public void SetCircle(int x1, int y1, int d1)
{
SetPoint(x1, y1);
d = d1;
}
public void GetCircle(ref int x1, ref int y1, ref int d)
{
GetPoint(ref x1, ref y1);
d = this.d;
}
~TCircle()
{
Console.WriteLine("End of Circle object.");
}
}
static void Main(string[] args)
{
TPoint p1 = new TPoint();
TPoint p2 = new TPoint(3, 5);
p1.ReadPoint();
p2.PrintPoint();

TCircle c1 = new TCircle();
TCircle c2 = new TCircle(3, 5, 7);
c1.ReadCircle();
c2.PrintCircle();

Console.ReadKey();

}
}
}

Executioner
01-04-2008, 06:54 AM
67- وراثة طالب من صنف (person):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public class TPerson
{
string Name;
public TPerson()
{
Name = "Mohammad";
}
public TPerson(string n1)
{
Name = n1;
}
public void ReadTPerson()
{
Console.WriteLine("Enter the name:");
Name = Console.ReadLine();
}
public void PrintTPerson()
{
Console.WriteLine("The Name Is: " +
Name);
}
public void SetTPerson(string n1)
{
Name = n1;
}
public void GetTPerson(ref string n1)
{
n1 = Name.Substring(0);
}
~TPerson()
{
Console.WriteLine("End Of TPerson");
}
}
public class TStudent : TPerson
{
double Avg;
public TStudent()
: base()
{
Avg = 0;
}
public TStudent(string n, double avg1)
: base(n)
{
Avg = avg1;
}
public void ReadTStudent()
{
ReadTPerson();
Console.WriteLine("Enter the avg:");
Avg = Convert.ToDouble(Console.ReadLine());
}
public void PrintTStudent()
{
PrintTPerson();
Console.WriteLine("The Avg Is: " +
Avg);
}
public void SetTStudent(string n1, double avg)
{
SetTPerson(n1);
Avg = avg;
}
public void GetTStudent(ref string n1, ref double avg)
{
GetTPerson(ref n1);
avg = Avg;
}
~TStudent()
{
Console.WriteLine("End Of TStudent");
}
}
static void Main(string[] args)
{
TPerson P = new TPerson();
P.ReadTPerson();
P.PrintTPerson();

Console.WriteLine("");
TStudent S = new TStudent("Mohammad Mohammad", 85.8);
S.PrintTStudent();

S.ReadTStudent();
S.PrintTStudent();

Console.ReadKey(true);
}
}
}

Executioner
01-04-2008, 06:54 AM
68- وراثة اسطوانة من دائرة من نقطة:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public class TPoint
{
int x, y;
public TPoint()
{
x = y = 1;
}
public TPoint(int x1, int y1)
{
x = x1;
y = y1;
}
public TPoint(TPoint p)
{
x = p.x;
y = p.y;
}
public void ReadPoint()
{
Console.WriteLine("Enter value x: ");
x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value y: ");
y = Convert.ToInt32(Console.ReadLine());
}
public void PrintPoint()
{
Console.WriteLine("Tha value of x is: " + x);
Console.WriteLine("Tha value of y is: " + y);
}
public void SetPoint(int x1, int y1)
{
x = x1;
y = y1;
}
public int Getx()
{
return x;
}
public int Gety()
{
return y;
}
public void GetPoint(ref int x1, ref int y1)
{
x1 = x;
y1 = y;
}
~TPoint()
{
Console.WriteLine("End of Point object.");
}
}
public class TCircle : TPoint
{
int d;
public TCircle(): base()
{
d = 1;
}
public TCircle(int x1, int y1, int d1)
: base(x1, y1)
{
d = d1;
}
public TCircle(TCircle c)
: base(c.Getx(), c.Gety())
{
d = c.d;
}
public void ReadCircle()
{
ReadPoint();
Console.WriteLine("Enter value d: ");
d = Convert.ToInt32(Console.ReadLine());
}
public void PrintCircle()
{
PrintPoint();
Console.WriteLine("Tha value of d is: " + d);
}
public void SetCircle(int x1, int y1, int d1)
{
SetPoint(x1, y1);
d = d1;
}
public int GetD()
{
return d;
}
public double GetCircleArea()
{
return Math.PI * Math.Pow(d,2);
}
public void GetCircle(ref int x1, ref int y1, ref int d)
{
GetPoint(ref x1, ref y1);
d = this.d;
}
~TCircle()
{
Console.WriteLine("End of Circle object.");
}
}
class TCylinder:TCircle
{
int H;
public TCylinder():base()
{
H = 1;
}
public TCylinder(int x1, int x2, int d1, int h1)
: base(x1, x2, d1)
{
H = h1;
}
public TCylinder(TCylinder c)
: base(c.Getx(),c.Gety(),c.GetD())
{
H = c.H;
}
public void ReadCylinder()
{
ReadCircle();
Console.WriteLine("Enter value H: ");
H = Convert.ToInt32(Console.ReadLine());
}
public void PrintCylinder()
{
PrintCircle();
Console.WriteLine("Tha value of H is: " + H);
}
public void SetCylinder(int x1, int y1, int d1, int h1)
{
SetCircle(x1,y1,d1);
H = h1;
}
public void GetCylinder(ref int x1, ref int y1, ref int d, ref int h)
{
GetCircle(ref x1, ref y1, ref d);
GetPoint(ref x1, ref y1);
h = this.H;
}
public double GetSizeCylinder()
{
return H * GetCircleArea();
}
~TCylinder()
{
Console.WriteLine("End of Cylinder object.");
}
}
static void Main(string[] args)
{
TPoint p1 = new TPoint();
TPoint p2 = new TPoint(3, 5);
p1.ReadPoint();
p2.PrintPoint();

TCircle c1 = new TCircle();
TCircle c2 = new TCircle(3, 5, 7);
c1.ReadCircle();
c2.PrintCircle();
Console.WriteLine("The Area is: " + c2.GetCircleArea());

TCylinder y1 = new TCylinder();
TCylinder y2 = new TCylinder(3,5,7,3);
y1.ReadCylinder();
y2.PrintCylinder();
Console.WriteLine("The Size is: " + y2.GetSizeCylinder());
Console.ReadKey();

}
}
}

Executioner
01-04-2008, 06:55 AM
69- برنامج للتعامل مع الملفات (مجرد تخزين نص في ملف ومن ثم قراءته):

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void WriteInFileFromUser(string Path)
{
StreamWriter w = new StreamWriter(Path);
int ch = 15;
ch = Console.Read();
while ((char)(ch) != '*')
{
w.Write((char)(ch));
ch = Console.Read();
}
w.Close();
}
static void WriteInFileFromMatrix(string Path, string str)
{
StreamWriter w = new StreamWriter(Path);
w.WriteLine(str);
w.Close();
}
static void ReadFromFile(string Path, ref string str)
{
Console.WriteLine("The text is: ");
StreamReader r = new StreamReader(Path);
int i = 0;
str = r.ReadToEnd();
Console.WriteLine(str);
}
static void Main(string[] args)
{
string Path = "C:\\MyFile.txt";
string Path1 = "C:\\MyFile1.txt";
Console.WriteLine("Enter the text: ");
WriteInFileFromUser(Path);
string str = "";
ReadFromFile(Path, ref str);
WriteInFileFromMatrix(Path1, str);
Console.ReadLine();
}
}
}

Executioner
01-04-2008, 06:56 AM
70- إدخال علامات الطالب مع التعامل مع الملفات (مع حساب المعدل ومقارنته مع متوسط المعدلات):

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void ReadMarks(int n1, int n2, ref double [,]Marks)
{
for (int i = 0; i < n1; i++)
{
double temp=0;
Console.WriteLine("Enter the marks of new student [" + (i+1) + "]: ");
for (int j = 0; j < n2; j++)
{
do {
Console.Write("Enter new mark [" + (j+1) + "]: ");
temp = Convert.ToDouble(Console.ReadLine());
} while (!(temp>=0 && temp<=100));
Marks[i, j] = temp;
}
}
}
static void PrintMarks(int n1, int n2, double [,]Marks, double[]Avg, double Avgs)
{
for (int i = 0; i < n1; i++)
{
Console.WriteLine("");
Console.WriteLine("Student [" + (i + 1) + "], The Average is: [" + Avg[i] + "] And his marks is:");
for (int j = 0; j < n2; j++)
Console.WriteLine("Mark [" + (j+1) + "]: " + Marks[i,j]);
if (Avg[i]>Avgs)
Console.WriteLine("The result is: [" + Avg[i] + "] larger than [" + Avgs + "].");
else
if (Avg[i]<Avgs)
Console.WriteLine("The result is: [" + Avg[i] + "] smaller than [" + Avgs + "].");
else
Console.WriteLine("The result is: [" + Avg[i] + "] equal [" + Avgs + "].");
}
}
static void ReadFromFile(int n1, int n2, ref double[,] Marks)
{
StreamReader r = new StreamReader("c:\\Marks.txt");
string []strs= new string[100];
//string str; // must separated tawzeaeee.
for (int i = 0; i < n1; i++)
{
strs= r.ReadLine().Split(' ');
for (int j = 0; j < n2; j++)
Marks[i, j] = Convert.ToDouble(strs[j]);
}
r.Close();
}
static void WriteInFile(int n1, int n2, double [,]Marks)
{
StreamWriter w = new StreamWriter("c:\\Marks.txt");
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n2; j++)
{
w.Write(Marks[i, j]);
w.Write(' ');
}
w.WriteLine();
}
w.Close();
}
static void Average(int n1, int n2, double [,]Marks,
ref double []Avg, ref double Avgs)
{
Avgs= 0;
for (int i=0; i<n1; i++)
{
Avg[i]= 0;
for (int j = 0; j < n2; j++)
{
Avg[i] += Marks[i, j];
Avgs += Marks[i, j];
}
Avg[i] /= n2;
}
Avgs/= n1*n2;
}
static void Main(string[] args)
{
int n1 = 0, n2=0;
Console.Write("Enter Count Of Student: ");
n1= Convert.ToInt16(Console.ReadLine());
Console.Write("Enter Count Of Marks: ");
n2= Convert.ToInt16(Console.ReadLine());
double [,]Marks= new double[100,100];

ReadMarks(n1,n2,ref Marks);
WriteInFile(n1,n2,Marks);
ReadFromFile(n1,n2, ref Marks);

double [] Avg= new double[100];
double Avgs=0;
Average(n1, n2, Marks, ref Avg, ref Avgs);
PrintMarks(n1, n2, Marks, Avg, Avgs);

Console.Read();
}
}
}

Executioner
01-04-2008, 06:56 AM
71- صنف كلمة سر (فيه توابع التشفير ... ... مع ظهور كلمة السر على الشاشة نجوم (****) ....إلخ) طبعا مع التعامل مع الملفات:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
public class LogIn
{
string ps1 = "";
string ps2;
string Path;
StreamReader fin;
StreamWriter fout;
public LogIn()
{
Path = "C:\\ps.txt";
try
{
if (File.Exists(Path))
{
fin = new StreamReader(Path);
try
{
if ((ps1 = fin.ReadLine()) != null)
{
DeCodeString(ref ps1);
}
else
{
ps1 = "ms";
ps2 = "ms"; // it is will store
ChangePassWord();
throw new Exception("Erorr: PassWord Not Found. And we created.");
}
fin.Close();
}
catch (Exception e1)
{
Console.WriteLine(e1.Message);
}
/*finally
{
Console.WriteLine("Finally");
}*/
}
else
{
ps1 = "ms";
ps2 = "ms"; // it is will store
ChangePassWord();
throw new Exception("Erorr: File Not Found. And we created.");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public LogIn(string p1)
{
Path = p1.Substring(0);
try
{
if (File.Exists(Path))
{
fin = new StreamReader(Path);
try
{
if ((ps1 = fin.ReadLine()) != null)
{
DeCodeString(ref ps1);
}
else
{
ps1 = "ms";
ps2 = "ms"; // it is will store
ChangePassWord();
throw new Exception("Erorr: PassWord Not Found.");
}
fin.Close();
}
catch (Exception e1)
{
Console.WriteLine(e1.Message);
}
/*finally
{
Console.WriteLine("Finally");
}*/
}
else
{
ps1 = "ms";
ps2 = "ms"; // it is will store
ChangePassWord();
throw new Exception("Erorr: File Not Found.");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
/*finally
{
Console.WriteLine("Finally");
}*/
}
private char InCode(char ch1)
{
char ch = ch1;
if (ch >= 'a' && ch < 'z' ||
ch >= 'A' && ch < 'Z' ||
ch >= '0' && ch < '9')
return ++ch;
else
if (ch == '9')
return '0';
else if (ch == 'z' || ch == 'Z')
{
ch = Convert.ToChar(ch - 25);
return ch;
}
return ch;
}
private char DeCode(char ch1)
{
char ch = ch1;
if (ch > 'a' && ch <= 'z' ||
ch > 'A' && ch <= 'Z' ||
ch > '0' && ch <= '9')
return --ch;
else
if (ch == '0')
return '9';
else if (ch == 'a' || ch == 'A')
{
ch = Convert.ToChar(ch + 25);
return ch;
}
return ch;
}
public void InCodeString(ref string ps)
{
string temp = "";
for (int i = 0; i < ps.Length; i++)
temp = temp + InCode(ps[i]);
ps = temp;
}
public void DeCodeString(ref string ps)
{
string temp = "";
for (int i = 0; i < ps.Length; i++)
temp = temp + DeCode(ps[i]);
ps = temp;
}
public void ReadPassWordFromFile()
{
fin = new StreamReader(Path);
ps1 = fin.ReadLine();
DeCodeString(ref ps1);
fin.Close();
}
public void ChangePassWord()
{
fout = new StreamWriter(Path);
ps1 = ps2.Substring(0);
InCodeString(ref ps2);
fout.WriteLine(ps2);
fout.Close();
}
public void ReadPassWordFromUser()
{
string temp = "";
Console.WriteLine("Enter the Password");
char ch = 'f';
ch = Console.ReadKey(true).KeyChar;
while (ch != 13)
{
Console.Write("*");
temp = temp + ch.ToString();
ch = Console.ReadKey(true).KeyChar;
}
Console.WriteLine();
if (temp == null)
{
Console.WriteLine("Error In Write PassWord.");
ReadPassWordFromUser();
}
ps2 = temp.Substring(0);
}
public bool CheckPassWord()
{
//Console.WriteLine("ps1: " + ps1);
//Console.WriteLine("ps2: " + ps2);
return ps1.Equals(ps2);
}
~LogIn()
{
Console.WriteLine("End Of Object");
}
}
static int Menu()
{
Console.WriteLine("Enter your choice:");
Console.WriteLine("Enter 1 to enter password and login.");
Console.WriteLine("Enter 2 to change password.");
Console.WriteLine("Enter 3 to exit.");
int choice = Convert.ToInt32(Console.ReadLine());
if (choice > 3 || choice < 1)
{
Console.WriteLine("Error in choice.");
return Menu();
}
return choice;
}
static void Main(string[] args)
{
int choice = 0;
bool ok = false;
LogIn l = new LogIn();
while (choice != 3)
{
choice = Menu();
if (choice == 1)
{
l.ReadPassWordFromUser();
if (l.CheckPassWord())
{
Console.WriteLine("Ok.");
ok = true;
}
else
Console.WriteLine("Not Ok");
}
if (choice == 2)
{
if (ok == true)
{
l.ReadPassWordFromUser();
l.ChangePassWord();
}
else
Console.WriteLine("You can not change password.");
}
if (choice == 3)
Console.WriteLine("Good By.");
}
}
}
}

Executioner
01-04-2008, 06:58 AM
السلام عليكم ورحمة الله وبركاته:

الله يوفقكم جميعاً

المهم:

حاولت أن أختصر قليلا بالتمارين لكي نلحق نصل للزبدة.

ومع ذلك على ما يبدو ما على لحق بقية البرامج (معالجة الأخطاء، .... ) للأسف فأرجو ممن لديه هذه البرامج أن يضعها ولكن يفضل أن يضعها بنفس التنسيق الذي أتبعه.

والله يوفقنا ويوفقكم.

*Islam_Rose*
01-04-2008, 03:17 PM
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
و بعد
أخي في الله
اللهم أن يرزقك فهم النبيين و حفظ المرسلين و سرعة إلهام الملائكة المقربين
اللهم و أن يرزقك سرعة الفهم و نور العلم و أن يخرجك من ظلمات الوهم
اللهم و أن يرزقك النجاح بتفوق لأنك تستحق
و أن يجعلك من عباده العلماء و الصالحين
و الله يوفقك
و ألف شكر
آمين
و السلام عليكم

So SAD
01-04-2008, 03:50 PM
مشكور على البرامج وبتمنى من يلي عندو اي تكملة ما يبخل علينا

snoop
01-05-2008, 03:41 AM
الله يعطيك العافيه ويسلم هل ايدين اومايضوعلك تعب او نشالله تجيب 100 ;)

Golden man
01-05-2008, 04:29 AM
السلام عليكم

و الله شيء رائع يا أستاذنا.
و انا بشكرك لأنك شجعتني بهالتمارين على الدراسة و هلق انا عمعيد حلهن بشكل كامل و لهلق انتهيت من المجموعة الأولى و هيي موجودة بالمرفقات كملف نصي .

و بالنسبة للأفكار المتبقية(معالجة الأخطاء و التعامل مع الخصائص و التعامل مع المفهرسات) كتبت البرامج التالية :

برنامج لمعالجة الأخطاء التي قد تحدث عند فتح ملف:


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Tran
{

class Program
{
static void Main(string[] args)
{
try
{
StreamWriter Sw = new StreamWriter("tk.txt");//لفتح الملف للكتابة دون إغلاقه لرمي استثناء عند محاولة فتحه للقراءة
Sw.Write("hello");
String Str = "";

StreamReader Sr = new StreamReader("tk.txt");
Str = Sr.ReadToEnd();
if(Str == "")
throw(new System.Exception());
Console.WriteLine(Str);
}
catch(FileNotFoundException)//إذا كان الملف غير موجود
{
Console.WriteLine("the file not exist!! . I will create new file .");
File.Create("tk.txt");
}
catch(IOException)//إذا كان الملف مفتوح
{
Console.WriteLine("the file is opened you must close it .");
}
catch//لا يتم تنفيذه إلا إذا حذفنا سطر تعريف مجرى الكتابة و كان الملف فارغا
{
Console.WriteLine("the file is empty.");
}
}
}
}


صنف الموظف مع تطبيق مبدأ الخصائص properties للتعامل مع أعضاء الصنف:


using System;
using System.Collections.Generic;
using System.Text;
namespace TEmployee
{

class Employee
{
int id;
string name;
double salary;
public int Id
{
set
{
id = value;
}
get
{
return id;
}
}
public string Name
{
set
{
if (value == "")
{
Console.Write("Name can't be null enter a name : ");
Name = Console.ReadLine();
}
else
name = value;
}
get
{
return name;
}
}
public double Salary
{
set
{
salary = value;
}
get
{
return salary;
}
}

public void Read()
{
Console.Write("Enter the ID : ");
Id = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the Name : ");
Name = Console.ReadLine();
Console.Write("Enter the Salary : ");
Salary = Convert.ToDouble(Console.ReadLine());
}
public void Write()
{
Console.WriteLine("the ID is : {0}", id);
Console.WriteLine("the Name is : {0}", name);
Console.WriteLine("the Salary : {0}", salary);
}
}
class Program
{
static void Main(string[] args)
{
Employee Emp = new Employee();
Emp.Read();
Emp.Write();
Emp.Name = "";
Emp.Id = 3;
Emp.Write();
Employee[] Arr = new Employee[10];
for (int i = 0; i < 10; i++)
{
Arr[i] = new Employee();//يجب الحجز لكل عنصر في المصفوفة على حدة
Arr[i].Read();
}
}
}


تطبيق فكرة الفهرسة على صنف المصفوفة السابق (الذي كتبته انت في مشاركة سابقة) :


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class array
{
int[] a = null;
int size;
public array()
{
a = null;
size = 0;
}
public array(int[] a1, int size1)
{
size = size1;
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = a1[i];
}
public array(int size1)
{
size = size1;
a = new int[size];
for (int i = 0; i < size; i++)
{
Console.Write("Enter new element: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void Read()
{
Console.Write("Enter the size of array: ");
size = Convert.ToInt32(Console.ReadLine());
a = new int[size]; // It is important.
for (int i = 0; i < size; i++)
{
Console.Write("Enter new element: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void Print()
{
Console.WriteLine("Size is: " + size);
for (int i = 0; i < size; i++)
Console.WriteLine("element " + (i + 1) + " is: " + a[i]);
}
public void Sort()
{
int temp = 0;
for (int i = 0; i < size - 1; i++)
{
for (int j = i + 1; j < size; j++)
{
if (a[i] > a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
}
public int this[int index]
{
set { a[index] = value; }
get { return a[index]; }
}
~array()
{
Console.WriteLine("End of object.");
}
}
class Program
{
static void Main(string[] args)
{
array a1;
a1 = new array();
a1.Read();
a1.Print();
a1.Sort();
a1.Print();
Console.WriteLine("enter the index of element u want to change ");
int i = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter the new value ");
int v = Convert.ToInt16(Console.ReadLine());
a1[i] = v;
a1.Print();
Console.ReadKey(true);
}
}
}

}


أرجو ممن يريد فكرة عن برنامج ما وضعه بهذا الموضوع و سوف يتم الرد عليه بأسرع وقت بإذن الله.

Golden man
01-05-2008, 07:26 AM
هنا حل أحد أسئلة الدورات عن الملفات أظن أنه السنة الماضية:
السؤال :
اكتب برنامجا يقوم بقراءة مجموعة من الأرقام الموجودة في ملف نصي منشأ سابقا على الجذر الرئيسي c:\ اسمه number.txt حيث كل رقم موجود على سطر ثم يقوم بإنشاء ملف نصي آخر باسم complexNumber.txt يتضمن كل سطر فيه على الرقم المقروء و مربعه و أكبر قاسم له يفصل فيما بينهم فراغ:

الحل :

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StreamReader Sr = new StreamReader("C:\\number.txt");
String Str = Sr.ReadToEnd();
String[] StrS = Str.Split('\n');
StreamWriter Sw = new StreamWriter("C:\\complexNumbers.txt");
String StrN = "";
int[] Nums = new int[StrS.Length];
for (int i = 0; i < StrS.Length; i++)
{
Nums[i] = Convert.ToInt16(StrS[i]);
int D = 1;
for(int j=Nums[i]-1 ; j>1 ; j--)
if(Nums[i]%j == 0)
{
D = j;
break;
}
StrN += Nums[i].ToString() + " " + Math.Pow(Nums[i], 2).ToString() + " " + D.ToString() + "\r\n";

}
Console.WriteLine(StrN);
}
}
}

Admin
01-05-2008, 07:33 AM
مشكور
Executioner (http://100hla.com/vb1/member.php?u=88)

ع الجهد الجبار يلي سويتو ...ويظن أنو في كتير استفادو ..وأنا أولهون لأني كنت عم دور ع التمارين ..لأنكون بتعرفو إني ما بحب أكتب ....برد بشكرك كتير وبشكر

Golden man (http://100hla.com/vb1/member.php?u=16)

ع إكمال الموضوع

So SAD
01-05-2008, 09:50 AM
مشكور كتير يا Golden Man
الله لا يحرمنا منك

Golden man
01-05-2008, 09:53 AM
هنا بعض الأسئلة المحلولة و التي أخذتها من صديق عزيز و هي من العام الماضي.

بين نتائج الطباعة والاخطاء مع تصحيح الاخطاء

namespace ConsoleApplication1
{
class test
{
static int x = 0;
void method1()
{
Console.WriteLine("method1");
if (x==0)
throw Exception();
Console.WriteLine("good");

}
void method2()
{
try
{
method1();
Console.WriteLine("method2");
}
finally { Console.WriteLine("finally1"); }
}
static void Main()
{
try
{
method2();
try { Console.WriteLine("try inside try"); }
catch { Console.WriteLine("general1"); }
}
catch (Exception e)
{ Console.WriteLine("catch1"); }

Finally { Console.WriteLine("finally2"); }
catch { Console.WriteLine("general catch"); }
}
}

}

--------------------------------------------------------
*أكتب برنامجاً يقوم بإدخال بيانات مجموعة أشخاص
* ينتمون إلى منتدى يؤمن التدريب على اتقان استثمار لغة البرمجة سي
* علماً أن البيانات تتضمن اسم الشحص وعمره ودرجة تحصيله العلمي ثم يقوم
* البرنامج بمعرفة العدد الكلي للمنتسبين وعدد
* الأشخاص ضمن المنتدى ذوي درجة التحصيل الجامعي أي حاملي الإجازة الجامعية
* وعدد وأسماء الأشخاص ذوي درجة التحصيل الثانوي والذين أعمارهم
* لا تزيد عن 17 عاماً وذلك باستخدام طريقة البرمجة غرضية التوجه
* ملاحظة أنشئ صنفين واحد للشخص واخر للمنتدى
*
*/

using System;
class Person
{
private string name;
private int age;
private int degree; // this must be 1 or 2
public Person(string n, int a, int d)
{
name = n;
age = a;
degree = d;
}
public string GetName()
{ return name; }
public int GetAge()
{ return age; }
public int GetDegree()
{ return degree; }
}
class Meeting
{
private Person[] P = new Person[100];
private int num = 0;
public int GetNum()
{ return num; }
public void Add(Person p1)
{
P[num] = p1;
num++;
}
public int CountOfDegree1()
{
int count = 0;
for (int i = 0; i < num; i++)
{
if (P[i].GetDegree() == 1)
count++;
}
return count;
}
public void CountOfDegree2(string[] names, out int count)
{
int c = 0;
for (int i = 0; i < num; i++)
{
if (P[i].GetDegree() == 2 && P[i].GetAge()<=17)
{
names[c] = P[i].GetName();
c++;
}
}
count = c;
}
}
class Program
{
static void Main()
{
Meeting M = new Meeting();
int number;
Console.Write("Enter Number Of Persons : ");
number = int.Parse(Console.ReadLine());
for (int i = 0; i < number; i++)
{
string name;
int age, degree;
Console.WriteLine("---------------\n" + (i + 1) + " - \n"+
"Name & Age & Degree");
name = Console.ReadLine();
age = int.Parse(Console.ReadLine());
degree = int.Parse(Console.ReadLine());
Person p = new Person(name, age, degree);
M.Add(p);
}
int N1 = M.CountOfDegree1();
Console.WriteLine("Number Of Degree1 Is : " + N1);
string[] Names = new string[100];
int N2;
M.CountOfDegree2(Names, out N2);
Console.WriteLine("Number Of Degree2 Is : " + N2);
for (int j = 0; j < N2; j++)
{
Console.WriteLine(j + 1 + " : " + Names[j]);
}
}
}

--------------------------------------------------------
* سؤال دورة للأستاذ محمود حيدر
* المطلوب رسم أحد الشكلين مثلث أو مستطيل
* باستخدام مفاهيم البرمجة غرضية التوجه
* abstraction <-> encapsulation <-> inheritance <-> polymorphism
*/

using System;
abstract class Grand_Shape
{

public Grand_Shape(int x) { this.x = x; }
protected int x;
public abstract void Draw();
}
class Trangle : Grand_Shape
{
public Trangle(int x) : base(x) { }
public override void Draw()
{
for (int i = 0; i < x; i++)
{
for (int j = 0; j < x - 1 - i; j++)
Console.Write(" ");
for (int k = 0; k < (2 * i) + 1; k++)
Console.Write("* ");
Console.Write("\n");
}
}
}
class Rectangle : Grand_Shape
{
public Rectangle(int x, int y) : base(x) { this.y = y; }
private int y;
public override void Draw()
{
for (int i = 0; i < y; i++)
{
for (int j = 0; j < x; j++)
if (i == 0 || j == 0 || i == y - 1 || j == x - 1)
Console.Write("* ");
else
Console.Write(" ");
Console.Write("\n");
}
}
}
class __Cl
{
static void Main()
{
Grand_Shape T;
Console.WriteLine("enter hight of trangle");
int hight = int.Parse(Console.ReadLine());
Console.WriteLine();
T = new Trangle(hight);
T.Draw();
/*-----------------------------------*/
Console.WriteLine("\n\nenter width & hight of rectangle");
int width = int.Parse(Console.ReadLine());
hight = int.Parse(Console.ReadLine());
Console.WriteLine();
T = new Rectangle(width,hight);
T.Draw();
Console.WriteLine("\n\n");
}
interface A
{
public void Drow();
}
}

--------------------------------------------------------------------

using System;
class Node // صـنـف الـعـقـدة
{
private char Data; // حـقـل الـبـيـانـات
private Node Next; // مـؤشـر إلـى الـعـقـدة الـتـالـيـة
public void SetData(char D)
{ Data = D; }
public void SetNext(Node N)
{ Next = N; }
public char GetData()
{ return Data; }
public Node GetNext()
{ return Next; }
}
class XStack
{
private Node Top;
public char GetTop() // تابع يرد القيمة التي في الأعلى
{ return Top.GetData(); }
public void Push(char D) // تابع إدخال رقم جديد للمكدس
{
Node Temp = new Node();
Temp.SetData(D);
Temp.SetNext(Top);
Top = Temp;
}
public void Pop() // تابع لحذف العقدة الأخيرة
{
Top = Top.GetNext();
}
public bool Is_True()
{
char[] str=new char[100];
int count=0;
while (Top != null) // نقل عناصر المكدس إلى شريط محرفي
{
str[count] = this.GetTop();
this.Pop();
count++; // عدد الأحرف
}
if (count % 2 == 0)
return false;
else
{
int index = -1;
for (int i = 0; i < count; i++)
{
if (str[i] == 'n')
{
index = i;
break;
}
}
if (index == -1 || index != (int)(count / 2))
return false;
else
{
for (int i = 1; i <= index; i++)
{
if (str[index - i] != str[index + i])
return false;
}
return true;
}
}
}
}
class Cl
{
static void Main()
{
XStack S = new XStack();
string str;
str = Console.ReadLine();
for (int i = 0; i < str.Length; i++)
S.Push(str[i]);
if (S.Is_True())
Console.WriteLine("This String Is True \n");
else
Console.WriteLine("This String Is False \n");
}
}

--------------------------------------------------------------
/*
المطلوب تعريف متتالية حسابية واختبار فيما إذا كانت متزايدة أم لا
*/

using System;
class Csequence
{
private int[] arr;
int m; // قيمة ثابتة تدل على أساس المتتالية
public Csequence(int[] a)
{
arr = a;
m = arr[1] - arr[0];
}
public bool increasing()
{
for (int i = 0; i < (arr.Length - 1); i++)
{
if ((arr[i + 1] - arr[i]) != m)
return false;
}
return true;
}
public override string ToString()
{
string STR = "";
for (int i = 0; i < arr.Length; i++)
STR += (arr[i] + " : ");
return STR;
}
}
class Cl
{
static void Main()
{
int[] a ={ 2, 5, 8, 11, 14 };
Csequence seq=new Csequence(a);
if (seq.increasing())
Console.WriteLine(seq + "\n\n");
else
Console.WriteLine("Not Sequence \n\n");
}
}

------------------------------------------------------------------
/*أكتب برنامجاً يقوم بإدخال أسماء ومهن عدد من الأشخاص
*ثم معرفة عدد الأشخاص ذوي مهنة يحددها مستثمر البرنامج
*كما يقوم البرنامج بالبحث عن مهنة شخص يدخل اسمه وذلك
*باستخدام طريقة البرمجة غرضية التوجه
*/

using System;
class Person
{
private string name,job;
public Person(string n, string j)
{
name = n;
job = j;
}
public string GetName()
{ return name; }
public string GetJob()
{ return job; }
public void print()
{
Console.WriteLine("Name\t:\t" + name + "\n" +
"Job\t:\t" + job + "\n" +
"------------------");
}
}
class Company
{
private Person[] P = new Person[100];
private int num = 0;
public int GetNum()
{ return num; }
public void Add(Person p1)
{
P[num] = p1;
num++;
}
public int CountOfPersons(string Sjob)
{
int count = 0;
for (int i = 0; i < num; i++)
{
if (P[i].GetJob() == Sjob)
count++;
}
return count;
}
public string LookUpJob(string Sname)
{
for (int i = 0; i < num; i++)
{
if (P[i].GetName() == Sname)
return P[i].GetJob();
}
return "";
}
}
class Cl
{
static void Main()
{
Company M = new Company();
int number;
Console.Write("Enter Number Of Persons : ");
number = int.Parse(Console.ReadLine());
for (int i = 0; i < number; i++)
{
string name,job;
Console.WriteLine("---------------\n" + (i + 1) + " - ");
Console.WriteLine("Name & Job : ");
name = Console.ReadLine();
job = Console.ReadLine();
Person p = new Person(name,job);
M.Add(p);
}
Console.WriteLine("--------------------------------\n");
Console.Write("Enter Job To Show Count Of Persons : ");
string Sjob = Console.ReadLine();
int N1 = M.CountOfPersons(Sjob);
Console.WriteLine("This Job Has : " + N1 + " Persons");
Console.WriteLine("--------------------------------\n");
Console.Write("Enter Name To Show His Job : ");
string Sname = Console.ReadLine();
Console.WriteLine(Sname + "Is Working In : " + M.LookUpJob(Sname));
}
}

----------------------------------------------------------

using System;
abstract class Employee
{
protected string name;
protected double sal;
protected double percent;
public Employee(string n, double s, double p)
{
name = n;
sal = s;
percent = p;
}
public abstract void print();
}
class SalesMan : Employee
{
private double Amount_Sales;
public SalesMan(string n, double s, double p, double a): base(n, s, p)
{
Amount_Sales = a;
}
public override void print()
{
Console.WriteLine("I am SalesMan : ");
Console.WriteLine("My Name : " + name);
Console.WriteLine("My salary : " + sal);
Console.WriteLine("Percent sales : " + percent);
Console.WriteLine("Amount Sales : " + Amount_Sales);
}
}
class DalyMan : Employee
{
public DalyMan(string n, double s, double days) : base(n, s, days)
{ }
public override void print()
{
Console.WriteLine("I am DalyMan : ");
Console.WriteLine("My Name : " + name);
Console.WriteLine("I got in day : " + sal);
Console.WriteLine("Count days : " + percent);
}
}
class Cl
{
static void Main()
{
Employee ptr;
SalesMan man1 = new SalesMan("samer", 5000, 0.05, 23400);
DalyMan man2 = new DalyMan("Majed", 200, 30);
ptr = man1;
ptr.print();
/* OR : You May Write :
* ptr = man2;
* ptr.print();
*/
}
}

------------------------------------------------------

Executioner
01-05-2008, 11:36 AM
شكراً لأستاذي Golden man على وضعه هذه البرامج القيمة بحق ;).

ولكن كنت أرجو أن يضعهم بنفس الترتيب السابق بأن يفصل كل برنامج لحال (شو بدك تساوي بحب الترتيب).

وإن شاء الله ما تكونوا التهيتم بالبرامج ونسيتم تدعولي :D.

المهم:

إن شاء لسّ في كم برنامج بدي حطهم.

والسلام عليكم ورحمة الله وبركاته

Golden man
01-05-2008, 12:17 PM
وإن شاء الله ما تكونوا التهيتم بالبرامج ونسيتم تدعولي :D.


ان شاء الله ما بتجيب علامة بالامتحان:eek: إلا كاملة:D.

بس يا أخي ليش هاد التواكل:mad: يعني دعائنا ما بيكفي إذا ما كنت دارس منيح و تعبان على حالك فقوم دروس و حاجه تضييع وقت (طبعا أنا قصدي غير البرمجة لأنو ما في حاجة لتدرسها شو بدك فيها مو مهمة بالنسبة الك هي عندك موجودة بدمك ما شاء الله يعني بالوراثة على ما أظن ).

Executioner
01-05-2008, 04:22 PM
ما كان كامل فكملت التحميل الزائد (في أحد تساءل)

63- صنف عدد عقدي (مع التحميل الزائد):

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public class Complex
{
private double I, R;
public double SetGetI
{
set { I = value; }
get { return I; }
}
public double SetGetR
{
set { R = value; }
get { return R; }
}
public Complex()
{
I = R = 0;
}
public Complex(double r, double i)
{
R = r;
I = i;
}
public Complex(Complex c)
{
R = c.R;
I = c.I;
}
public void Read()
{
Console.Write("Enter the value of Real: ");
this.SetGetR = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the value of Image: ");
this.SetGetI = Convert.ToInt32(Console.ReadLine());
}
public void Get(ref double r, ref double i)
{
r = this.SetGetR;
i = this.SetGetI;
}
public void Set(double r, double i)
{
this.SetGetR = r;
this.SetGetI = i;
}
public void Print()
{
Console.WriteLine("The Value Of Real Is: " + this.SetGetR);
Console.WriteLine("The Value Of Image Is: " + this.SetGetI);
}
static public Complex operator+(Complex c1, Complex c2)
{
Complex c3= new Complex();
c3.SetGetI = c2.SetGetI + c1.SetGetI;
c3.SetGetR = c2.SetGetR + c1.SetGetR;
return c3;
}
static public Complex operator-(Complex c1, Complex c2)
{
Complex c3 = new Complex();
c3.SetGetI = c1.SetGetI - c2.SetGetI;
c3.SetGetR = c1.SetGetR - c2.SetGetR;
return c3;
}
static public Complex operator/(Complex c1, Complex c2)
{
Complex c3 = new Complex();
if (c2.SetGetI!=0)
c3.SetGetI = c1.SetGetI / c2.SetGetI;
if (c2.SetGetR != 0)
c3.SetGetR = c1.SetGetR / c2.SetGetR;
return c3;
}
static public Complex operator *(Complex c1, Complex c2)
{
Complex c3 = new Complex();
c3.SetGetI = c1.SetGetI * c2.SetGetR + c2.SetGetI * c1.SetGetR;
c3.SetGetR = c1.SetGetI * c2.SetGetI + c1.SetGetR * c2.SetGetR;
return c3;
}
~Complex()
{
Console.WriteLine("End Of Object.");
}
}
static void Main(string[] args)
{
Complex c1= new Complex(3,5), c2= new Complex(8,4);

Console.WriteLine("The result of +:");
Complex c3 = c1 + c2;
c1.Print();
c2.Print();
c3.Print();

Console.WriteLine("\nThe result of -:");
c3 = c1 - c2;
c1.Print();
c2.Print();
c3.Print();

Console.WriteLine("\nThe result of /:");
c3 = c1 / c2;
c1.Print();
c2.Print();
c3.Print();

Console.WriteLine("\nThe result of *:");
c3 = c1 * c2;
c1.Print();
c2.Print();
c3.Print();

Console.ReadKey(true);
}
}
}

Executioner
01-05-2008, 04:23 PM
72- صنف ملف نصي:

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public class TextFile
{
StreamReader fin;
StreamWriter fout;
string Path;
string Contain;
public TextFile()
{
Path = "C:\\TextFile.txt";
if (File.Exists(Path))
{
fin = new StreamReader(Path);
Contain = fin.ReadToEnd();
fin.Close();
}
else
{
Contain = "";
fout = new StreamWriter(Path);
fout.Close();
}
}
public TextFile(string str)
{
Path = str;
if (File.Exists(Path))
{
fin = new StreamReader(Path);
Contain = fin.ReadToEnd();
fin.Close();
}
else
{
File.Create(Path);
Contain = "";
}
}
public void ReadFromFile() // ReadFromFileToArray.
{
if (File.Exists(Path)==false)
File.Create(Path);
fin= new StreamReader(Path);
Contain= fin.ReadToEnd();
if (Contain.Length!=0)
Contain= Contain.Substring(0,Contain.Length-1);
fin.Close();
}
public void Print() // ReadFromArrayToScreen.
{
Console.WriteLine("Text File Is:");
Console.WriteLine(Contain);
}
public void Save() // ReadFromArrayToFile.
{
fout = new StreamWriter(Path);
fout.WriteLine(Contain);
fout.Close();
}
public void ReadFromUser() // ReadFromScreenToArray
{
Console.WriteLine("Enter The Contain Of The File (Enter * to end): ");
Contain = "";
char ch = (char)(Console.Read());
while(ch != '*')
{
Contain += ch.ToString();
ch = (char)(Console.Read());
}
}
public void DeleteFromFile()
{
fout = new StreamWriter(Path);
fout.WriteLine("");
fout.Close();
}
public void Menu()
{
Console.WriteLine("Enter 1 To Enter Text.");
Console.WriteLine("Enter 2 To Read From File.");
Console.WriteLine("Enter 3 To Save.");
Console.WriteLine("Enter 4 To Print.");
Console.WriteLine("Enter 5 To Delete Text In File.");
Console.WriteLine("Enter 6 To Exit.");
int Choice = 0;
do {
string str = Console.ReadLine();
if (str!= "")
Choice = Convert.ToInt32(str);
else
Choice=0;
if (!(Choice >= 1 && Choice <= 6))
Console.WriteLine("Error In Choice.");
} while (!(Choice >= 1 && Choice <= 6));
switch (Choice)
{
case 1: this.ReadFromUser(); Menu(); break;
case 2: this.ReadFromFile(); Menu(); break;
case 3: this.Save(); Menu(); break;
case 4: this.Print(); Menu(); break;
case 5: this.DeleteFromFile(); Menu(); break;
case 6: Console.WriteLine("Good Bye."); break;
default: Console.WriteLine("Error In Choice."); break;
}
}
~TextFile()
{
Console.WriteLine("End Of Object.");
}
}
static void Main(string[] args)
{
TextFile t = new TextFile();
t.Menu();
/*t.Print();

t.DeleteFromFile();
t.ReadFromFile();
t.Print();

t.ReadFromUser();
t.Save();
t.ReadFromFile();
t.Print();*/

Console.ReadKey(true);
}
}
}

So SAD
05-14-2008, 04:01 PM
سلام يا شباب
هدو ل ا لبرامج كتير مناح والله يخليكون يلي عندو بعد ايا شي برمجة 1
و بامكانو يفيدنا لا يبخل علينا لعل نتخرج ونتراح من عي المواد
ومشكورين سلفا

hamza
06-02-2009, 12:52 PM
جزاك الله ألف خير بس بدنا نسأل عطاكم ياها الأستاذ محمود حيدر بالعملي

Executioner
06-03-2009, 08:34 PM
السلام عليكم

للأسف الشديد ما درسنا الأستاذ م. محمود حيدر :p لا بالعملي ولا بالنظري ولا حتى بأي سنة :)، درسنا بس الأستاذ م. حنين دعبول.

هي البرامج بشكل عام مشكلة مالها علاقة بأستاذ معين ;).

موفقين إن شاء الله بدارستكم :)

السلام عليكم