⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base.cpp.bak

📁 命令行模式下的简单宾馆管理系统..各种基本功能齐全..属于新人练习作品..hotel manager..
💻 BAK
字号:
/*
 * File: base.cpp
 * --------------
 * This file implements the base.h interface. 
 */


#include "base.h"

/* Implements */

void ReadStringFromFile(ifstream *fin, string &s)
{
	char temp_c;
	s = "";
	*fin >> temp_c;
	while (temp_c == ' ') *fin >> temp_c;
	while (temp_c != ' ')
	{
		s += temp_c;
		*fin >> temp_c;
	}
}
string _TWO(int x)
{
	string s;
	s += char(x / 10 % 10 + '0');
	s += char(x % 10 + '0');
	return s;
}
#define YEAR_FURTHER 2108
#define YEAR_NOW 2008
//For Date
int Date::GetDay()
{
	return day;
}
int Date::GetMonth()
{
	return month;
}
int Date::GetYear()
{
	return year;
}
int Date::Good()
{
	if (CheckDay() && CheckMonth() && CheckYear()) return 1;
	return 0;
}
int Date::CheckDay()
{
	if (!CheckMonth()) return 0;
	if (day <= 0) return 0;
	if ((12 == month) || (10 == month) || (8 == month) || (7 == month) || (5 == month) || (3 == month) || (1 == month))
	{
		if (day <= 31) return 1;
		return 0;
	}
	else if (2 == month)
	{
		if ((0 == year % 4) && (year % 100 != 0))
		{
			if (day <= 29) return 1;
			return 0;
		}
		else
		{
			if (day <= 28) return 1;
			return 0;
		}
	}
	else
	{
		if (day <= 30) return 1;
		return 0;
	}
	return 0;
}
int Date::CheckMonth()
{
	if (month > 0 && month < 13) return 1;
	return 0;
}
int Date::CheckYear() //user for 100 years
{
	if ((year >= YEAR_NOW) && (year <= YEAR_FURTHER)) return 1;
	return 0;
}
void Date::SetDate( int dy, int mh, int yr)
{
	day = dy;
	month = mh;
	year = yr;
}
void Date::Print()
{
	if (Good()) cout << year << '.' << _TWO(month) << '.' << _TWO(day);
	else cout << "Invaild date!";
}
Date::Date( int dy, int mh, int yr )
{
	SetDate(dy, mh, yr);
}
Date::~Date()
{
}
//for Time
Time::Time(int sd, int me, int hr)
{
	SetTime(sd, me, hr);
}
void Time::SetTime( int sd, int me, int hr)
{
	second = sd;
	minute = me;
	hour = hr;
}
int Time::GetSecond()
{
	return second;
}
int Time::GetMinute()
{
	return minute;
}
int Time::GetHour()
{
	return hour;
}
int Time::Good()
{
	if (CheckSecond() && CheckMinute() && CheckHour()) return 1;
	return 0;
}
void Time::PrintStandard()
{
	if (Good()) cout << _TWO((hour - 1) % 12 + 1) << ':' << _TWO(minute) << ':' << _TWO(second);
	else cout << "Invaild time!";
}
void Time::PrintUniversal()
{
	if (Good()) cout << _TWO(hour) << ':' << _TWO(minute) << ':' << _TWO(second);
	else cout << "Invaild time!";
}
int Time::CheckSecond()
{
	if ((second >= 0) && (second < 60)) return 1;
	return 0;
}
int Time::CheckMinute()
{
	if ((minute >= 0) && (minute < 60)) return 1;
	return 0;
}
int Time::CheckHour()
{
	if ((hour >= 0) && (hour < 24)) return 1;
	return 0;
}
Time::~Time()
{
}


void Error( string errorInfo )
{
	cout<<"Error~Info:"<<errorInfo<<endl;
	return ;
}

time_t curTime;

string CharToStr( char base[] )
{
	string tar="";
	while (*base != '\0') tar+=*base++;
	return tar;
}

int CharToInt( char base[] )
{
	int i=0;
	int sum=0;
	while (base[i] != '\0') sum=sum*10+base[i++]-48;
	return sum;
}

string GetString()
{
	char temp_c[max_c]="";
	while (temp_c[0] == '\0') cin.getline(temp_c,max_c,'\n');
	return CharToStr(temp_c);
}

int GetInt()
{
	char temp_c[max_c];
	int i=0;
	bool p=false;
	//cin.ignore(max_c,'\n');
	do{
		p=false;
		i=0;
		cin.getline(temp_c,max_c,'\n');
		while (temp_c[0] == '\0') cin.getline(temp_c,max_c,'\n');
		while (temp_c[i] != '\0') {
			if (temp_c[i]<48 || temp_c[i]>57) p=true;
			i++;
		}
		if (p) cout<<"Input must be a number~"<<endl<<"Please try again:";
	}while (p);
	return CharToInt(temp_c);
}

char GetYesNo()
{
	string t=GetString();
	while (t[0] != 'y' && t[0] !='n' || t[1] != '\0'){
			cout<<"Input must be 'y' or 'n' .:";
			t=GetString();
		}
	return t[0];
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -