Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program in C++: Given the main, Create a type that will let us build chemical compounds. Thank you! *****Hint for the program: /***************************************** The purpose

Program in C++: Given the main, Create a type that will let us build chemical compounds. Thank you! image text in transcribed

*****Hint for the program:

/***************************************** The purpose of this is to provide you with a single function which will convert an integer to a string, which will be useful in homework 8 The main that appears under the function is just to demo that it works. *********************************************/ 
#include #include 
using namespace std; string itostr(int num){ string one,result; while(num > 0){ //converts the last digit of num to a char and then to a string one += static_cast(num%10)+'0'; //puts most recently converted digit at the beginning of // the result string result.insert(0,one); one = ""; // empty the one-character string num /= 10; // chop off the last digit of the number } return result; } int main(){ string sample; int anumber; cout>anumber; sample = itostr(anumber); cout 

chem_main.cc Main Function:

/******************************** The purpose of this project is to develop a class describing chemicals. A chemical can be either a single atom of a single element or a molecule. Addition and multiplication operations defined for the class allow us to combine elements into molecules and molecules into larger molecules. **************************************************/ 
#include #include #include #include 
using namespace std; // The chemical class class Chemical{ // This is one of the parts that you write }; // This function shows the user their choices and returns // the menu item they have selected int menu(); // The main for the project int main(){ ifstream fin; ofstream fout; Chemical element, molecule; string chemsym; int multiplier; int chosen; fin.open("elements.txt"); if(fin.fail()){ coutchemsym; element.get_element(chemsym, fin); break; case 3: cout>multiplier; element = element*multiplier; break; case 4: molecule = molecule + element; break; case 5: foutelement; break; case 0: cout>choice; return choice; } 

Input to test with:

// Here are the compounds that I am asking you to input // The MyChemicals.txt file will contain these along with their total atomic number // and atomic weight H2O NaClO NaHCO3 C2H5OH SiO2 PbS C12H22O11 

Elements.txt file for atomic weights and numbers:

H 1 1.0079 He 2 4.0026 Li 3 6.941 Be 4 9.0122 B 5 10.811 C 6 12.0107 N 7 14.0067 O 8 15.9994 F 9 18.9984 Ne 10 20.1797 Na 11 22.9897 Mg 12 24.305 Al 13 26.9815 Si 14 28.0855 P 15 30.9738 S 16 32.065 Cl 17 35.453 Ar 18 39.948 K 19 39.0983 Ca 20 40.078 Sc 21 44.9559 Ti 22 47.867 V 23 50.9415 Cr 24 51.9961 Mn 25 54.938 Fe 26 55.845 Co 27 58.9332 Ni 28 58.6934 Cu 29 63.546 Zn 30 65.39 Ga 31 69.723 Ge 32 72.64 As 33 74.9216 Se 34 78.96 Br 35 79.904 Kr 36 83.8 Rb 37 85.4678 Sr 38 87.62 Y 39 88.9059 Zr 40 91.224 Nb 41 92.9064 Mo 42 95.94 Tc 43 98 Ru 44 101.07 Rh 45 102.906 Pd 46 106.42 Ag 47 107.868 Cd 48 112.411 In 49 114.818 Sn 50 118.71 Sb 51 121.76 Te 52 127.6 I 53 126.904 Xe 54 131.293 Cs 55 132.905 Ba 56 137.327 La 57 138.905 Ce 58 140.116 Pr 59 140.908 Nd 60 144.24 Pm 61 145 Sm 62 150.36 Eu 63 151.964 Gd 64 157.25 Tb 65 158.925 Dy 66 162.5 Ho 67 164.93 Er 68 167.259 Tm 69 168.934 Yb 70 173.04 Lu 71 174.967 Hf 72 178.49 Ta 73 180.948 W 74 183.84 Re 75 186.207 Os 76 190.23 Ir 77 192.217 Pt 78 195.078 Au 79 196.966 Hg 80 200.59 Tl 81 204.383 Pb 82 207.2 Bi 83 208.98 Po 84 209 At 85 210 Rn 86 222 Fr 87 223 Ra 88 226 Ac 89 227 Th 90 232.038 Pa 91 231.036 U 92 238.029 Np 93 237 Pu 94 244 Am 95 243 Cm 96 247 Bk 97 247 Cf 98 251 Es 99 252 Fm 100 257 Md 101 258 No 102 259 Lr 103 262 Rf 104 261 Db 105 262 Sg 106 266 Bh 107 264 Hs 108 277 Mt 109 268 
Program in C++: Create a type that will let us "build" chemical compounds. I have provided a list of the known elements in a data file called "elements.txt." The class that you write is able to store the chemical symbol (a string), the atomic number (an integer) and the atomic weight (a double) In order to clarify what I want this program to do l have already written the main for you, and you are to begin the project by copying the main and the elements.txt both located below. Now chemical elements can be added together and the resulting compound also has a chemical number and a weight, which is the sum of the numbers and weights of all the elements in the compound. H20 has a number of (1 8) and an atomic weight of 18.0132 (1.0079 2+ 15.9994). SO4 is 48 (16+4 8) and 96.0626 (32.065 4*15.9994). We are going to allow an application to build these compounds with overloaded and operators. And we are going to have the ability to output our compounds with an overloaded operator, and input them with an overloaded operator The class that you write will have: A default constructor A constructor that takes 1 argument, the name of an element A constructor that takes 3 arguments Three accessor functions A set function A get element function that takes a string and the file stream for elements.txt lt will search the file to find the element and load the correct atomic number and weight into the element of which it is a member An overloaded operator that adds two chemicals, concatenating their strings and combining their numbers An overloaded operator that multiplies a chemical and an integer, the string will have the number concatenated onto the string An overloaded operator that outputs the information about a chemical An overloaded operator that lets a chemical be loaded from keyboard or file Your program will be creating a Mychemicals.txt file (my main sets that up) List of compounds to build for that file: The MyChemicals.txt file will contain these along with their total atomic number and atomic weight H20 Nacio NaHCO3 C2H50H SiO2 PbS C12H22011 Finally you are to break your program into three files chem main.cc, chemical. h and chemical.cc

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions