الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج يعرض قائمة ومطلوب طريقة البحث

بدأه خيال وحب في 14 نوفمبر 2008 · 4 رد · 626 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

صلى الله على النبي الامين وسلم تسليما كثيرا

مرحبا بالجميع :lol:

اود عمل كلاس يحتوي على قائمة بالطلاب والنتيجة النهائية بهذا الترتيب

الرقم المتسلسل، الاسم ، السنة ،التخصص ، الدرجة النهائية

المطلوب

الرقم المتسلسل يكون مميز كل مرة يعني حتى ولو كان نفس الطالب لسنة اخرى بيكون رقم متسلسل جديد.

1- كيف ممكن اضيف مثلا 10 طلاب عن طريق اي Data Structure وانا اخترت Hashtable

2- بحث النتيجة النهائية عن طريق الرقم المتسلسل يعني نتيجة الرقم المتسلسل 4 هي 70

3- بحث عن طريق الاسم ويظهر جميع الدرجات النهائية لكل السنوات معناه مثلا وليد سنة 2000 درجته 90 وسنة 2001 درجته 80 .... الخ

بداية تجربتي بعد البحث

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

	class Students
	{
		public static void Main()
		{
			Hashtable aa = new Hashtable();
			aa.Add("1", "Ahmed");
			aa.Add("2", "Marwa");

			Console.WriteLine("Search Values");
			string name = aa["1"].ToString();
			Console.WriteLine(name);

			Console.WriteLine("List of all students");
			foreach (DictionaryEntry entry in aa)
			Console.WriteLine("{0} {1}", entry.Key, entry.Value, entry.Value);

		}
	}

سؤالي هل الطريقة نافعة ام يوجد طريقة اسهل لذلك ؟؟؟؟؟؟؟؟؟؟؟؟

وكيف اضيف باقي البيانات الى الHashtable احتاج مثلا 5 متغيرات وليس 2 فقط

aa.Add("2", "Marwa");

لان عند اضافة اكثر من قيمتين تظهر Error

وهل يمكن ان اضيف البحث في فنكشن منفصل يعني بهذا الشكل

void search_Student()
{

 Console.WriteLine("Search Values");

string name = aa["1"].ToString();

Console.WriteLine(name);

}

لاني اود فصل الفنكشن واجعل التحكم للمستخدم باي طريقة يود البحث لاحقا .......

اخيرا البحث لكل السنوات كيف اعمله المطلوب رقم 3

اسف على الاطالة،،،،،،،،

واتمنى ان اجد اجابة مفيدة لي لاستطيع ان اتعلم المزيد عن C# وكل شكري مقدما لكل اعضاء المنتدى.

تحياتي للجميع

:wub:

تم تعديل هذه المشاركة بواسطة خيال وحب في 14 نوفمبر 2008 في 13:19

انا افكر اذا انا مبدع .... I think therfore I am Creative

#2

up

انا افكر اذا انا مبدع .... I think therfore I am Creative

#3

السلام عليكم

هذا هو الكود كاملا:

