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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <iostream>
#include <fstream>
#include <windows.h>
void statistics();
void start();
void cls()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
return;
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten ) ||
!GetConsoleScreenBufferInfo( hConsole, &csbi ) ||
!FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ))
return;
SetConsoleCursorPosition( hConsole, coordScreen );
}
int main()
{
int decision;
std::cout << "Enter 1 to start a new day.\nEnter 2 to see the statistics.\nEnter 3 to reset the program\nAnother number to exit." << std::endl;
std::cin >> decision;
switch(decision)
{
case 1:{
start();
break;
}
case 2:{
statistics();
break;
}
case 3:{
std::ofstream ofs;
ofs.open("PushUps.txt", std::ofstream::out | std::ofstream::trunc);
ofs.close();
cls();
std::cout << "The program has been cleared\n";
break;
std::cin >> decision;
}
}
}
void start()
{
cls();
int push, day, dec;
std::cout << "Enter the number of the day\nIf this it's the first time you are running the program you should enter 1\n";
std::cin >> day;
std::cout << "Enter how many Push Ups you did today\n";
std::cin >> push;
cls();
std::cout << "The statistics are:" << std::endl;
{
std::ofstream pushups( "PushUps.txt", std::ios::app );
pushups << day << ' ' << push << '\n';
}
std::ifstream ipushups( "PushUps.txt" );
const int maxday = 10 ;
int arraypush[maxday];
int arrayday[maxday];
int n = 0;
while( n < maxday && ipushups >> day >> push )
{
arrayday[n] = day ;
arraypush[n] = push ;
++n;
}
for( int i = 0 ; i < n ; ++i )
{
std::cout << "Day " << arrayday[i]<< ":" << ' ' << "PushUps = " <<arraypush[i] << '\n' << '\n';
}
std::cout << "Press a lower number than 9 to close, or 9 to reset the program.\n(Press 10 for more statistics)" << std::endl;
std::cin >> dec;
switch(dec)
{
case 10:
{
statistics();
break;
}
case 9:
{
std::ofstream ofs;
ofs.open("PushUps.txt", std::ofstream::out | std::ofstream::trunc);
ofs.close();
cls();
std::cout << "The program has been cleared\n";
break;
std::cin >> n;
}
}
}
void statistics()
{
int dummy, pushups, days=0;
float sum =0;
std::ifstream pushcalc("PushUps.txt");
while(pushcalc >> dummy >> pushups)
{
sum = sum+pushups;
days++;
}
cls();
std::cout << "In " << days << " days you made " << sum << " Push Ups" << std::endl;
pushcalc.close();
float avr = sum/days;
std::cout << "Your average Push Ups /day is " << avr << std::endl;
}
|