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

سؤال

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

السلام عليكم

في الحقيقة لدي سؤال ولكن لم افهم ماهو المطلوب واتمنى الحصول على الاجابه ومساعدتي

عندي برنامج عن trees

// main.cpp : Defines the entry point for the console application.

#include 
#include "bst.h"

using namespace std;

int main(int argc, char* argv[])
{
	bst* tree = new bst();
	int* x = NULL;
	while(true){
		cout << "Please enter a number(-1 to exit): ";
		x = new int;
		cin >> *x;
		if(*x == -1) break;
		tree->insert(new comparable(x));
		cout << "The elements in the tree are:";
		tree->printAscending(cout);
	}
	return 0;
}

و

#ifndef _CONTAINER_H_
#define _CONTAINER_H_

#include 
#include "comparable.h"
using namespace std;

template
class container {
public:
	container();
	virtual ~container();
	virtual void insert(comparable* item) = 0;
	virtual void printAscending(ostream&) = 0;
};

template 
container::container(){}
template 
container::~container(){} 

#endif //_CONTAINER_H_

و

#ifndef _COMPARABLE_H_
#define _COMPARABLE_H_

#include 

using namespace std;

template 
class comparable{
	friend ostream& operator<<(ostream&, comparable*);
public:
	comparable(t*);
	~comparable();
	bool operator<(const comparable&) const;
	bool operator>(const comparable&) const;
	bool operator==(const comparable&) const;
	t* getData() const;
private:
	t* data;
};

template 
ostream& operator<<(ostream& out, comparable* c){
	out << *c->data << ' ';
	return out;
}

template
comparable::comparable(t* item){
	data = item;
}
template
comparable::~comparable(){
}
template
bool comparable::operator <(const comparable& r) const {
	return *data < *(r.getData());
}
template
bool comparable::operator ==(const comparable& r) const {
	return *(this->data) == *(r.getData());
}
template
bool comparable::operator >(const comparable& r) const {
	return *data > *(r.getData());
}
template
t* comparable::getData() const {
	return data;
}

#endif //_COMPARABLE_H_

و

#ifndef _NODE_H_
#define _NODE_H_

#include "comparable.h"
#include 
using namespace std;



template 
class node{
public:
	node(comparable*);
	~node();
	void setData(comparable*);
	comparable* getData();
	node* getRight() const;
	node* getLeft() const;
	void setRight(node*);
	void setLeft(node*);
private:
	node* right;
	node* left;
	comparable* data;
};

template
node* node::getRight() const{
	return right;
}
template
node* node::getLeft() const{
	return left;
}
template
void node::setRight(node* r){
	right = r;
}
template
void node::setLeft(node* l){
	left = l;
}

template
comparable* node::getData(){
	return data;
}
template 
node::node(comparable* d){
	right = NULL;
	left = NULL;
	data = d;
}
template
node::~node(){
	delete right;
	delete left;
	delete data;
}

template 
void node::setData(comparable* d){
	data = d;
}


#endif //_NODE_H_

و المطلوب كتابة bst.h لكي يعمل البرنامج و ايضا يجب ان يكون

bst class should inherit and implement the public methods of the container class.

#2

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

#3

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

#4

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

ثانيا لم افهم بالضبط ماذا تريد

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#5

السالم عليكم

انا اسف يا اخي الكريم ولكن في الحقيقة انا قرات السؤال بالانجليزي ولكن لم افهم المطلوب وهذا النص :

You are to implement the missing bst.h binary tree template file.

You will need to implement these member functions as shown to work with our program.

The other program files are: main.cpp container.h comparable.h node.h.

The Class diagrams are here [ps].

Your bst class should inherit and implement the public methods of the container class.

طبعا الملفات في الاعلى

مع السلامة

#6

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

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

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