This is the assignment
For this assignment you will be required to write a C++ program which accepts a text file containing information about a series of hits to various websites. Your program will then store this information and will provide the user with a menu that will look up information about a website of his or her choosing.
Here is the format for the input file:
(IP_Address) (Link_Name) (Date_Accessed)
IP_Address is the IP Address of the user which does not contain any spaces.
Link_Name is the name of a website that does not contain any spaces (maximum 50 characters).
Date_Accessed is the date of the hit in mm/dd/yyyy format (Ex: 07/06/2013)
Each hit has its information on its own line in the input file.
Entries for hits in the data file which contain invalid data (such as an invalid date, etc.) should be reported to the user with an error message.
The entire entry for that hit should then be ignored.
Your program should provide a menu with the following items:
1) Report information about hits for a given link in a period of time:
Asks the user for a link to a website and a starting date and ending date, each in mm/dd/yyyy form
For the given input, your program must search through the list of hits and report the following information about the link by considering only the hit entries in the given time period:
- the number of total hits (times that the link was listed altogether)
- the number of hits by unique visitors (the number of visitors who visited the link, not counting duplicate visits)
- the number of hits by returning visitors (number of visits beyond the first by visitors)
NOTE: The sum of the unique visitor hits and repeating visitor hits should equal the total hits. Thus, it is not necessary to search the list a third time for the returning visitor hits if you already know the total hits and unique visitor hits.
If the user inputs any invalid information (non-existent date, start date comes after end date, or a link that was not in the input file) an error message should be displayed and you should then prompt the user to re-enter the data.
2) Print the input information from the text file based upon number of unique visitors to each website (in increasing order)
3) Quit the program
Optional Extra Credit: Include an additional menu option which prompts the user for a link and creates a bar chart for the past twelve months of hits in each month. Each month must fit on one page, so if there are too many hits for a given month you must change the number of hits each star represents.
Your program should also follow the following requirements:
You must prompt the user for the name of the input file, which the user will then enter by using the keyboard
Your program must be written in C++ to receive any credit.
You must use at least one class in addition to the main program
Your output should be printed in a neatly formatted table (see SAMPLE OUTPUT below)
You may use any sorting algorithm you wish to perform the sorting operation, including any algorithms listed in textbooks.
If there is an error reading from the file or if any input data is invalid you should inform the user of the situation.
In the event that the input data is invalid, you must ingore the record and print along with your error message the name of the owner of the invalid account.
Your program should make good use of functions and be well commented
You must include a "makefile" which correctly compiles your multiple source files
SAMPLE INPUT AND OUTPUT
Note that the input file is in black, commnets are in green and the output follows in blue:
//Sample input file (hits.txt):
192.168.1.101 www.cs.stonybrook.edu 01/01/2013
192.168.1.101 www.cs.stonybrook.edu 01/01/2013
123.112.15.151 www.cs.stonybrook.edu 01/01/2013
192.168.1.101 www.espn.com 01/01/2013
123.112.15.151 www.cs.stonybrook.edu 01/04/2013
123.112.15.151 www.cs.stonybrook.edu 01/01/2013
192.168.1.101 www.espn.com 01/11/2013
192.168.1.101 www.espn.com 01/1/2013 //Error in date format
192.168.1.101 www.espn.com 01/41/2013 //Error in date
192.168.1.101 www.cs.stonybrook.edu 01/09/2013
111.176.4.191 www.cs.stonybrook.edu 01/03/2013
111.176.4.191 www.yahoo.com 01/04/2013
111.176.4.191 www.yahoo.com 01/09/2013
192.168.1.101 www.yahoo.com 01/04/2013
111.176.4.191 www.yahoo.com 01/12/2013
192.168.1.101 www.espn.com 01/05/2013
//Running the programming
Enter the name of a file to load: hits.txt
Loading hits.txt...
Found a record with an invalid date format (not mm/dd/yyyy)... ignoring entry
Found a record with an invalid date ... ignoring entry
Please select a menu option:
1)Link Information in date range
2)Information about all links
3)Quit the program
Option (1,2,3): 1
Enter a link name: www.espn.com
Enter a start date: 01/01/2013
Enter a finish date: 01/09/2013
Link: www.espn.com
Total hits: 2
Unique: 1
Returning: 1
Please select a menu option:
1)Link Information in date range
2)Information about all links
3)Quit the program
Option (1,2,3): 1
Enter a link name: www.espn.com
Enter a start date: 01/01/2013
Enter a finish date: 01/19/2013
Link: www.espn.com
Total hits: 3
Unique: 1
Returning: 2
Please select a menu option:
1)Link Information in date range
2)Information about all links
3)Quit the program
Option (1,2,3): 1
Enter a link name: www.cs.stonybrook.edu
Enter a start date: 01/01/2013
Enter a finish date: 01/29/2013
Link: www.cs.stonybrook.edu
Total hits: 7
Unique: 3
Returning: 4
Please select a menu option:
1)Link Information in date range
2)Information about all links
3)Quit the program
Option (1,2,3): 1
Enter a link name: www.espn.com
Enter a start date: 01/1/2013
Enter a finish date: 01/09/2013
Invalid date format... please re-enter information
Enter a start date: 01/11/2013
Enter a finish date: 01/09/2013
Dates out of order... please re-enter information
Enter a start date: 01/01/2013
Enter a finish date: 01/09/2013
Link: www.espn.com
Total hits: 2
Unique: 1
Returning: 1
Please select a menu option:
1)Link Information in date range
2)Information about all links
3)Quit the program
Option (1,2,3): 2
Link Name Unique Visits Return Visits Total Visits
-------------------- ------------- ------------- ------------
www.espn.com 1 2 3
www.yahoo.com 2 2 4
www.cs.stonybrook.edu 3 4 7
Please select a menu option:
1)Link Information in date range
2)Information about all links
3)Quit the program
Option (1,2,3): 3
Program terminating normally...
//Example of a bar chart, for extra credit, for www.espn.com
//Assume that the last time this link was accessed was in December 2013 and
has the following distribution of hits:
//Jan: 0, Feb: 2, Mar: 3, Apr: 6, May: 12, Jun: 11,
//Jul: 10, Aug: 10, Sep: 8, Oct: 5, Nov: 3, Dec: 1
Bar chart for www.espn.com:
1/13:
2/13: **
3/13: ***
4/13: ******
5/13: ************
6/13: ***********
7/13: **********
8/13: **********
9/13: ********
01/13: *****
11/13: ***
12/13: *
GRADING KEY
(5 pts): Proper use of Comments. Include your name, assignment number and a brief description of the program at the top of main program, and brief description of each function. Also, include name of the C++ compiler that you have used.
(5 pts): Good use of Functions
(20 pts): Use of at least one additional class
(5 pts): Inclusion of a makefile
(5 pts): Input file is read correctly from keyboard
(10 pts): Error message displayed when a problem reading information from a file has been encountered or invalid user information is entered
(5 pts): Program compiles without error
(20 pts): The program correctly prints all hit information in a date range for a given link
(20 pts): The information for each link is printed in increasing order of unique hits.
(5 pts): Information is printed in a neatly formatted table
(25 pts, Extra Credit):The program correctly prints a bar chart for the hits of a given link in the last 12 months.
This is my code so far
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 45 46 47 48 49 50 51 52 53 54
|
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <iomanip.h>
#include <fstream.h>
using namespace std;
int fileinfo(void);
int fileinfo(void) {
int IP_Address[32] ;
int Date_Accessed[8];
char Link_Name [50];
char filename[10];
ifstream inFile;
inFile.open(IP_Address,ios::in );
inFile.open( Link_Name,ios::in );
inFile.open(Date_Accessed,ios::in );
cout<<"Enter filename : ";
cin>>"filename";
cout<<" What is the website Link Name? : " ;
cin>>"Link_Name";
cout<<"Enter starting date: ";
cin>>"Date_Accessed ";
cout<<"Enter ending date: " ;
cin>>"Date_Accessed ";
}
| |