CSCI assignment
a12/Makefile
test_counter: test_counter.o Webcounter.o g++ -std=c++11 -o test_counter test_counter.o Webcounter.o test_counter.o: test_counter.cpp Webcounter.h g++ -std=c++11 -c test_counter.cpp Webcounter.o: Webcounter.cpp Webcounter.h g++ -std=c++11 -c Webcounter.cpp clean: rm test_counter test_counter.o Webcounter.o
a12/test_counter.cpp
#include "Webcounter.h" //let's test that the "header guards" are inside the header file //by including it a second time #include "Webcounter.h" #include<iostream> int main() { //create a Webcounter object Webcounter wc; //wc.load("counter_data.txt"); //std::cout << "From file: " << wc.get() << std::endl; wc.reset(); std::cout << "Should be 0. And it is " << wc.get() << std::endl; wc.set(25); std::cout << "Should be 25. And it is " << wc.get() << std::endl; wc.set(-8); std::cout << "Should be 0. And it is " << wc.get() << std::endl; wc.hit(); wc.hit(); std::cout << "Should be 2. And it is " << wc.get() << std::endl; //wc.save("counter_data.txt"); return 0; }
a12/Webcounter.cpp
a12/Webcounter.cpp
//In this file write the member functions for the Webcounter class
//These member functions taken as a whole are referred to as
//the "class definition"
#include
"Webcounter.h"
//Hint for Webcounter::load
//This member function should first check to see if opening the file
//failed. If it failed then the value of the Webcounter should be
//set to zero:
ifstream infile
(
filename
);
if
(
!
infile
)
//problem opening file
current_number_of_hits
=
0
;
else
//file opened fine
//read in the number from the file and assign it
//to current_number_of_hits
//don't forget to close the file
a12/Webcounter.h
//In this file write the "class declaration" for the Webcounter class