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

سؤال واتمنى المساعدة فيه

مغلق
بدأه alr7al في 21 يونيو 2003 · 6 رد · 673 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

هذا سؤالي :

write a program that takes in words from the console and inserts them into an alphabetizing data structure which is a linked list class. To

facilitate user interaction your program is to print a command prompt. Then it will take four possible commands from the user. Your program should loop on the prompt until the user types exit as described below.

> add *word*

where add is a keyword to your program and *word* gets inserted into your list.

> size

where size is a keyword to your program. Your program should determine the number of elements in the list and return this to the console.

> print

where print is a keyword to your program and causes your program to print out the words in the list

> exit

where exit is a keyword to your program and causes your program to terminate.

A sample run of the program is as follows. Your program should produce identical output if given identical input.

> size

There are 0 words in the database.

> add foo

> add C++

> add list

> size

There are 3 words in the database.

> add foo

> size

There are 4 words in the database.

> print

C++ foo foo list

> exit

Operations on the linked list are (you are to use this interface):

void insert(char* word); //Adds a word to the list.

void printList(); //Prints each element in the list in lexicographical order.

int getCount(); //Returns the number of words in the list

#2

الرجاء المساعدة يا اخوان

:'(:'(:'(:'(:'(:'(:'(:'(:'(:'(

#3

ممكن تلخصلنا ماهو المطلوب بالعربي علشان أن كنا نقدر نساعدك ما نتأخر ..

المطلوب ...ماذا تريد؟

اللهم علمنا ما ينفعنا وأنفعنا بما علمتنا أنك أنت العليم الحكيم

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

لاحول ولاقوة الا بالله( كنز من كنوز الجنة ).

#4

السالم عليكم يا اخي العزيز وشكرا على تجاوبك

عمل البرنامج بختصار شديد هو يتضمن اربع اوامر منها

اضافة كلمة add word

معرفة عدد الكلمات المدخلة عن طريق size

طباعة الكلمات المدخلة عن طريق print

والخروج من البرنامج عن طريق exit

مثال على ذلك

مثلا عند فتحنا للبرنامج قمنا بادخال كلمة size

نحصل على 0 كلمة

بعد ذلك اذا وضعنا add computer

ثم كتبنا size مرة اخرى

نحصل على 1 كلمة

وعند كتابة الامر print

يقوم البرنامج بطباعة الكلمة التي قمتا بادخالها وهي computer

عن ادخال exit نخرج من البرنامج

مع السلامة

#5

الرجاء المساعدة يا اخوان

:'(:'(:'(:'(:'(:'(:'(:'(:'(

#6
#include "string.h"



class CListWords  

{

private:

	char * word;



public:

	CListWords();

	virtual ~CListWords();



	void setWord(char * word);

	char * getWord();



	CListWords * Next;

};

الكود السابق يمثل تعريف CListWords

#include "ListWords.h"



CListWords::CListWords()

{



}



CListWords::~CListWords()

{



}



void CListWords::setWord(char * word)

{

	this->word = new char[strlen(word)];

	strcpy(this->word, word);

}



char * CListWords::getWord()

{

	return word;

}

الكود السابق يمثل تعريف CListWords

#include <iostream.h>

#include <stdlib.h>

#include "ListWords.h"



CListWords * MainList = new CListWords();

CListWords * TempList;

CListWords * AuxList;



void insert(char * word)

{

	AuxList = new CListWords();

	AuxList->Next = NULL;

	if (MainList == NULL)

	{

  MainList = AuxList;

  TempList = MainList;

	}

	else

	{

  TempList->Next = AuxList;

  TempList = AuxList;

	}

	AuxList->setWord(word);

	cout << endl;

}



void printList()

{

	CListWords * tempList = MainList;

	while (MainList != NULL)

	{

  cout << MainList->getWord() << " ";

  MainList = MainList->Next;

	}

	cout << endl << endl;

	MainList = tempList;

}



int getCount()

{

	int count = 0;

	CListWords * tempList = MainList;

	while (tempList != NULL)

	{

  count++;

  tempList = tempList->Next;

	}

	return count;

}



void delList()

{

	while (MainList != NULL)

	{

  AuxList = MainList->Next;

  delete MainList;

  MainList = AuxList;

	}

}







void main()

{

	char * order[] = {"add", "size", "print", "exit"};

	char * word = new char[20];

	char * tempOrder;





	MainList = NULL;

	while (true)

	{

  cin.getline(word, 20);

  if (strcmp(word, order[2]) == 0)

  {

 	 printList();

 	 continue;

  }

  if (strcmp(word, order[1]) == 0)

  {

 	 cout << "There are " << getCount() << 

        " words in the database " << endl << endl;

 	 continue;

  }

  if (strcmp(word, order[3]) == 0)

  {

 	 exit(0);

  }

  tempOrder = strtok(word, " ");

  if (strcmp(tempOrder, order[0]) == 0)

  {

 	 tempOrder = strtok(NULL, " ");

 	 insert(tempOrder);

 	 continue;

  }

	}

	delList();



}

الكود السابق يمثل البرنامج الرئيسي

أرجو إذا كان هناك خطأ أن أعلم (f)(f)(f)(f)

consol.zip

#7

السلام عليكم اشكرك اخي الكريم

:D:D:D:D:D:D:D:D:D:D:D:D:D:D

هذا الموضوع مغلق.

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