DNA-sim

git clone git://git.codymlewis.com/DNA-sim.git
Log | Files | Refs | README | LICENSE

main.cpp (1954B)


      1 /**
      2  * main.cpp - DNA_sim
      3  * Author: Cody Lewis
      4  * Description:
      5  *  The UI for the DNA_sim
      6  */
      7 #include <iostream>
      8 #include <cstdlib>
      9 #include <fstream>
     10 #include <vector>
     11 #include "Strand.h"
     12 void add_strand(std::vector<DNA_sim::Strand>& strands);
     13 void view_stats(std::vector<DNA_sim::Strand>& strands);
     14 void view_strands(std::vector<DNA_sim::Strand>& strands);
     15 int main() {
     16   int input;
     17   std::vector<DNA_sim::Strand> strands;
     18   bool exit = false;
     19   while(!exit) {
     20     std::cout << "Add Strand(1), View strand stats(2), View strands(3), Exit(9)" << std::endl;
     21     std::cin >> input;
     22     switch(input) {
     23       case 1:
     24         add_strand(strands);
     25         break;
     26       case 2:
     27         view_stats(strands);
     28         break;
     29       case 3:
     30         view_strands(strands);
     31         break;
     32       case 9:
     33         exit = true;
     34         break;
     35       default:
     36         std::cout << "Invalid input, please try again." << std::endl;
     37     }
     38   }
     39   return 0;
     40 }
     41 void add_strand(std::vector<DNA_sim::Strand>& strands) {
     42   std::string input;
     43   std::cout << "Do you want to use a file (y/N) ";
     44   std::cin >> input;
     45   if(input == "y" || input == "Y") {
     46     std::cout << "Specify a file name: ";
     47     input.clear();
     48     std::cin >> input;
     49     std::ifstream in_data;
     50     in_data.open(input.c_str());
     51     input.clear();
     52     in_data >> input; // takes a single line
     53     strands.push_back(DNA_sim::Strand(input));
     54   } else {
     55     std::cout << "Input your strand: ";
     56     input.clear();
     57     std::cin >> input;
     58   }
     59   strands.push_back(DNA_sim::Strand(input));
     60 }
     61 void view_stats(std::vector<DNA_sim::Strand>& strands) {
     62   for(std::size_t i = 0; i < strands.size(); ++i) {
     63     std::cout << "Strand " << i << ":" << std::endl;
     64     std::cout << strands[i].stats() << std::endl;
     65   }
     66 }
     67 void view_strands(std::vector<DNA_sim::Strand>& strands) {
     68   for(std::size_t i = 0; i < strands.size(); ++i) {
     69     std::cout << "Strand " << i << ":" << std::endl;
     70     std::cout << strands[i] << std::endl;
     71   }
     72 }