Problem A: A Basic Molecule Class (20 points) A molecule is an electrically ncut
ID: 554873 • Letter: P
Question
Problem A: A Basic Molecule Class (20 points) A molecule is an electrically ncutral group of two or more atoms held together by chemical bonds. Atoms are held together by bonds, mostly single bonds, but in some (rare) cases the bonding may include two double bonds and/or a triple bond. Many experiments involve the use of molecules, and a plethora of data can be created and analyzed by a system which can represent and encode their properties and workings. Write a C++program that creates, stores, and provides access to Molecule objects. Create a class named Molecule. This class maintains an array of elements (of max size 10), an array of counts of each element (of max size 10), the number of bonds (no more than the total number of elements plus 4), and a charge (which can be positive, negative, or neutral). You should build the appropriate mutators and accessors (you will not need for an accessor for each individual element count) The accessor method for elements should return a comma-separated list of the values as a string. You should also declare and define a method that returns the total count of elements, a method that prints the counts as a comma-separated list, and finally, declare and define a method that prints out all the values associated with a molecule object To test the Molecule class, write a main function which allows the user to enter elements (a maximum of 10); counts (a maximum of 10); a number of bonds, and a charge. The main function should then call the method to print the resulting Molecule. Your program should include a continuation loop so you can test more than one molecular configuration. An example run of the program is as follows (user input is in bold font) Enter the element and its count (enter 0 to stop): H2 Enter the element and its count (enter Q 0 to stop): O 1 Enter the element and its count (enter 0 to stop): Q0 Enter the number of bonds:1 Enter the charge (-1 for negative, O for neutral, 1 for positive): 0 H, O 2. 1 Total count: Bonds: Charge: Would you like to continue (y/n)? Y Enter the element and its count (enter 0 to stop): C 1 Enter the element and its count (enter 0 to stop): o2 Enter the element and its count (enter O 0 to stop): a 0 Enter the number of bonds: 1 Enter the charge (-1 for negative, o for neutral, 1 for positive): 0Explanation / Answer
Elements : H O
Counts : 2 1
Total count : 3
Bonds : 2 (H---O----H)
Charge : 0 (As water is a neutral molecule)
Elements : C O
Count : 1 1
Total count : 2
Bonds : 3
Charge : 0
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.