阿猫阿狗的爱情游戏2

 
// 案例5 阿猫阿狗的爱情游戏2
#include<iostream>
#include <cstring>
#include <ctime>
#include <cstdlib>
using namespace std;
class Boy
{
	public:
	bool House; //有房;
	int Age; //年龄;
	char Name[20];
	public:
	Boy(char *name);
	bool Gift(char gift);
	int AnnualSalary(int salary);
};
Boy::Boy(char *name)
{
	srand((unsigned)time(NULL));		// 为rand()函数提供一个随机数种子
	if(rand() == 100) House=true;
	strcpy(Name,name);
}
bool Boy::Gift(char gift)
{
	if(gift=='Y'||gift=='y')
	return true;
	else
	return false;
}
int Boy::AnnualSalary(int salary)
{
	cout<<Name<<"日夜操劳,两眼发黑,为的是早日赚到老婆本。"<<endl;
	salary=salary*365;
	return salary;
}
class Girl
{
	public:
		int Feeling; // 情感指数
		bool Willing; // 是否愿意等
		int Birthday; // 生日
		char Name[20];
	public:
		Girl(char *name);
		void Love(char *name);
		void Marry(char *name);

};
Girl::Girl(char *name)
{
	strcpy(Name,name);
}
void Girl::Love(char *name)
{
	cout<<"\n 新的故事开始了,"<<Name<<"与"<<name<<"进入相恋阶段......"<<endl;
}
void Girl::Marry(char *name)
{
	cout<<"\n 大团圆结局,"<<Name<<"同意嫁给"<<name<<",从此两人过上了幸福生活......"<<endl;
}
/*
日期转换
参数 
	int day:距元月一日的天数
返回值:	
	表示日期中的月日
*/
int convertDate(int day)
{
	int days[]=
	{
		31,28,31,30,31,30,31,30,30,31,30,31
	};
	int i=0;
	for (; i<12; i++)
	{
		if (day>days[i])
		{
			day=day-days[i];
		}
		else
		{
			break;
		}
	}
	return ((i+1)*100+day);
}
int main( )
{
	Boy theBoy("dog");
	Girl theGirl("cat");
	theBoy.Age=24;
	theGirl.Feeling=1;
	theGirl.Willing=true;
	theGirl.Birthday=1001;
	int year=1;
	char gift='N';
	int money=0;
	int salary=0;
	theGirl.Love(theBoy.Name ); //故事开始
	if(theBoy.House == true)
	{
		theGirl.Marry(theBoy.Name);
		return 0;
	}
	while(theGirl.Willing==true)
	{
		cout<<"\n*****第"<<year<<"年*****\n";
		for( int day=1; day<=365; day++)
		{
			if( convertDate(day) == 214) // if ( 节日转换(day) == 情人节)
			{
				cout<<"情人节到了,是否给女朋友送礼物呢?(Y/N)";
				cin>>gift;
				if( theBoy.Gift(gift))
					theGirl.Feeling++;
				else
					theGirl.Feeling--;
			}
			if( convertDate(day) == theGirl.Birthday) //if ( 日期转换(day) == theGirl.Birthday)
			{
				cout<<"生日到了,是否给女朋友送礼物呢?(Y/N)";
				cin>>gift;
				if( theBoy.Gift(gift))
					theGirl.Feeling++;
				else
					theGirl.Feeling--;
			}
		}
		cout<<"请输入今年的日工资:";
		cin>>salary;
		money=money+theBoy.AnnualSalary(salary);
		cout<<"年终小结:\t"<<"男孩年龄:"<<theBoy.Age<<", 男孩存款:"<<money<<", 女孩情感指数:"<<theGirl.Feeling;
		if(money>1000000)
		{
			theBoy.House=true;
			break;
		}
		year++;
		theBoy.Age++;
		theGirl.Feeling--;
		if(theBoy.Age>30 || theGirl.Feeling<0) theGirl.Willing=false;
	}
	if(theBoy.House==true)
		theGirl.Marry(theBoy.Name);
	else
	{
		Boy anotherBoy("Mouse");
		theGirl.Love(anotherBoy.Name);
	}
	return 0;
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值