Advertisement
NAK

Simple Menu

NAK
Apr 20th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.48 KB | None | 0 0
  1. // WebStats.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <fstream>
  8. #include <vector>
  9. #include <iomanip>      // std::setw
  10.  
  11. using namespace std;
  12.  
  13. //////////////////////////////////////////////////////////
  14. // your class
  15. //////////////////////////////////////////////////////////
  16. class WebStat1
  17. {
  18. public:
  19.     std::string m_IP_Address, m_Link_Name, m_Date_Accessed;
  20.  
  21.     WebStat1 (const std::string &IP_Address,const std::string &Link_Name,const std::string &Date_Accessed)
  22.     : m_IP_Address(IP_Address),m_Link_Name(Link_Name),m_Date_Accessed(Date_Accessed){}
  23. };
  24. //------------------------------------------------------//
  25.  
  26. //////////////////////////////////////////////////////////
  27. // Overload the << operator
  28. //(need this to coalesce the three properties of WebStat1)
  29. //////////////////////////////////////////////////////////
  30. ostream &operator<<(ostream &os, const WebStat1 &w)
  31. {
  32.     os << w.m_Link_Name << setw(15) << w.m_IP_Address << setw(15) << w.m_Date_Accessed << endl;
  33.     return os;
  34. }  
  35. //------------------------------------------------------//
  36.  
  37. //////////////////////////////////////////////////////////
  38. // Print the content of the Vector
  39. //////////////////////////////////////////////////////////
  40. void print(vector<WebStat1> wbs)
  41. {
  42.     for(vector<WebStat1>::iterator it = wbs.begin(); it != wbs.end(); ++it )
  43.         cout << *it;
  44. }
  45. //------------------------------------------------------//
  46.  
  47. ////////////////////////////////////////////////////////
  48. // your main
  49. ////////////////////////////////////////////////////////
  50. int main()
  51.  {
  52.     int choice= 0;
  53.     string FilePath, yes_no ="y";
  54.     vector<WebStat1> WebStats;
  55.  
  56.     while (yes_no=="y"||yes_no=="Y")
  57.     {
  58.         system("cls");
  59.         FilePath = "";
  60.         cout <<"Enter the name of a file to load : ";
  61.         cin >> FilePath;
  62.         ifstream myfile (FilePath);
  63.         if (myfile.is_open())
  64.         {
  65.             cout <<"Loading " <<  FilePath << "...";
  66.             // OK rip the data from the file here
  67.             while ( myfile.good() )
  68.             {
  69.                 // you still need to validate the data somewhere here
  70.                 // and out put a message
  71.                 std::string IP_Address, Link_Name, Date_Accessed;
  72.                 myfile >> IP_Address  >> Link_Name >> Date_Accessed;
  73.                 WebStat1 p(IP_Address, Link_Name, Date_Accessed);
  74.                 WebStats.push_back(p);
  75.             }
  76.             break; // and escape the loop
  77.         }
  78.         else // can't find that file... try again?
  79.         {
  80.             do
  81.             {
  82.                 cout <<"\nFile Not Found. do you wish to continue? Y/N : ";
  83.                 cin >> yes_no;
  84.             }
  85.             while((yes_no !="Y")&&(yes_no !="N")&&(yes_no !="y")&&(yes_no !="n"));
  86.         }
  87.     }
  88.  
  89.  
  90.     if (yes_no=="y"||yes_no=="Y")
  91.     {
  92.         while( choice != 3)
  93.         {
  94.             system("cls");
  95.             cout<<"Please select a menu option: \n"<<endl;
  96.             cout<<"1)Link Information in date range."<<endl;
  97.             cout<<"2)Information about all links."<<endl;
  98.             cout<<"3)Quit the program"<<endl;
  99.             cout<<"999)List the content of Vector :: remove this option later"<<endl;
  100.             cout<<"\nSelect Option (1,2,3): "<<endl;
  101.             cin>>choice;
  102.             system("cls");
  103.             switch (choice)
  104.             {
  105.             case 1:
  106.                 cout<<"1. Do First Choice."<<endl;
  107.                 system("pause");
  108.                 break;
  109.             case 2:
  110.                 cout<<"2. Do Second Choice."<<endl;
  111.                 system("pause");
  112.                 break;
  113.             case 999:
  114.                 cout<<"999. List the content of Vector."<<endl<<endl;
  115.  
  116.                 // print tout the content of the Vector
  117.                 print(WebStats);
  118.  
  119.                 system("pause");
  120.                 break;
  121.             default:
  122.                 break;
  123.             }
  124.         }
  125.     }
  126.     return 0;
  127. }
  128. //------------------------END---------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement