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

هياكل البيانات باستخدام لغة السي بلآس بلآس

بدأه متى أرى حلمي حقيقة في 12 نوفمبر 2011 · 7 رد · 905 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

يسعدني تواجدي في هذا المنتدى الأكثر من رآئع وأتمنى لكم مزيداَ من التقدم ان شاء الله.

أتمنى انكم تضعون قسم مخصص لهيآكل البيانات لأنهآ جدا دسمه وصعبه

واتمنى انكم تساعدوني في هالماده لانهآ مره موت ودكتور الماده يصعبها علينا اكثر وشرحه مو واضح

عندي سؤال فيهآ اتمنى انكم تساعدوني سؤالي هو: مطلوب مني أدرج خمسة اعداد عشرية داخل queue وانشيء دالة تعطيني او تحسب لي المعدل واسم هالداله average

وهذا كود البرنامج كآمل وين أضيف دالة المعدل وكيف اسويهآ؟

#include<iostream>

#include<stdio.h>

#include<conio.h>

#include<process.h>

usingnamespace st

constint max_length=10;

class Queue

{

private:

int queue[max_length];

int rear;

int front;

public:

Queue( );

void Delete( );

void Insert( );

void print_queue( );

~Queue();

};

Queue::Queue( )

{

rear=-1;

front=-1;

for(int count=0;count<max_length;count++)

queue[count]=0;

}

Queue::~Queue()

{

if(front!=-1 && rear!=-1)

{

cout<<"the values deleted from the queue are"<<endl;

for(int i=front; i<=rear; ++i)

{

cout<<"queue["<<i<<"]="<<queue<<endl;

queue=0;

}

front=rear=-1;

}

else

cout<<"There are nor values in the queue to be delete"<<endl;

}

void Queue::Insert( )

{

int item;

cout<<"\n\n\n\n\n\t Enter value to insert into the Queue : ";

cin>>item;

if(rear==(max_length-1))

cout<<"\n\n\t *** Error : Queue is full. \n"<<endl;

elseif(rear==-1 && front==-1)

{

rear++;

queue[rear]=item;

front=rear;

cout<<"\n\n\t *** "<<item<<" is inserted into the Queue."<<endl;

}

else

{

rear++;

queue[rear]=item;

cout<<"\n\n\t *** "<<item<<" is inserted into the Queue."<<endl;

}

}

void Queue::Delete( )

{

if(rear==-1 && front==-1)

cout<<"\n\n\n\t *** Error : Queue is empty. \n"<<endl;

else

{

cout<<"\n\n\n\t *** "<<queue[front]<<" is deleted from the Queue."<<endl;

queue[front]=0;

if(front==rear)

front=rear=-1;

else

front++;

}

}

void Queue::print_queue( )

{

if(front!=-1 && rear!=-1)

{

cout<<"\n\n\n\n\n\t Values inserted into the Queue are : \n"<<endl;

for(int count=front;count<=rear;count++)

cout<<"\t Stack ["<<count<<"] = "<<queue[count]<<endl;

}

else

cout<<"\n\n\n\n\n\t *** Nothing to show. "<<endl;

}

void main( )

{

Queue obj;

int Key=1;

do

{

cout<<"********** Implementation of Array as Queue **********"<<endl;

cout<<"Select one of the listed operation :"<<endl;

cout<<"- Press \'1\' to Insert a value"<<endl;

cout<<"- Press \'2\' to Delete a value"<<endl;

cout<<"- Press \'3\' to Print the values"<<endl;

cout<<"- Press \'4\' to destroy the queue"<<endl;

cout<<"- Press \'5\' to Exit"<<endl;

cout<<" ";

cout<<"Enter your Choice : ";

cin>>Key;

switch(Key)

{

case 1:

obj.Insert( );

break;

case 2:

obj.Delete( );

break;

case 3:

obj.print_queue( );

break;

case 4:

obj.~Queue();

break;

default:

cout<<"The option is invalid...";

return;

}

}while(Key!=5);

getch();

return;

}

وشكرا مقدما......اتمنى انكم تساعدوني

#2

معقووووووووووووله 33 مشاهده مافيش ولا رد وآحد

