2011年5月6日7:56:18
一个简单的例子,让我对C++的面向对象的程序思想, 有了更进一步的了解!
/*
说明:3种逻辑关系----否定、合取及析取
*/
#include <iostream>
using namespace std;
int main()
{
bool bSunny;
// 定义一个逻辑变量,表示天气是否晴朗
bSunny = true;
// 预先假设天气晴朗
bool bWeather;
// 定义当前天气的逻辑变量
bWeather = !bSunny;
// 当前天气是晴天的否定,表示要下雨
cout << "今天的天气是:" << bWeather << endl;
bool bTodayWeather;
bool bTomorrowWeather;
bTodayWeather = true;
bTomorrowWeather = true;
bool bCanWash;
bCanWash = bTodayWeather && bTomorrowWeather;
cout << "今天能否洗被子:" << bCanWash << endl;
bTodayWeather = true;
bTomorrowWeather = false;
bool bCanPlayFootball;
bCanPlayFootball = bTodayWeather || bTomorrowWeather;
cout << "周末是否能踢球:" << bCanPlayFootball << endl;
cin.get();
return 0;
}