您的位置:首页 > 编程语言 > C语言/C++

简易恋爱游戏程序 C++

2012-04-21 10:02 501 查看


#include<iostream>

#include<cstring>

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)

{

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 main()

{

Boy theBoy("Jay");

Girl theGirl("Vivian");

theBoy.Age=24;

theGirl.Feeling=1;

theGirl.Willing=true;

theGirl.Birthday=1224;

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(day==45)

{

cout<<"情人节到了,是否送给女朋友礼物呢?(Y\\N)";

cin>>gift;

if(theBoy.Gift(gift))

theGirl.Feeling++;

else

theGirl.Feeling--;

}

if(day==350)

{

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("Jahn");

theGirl.Love(anotherBoy.Name);

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: