Subversion Repository Public Repository

ChemEqBalancer

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Molecule.h"
#include "Element.h"

#include <string>
#include <iostream>
#include <sstream>

  // molecule keeps track of number of atoms (subscript)
  // equation keeps track of number of molecules (coefficient)

  // Molecule("Br", 2);
  // Molecule("H", 5);
  // Equation(&Br2, 6); // 6Br_2ooh

Molecule::Molecule(std::string atom, int subscript)
{
  addAtom(atom, subscript);
}

void Molecule::addAtom(std::string atom, int subscript)
{
  Element* temp1 = new Element(atom);
  element_s_t temp2 = {temp1, subscript};
  atoms.push_back(temp2);
}

std::string Molecule::getName()
{
  std::string name;
  std::ostringstream os;

  element_s_t_v::iterator it = atoms.begin();
  while (it != atoms.end()) {
    name += it->_atom->getName();
    if (it->_subscript != 1) {
      os << it->_subscript;
      name += os.str();
      os.str("");
    }
    it++;
  }

  return name;
}

Commits for ChemEqBalancer/Molecule.cpp

Diff revisions: vs.
Revision Author Commited Message
2 Shaun Mon 24 Jan, 2011 23:32:14 +0000