using System;
using System.Collections.Generic;

	class Student
	{
		static void Main()
		{
			Dictionary<int, string> lst = new Dictionary<int, string>();

			//Programmatically adding students 
			for (byte b = 65; b < 91; b++) // 65 through 91 is the capital letters a - z
				lst.Add(lst.Count + 1, ((char)b).ToString());

			//Reading student names from the user
			while (true)
			{
				Console.WriteLine("Please enter a student names:");
				Console.Write("> ");
				string input = Console.ReadLine();
				input = input.Trim();
				if (input == string.Empty)
					Console.WriteLine("Invlid student name.");
				else if (lst.ContainsValue(input))
					Console.WriteLine("Student already exists.");
				else
				{
					lst.Add(lst.Count + 1, input);
					Console.WriteLine("Student added.");
				}

				Console.WriteLine("Press Enter to add another student, or any key to continue...");
				Console.WriteLine();
				if (Console.ReadKey(true).Key != ConsoleKey.Enter) break;
			}

			Console.WriteLine(new string('*', 50));

			Console.WriteLine();

			Console.WriteLine("Students:");
			foreach (KeyValuePair<int, string> pair in lst)
				Console.WriteLine("\t{0,2} - {1}", pair.Key, pair.Value);

			Console.WriteLine();

			Console.WriteLine(new string('*', 50));

			Console.WriteLine();

			Console.WriteLine("Enter search string:");
			Console.Write("> ");
			string search = Console.ReadLine();
			search = search.Trim();
			if (search == string.Empty)
				Console.WriteLine("Invalid input.");
			bool found = false;
			foreach (KeyValuePair<int, string> pair in lst)
				if (pair.Value.ToLower() == search.ToLower())
				{
					Console.WriteLine("Found student '{0}' at index {1}", search, pair.Key);
					found = true;
					break;
				}
			if (found == false)
				Console.WriteLine("Student not found!");

			Console.WriteLine();


			Console.WriteLine("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}

لكن إذا بتحبي تستخدمي HashTable (لكن الكود السابق هو الأفضل) هذا هو الكود:

using System;
using System.Collections.Generic;

namespace MyApp
{
	class Student
	{
		static void Main()
		{
			Hashtable hash = new Hashtable();
			hash.Add(hash.Count + 1, "A");
			hash.Add(hash.Count + 1, "B");
			hash.Add(hash.Count + 1, "C");
			hash.Add(hash.Count + 1, "D");
			hash.Add(hash.Count + 1, "E");
			hash.Add(hash.Count + 1, "F");
			hash.Add(hash.Count + 1, "G");


			SeekStudent(hash, "E");
			SeekStudent(hash, "Z");
		}

		static void SeekStudent(Hashtable hash, string searchStr)
		{
		   foreach(DictionaryEntry entry in hash)
			   if (entry.Value.ToString().ToLower() == searchStr.ToLower())
			   {
				   Console.WriteLine("Student '{0}' found at index {1}", searchStr, entry.Key);
				   return;
			   }
		   Console.WriteLine("Student not found!");
		}
	}

}

تم تعديل هذه المشاركة بواسطة OOP Emperor في 18 نوفمبر 2008 في 15:31

#4

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

اولا اتقدم بالشكر الجزيل اليك اخي OOP Emperor على مساعدتك القيمة

الكود لم يكن مثل الفكرة التي اريد والكود صعب علي فهمه ولكنني لم اتوقف عند هذا

وقد حاولت مرة اخرى باستخدام الستركشر ولكن لا زال لا يعمل بالشكل المطلوب وقد كتبت الملاحظات المطلوبة داخل الكود

ارجو ان توضح لي طريقة اكماله ام انني لا يمكن ان اتبع هذه الطريقة ؟؟؟؟؟

والكود هنا :

using System;
using System.Collections;

class Search
{
	public struct Student
	{
		public int id;
		public string student_name;
		public string module;
		public string year;
		public double mark;
	}

	public void searchMark(int EnterStudentID)
	{
		// if id =1
		// Result is that 
	}

	public void searchAllYearsMark(int EnterStudentName)
	{
		//Result will be for ahmed
		// in 2007 study algebra mark is 80
		// in 2008 study algebra2 mark is 90
	}


	foreach (Student in a )
	{
	//Show all students with Details as full report
	// Ahmed .....
	// Ahmed .....
	// Mohammed ... 
	}


	public static void main(string[] arg)
	{
		Student A;
		A.id = 1;
		A.student_name = "Ahmed";
		A.module = "Algebra";
		A.year = "2007";
		A.mark = 80;

		Student AA;
		AA.id = 2;
		AA.student_name = "Ahmed";
		AA.module = "Algebra 2";
		AA.year = "2008";
		AA.mark = 90;

		Student B;
		B.id = 3;
		B.student_name = "Mohammed";
		B.module = "Math";
		B.mark = 90;
	}
}

تم تعديل هذه المشاركة بواسطة خيال وحب في 25 نوفمبر 2008 في 14:06

انا افكر اذا انا مبدع .... I think therfore I am Creative

#5

up

انا افكر اذا انا مبدع .... I think therfore I am Creative

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…