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

تصحيح الاكواد

بدأه سرمد الليل في 29 أبريل 2010 · 15 رد · 2,218 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

َالسوال الاول:

Write program that deal with array of integers that contains random values,

that's mean you should use rand() function that's generate array's elements. In

your program, you should sort the elements of randomly array. Then print your

array before and after sorting.

Output sample:-

Array which generated randomly :

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

0 3 3 2 9 0 8 2 6 6

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

Array's elements after sorted :

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

0 0 2 2 3 3 6 6 8 9

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

محاولتى

#include <iostream>

using namespace std;

void rond(int a[],int x){

cout<<"Enter";

for(x=0;x<10;x++)

cin>>a[x];

}

void sort(int a[],int x,int y){

for(x=0;x<10;x++)

for(y=1;y<10;y++)

}

int main(){

rond(a[],x);

stor(a[],x,y);

return 0;

}

السوال الثانى:

Write C++ program that define an array of strings word as following:-

string Fruits ={"apple", "orange" , "banana",

"grape" , "pear" , "strawberry" ,

"berry" , "peach" , "dates" };

Your program should ask user to enter any kind of fruits, then search in your

array to verify if it's in the list or no. Then print one of the following massages

up to the searching result.

Output samples:-

Search in the Fruit's Array!

apple

apple** is in the Fruits list!**

محاولتى :

#include <iostream>

#include<string>

using namespace std;

int main(){

string Fruits ={"apple", "orange" , "banana",

"grape" , "pear" , "strawberry" ,

"berry" , "peach" , "dates" };

cout<<"Enter a kind of fruit and I'll\nSearch in the Fruit's Array!";

string a;

cin>>a;

if(Fruits==a)

cout<<a<<"** is in the Fruits list!**";

else

cout<<a<<"** is not in Fruits list!**";

return 0;

}

السوال الثالث:

Write a program that read one dimensional array that contain of five elements from the

user, then do the following:-

Print all yours array's elements.

Define function which receives your array and calculate the mean of array's

elements and print return it.

Define another function that find the maximum value from array's elements

and print also return it.

Print both the mean and maximum values.

محاولتى

include<iostream>

using namespace;

int c[5];

cout<<"enter number;"

cin>>c[5];

int su(int sum )

{

sum+=c[5];

return sum; }

int maxum(int max,int c[5])

{

max=c[5];

return max;

}

int main()

{

su( sum );

maxum( max, c[5]);

return 0;

}

#2

السؤال الأول :

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
void rond(int x[])
{
    srand(time(NULL));
   cout<<"Array which generated randomly :"<<endl;
  for(int i=0 ; i<10 ; ++i)
  {
  x= rand() % 10 ;
   cout<<x<<" ";
  }
  cout<<endl;
}

void sort(int x[])
{
  int temp;
  for (int i=0 ; i<10 ; ++i)
  {
   for (int j=1 ; j<10 ; ++j)
    {
      if (x[j-1]>x[j])
      {
       temp = x[j-1];
       x[j-1]=x[j];
       x[j]=temp;
      }
    }
  }
  cout<<"Array's elements after sorted :"<<endl;
  for(int i=0 ; i<10 ; ++i)
  cout<<x<<" ";
}
main()
{
int x[10];
 rond(x);
 sort(x);
getch();
}

السؤال الثاني :

#include <conio.h>
#include <iostream.h>
#include <string>
main()
{
bool found = false;
string Fruits[] ={"apple", "orange" , "banana",
"grape" , "pear" , "strawberry" ,
"berry" , "peach" , "dates" };

cout<<"Enter a kind of fruit and I'll\nSearch in the Fruit's Array!";
string a;
cin>>a;
for (int i=0 ; i<9 ; ++i)
if(a==Fruits)
found=true;
if (found)

cout<<a<<"** is in the Fruits list!**";
else
cout<<a<<"** is not in Fruits list!**";
getch();
}

تم تعديل هذه المشاركة بواسطة إشراقــه فجــر في 29 أبريل 2010 في 16:33

2

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#3

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

تم تعديل هذه المشاركة بواسطة حلمي ويستحق العناء في 29 أبريل 2010 في 17:14

عضوية مشطوبة - spam

#4

أختي حلمي ويستحق العناء ..

الأكواد صحيحة , لكن المترجم اللي أشتغل عليه يختلف عنكم ..

ما هي الأخطاء ؟

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#5

^

بـ الفعل اكوآدكْ صحيحهْ ..

بسْ يآليتْ يآقلبيْ تشرحين كل سوآل انت حآلتهْ عشآن نفهمْ .. =) ..

والله يوفقكْ ..

#6

السؤال الأول ,

أنشأنا مصفوفة عناصرها هي قيم عشوائية .. من خلال الدالة ()rand وبعد تعبئتها نطبعها .

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

بشرح الكود بداية من الـ main ..

main()
{
int x[10];
 rond(x);
 sort(x);
getch();
}