الله يخليكم ساعدوني

#3
متى أرى حلمي حقيقة كتب:

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

يسعدني تواجدي في هذا المنتدى الأكثر من رآئع وأتمنى لكم مزيداَ من التقدم ان شاء الله.

أتمنى انكم تضعون قسم مخصص لهيآكل البيانات لأنهآ جدا دسمه وصعبه

واتمنى انكم تساعدوني في هالماده لانهآ مره موت ودكتور الماده يصعبها علينا اكثر وشرحه مو واضح

عندي سؤال فيهآ اتمنى انكم تساعدوني سؤالي هو: مطلوب مني أدرج خمسة اعداد عشرية داخل queue وانشيء دالة تعطيني او تحسب لي المعدل واسم هالداله average

وهذا كود البرنامج كآمل وين أضيف دالة المعدل وكيف اسويهآ؟

#include<iostream>

#include<stdio.h>

#include<conio.h>

#include<process.h>

usingnamespace st

constint max_length=10;

class Queue

{

private:

int queue[max_length];

int rear;

int front;

public:

Queue( );

void Delete( );

void Insert( );

void print_queue( );

~Queue();

};

Queue::Queue( )

{

rear=-1;

front=-1;

for(int count=0;count<max_length;count++)

queue[count]=0;

}

Queue::~Queue()

{

if(front!=-1 && rear!=-1)

{

cout<<"the values deleted from the queue are"<<endl;

for(int i=front; i<=rear; ++i)

{

cout<<"queue["<<i<<"]="<<queue<<endl;

queue=0;

}

front=rear=-1;

}

else

cout<<"There are nor values in the queue to be delete"<<endl;

}

void Queue::Insert( )

{

int item;

cout<<"\n\n\n\n\n\t Enter value to insert into the Queue : ";

cin>>item;

if(rear==(max_length-1))

cout<<"\n\n\t *** Error : Queue is full. \n"<<endl;

elseif(rear==-1 && front==-1)

{

rear++;

queue[rear]=item;

front=rear;

cout<<"\n\n\t *** "<<item<<" is inserted into the Queue."<<endl;

}

else

{

rear++;

queue[rear]=item;

cout<<"\n\n\t *** "<<item<<" is inserted into the Queue."<<endl;

}

}

void Queue::Delete( )

{

if(rear==-1 && front==-1)

cout<<"\n\n\n\t *** Error : Queue is empty. \n"<<endl;

else

{

cout<<"\n\n\n\t *** "<<queue[front]<<" is deleted from the Queue."<<endl;

queue[front]=0;

if(front==rear)

front=rear=-1;

else

front++;

}

}

void Queue::print_queue( )

{

if(front!=-1 && rear!=-1)

{

cout<<"\n\n\n\n\n\t Values inserted into the Queue are : \n"<<endl;

for(int count=front;count<=rear;count++)

cout<<"\t Stack ["<<count<<"] = "<<queue[count]<<endl;

}

else

cout<<"\n\n\n\n\n\t *** Nothing to show. "<<endl;

}

void main( )

{

Queue obj;

int Key=1;

do

{

cout<<"********** Implementation of Array as Queue **********"<<endl;

cout<<"Select one of the listed operation :"<<endl;

cout<<"- Press \'1\' to Insert a value"<<endl;

cout<<"- Press \'2\' to Delete a value"<<endl;

cout<<"- Press \'3\' to Print the values"<<endl;

cout<<"- Press \'4\' to destroy the queue"<<endl;

cout<<"- Press \'5\' to Exit"<<endl;

cout<<" ";

cout<<"Enter your Choice : ";

cin>>Key;

switch(Key)

{

case 1:

obj.Insert( );

break;

case 2:

obj.Delete( );

break;

case 3:

obj.print_queue( );

break;

case 4:

obj.~Queue();

break;

default:

cout<<"The option is invalid...";

return;

}

}while(Key!=5);

getch();

return;

}

وشكرا مقدما......اتمنى انكم تساعدوني

السلام عليكم

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

تحياتي

#4

مشكوووووووووووووووور الله يعافيك ويوفقك

#5

يا جماعة استخدموا علامة التنسيق <> فى اضافى رود او اضافة مواضيع وذلك حتى نتمكن من قراءة الكود بسهولة

بدﻻ من

int x=0;

printf("%d",x);

يكون كما يلى:

int x=0;
printf("%d",x);

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#6

بسيطة برجع لك بعد دقائق

#7

هذا الكود جاهز

#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<process.h>
using namespace std;
const int max_length=10;
class Queue
{
private:
int queue[max_length];
int rear;
int front;
int counter, total;
float average;

public:
Queue( );

void Delete( );
void Insert( );
void print_queue( );
~Queue();
};

Queue::Queue( )
{
rear=-1;
front=-1;

total=0;
counter=0;

for(int count=0;count<max_length;count++)
queue[count]=0;
}
Queue::~Queue()
{
if(front!=-1 && rear!=-1)
{

cout<<"the values deleted from the queue are"<<endl;
for(int i=front; i<=rear; ++i)
{
cout<<"queue["<<i<<"]="<<queue<<endl;
queue=0;
}
front=rear=-1;
}
else
cout<<"There are nor values in the queue to be delete"<<endl;


}

void Queue::Insert( )
{
int item;

cout<<"\n\n\n\n\n\t Enter value to insert into the Queue : ";
cin>>item;

if(rear==(max_length-1))
cout<<"\n\n\t *** Error : Queue is full. \n"<<endl;

else if(rear==-1 && front==-1)
{
rear++;
queue[rear]=item;
front=rear;

total+=item;
counter++;
average = total / (float) counter; 
cout<<"\n\n\t *** "<<item<<" is inserted into the Queue."<<endl;
}

else
{
rear++;
queue[rear]=item;

cout<<"\n\n\t *** "<<item<<" is inserted into the Queue."<<endl;
total+=item;
counter++;
average = total / (float) counter; 
}
}


void Queue::Delete( )
{
if(rear==-1 && front==-1)
cout<<"\n\n\n\t *** Error : Queue is empty. \n"<<endl;

else
{
cout<<"\n\n\n\t *** "<<queue[front]<<" is deleted from the Queue."<<endl;
total-=queue[front];
counter--;
average = total / (float) counter; 
queue[front]=0;

if(front==rear)
front=rear=-1;

else
front++;
}


}


void Queue::print_queue( )
{
if(front!=-1 && rear!=-1)
{
cout<<"\n\n\n\n\n\t Values inserted into the Queue are : \n"<<endl;

for(int count=front;count<=rear;count++)
cout<<"\t Stack ["<<count<<"] = "<<queue[count]<<endl;

cout<<"\nAverage = "<<average<<endl;

}

else
cout<<"\n\n\n\n\n\t *** Nothing to show. "<<endl;


}

int main( )
{
Queue obj;

int Key=1;

do
{

cout<<"********** Implementation of Array as Queue **********"<<endl;
cout<<"Select one of the listed operation :"<<endl;
cout<<"- Press \'1\' to Insert a value"<<endl;
cout<<"- Press \'2\' to Delete a value"<<endl;
cout<<"- Press \'3\' to Print the values"<<endl;
cout<<"- Press \'4\' to destroy the queue"<<endl;
cout<<"- Press \'5\' to Exit"<<endl;

cout<<" ";
cout<<"Enter your Choice : ";
cin>>Key;

switch(Key)
{

case 1:
obj.Insert( );
break;
case 2:
obj.Delete( );
break;

case 3:
obj.print_queue( );
break; 

case 4:
obj.~Queue();
break;
case 5:
exit(0);
default:
cout<<"The option is invalid...";

}
}while(Key!=5);
getch();
return 0;
}

تم تعديل هذه المشاركة بواسطة ماهر نبيل في 18 نوفمبر 2011 في 16:08

1
#8

السلام عليكم اخواني الاعزاء

البرنامج تسلم ايدك اخ ماهر على البرنامج, لكن لدي سؤال

قمت بقراءة البرنامج قراءة سريعة,و حسب ما هو مطلوب من البرنامج ادراج 5 اعداد عشرية فكيف حددت انت ذلك في البرنامج.

المطلوب كتابة دالة للمعدل

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

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

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

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

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