Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


COSC-1436, Element Array Project

 

Define a C++ struct named Element with the following members:

•     symbol : string, The symbol for the chemical element

•    name : string, The name of the chemical element

•    atomicNumber : int, The atomic number of the element

•    atomicWeight : double, The atomic weight of the element

•    active : bool, Flag variable controlling its visibility

Define an array of Element structures named elements that can hold up to 50 instances of the Element structure.

Write a menu-driven program that prompts your user with the following six choices:

Select an option number from the following menu:

 


Option

------

1

2

3

4

5

6


Action

-----------------------------------------

Define a chemical element.

Search for an element.

Change the visibility of an element.

Define elements from a text file.

Display the elements sorted by symbol.

Quit.


Enter your choice:

 

Option 1 will prompt the user for a chemical symbol, the corresponding element name, atomic number, and atomic weight. It will then use that information to define the next available entry in the array of elements.

Option 2 will prompt the user for a chemical symbol such as “C” for Carbon. If that chemical symbol exists in the array of elements, the program will     display the symbol, name, atomic number, and atomic weight of that          element. If the chemical symbol is not in the array of elements, display an  informative message instead.

Option 3 will prompt the user for a chemical symbol such as “B” for Boron. If that chemical symbol exists in the array of elements, the program will          assign the value false to the active member for that array entry. If the      chemical symbol does not exist in the array of elements, an informative        message will be displayed instead.


Note: The structure member named active is initialized to true when an entry is created. Once the member named active is     set to the value false in Option 3, it is invisible to all other         program options. Your program does not have to delete such an  entry. It just has to ignore it by not displaying it.

Option 4 prompts the user to identify a file containing the descriptions of       several elements This text file contains one record per line containing the      chemical symbol, element name, atomic number, and atomic weight of         several elements. The fields are separated from each other by a blank space. A sample file named “elements.txt” is available in Blackboard to assist you  in testing this portion of your program. Your program will read and process    all the records in the file, adding an entry to the array of elements for each   record in the file.

Option 5 will display a formatted list of the contents of the elements array sorted in ascending order by chemical symbol. This is an example of the    desired output from selecting this option:

 


 

Symbol ------

Al

Ar

B

Be

C

Ca

Cl


 

Name         ------------ Aluminum     Argon

Boron

Beryllium

Carbon

Calcium

Chlorine


Atomic Number

------

13

18

5

4

6

20

17


Atomic

Weight

-------

26.982

39.880

10.810

9.012

12.011

40.078

35.450


 

Option 6 will terminate the program.

Your program will repeatedly prompt the user with the menu choices until  the user enters option 6 to quit. Use input validation to guard against your user from entering menu choices outside the range from 1 to 6.

Use formatting to display the information contained in the array of Element structures. Display atomic weights with three digits after the decimal point.

To receive full credit for this programming assignment, your submission must:

•    Use a correctly formed file name.

•    Submit a program that executes correctly.

•    Interact effectively with the user in your prompts and messages.


Grading Guideline:

•    Create a comment containing the student’s full name. (5 points)

•     Document the program with other meaningful comments. (5 points)

•     Repeatedly display the required choices. (10 points)

•    Use input validation to verify the user’s option choice. (5 points)

•     Process Option 1 correctly, adding an element. (15 points)

•     Process Option 2 correctly, identifying and displaying an entry. (15 points)

•     Process Option 3 correctly, making an entry “invisible” . (10 points)

•     Process Option 4 correctly, adding elements from a file. (15 points)

•     Process Option 5 correctly, displaying the contents sorted in ascending order by chemical symbol. (15 points)

•    Use prompts and messages that are easy to understand. (5 points)