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

ساعدوني عندي برنامج لازم أسلمه بكره :(

بدأه همسة نورانية في 18 مايو 2009 · 1 رد · 291 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

يااااااااااااليت تساعدوني لأن والله خايفه ومو عارفه ايش اسوي

لو سمحتم محتاجه مساعدتكم العاجله جدااا جدا اليوم لأن بكره لازم أسلم هالواجب

هذا

البرنامج عباره عن إدارة بيانات مكتبه باستخدام الـ

struct

والدكتور طالب منا نحول هذا البرنامج باستخدام الـ

class

ليحفظ بيانات مجموعة من الكتب يعني نستخدم

array of objects

وهذا نص السؤال

قومي بتحويل برنامج المكتبه ليقوم بدلا من حفظ بيانات كتاب واحد إلى حفظ بيانات مجموعة من الكتب (مصفوفة من الاوبجيكت ) ووفري الخدمات التاليه في البرنامج من خلال ثائمة يختار منها المستخدم مايريد كالتالي :

1/عرض بيانات جميع الكتب

2/البحث عن كتاب معين تبعا لـ

اسم الكتاب

رقم الكتاب

3/ حذف كتاب (تبعا للكيفية التي تتحكمين فيها في تخزين الكتاب)

مع ملاحظة التالي

اتكرار عرض الأوامر المتاحة إلى أن يختار المستخدم الخروج من البرنامج

إا كان سيختار من القائمة بواسطة حرف يدخله فيجب أن يراعي أن البرنامج سواء أدخل المستخدم حرف صغير أو كبير ) أنا أفضل الأرقام بدل الحروف للسهوله

ولو أردنا التالي فماذا ترتائين

أن نعطي المصفوفه قيم افرتاضيه بمجرد إنشائها برمجيا :

المره الأولى إا كنا فقط سنهيئها بقيمة أحاديه هي قيمة الـ

id؟

المره الثانيه إا منا سنهيئها بجميع قيمها ؟

لو أردنا أن نطبق نفس البرنامج لكن من خلال المؤشرات ؟

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <string>
  5. void init_list();
  6. int menu();
  7. void enter();
  8. void input(int i);
  9. void update();
  10. void display();
  11.  
  12. const int SIZE=20;
  13. struct Book
  14. {
  15. char Title[SIZE];
  16. int ID;
  17. int Quantity;
  18. float cost;
  19. }Library[20];
  20.  
  21. int main()
  22. {
  23. char choice;
  24. init_list();
  25. for(;;)
  26. {
  27. choice = menu();
  28. switch(choice)
  29. {
  30. case 'e':
  31. enter();
  32. break;
  33. case 'd':
  34. display();
  35. break;
  36. case 'u':
  37. update();
  38. break;
  39. case 'q':
  40. return 0;
  41. }
  42. }
  43. getch();
  44. }
  45.  
  46. // Initialize the array.
  47. void init_list()
  48. {
  49. int t;
  50.  
  51. for(t=0; t<SIZE; t++)
  52. *Library[t].Title = '\0';
  53. }
  54.  
  55. // Get a menu selection.
  56. int menu()
  57. {
  58. char ch;
  59. cout << 'n';
  60. do {
  61. cout << "ntt(E)ntern";
  62. cout << "ntt(D)isplayn";
  63. cout << "ntt(U)pdaten";
  64. cout << "ntt(Q)uitnn";
  65. cout << "ntttchoose one: ";
  66. cin >> ch;
  67. } while(!strchr("eduq", tolower(ch)));
  68. return tolower(ch);
  69. }
  70. // Enter Titles into the list.
  71. void enter()
  72. {
  73. int i;
  74. // find the first free structure
  75. for(i=0; i<SIZE; i++)
  76. if(!*Library[i].Title)
  77. break;
  78. // i will equal SIZE if the list is full
  79. if(i==SIZE)
  80. {
  81. cout << "List full.n";
  82. return;
  83. }
  84. input(i);
  85. }
  86. // Input the information.
  87. void input(int i)
  88. {
  89. // enter the information
  90. cout << "ntBook Title: ";
  91. gets(Library[i].Title);
  92. cout << "ntBook ID: ";
  93. cin >> Library[i].ID;
  94. cout << "ntBook price: ";
  95. cin >> Library[i].cost;
  96. cout << "ntBook Quantity: ";
  97. cin >> Library[i].Quantity;
  98. }
  99. // Modify an existing Title.
  100. void update()
  101. {
  102. int i;
  103. char name[80];
  104. cout << "Enter Title: ";
  105. cin >> name;
  106. for(i=0; i<SIZE; i++)
  107. if(!strcmp(name, Library[i].Title))
  108. break;
  109. if(i==SIZE)
  110. {
  111. cout << "nttTitle not found.n";
  112. return;
  113. }
  114. cout << "ntEnter new information.n";
  115. input(i);
  116. }
  117.  
  118. // Display the list.
  119. void display()
  120. {
  121. int t;
  122. for(t=0; t<SIZE; t++)
  123. {
  124. if(*Library[t].Title)
  125. {
  126. cout << "ntBook Title: "<<Library[t].Title;
  127. cout << "ntBook ID: "<<Library[t].ID;
  128. cout << "ntBook price: "<<Library[t].cost;
  129. cout << "ntBook Quantity: "<<Library[t].Quantity;
  130. }
  131. }
  132. }
  133.  

