Create the following classes in C++ 1. Class \'tis contains the following proper
ID: 3863308 • Letter: C
Question
Create the following classes in C++ 1. Class 'tis contains the following properties a) An unsigned integer called the 'seed': (the seed value will range between 0 to 255) b) A reciprocal characteristic/feedback polynomial function: (the user will set the characteristic polynomial. Basically, the user will specify the bit-positions which your class will use to generate the random numbers. The bits in the LFSR state that influence the input are called taps) Add appropriate member-functions such as a) Constructor(s) b) A function to print the seed and generated numbers (both in integer and binary number system) c) A function (named as "random number generator) to create 20 consecutive random numbers from the given seed and the characteristic polynomial. d) Based on the requirements of the class, you might have to convert any given decimal number to a binary number and store it. So, you need to implement a function that converts a given decimal number to a corresponding binary number.Explanation / Answer
SOLUTION OF QUESTION 2: BINARY SEARCH TREE
/TREE STRUCTURE
struct node
{
int key;
struct node *left, *right;
};
// A function to create a new BST node
struct node *newNode(int item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
// A function to do inorder traversal of BST
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%d ", root->key);
inorder(root->right);
}
}
/* A function to insert a new node with given key in BST */
struct node* insert(struct node* node, int key)
{
/* If the tree is empty, return a new node */
if (node == NULL) return newNode(key);
/* Otherwise, recur down the tree */
if (key < node->key)
node->left = insert(node->left, key);
else if (key > node->key)
node->right = insert(node->right, key);
/* return the (unchanged) node pointer */
return node;
}
//PROGRAM TO FIND HEIGHT OF A TREE
int height(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the depth of each subtree */
int lheight = height(node->left);
int rheight = height(node->right);
/* use the larger one */
if (lheight > rheight)
return(lheight+1);
else return(rheight+1);
}
}
//print leaf node
void leafNodes(struct node *r) {
int key;
if(r!= null) {
leafNodes(r->left);
leafNodes(r->right);
if(r->eft == null && r->right == null) {
println(r->key);
}
}
}
//delete a node
struct node* deleteNode(struct node* root, int key)
{
if (root == NULL) return root;
if (key < root->key)
root->left = deleteNode(root->left, key);
// If the key to be deleted is greater than the root's key,
// then it lies in right subtree
else if (key > root->key)
root->right = deleteNode(root->right, key);
// if key is same as root's key, then This is the node
// to be deleted
else
{
// node with only one child or no child
if (root->left == NULL)
{
struct node *temp = root->right;
free(root);
return temp;
}
else if (root->right == NULL)
{
struct node *temp = root->left;
free(root);
return temp;
}
// node with two children: Get the inorder successor (smallest
// in the right subtree)
struct node* temp = minValueNode(root->right);
// Copy the inorder successor's content to this node
root->key = temp->key;
// Delete the inorder successor
root->right = deleteNode(root->right, temp->key);
}
return root;
}
// Driver Program to test above functions
int main()
{
struct node *root = NULL;
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
// print inoder traversal of the BST
inorder(root);
int z=height(root);
printf("height is %d",z);
leafnodes(root);
int k1;
printf("enter node to be deleted");
scanf("%d",&k1);
root = deleteNode(root, k1);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.