نعرف المصفوفة , و أعطيناها طول يساوي 10 ..

أستدعينا الدالة rond و أرسلنا لها المصفوفة ..

وبعدين أستدعينا الدالة sort ..

void rond(int x[])
{
    srand(time(NULL));
   cout<<"Array which generated randomly :"<<endl;
  for(int i=0 ; i<10 ; ++i)
  {
  x= rand() % 10 ;
   cout<<x<<" ";
  }
  cout<<endl;
}

في الدالة rond سنقوم بتعبئة المصفوفة بقيم عشوائية .. من خلال الدلة ()rand

راجعي هالرابط

بعد ما نعبي المصفوفة نطبع العناصر ..

void sort(int x[])
{
  int temp;
  for (int i=0 ; i<10 ; ++i)
  {
   for (int j=1 ; j<10 ; ++j)
    {
      if (x[j-1]>x[j])
      {
       temp = x[j-1];
       x[j-1]=x[j];
       x[j]=temp;
      }
    }
  }
  cout<<"Array's elements after sorted :"<<endl;
  for(int i=0 ; i<10 ; ++i)
  cout<<x<<" ";
}

في دالة الترتيب ..

رتبنا العناصر بإستخدام two for و طبعناهم ..

إن شاء الله يكون وآضح .. و أدري كلفت على عمري بالشرح :lol: ..

والسؤال الثاني ..

وين اللي مب فاهمته وأشرحه لك :happy: ..

بالتوفيق ,

2

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#7

طيب حل السوال الثالث هل حلى صح ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

#8

تصحيح السؤال الثالث ..

#include<iostream>
using namespace std;
float mean (int x[]);
int max (int x[]);
int main()
{
	int element[5];
	cout<<"Please Enter the Element "<<endl;
	for (int i=0 ; i<5 ; i++)
		cin>>element;
	for (int i=0 ; i<5 ; i++)
		cout<<element<<endl;
	cout<<"The Mean : "<<mean(element)<<endl;
	cout<<"The Maximum Value : "<<max(element)<<endl;
	system("pause");
}
float mean (int x[])
{
float sum =0;
	for (int i=0 ; i<5 ; i++)
sum+=x;
return (sum/5); 
}
int max (int x[])
{
int max = x[0];
for (int i=0 ; i<5 ; i++)
if (max < x)
max = x;
return max;
}

موفقيــن :happy: ,

1

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#9

system("pause");< وش فآيدتهآْ ياحلوهْ ..

ويآلييت تشرحين الحل اذآ تقدرينْ ..

#10

طيبْ ليه كتبنآ هنآ فولسْ واستخدمنآ البوولْ :

bool found = false;

تم تعديل هذه المشاركة بواسطة سآرآْ في 30 أبريل 2010 في 14:46

#11
سآرآْ كتب:

طيبْ ليه كتبنآ هنآ فولسْ واستخدمنآ البوولْ

:bool found = false;

فرضت من البداية أن المدخل ما راح ألقاه ..

و عند البحث بتتغير قيمة إلى true في حال وجوده ..

و كتبت جملة شرط إذا true أطبع أنه المدخل موجود في القائمة ,

إذا false اطبع غير موجود ..

إن شاء الله يكون مفهووم :happy:

موفقه.. ,

1

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#12

^

يعطيكْ العآفيهْ ع الشرررحْ ..

سآرآْ كتب:

system("pause");< وش فآيدتهآْ ياحلوهْ ..

ويآلييت تشرحين الحل اذآ تقدرينْ ..

يآليت تفيدينيء هنآ لاني مآاستوعبتهآْ :( ..

#13
سآرآْ كتب:

يآليت تفيدينيء هنآ لاني مآاستوعبتهآْ :( ..

system("pause");

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

(بصراحه ما أدري ليه بالضبط لكن أتوقع تثبت الشاشة :wink: )

بالتوفيق :happy: .. ,

1

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#14

srand(time(NULL));

^

وش معنىْ الـ s والـtimeوالـnull(نل كركترْ) اقصد ليه حطيتيهمْ ..

ودآله الsort:

ليه عرفتي متغير الـ temp

#15
سآرآْ كتب:

srand(time(NULL)); ^وش معنىْ الـ s والـtimeوالـnull(نل كركترْ) اقصد ليه حطيتيهمْ ..

الدالة srand وضع الـ s حتى لا تتكرر الأرقام العشوائية ,

وهذه دالة تآخذ Argument وهو الـ (time(NULL ..

سآرآْ كتب:

ودآله الsort:

ليه عرفتي متغير الـ temp

دالة الـ sort بتقوم بترتيب العناصر .. و تنقل العنصر من مكان إلى آخر ,

فأنا بحاجه إلى مخزن يحفظ قيمة أحدهم و التبديل فيما بينهم .. ,

بالتوفيق :happy: ,

1

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#16

^

وهْ بس ^_^ ..

الله يخلييكْ على الشرح ..

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