تم تعديل هذه المشاركة بواسطة همسة نورانية في 18 مايو 2009 في 20:11

#2

حاولت أكتب البرنامج بس تتوقعون عفست السالفه :huh:

أحس نفسي مخبطه بس مو مشكله من التجربه ياليت تساعدوني وتقولون لي الأخطاء بالشرح ترى أختكم ماتعرف شي في البرمجه

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
 
 
 
 
const int SIZE=100;
class Book
{
 char  Title[SIZE];
   int   ID;
   int   Quantity;
   float cost;
 
   public:
 
int menu(){
int ch;
 
 do {
  cout << "n1.Enter";
  cout << "n2.Delete";
  cout << "n3.Display";
	  cout << "n4.search";
	   cout << "n5.quit";
  cout << "ntttchoose one: ";
	  cin >> ch;
  } while(ch!=5);
	return ch;
}
 
void Enter(){
{
 int i;
 
 for(i=0; i<SIZE; i++)
 if(!*Library.Title)
	break;
 
 if(i==SIZE)
	{
  cout << "List full.n";
  return;
	}
 input(i);
void Delete(int i);
void Display(){
 
 int i;
 for(i=0; i<SIZE; i++)
   {
  if(*Library.Title)
	  {
   cout << "ntBook Title: "<<Library.Title;
   cout << "ntBook ID: "<<Library[t].ID;
   cout << "ntBook price: "<<Library[t].cost;
   cout << "ntBook Quantity: "<<Library[t].Quantity;
  }
 
void search(){
int choice;
cout<<"choose what do you wantn";
cout<<"1.search by name's of bookn";
cout<<"2.search by idn";
cin>>choice;
 
if (choice==1)
 cout>> "enter name";
 cin>>name;
 
 for (int i=0;i<=100;i++)
 
 if( name ==library.name)
  cout<<library.name;
 
  else
  cout<<"is not found";
 
  if (coice==2)
  cout>> "enter id";
 cin>>id;
 
 for (int i=0;i<=100;i++)
 
 if( id ==library.id)
  cout<<library.id;
 
  else
  cout<<"is not found";
 
}
int main()
{  book Library[100];
 
 int choice;
 init_list();
 for(;;)
   {
  choice = menu();
  switch(choice)
	   {
   case '1':
		  Enter();
	break;
		 case '2':
		  Delete();
	break;
   case '3':
		  Display();
	break;
			case '4':
			search();
		 case '5':
		  return 0;
	   }
 }
   getch();
 
 
 
 
void input(int i)
{
 
 cout << "ntBook Title: ";
 gets(Library.Title);
 cout << "ntBook ID: ";
 cin >> Library.ID;
 cout << "ntBook price: ";
 cin >> Library.cost;
 cout << "ntBook Quantity: ";
 cin >> Library.Quantity;
}

تم تعديل هذه المشاركة بواسطة time1 في 18 مايو 2009 في 21:33

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