Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/periodentafel.cpp

    rf66195 rfb73b8  
    2121 * Initialises start and end of list and resets periodentafel::checkliste to false.
    2222 */
    23 periodentafel::periodentafel()
    24 {
    25   start = new element;
    26   end = new element;
     23periodentafel::periodentafel() : start(new element), end(new element)
     24{
    2725  start->previous = NULL;
    2826  start->next = end;
     
    4543 * \return true - succeeded, false - does not occur
    4644 */
    47 bool periodentafel::AddElement(element *pointer)
     45bool periodentafel::AddElement(element * const pointer)
    4846{
    4947  pointer->sort = &pointer->Z;
     
    5755 * \return true - succeeded, false - element not found
    5856 */
    59 bool periodentafel::RemoveElement(element *pointer)
     57bool periodentafel::RemoveElement(element * const pointer)
    6058{
    6159  return remove(pointer, start, end);
     
    7169
    7270/** Finds an element by its atomic number.
    73  * If element is not yet in list, datas are asked and stored in database.
     71 * If element is not yet in list, returns NULL.
    7472 * \param Z atomic number
    75  * \return pointer to element
    76  */
    77 element * periodentafel::FindElement(int Z)
     73 * \return pointer to element or NULL if not found
     74 */
     75element * const periodentafel::FindElement(const int Z) const
    7876{
    7977  element *walker = find(&Z, start,end);
    80   if (walker == NULL) { // not found: enter and put into db
    81     cout << Verbose(0) << "Element not found in database, please enter." << endl;
    82     walker = new element;
    83     cout << Verbose(0) << "Mass: " << endl;
    84     cin >> walker->mass;
    85     walker->Z = Z;
    86     cout << Verbose(0) << "Atomic number: " << walker->Z << endl;
    87     cout << Verbose(0) << "Name [max 64 chars]: " << endl;
    88     cin >> walker->name;
    89     cout << Verbose(0) << "Short form [max 3 chars]: " << endl;
    90     cin >> walker->symbol;
    91     periodentafel::AddElement(walker);
    92   }
    9378  return(walker);
    9479};
     
    9984 * \return pointer to element
    10085 */
    101 element * periodentafel::FindElement(const char *shorthand) const
     86element * const periodentafel::FindElement(const char * const shorthand) const
    10287{
    10388  element *walker =  periodentafel::start;
     
    11297/** Asks for element number and returns pointer to element
    11398 */
    114 element * periodentafel::AskElement()
     99element * const periodentafel::AskElement() const
    115100{
    116101  element *walker = NULL;
     
    124109};
    125110
     111/** Asks for element and if not found, presents mask to enter info.
     112 * \return pointer to either present or newly created element
     113 */
     114element * const periodentafel::EnterElement()
     115{
     116  element *walker = NULL;
     117  int Z = -1;
     118  cout << Verbose(0) << "Atomic number: " << Z << endl;
     119  cin >> Z;
     120  walker = FindElement(Z);
     121  if (walker == NULL) {
     122    cout << Verbose(0) << "Element not found in database, please enter." << endl;
     123    walker = new element;
     124    walker->Z = Z;
     125    cout << Verbose(0) << "Mass: " << endl;
     126    cin >> walker->mass;
     127    cout << Verbose(0) << "Name [max 64 chars]: " << endl;
     128    cin >> walker->name;
     129    cout << Verbose(0) << "Short form [max 3 chars]: " << endl;
     130    cin >> walker->symbol;
     131    periodentafel::AddElement(walker);
     132  }
     133  return(walker);
     134};
     135
    126136/** Prints period table to given stream.
    127137 * \param output stream
    128138 */
    129 bool periodentafel::Output(ofstream *output) const
     139bool periodentafel::Output(ofstream * const output) const
    130140{
    131141  bool result = true;
     
    145155 * \param *checkliste elements table for this molecule
    146156 */
    147 bool periodentafel::Checkout(ofstream *output, const int *checkliste) const
     157bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const
    148158{
    149159  element *walker = start;
     
    215225        cout << "Could not parse element: ";
    216226        neues->Output((ofstream *)&cout);
     227        delete(neues);
    217228      }
    218229    }
Note: See TracChangeset for help on using the changeset viewer.