CPP_Basic_Code_P2.1-PP2.7.7

CPP_Basic_Code_P2.1-PP2.7.7

//  The Notes Created by Z-Tech on 2017/2/17.
//  All Codes Boot on 《C++ Primer Plus》V6.0
//  OS:MacOS 10.12.4
//  Translater:clang/llvm8.0.0 &g++4.2.1
//  Editer:iTerm 2&Sublime text 3
//  IDE: Xcode8.2.1&Clion2017.1

//P2.1
#include <iostream>//Hello兼搏,C++
int main()
{
    using namespace std;
    cout <<"Come up and C++ me some time.";
    cout <<endl;
    cout <<"You won't regret it"<<endl;
    return 0;
}

//P2.2
#include <iostream>
int main()
{
    using namespace std;
    int carrots;
    carrots=25;
    cout<<"I Have ";
    cout<<carrots;
    cout<<" carrots.";//注意前后空格
    cout<<endl;
    carrots=carrots-1;
    cout<<"Crunch,crunch,Now I have "<<carrots<<" carrots."<<endl;
    return 0;
}

//P2.3
#include <iostream>
int main()
{
    using namespace std;
    int carrots;
    cout<<"How many Carrots do you have?"<<endl;
    cin>>carrots;
    cout<<"Here are two more. ";
    carrots=carrots+2;
    cout<<"Now you have "<<carrots<<" carrots."<<endl;//輸出流
    return 0;
}

//P2.4
#include <iostream>
#include <cmath>//是C中math.h的升級
int main()
{
    using namespace std;
    double area;
    cout<<"Enter the floor area,in square feet,of your home:";
    cin>>area;
    double side=sqrt(area);//開方計算
    cout<<"That's the equvalent of a square  "<<side
        <<" feet to the side."<<endl;
    cout<<"How Fascinating"<<endl;
    return 0;
}

//P2.5
#include <iostream>
void simon(int)//函數(shù)聲明
int main()
{
    using namespace std;
    simon(3);
    cout<<"Pick an integer: ";
    int count;
    cin>>count;
    simon(count);
    cout<<"Done"<<endl;
    return 0;
}
void simon(int n)//打印函數(shù)斟冕,無返回值觉阅。
{
    using namespace std;
    cout<<"Simon says touch your toes "<<n<<" times"<<endl;
}

//P2.6
#include <iostream>
int stonetolb(int);
int main()
{
    using namespace std;
    int stone;
    cout<<"Enter the weight in stone:";
    cin>>stone;
    int pounds=stonetolb(stone);
    cout<<stone<<" stone= ";
    cout<<pounds<<" pounds."<<endl;
    return 0;
}
int stonetolb(int sts)
{
    return 14*sts;//1英石=14磅脸爱,使用表達式避免創(chuàng)建新變量
}

//PP2.7.2
#include <iostream>
int main()
{
    using  namespace std;
    cout<<"Please input a distance:";
    double xLong;
    cin>>xLong;
    double  Ma=220*xLong;
    cout<<xLong<<"long = "<<Ma<<"Ma";
    return 0;
}

//PP2.7.3
#include <iostream>
void z_tech1();
void z_tech2();
int main()
{
    using namespace std;
    z_tech1();//無參數(shù)無返回值
    z_tech1();
    z_tech2();
    z_tech2();
    return 0;
}
void z_tech1()
{
    using namespace std;
    cout<<"Three blind mice "<<endl;
}
void z_tech2()
{
    using namespace std;
    cout<<"See how they run "<<endl;
}

//PP2.7.4
#include<iostream>
int main()
{
    using namespace std;
    cout<<"Please enter your age(years):"<<endl;
    int Year;
    cin>>Year;
    cout<<Year<<" years is about "<<12*Year<<" months.";
    return 0;
}

//PP2.7.5
#include <iostream>
double Fahrenheit(double);
int main()
{
    using namespace std;
    cout<<"Please enter a celsius value: "<<endl;
    double Celsius;
    cin>>Celsius;
    cout<<Celsius<<" degrees Celsius is "<<Fahrenheit(Celsius)<<" degrees Fahrenheit.";
    return 0;
}
double Fahrenheit(double n)
{
    n=1.8*n+32.0;
    return n;
}

//PP2.7.6
#include <iostream>
double astronomical_units(double);
int main()
{
    using namespace std;
    cout<<"Please enter the number of light year: "<<endl;
    double Lightyear;
    cin>>Lightyear;
    double astr_units=astronomical_units(Lightyear);
    cout<<Lightyear<<" light year = "<<astr_units<<" astronomical units.";
    return 0;
}
double astronomical_units(double x)
{
    x=63240*x;
    return x;
}

//PP2.7.7
#include <iostream>
void time(int,int);//多參數(shù)申明
int main()
{
    using namespace std;
    cout<<"Please enter the number of hours: ";
    int hours;
    cin>>hours;
    cout<<"Please enter the number of minutes: ";
    int minutes;
    cin>>minutes;
    time(hours,minutes);
    return 0;
}
void time(int a,int b)//多參數(shù)函數(shù)實體
{
    using namespace std;
    cout<<"Time: "<<a<<":"<<b;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末蕾总,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖诫肠,帶你破解...
    沈念sama閱讀 216,651評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件司澎,死亡現(xiàn)場離奇詭異欺缘,居然都是意外死亡,警方通過查閱死者的電腦和手機挤安,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,468評論 3 392
  • 文/潘曉璐 我一進店門谚殊,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人蛤铜,你說我怎么就攤上這事嫩絮。” “怎么了围肥?”我有些...
    開封第一講書人閱讀 162,931評論 0 353
  • 文/不壞的土叔 我叫張陵剿干,是天一觀的道長。 經常有香客問我穆刻,道長置尔,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,218評論 1 292
  • 正文 為了忘掉前任氢伟,我火速辦了婚禮榜轿,結果婚禮上,老公的妹妹穿的比我還像新娘朵锣。我一直安慰自己谬盐,他們只是感情好,可當我...
    茶點故事閱讀 67,234評論 6 388
  • 文/花漫 我一把揭開白布诚些。 她就那樣靜靜地躺著飞傀,像睡著了一般。 火紅的嫁衣襯著肌膚如雪诬烹。 梳的紋絲不亂的頭發(fā)上砸烦,一...
    開封第一講書人閱讀 51,198評論 1 299
  • 那天,我揣著相機與錄音椅您,去河邊找鬼外冀。 笑死,一個胖子當著我的面吹牛掀泳,可吹牛的內容都是我干的雪隧。 我是一名探鬼主播西轩,決...
    沈念sama閱讀 40,084評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼脑沿!你這毒婦竟也來了藕畔?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 38,926評論 0 274
  • 序言:老撾萬榮一對情侶失蹤庄拇,失蹤者是張志新(化名)和其女友劉穎注服,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體措近,經...
    沈念sama閱讀 45,341評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡溶弟,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,563評論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了瞭郑。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片辜御。...
    茶點故事閱讀 39,731評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖屈张,靈堂內的尸體忽然破棺而出擒权,到底是詐尸還是另有隱情,我是刑警寧澤阁谆,帶...
    沈念sama閱讀 35,430評論 5 343
  • 正文 年R本政府宣布碳抄,位于F島的核電站,受9級特大地震影響场绿,放射性物質發(fā)生泄漏剖效。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,036評論 3 326
  • 文/蒙蒙 一裳凸、第九天 我趴在偏房一處隱蔽的房頂上張望贱鄙。 院中可真熱鬧,春花似錦姨谷、人聲如沸逗宁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,676評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽瞎颗。三九已至,卻和暖如春捌议,著一層夾襖步出監(jiān)牢的瞬間哼拔,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,829評論 1 269
  • 我被黑心中介騙來泰國打工瓣颅, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留倦逐,地道東北人。 一個月前我還...
    沈念sama閱讀 47,743評論 2 368
  • 正文 我出身青樓宫补,卻偏偏與公主長得像檬姥,于是被迫代替她去往敵國和親曾我。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,629評論 2 354

推薦閱讀更多精彩內容