Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; struct Node { int data; Node * left; Node * right; } ; Node * createNode ( int data ) {

#include
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
};
Node* createNode(int data){
Node* newNode = new Node();
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
Node* insert(Node* root, int data){
if (root == NULL){
root = createNode(data);
} else if (data <= root->data){
root->left = insert(root->left, data);
} else {
root->right = insert(root->right, data);
}
return root;
}
void preorderTraversal(Node* root){
if (root == NULL){
return;
}
cout << root->data <<"";
preorderTraversal(root->left);
preorderTraversal(root->right);
}
int main(){
Node* root = NULL;
root = insert(root,8);
root = insert(root,4);
root = insert(root,12);
root = insert(root,5);
root = insert(root,2);
root = insert(root,29);
cout << "Preorder Traversal: ";
preorderTraversal(root);
return 0;
}
Using the code above, make the following Program Changes
Modify the program so that it includes struct s for each of the eight shapes that were the subject of Assignment 1. Name these as follows: Square, Rectangle, Circle, Triangle, Cube, Box, Cylinder, and Prism. Include attributes of the double data type for the required dimensions for each (for example, length and width for the Rectangle). Provide a descriptive name for each of these data elements (for example, "radius" instead of "r"). Do NOT include any other attributes, and do NOT include any "member functions" -- avoid the temptation to extend the specifications beyond what is required. If you include attributes for area, volume, or perimeter, you are not doing this right!
Write supporting functions to do console output each shape (for example, void outputBox(ostream&, const Box&); ), which should output to either cout or fout -- whichever is the first parameter in a call, using the same format as v.1. Note that cout is an object of type ostream . So use cout as the first parameter in the function call in order to produce console output. Use the exact same supporting functions for text file output, which should output to fout . Create, open, and close fout in int main . fout is also an object of type ostream . Remember, the ROUNDING Format - the calculated results to 2 digits after the decimal (out.setf(ios::fixed); out.precision(2); ). But echo the input values without formatting. (out.unsetf(ios::fixed); out.precision(6);)
Use any type of array for your bag -- C, C++, or STL vector -- your choice. STL vectors track their or size, so if you use a C or C++ array instead, you'll have to use an int to track size yourself.
Write 4 loops -- one to process the input file and fill the bag, one for console output, one for TXT output, and one for deallocation. If you don't have 4 loops, or if you do more than one of these things in any single loop, you're not doing this right!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. Identify challenges to good listening and their remedies

Answered: 1 week ago

Question

4. Identify ethical factors in the listening process

Answered: 1 week ago