西科人BBS_西安科技大学学生论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: 王少爷

[语言编程] 一个女孩写的经典程序!!!

[复制链接]
发表于 2006-9-6 13:24:38 | 显示全部楼层
哈哈
有点意思
发表于 2007-5-27 17:01:45 | 显示全部楼层
// 给个代码瞧瞧


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

#define YES                 true
#define NO                  false
#define VALENTINE_DAY       31 + 14       // 情人节
#define ROSE                1             // 玫瑰
#define NOTHING            
#define OTHER_BOY                         // 其他男生

#define ENOUGH_BUY_HOUSE    400000        // 买房钱
#define ENOUGH_BUY_CAR      120000        // 买车钱
#define BASE_PAY            1000           // 男生每天最多收入


/* class boy */
class Boy
{
public:
       Boy (bool car, bool house, unsigned long money):
           Car(car), House(house), Money(money), HaveGirl(false)
       {
           cout << "男生基本情况:" << '\n'
                << "车: " << Car << '\n'
                << "房子: " << House << '\n'
                << "钱: " << Money << '\n'
                << "女朋友:" << HaveGirl << '\n'
                << endl;
       }

       bool HaveCar() { return Car; }             // 是否有车
       bool HaveHouse()        { return House; }         // 是否有房
       unsigned long GetMoney() { return Money;}  // 挣钱数量
       void MakeMoney ()                          // 挣命挣钱
       {       
           srand( time(0) );
           Money += rand() % BASE_PAY;

           if (Money >= ENOUGH_BUY_HOUSE && !House)  // 有钱买房
           {
               House = YES;
               Money -= ENOUGH_BUY_HOUSE;
                          
               cout << "钱够买房了!" << '\n'
                    << "买完房还剩: " << Money << '\n'
                    << endl;
           }


           if (Money >= ENOUGH_BUY_CAR && !Car)           // 有钱买车
           {
               Car = YES;
               Money -= ENOUGH_BUY_CAR;

               cout << "钱够买车了!" << '\n'
                    << "买完车还剩: " << Money << '\n'
                    << endl;
           }
       }
               
       bool GiveGirl(int SomeThing)               // 送女孩子东西
       {
           cout << "男生送玫瑰花给女孩!\n" << endl;
           return (SomeThing == ROSE);
       }

       void Set() { }

       friend class Girl;

private:
       bool Car;                 // 是否有车
       bool House;               // 是否有房
       unsigned long Money;      // 钱
       bool HaveGirl;            // 有女孩子
};

/* class Girl */
class Girl
{
public:
       Girl (int birthday, int emothion, bool argeewait, int age):
            Birthday(birthday), Emotion(emothion), ArgeeWait(argeewait), Age(age)
       {
           cout << "女生基本情况:" << '\n'
                << "生日: " << Birthday << '\n'
                << "感情: " << Emotion << '\n'
                << "愿意等: " << ArgeeWait << '\n'
                << "年龄:" << Age << '\n'
                << endl;
       }
      
       friend bool Love(Boy & boy, Girl & girl);
       bool Marry(Boy & boy)               // 嫁给
       {
                  cout << "女孩愿嫁给男生!" << endl;
           boy.HaveGirl = YES;
           return true;
       }
      
       int GetEmotion() { return Emotion; }     // 感情
       bool Goto ( OTHER_BOY )                  // 跟了别人
       {
                  cout << "女孩跟了别男生!" << endl;
           return true;
       }

private:
       int Birthday;    // 生日
       int Emotion;     // 情感
       bool ArgeeWait;  // 愿意等
       int Age;         // 年龄
};


bool Love(Boy & boy, Girl & girl)
{
    if (boy.HaveCar() && boy.HaveHouse())
    {
        boy.Set(NOTHING);
        return girl.Marry(boy);
    }

    if (girl.ArgeeWait)
    {
        while ( !(boy.GetMoney() > 100000 && girl.GetEmotion() > 8))
        {
            for (int day = 1; day <= 365; day++)
            {
                if (day == VALENTINE_DAY)                // 情人节
                {
                   cout << "情人节到了!" << endl;

                    if ( boy.GiveGirl(ROSE) )        // 是否送玫瑰
                    {
                        girl.Emotion++;
                    }
                    else
                    {
                        girl.Emotion--;
                    }
                }

                if (day == girl.Birthday)                        // Girl's 生日
                {
                    cout << "女孩生日到了!" << endl;

                    if ( boy.GiveGirl(ROSE) )                // 是否送玫瑰
                    {
                        girl.Emotion++;
                    }
                    else
                    {
                        girl.Emotion--;
                    }
                }

                boy.MakeMoney();                                // 拼命拼钱
            }
            
            if (boy.HaveCar() && boy.HaveHouse())
            {
                boy.Set(NOTHING);
                return girl.Marry(boy);
            }
                       
            girl.Age++;
            girl.Emotion--;               
        }
    }

    return girl.Goto( OTHER_BOY );
}

void main()
{

//        Boy (bool car, bool house, unsigned long money)
//        Girl (int birthday, int emothion, bool argeewait, int age)
   
    Boy boy(NO, NO, 500);
    Girl girl(48, 3, YES, 21);

    Love(boy, girl);

}
回复 支持 反对

使用道具 举报

发表于 2007-5-28 17:54:08 | 显示全部楼层
汗。。。。。。。。
回复 支持 反对

使用道具 举报

发表于 2007-5-31 12:02:19 | 显示全部楼层
我来学习一哈
回复 支持 反对

使用道具 举报

发表于 2007-6-7 20:57:33 | 显示全部楼层
晕!  看不出是c++干的................................................
回复 支持 反对

使用道具 举报

发表于 2010-1-19 11:50:52 | 显示全部楼层
顶起~~~~~为什么都没人来了呢
回复 支持 反对

使用道具 举报

发表于 2010-1-19 13:01:42 | 显示全部楼层
顶一哈巴。。。
回复 支持 反对

使用道具 举报

发表于 2013-8-19 20:18:54 | 显示全部楼层
为保住菊花,这个一定得回复!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西科人BBS ( 粤ICP备20049523号-3 )

GMT+8, 2026-3-23 09:10 , Processed in 0.076266 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表