الاسلام عليكم , اريد مساعدتي في فهم هذان السؤالين المطلوب تنفيذه امام الطالبات, اي اريد ما المطلوب مني بالضبط
السؤال الاول
Topic 1:
Object-oriented programming depends on the concept of classes. An important advantage of using classes is to obtain data encapsulation. In C++ this is achieved with the ‘private’ and ‘public’ keywords. Explain which parts of a class are generally made public, which are made private, and how they are used/accessed.
You may use JAVA instead of C++ if you prefer.
Assumptions:
The students know structured programming, pointers, and arrays.
The students are just beginning to learn about objects.
They already know that an object has member variables and member functions.
They know what constructors are.
Scenario:
The students were given a sheet a few days earlier.
In the sheet they are asked to extend a class for an object called basket (see below) that depending on its size can hold a different number of items. They are asked to write a member function that allows adding items to the basket while it is not full and another one that allows checking whether the basket is full or not.
class basket
{public:
basket(int s)
{
size=s;
items = (int*)calloc(s,sizeof(int));
}
private:
int *items;
int current; // current number of items
int size; // size of basket
}
السؤال الثاني
Topic 2:
Data Structures are the basis for many programming concepts.
A major data structure that needs to be mastered by students is a binary search tree.
Assumptions:
The students know basic programming, pointers, and arrays.
Some of the students are weak with regard to pointers specially when it comes to differentiating between when to use (.) vs. (->)
They know what a binary search tree is.
Scenario:
The students were given a sheet a few days earlier.
In the sheet they are asked to trace the insertion of an element into a binary search tree that is implemented with pointers.
You are now entering the class to give a tutorial lesson
class Node
{
public:
Node( char e)
{
element = e;
right = NULL;
left = NULL;
}
Node *right;
Node *left;
char element;
};
class BST
{
public:
BST(){root=NULL;}
void insert(char e)
{
// check if it is the first element
if(root==NULL)
{ root = new Node(e);
return;
}
Node *current,*previous;
current = root;
previous = current;
// move to the correct position
while (current!= NULL)
{ previous = current;
if (e>current->element)
current = current->right;
else
current = current->left;
}
// create the new node and attach it
current = new Node(e);
if(e>previous->element)
previous->right=current;
else
previous->left=current;
}
Node *root;
};
void main()
{
BST myTree;
myTree.insert('o');
myTree.insert('a');
myTree.insert('z');
myTree.insert('y');
return;
}