Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*********C++ Program******* Given the main, create a type to build compounds in

ID: 3828694 • Letter: #

Question

*********C++ Program******* Given the main, create a type to build compounds in 3 separate files******

****************Function to convert integer to string*******************

*****************************************************************************

chemmain.cc Main Function:

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include"chemical.h"
using namespace std; // The chemical class class Chemical{ // This is one of the parts that you write

int menu();
int main(){
// 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()){
        cout<<"Unable to open the File of Elements. ";
        cout<<"Exiting the program. ";
        return 1;
   }
   fout.open("Mychemicals.txt");
   if(fout.fail()){
        cout<<"Unable to open output file. ";
        cout<<"Exiting program. ";
        return 1;
   }
   do{
        chosen = menu();
        switch(chosen){
            case 1: cout<<molecule<<endl;
                break;

case 2: fin.clear();
                fin.seekg(0, ios::beg);
                element.clear();
                cout<<"Give the Chemical Symbol for your element: ";
                cin>>chemsym;
                element.get_element(chemsym, fin);
                break;
            case 3: cout<<"Multiply your element by what? ";
                cin>>multiplier;
                element = element*multiplier;
                break;
            case 4: molecule = molecule + element;
                break;
            case 5: fout<<molecule<<endl;
                break;
            case 6: molecule.clear();
                break;
            case 7: cout<<"Enter your own element: ";
                element.clear();
                cin>>element;

break;
            case 0: cout<<"Thank you for using Chemical Builder. ";
                cout<<"I hope that you have used it for good and not for evil. ";
                break;
            default: cout<<"Not a valid choice. ";
                break;
            } // bottom of the switch;
    }while(chosen != 0);
    fin.close();
    fout.close(); return 0;
}

int menu(){
    int choice;
    cout<<"Chose from the options below. ";
    cout<<"1) View your molecule thus far. ";
    cout<<"2) Input an element for your molecule. ";
    cout<<"3) Use multiples of your element. ";
    cout<<"4) Add your multi-atom element to your molecule. ";
    cout<<"5) Save your molecule into your collection. ";

cout<<"6) Clear your molecule. ";
    cout<<"7) Invent your own element - must know atomic number and atomic weight. ";
    cout<<"0) Quit The Chemical Builder. ";
    cout<<"Choice: ";
    cin>>choice; return choice;
}

Input to test with:

Elements.txt file for atomic weights and numbers:

Program In C Given the main, Create a type that will let us Tbuild chemical compounds. Thank you! 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 want this program to do I 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 gf 1Q (1 2 8) and an atomic weight of 18.0132 (1.0079 2. 15.9994), SO4 is 48 (16.4 80 and 96.0626 B2.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 It 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 ur 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.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include"chemical.h"
using namespace std; // The chemical class class Chemical{ // This is one of the parts that you write

int menu();
int main(){
// 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()){
        cout<<"Unable to open the File of Elements. ";
        cout<<"Exiting the program. ";
        return 1;
   }
   fout.open("Mychemicals.txt");
   if(fout.fail()){
        cout<<"Unable to open output file. ";
        cout<<"Exiting program. ";
        return 1;
   }
   do{
        chosen = menu();
        switch(chosen){
            case 1: cout<<molecule<<endl;
                break;

case 2: fin.clear();
                fin.seekg(0, ios::beg);
                element.clear();
                cout<<"Give the Chemical Symbol for your element: ";
                cin>>chemsym;
                element.get_element(chemsym, fin);
                break;
            case 3: cout<<"Multiply your element by what? ";
                cin>>multiplier;
                element = element*multiplier;
                break;
            case 4: molecule = molecule + element;
                break;
            case 5: fout<<molecule<<endl;
                break;
            case 6: molecule.clear();
                break;
            case 7: cout<<"Enter your own element: ";
                element.clear();
                cin>>element;

break;
            case 0: cout<<"Thank you for using Chemical Builder. ";
                cout<<"I hope that you have used it for good and not for evil. ";
                break;
            default: cout<<"Not a valid choice. ";
                break;
            } // bottom of the switch;
    }while(chosen != 0);
    fin.close();
    fout.close(); return 0;
}

int menu(){
    int choice;
    cout<<"Chose from the options below. ";
    cout<<"1) View your molecule thus far. ";
    cout<<"2) Input an element for your molecule. ";
    cout<<"3) Use multiples of your element. ";
    cout<<"4) Add your multi-atom element to your molecule. ";
    cout<<"5) Save your molecule into your collection. ";

cout<<"6) Clear your molecule. ";
    cout<<"7) Invent your own element - must know atomic number and atomic weight. ";
    cout<<"0) Quit The Chemical Builder. ";
    cout<<"Choice: ";
    cin>>choice; return choice;
}