Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WebStats.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <iomanip> // std::setw
- using namespace std;
- //////////////////////////////////////////////////////////
- // your class
- //////////////////////////////////////////////////////////
- class WebStat1
- {
- public:
- std::string m_IP_Address, m_Link_Name, m_Date_Accessed;
- WebStat1 (const std::string &IP_Address,const std::string &Link_Name,const std::string &Date_Accessed)
- : m_IP_Address(IP_Address),m_Link_Name(Link_Name),m_Date_Accessed(Date_Accessed){}
- };
- //------------------------------------------------------//
- //////////////////////////////////////////////////////////
- // Overload the << operator
- //(need this to coalesce the three properties of WebStat1)
- //////////////////////////////////////////////////////////
- ostream &operator<<(ostream &os, const WebStat1 &w)
- {
- os << w.m_Link_Name << setw(15) << w.m_IP_Address << setw(15) << w.m_Date_Accessed << endl;
- return os;
- }
- //------------------------------------------------------//
- //////////////////////////////////////////////////////////
- // Print the content of the Vector
- //////////////////////////////////////////////////////////
- void print(vector<WebStat1> wbs)
- {
- for(vector<WebStat1>::iterator it = wbs.begin(); it != wbs.end(); ++it )
- cout << *it;
- }
- //------------------------------------------------------//
- ////////////////////////////////////////////////////////
- // your main
- ////////////////////////////////////////////////////////
- int main()
- {
- int choice= 0;
- string FilePath, yes_no ="y";
- vector<WebStat1> WebStats;
- while (yes_no=="y"||yes_no=="Y")
- {
- system("cls");
- FilePath = "";
- cout <<"Enter the name of a file to load : ";
- cin >> FilePath;
- ifstream myfile (FilePath);
- if (myfile.is_open())
- {
- cout <<"Loading " << FilePath << "...";
- // OK rip the data from the file here
- while ( myfile.good() )
- {
- // you still need to validate the data somewhere here
- // and out put a message
- std::string IP_Address, Link_Name, Date_Accessed;
- myfile >> IP_Address >> Link_Name >> Date_Accessed;
- WebStat1 p(IP_Address, Link_Name, Date_Accessed);
- WebStats.push_back(p);
- }
- break; // and escape the loop
- }
- else // can't find that file... try again?
- {
- do
- {
- cout <<"\nFile Not Found. do you wish to continue? Y/N : ";
- cin >> yes_no;
- }
- while((yes_no !="Y")&&(yes_no !="N")&&(yes_no !="y")&&(yes_no !="n"));
- }
- }
- if (yes_no=="y"||yes_no=="Y")
- {
- while( choice != 3)
- {
- system("cls");
- cout<<"Please select a menu option: \n"<<endl;
- cout<<"1)Link Information in date range."<<endl;
- cout<<"2)Information about all links."<<endl;
- cout<<"3)Quit the program"<<endl;
- cout<<"999)List the content of Vector :: remove this option later"<<endl;
- cout<<"\nSelect Option (1,2,3): "<<endl;
- cin>>choice;
- system("cls");
- switch (choice)
- {
- case 1:
- cout<<"1. Do First Choice."<<endl;
- system("pause");
- break;
- case 2:
- cout<<"2. Do Second Choice."<<endl;
- system("pause");
- break;
- case 999:
- cout<<"999. List the content of Vector."<<endl<<endl;
- // print tout the content of the Vector
- print(WebStats);
- system("pause");
- break;
- default:
- break;
- }
- }
- }
- return 0;
- }
- //------------------------END---------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement