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

الرجاء مساعدتي في حل السؤال linked list

بدأه no yes في 3 يونيو 2011 · 5 رد · 591 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

كيف الحال

ممكن اخوتي وخواتي تساعدوني في الحل لهذا السؤال,,

رقم 2 و3 مو واضح كفاية بالنسبة لي

واكون شاكرة لكم

post-246009-037543900 1307065780_thumb.j

المرفقات
scan0001.jpg
#2

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

سؤال في Array list type

مارأيكم في الحل

اعتقد ان هناك خطأ بسيط في الفنكشن printone يؤدي الى اظهار الكثير من الاخطاء,,

الرجاء منكم اعزائي تجربة هذا الكود في البرنامج لمعرفه الاخطاء,, فأنا اريده بدون اخطاء

Problem 1 : using classes , design a program that keep track of cars in a car show store. the main program should allow user to select from a main menu that contains all the member functions defined in the Array Based Class. The Car's info that your class should have are :

1 - car's model ( year of make )

2 - car's plate number ( only numbers )

3 - car's brand ( for example : 'toyota' , 'bmw' , nissan etc )

4 - car's mileage ( how many kilometers )

5 - car's price

You should also add the following new member function:

CheckSameBrand: where it return 1 if a given cars brand is similar to another car's brand.

Example of the main menu :

Input you choice :

0- exit the program

1- insert new car's info

2- delete a car ( according to plate num )

3- retrieve a car ( according to plate num )

4- print all cars

5- print one car info ( according to plate num)

6- search for a car ( according to plate num)

7- CheckSameBrand





# include <iostream>
# include <string>
using namespace std;


struct car
{
int Modle;
int PlateNumber;
string Brand;
double mileage;
double price;
};


template <class Type>
class arrayListType
{
protected:
Type *list;
int length;
int maxSize;

public:
void print();
void printone(Type n);
int CheckSameBrand(car c,car t);
void insert(Type& elem);
void insertEnd (Type& elem);
void removeAt(int loc);
void remove(Type& elem);
int retrieve(car m);
int seqSearch(Type& elem);
}










template <class Type>
int arrayListType <Type>::CheckSameBrand(car c,car t)
{
seqSearch(car c);
seqSearch(car t);
if(c.Brand==t.Brand)
{
return 1;
else
return -1;
}
}


template <class Type>
void arrayListType <Type>:: print()
{
for( int i=0; i< length; i++)
cout<<list.Modle<<list.PlateNumber<<list.Brand<<list.mileage<<list.price;
}

template <class Type>
void arrayListType <Type>:: printone(Type n)
{
int index=seqSearch(Type n);
cout<<list[index].Modle<<list[index].PlateNumber<<list[index].Brand<<list[index].mileage<<list[index].price;
}


template <class Type>
void arrayListType <Type>:: insert(Type& elem)
{
if (seqSearch(elem)== -1)
insertEnd(elem);
else
cout<<" do duplicated allowed";

}

template <class Type>
void arrayListType <Type>:: insertEnd(Type& elem)
{
if (length == maxSize)
cout<<" full list ";
else
{
list[length]=elem;
length++;
}
}


template <class Type>
void arrayListType <Type>:: remove(Type& elem)
{
if (seqSearch(elem)== -1)
cout<<" not found";
else
{
removeAt(elem);
}
}



template <class Type>
void arrayListType <Type>:: removeAt(int loc)
{
if (length == 0)
cout<<" Empty list ";
else if (loc<0 ||loc>+ length )
cout<< " incorect index ";
else
{
for (int i=loc ;i<length-1 ;i++)
list= list[i+1];
}
length--;
}





template <class Type>
int arrayListType <Type>::retrieve(car m )
{
if( length == maxSize)
cerr<<"the loc of the item to be retrieved is out of range."<< endl;
else
m=PlateNumber;
return m;
}



template <class Type>
int arrayListType <Type>::seqSearch(Type& elem)
{
for (int i=0; i<length ;i++)
if (list==elem)
return i;
else
return -1;






int main()
{

arrayListType <car> l1;
car c1,c,t;
int num;


cout<<" enter an integer between 0 and 7:";
cin>> num;
cout<< endl;
cout<<" the number you entered is"<<num<<endl;

while (num != 0)
{
switch(num)
{

case 1:
cout<<" enter your car info.";
cin>>c1.Modle>>c1.PlateNumber>>c1.Brand>>c1.mileage>>c1.price;
l1.insert(c1);

case 2:
cout<<" enter your plate number.";
cin>>c1.PlateNumber;
l1.remove(c1);

case 3:
cout<<" enter your plate number.";
cin>>c1.PlateNumber;
l1.retrieve(c1);

case 4:
l1.print();

case 5:
cout<<" enter your plate number.";
cin>>c1.PlateNumber;
l1.printone(c1);

case 6:
cout<<" enter your plate number.";
cin>>c1.PlateNumber;
l1.seqSearch(c1);

case 7:
l1.CheckSameBrand(c,t);
}
}




return 0;

}



ارجو مساعدتي,,

تم تعديل هذه المشاركة بواسطة no yes في 3 يونيو 2011 في 05:03

#3

up

up

up

i need it

#4

لم اجد اي ردوود تفيدني :(

#5

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

بالنسبه للسؤال الثاني قم بتقسم القائمة الى قائمتين بحيث ان الاول تحتوي الكتب التي سعرها اقل من او يساوي 20 والاخرى اكبر من 20, ففكرة الحل بسيطه قم بزيارة عناصر القائمه الاساسيه ومن ثم قم بفحص سعر الكتاب على اساسه بتضيفه في القائمه الاولى او الثانيه .. وطبعا لو توصلت للحل السؤال الي بعده مقارب له ..

.:: Wish to become better and better ::.

#6

شكرا اخي

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