Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the ElementDatabase.cpp file given below, create a database of chemical elements (elements from the periodic table). The program interface should match the example below.

Using the ElementDatabase.cpp file given below, create a database of chemical elements (elements from the periodic table). The program interface should match the example below. File -

#include using namespace std; struct Element { int atomicNumber; string symbol; string name; Element *left; Element *right; }; class ElementDatabase{ private: Element* root; void addElement(Element *&e, int atomicNumber, string symbol, string name){ } void printElements(Element *e){ } // Returns the address of the element if a match is found // Return NULL if no match is found Element* findElementBySymbol(Element *e, string symbol){ return NULL; } // Returns the address of the element if a match is found // Return NULL if no match is found Element* findElementByName(Element *e, string name){ return NULL; } void deleteElement(Element *&e, int atomicNumber){ } public: ElementDatabase(){ root = NULL; } void addElement(int atomicNumber, string symbol, string name){ addElement(root, atomicNumber, symbol, name); } void printElements(){ printElements(root); } // Returns the address of the element if a match is found // Return NULL if no match is found Element* findElementBySymbol(string symbol){ return findElementBySymbol(root, symbol); } // Returns the address of the element if a match is found // Return NULL if no match is found Element* findElementByName(string name){ return findElementByName(root,name); } void deleteElement(int atomicNumber){ deleteElement(root,atomicNumber); } }; int main(){ // Complete the functions above // Add more functions if necessary // Create the menu as shown in the example of program execution // The program should only exit when the user chooses "Exit program" } Example - ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 1 ** Add an element ** Enter atomic number: 3 Enter chemical symbol: Li Enter element name: Lithium Element added successfully. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 1 ** Add an element ** Enter atomic number: 36 Enter chemical symbol: Kr Enter element name: Krypton Element added successfully. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 1 ** Add an element ** Enter atomic number: 2 Enter chemical symbol: He Enter element name: Helium Element added successfully. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 2 ** View Elements ** 2, He, Helium 3, Li, Lithium 36, Kr, Krypton ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 3 ** Search Elements by Chemical Symbol ** Enter chemical symbol: Li Search result: 3, Li, Lithium ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 3 ** Search Elements by Chemical Symbol ** Enter chemical symbol: Co Search result: No element was found. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 4 ** Search Elements by Element Name ** Enter chemical symbol: lithium Search result: 3, Li, Lithium ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 4 ** Search Elements by Element Name ** Enter element name: HELIUM Search result: 2, He, Helium ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 4 ** Search Elements by Element Name ** Enter element name: Oxygen Search result: No element was found. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 5 ** Delete an element ** Enter atmoic number: 2 Do you want to delete: 2, He, Helium Enter y or n:y Element deleted successfully. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 5 ** Delete an element ** Enter atmoic number: 5 No element was found. ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 2 ** View Elements ** 3, Li, Lithium 36, Kr, Krypton ----------------------------- 1. Add an element 2. View elements 3. Search elements by chemical symbol 4. Search elements by element name 5. Delete an element 6. Exit program Enter your choice: 6 Program has exited.. Provide a single cpp file. The database must be implemented using Binary Search Tree data structure. Use the atomic number as the key (to decide which element will got left or right in the tree). *Search by name should work for uppercase and lowercase letters.

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

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

4. Explain the role of followers in the leadership process.

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago

Question

=+ What is the role of government in bargaining?

Answered: 1 week ago

Question

=+ Who is the negotiation partner at company level?

Answered: 1 week ago

Question

=+Which associations exist?

Answered: 1 week ago