// VS 2008
#include "stdafx.h"
#include <stdlib.h>
#include "windows.h"
#include <stdio.h>
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
const char* szcFile = "D:\\ReadRecord.ini";
int nLastDate = 0;
int nLastScore = 0;
int nSumScore = 0;
int nOperCnt = 0;
// 获取当前系统日期
SYSTEMTIME sysTime = { 0 };
GetSystemTime( &sysTime );
int nToday = sysTime.wYear*10000 + sysTime.wMonth*100 + sysTime.wDay;
// 获取上次阅读的日期,分数,次数
nLastDate = GetPrivateProfileInt( "History", "LastDate", nToday/*20131011*/, szcFile );
nLastScore = GetPrivateProfileInt( "History", "LastScore", 0, szcFile );
nSumScore = GetPrivateProfileInt( "History", "SumScore", 0, szcFile );
nOperCnt = GetPrivateProfileInt( "History", "OperCnt", 0, szcFile );
// 两个日期比较
int nDateDiff = sysTime.wYear*10000 + sysTime.wMonth*100 + sysTime.wDay - nLastDate ;
if ( nDateDiff > 1 )
{
// 说明中间至少一天没有阅读
for( int i=1; i<nDateDiff; i++ ) // 1开始==不含今天的
{
nLastScore -= 3;
}
printf( "注意啦,小伙伴们, 学习如逆水行舟,不进则退啊。\n 你们已经 %d 天没有好好学习了,目前得分为 %d。\n",nDateDiff, nLastScore );
}
else
{
printf( "\t============学习情况统计============\t\n" );
printf( "\t\t累计得分:%d\t\n" ,nLastScore );
printf( "\t\t累计学时:%d\t\n" ,nSumScore );
printf( "\t\t阅读次数:%d\t\n" ,nOperCnt );
printf( "\t\t平均学时:%g\t\n" ,(nOperCnt==0?0:nSumScore*1.0/nOperCnt) );
printf( "\t\t上次阅读:%d\t\n" ,nLastDate );
printf( "\n\t\t贵有恒,何必三更眠五更起;\n\t\t最无益,只怕一日曝十日寒!\t\n" );
printf( "\t====================================\t\n" );
}
printf( "您今天[%4d-%02d-%02d]的阅读时间为:",
sysTime.wYear, sysTime.wMonth,sysTime.wDay );
int nTodayScore = -1;
if ( 1 != scanf( "%d", &nTodayScore ) )
{
scanf( "%*c" );
printf( "输入出错啦...\n" );
return 0;
}
if ( nTodayScore < 0)
{
scanf( "%*c" );
printf( "输入出错啦...\n" );
return 0;
}
else if ( nTodayScore == 0 )
{
nLastScore -= 3;
}
else
{
if ( nTodayScore > 24 )
{
printf( " 要么是输错,要么吹大了,或者抱佛脚,不然就是...\n" );
return 0;
}
if ( nTodayScore > 12 )
{
printf( " 努力学习固然重要,但别忘了健康...\n" );
}
nLastScore += nTodayScore;
nSumScore += nTodayScore;
printf( "今天经验值 +%d...\n",nTodayScore );
}
// 写入文件保存
nOperCnt++;
char szcText[20] = { 0 }, szcText2[20] = { 0 };
sprintf( szcText, "%d", nLastScore );
WritePrivateProfileString( "History","LastScore", szcText, szcFile );
sprintf( szcText, "%d", nSumScore );
WritePrivateProfileString( "History","SumScore", szcText, szcFile );
sprintf( szcText, "%d", nToday );
WritePrivateProfileString( "History","LastDate", szcText, szcFile );
sprintf( szcText, "%d", nOperCnt );
WritePrivateProfileString( "History","OperCnt", szcText, szcFile );
sprintf( szcText2, "%d-%d-%d %02d:%02d", sysTime.wYear, sysTime.wMonth,sysTime.wDay, sysTime.wHour, sysTime.wMinute );
WritePrivateProfileString( "Date",szcText, szcText2, szcFile );
return 0;
}