Subject Computer Science C-Family Programming
Write a program that reads a person’s physical activity from a file, collects statistics by month, and prints a table showing those statistics.
The program should prompt the user for the name of the file. This file contains information on the number of steps a person has taken on a given day. Each line of the file is of the form #1/#2 #3 where:
• #1 is the one or two-digit month, ranging from 1 to 12
• #2 is the one or two-digit day of the month, ranging from 1 to 31
• #3 is the number of steps the person walked that day If a line in the file contains something other than data of this format, that line should be ignored and a warning printed to the user about the ignored line. White space between values are not considered relevant and should not impact the validity of a line. Don’t worry about the same day appearing multiple times in the file… that is guaranteed not to happen. Lines consisting of only whitespace should be ignored.
While reading the file, the program should capture and calculate the minimum number of steps taken in each month and the day those steps were taken, the maximum number of steps taken in each month and the day those steps were taken, the total number of steps taken in each month, and the average number of steps taken each day in a month (only for the days that have steps provided… don’t include days without steps in the average).
After reading all the data in the file, the program should print a nicely formatted table with all the statistics gathered and calculated.
Your program should validate the data as much as possible. In addition, the program should recover from unexpected input as much as possible.
Do NOT use arrays in this program.
HINT: Start with input files that contain only well-formed, valid input. Then gradually introduce invalid data into the input file and ensure your program handles it as well as possible.
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
const int DaySize = 5;
const int CountSize = 7;
const int StepsSize = 11;
const int AverageSize = 13;

// All these constants are posted based on the values because of better printing
// It will be explained further in function PrintMonth

namespace patch
    template < typename T > std::string to_string( const T& n )
       std::ostringstream stm ;
       stm << n ;
       return stm.str() ;

void PrintMonth(int month, int dayMin, int dayMax, int min, int max, double totalSteps, double average)
// This is the name of the function that is printing one line
// This "switch" is there to print a name of the month at the beginning of the line according to the value of "month" variable and certain number empty places
// So, that the signs "|" would not be at the same level
// For example, if we print January that consists of 8 characters and 3 signs of spaces then sign "|"
// For example, if we print April that consists of 5 characters and 6 signs of spaces then sign "|"...
switch (month)...

This is only a preview of the solution. Please use the purchase button to see the entire solution


or free if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats