C++ Primer Plus范例
黑眼圈的意志
自我学习的地方
展开
-
Sample 5.14:waiting
#include#includeint main(){ using namespace std; cout << "Enter the dealy time ,in seconds: "; float secs; cin >> secs; clock_t delay = secs * CLOCKS_PER_SEC; cout << "start转载 2013-12-25 19:26:55 · 470 阅读 · 0 评论 -
Sample 4.6:numstr.cpp
#includeint main(){ using namespace std; cout << "What year was your house built?\n"; int year; cin >> year; cout << "What is its street address?\n"; char address[80]; ci转载 2013-12-02 22:00:02 · 447 阅读 · 0 评论 -
Sample 4.5:instr3.cpp
#includeint main(){ using namespace std; const int ArSize = 20; char name[ArSize]; char dessert[ArSize]; cout << "Enter your name:\n"; cin.get(name, ArSize).get(); cout转载 2013-12-02 21:59:34 · 476 阅读 · 0 评论 -
Sample 4.4:instr2.cpp
#includeint main(){ using namespace std; const int ArSize = 20; char name[ArSize]; char dessert[ArSize]; cout << "Enter your name: \n"; cin.getline(name,ArSize); cout <<转载 2013-12-02 21:58:48 · 389 阅读 · 0 评论 -
Sample 4.2:string.cpp
#include#includeint main(){ using namespace std; const int Size = 15; char name1[Size]; char name2[Szie] = "C++owboy"; cout << "Howdy! I'm " << name2; cout << "! What's you转载 2013-12-02 21:56:43 · 440 阅读 · 0 评论 -
Sample 4.20:ptrstr.cpp
#include#includeint main(){ using namespace std; char animal[20] = "bear"; const char * bird = "wren"; char * ps; cout << animal << " and "; cout << bird << "\n"; cout转载 2013-12-02 22:08:54 · 456 阅读 · 0 评论 -
Sample 4.19:addpntrs.cpp
#includeint main(){ using namespace std; double wage[3] = {10000.0, 20000.0, 30000.0}; short stacks[3] = {3, 2, 1}; double * pw = wages; short * ps = &stacks[0]; cout << "pw转载 2013-12-02 22:08:21 · 478 阅读 · 0 评论 -
Sample 4.11:structur.cpp
#includestruct inflatable{ char name[20]; float volume; double price;};int main(){ using namespace std; inflatable guest = { "Glorious Gloria", 1.88,转载 2013-12-02 22:03:03 · 446 阅读 · 0 评论 -
Sample 4.10:strtype4.cpp
#include#include#inclueint main(){ using namespace std; char charr[20]; string str; cout << "Length of string in charr before input: " <<strlen(charr) << endl; cout <<转载 2013-12-02 22:02:25 · 536 阅读 · 0 评论 -
Sample 4.22:delete.cpp
#include#includeusing namespace std;char * getname(void);int main(){ char * name; name = getname(); cout << name << " at " << (int *)name << "\n"; delete [] name; name = ge转载 2013-12-03 06:28:43 · 579 阅读 · 0 评论 -
Sample 4.18:arraynew.cpp
#includeint main(){ using namespace std; double * p3 = new double [3]; p3[0] = 0.2; p3[1] = 0.5; p3[2] = 0.8; cout << "p3[1] is " << p[3] << ".\n"; p3 = p3 + 1; cout转载 2013-12-02 22:07:56 · 454 阅读 · 0 评论 -
Sample 4.16:init_ptr.cpp
#includeint main(){ using namespace std; int higgens = 5; int * pt = & higgens; cout << "Value of higgens = " << higgens << "; Address of higgens = " << &higgens << endl;转载 2013-12-02 22:06:29 · 444 阅读 · 0 评论 -
Sample 4.13:arrstruct.cpp
#includestruct inflatable{ char name[20]; float volume; double price;};int main(){ using namespace std; inflatable guests[2] = { { "Bambi", 0.5, 21.99转载 2013-12-02 22:04:13 · 455 阅读 · 0 评论 -
Sample 4.12:assgn_st.cpp
#includestruct inflatable{ char name[20]; float volume; double price;};int main(){ using namespace std; inflatable bouquet = { "sunflowers", 0.20,转载 2013-12-02 22:03:34 · 524 阅读 · 0 评论 -
Sample 4.7:strtype1.cpp
#include#includeint main(){ using namespace std; char charr1[20]; char charr2[20] = "jaguar"; string srt1; string str2 = "panther"; cout << "Enter a kind of feline:"; c转载 2013-12-02 22:00:35 · 464 阅读 · 0 评论 -
Sample 4.14:address.cpp
#includeint main(){ using namespace std; int donuts = 6; double cups = 4.5; cout << "donuts value = " << donuts; cout << " and donuts address = " << &donuts << endl; cout <转载 2013-12-02 22:04:45 · 483 阅读 · 0 评论 -
Sample 4.21:newstrct.cpp
#includestruct inflatable{ char name[20]; float volume; double price;};int main(){ using namespace std; inflatable * ps = new inflatable; cout << "Enter name of inflatable转载 2013-12-02 22:09:28 · 476 阅读 · 0 评论 -
Sample 5.19:textin4.cpp
#includeint main(){ using namespace std; int ch; int count = 0; while((ch = cin.get()) != EOF){ cout.put(char(ch)); ++count; } cout << endl << count << " char转载 2013-12-25 19:29:31 · 588 阅读 · 0 评论 -
Sample 5.18:textin3.cpp
#includeint main(){ using namespace std; char ch; int count = 0; cin.get(ch); while(cin.fail() == false){ cout << ch; ++count; cin.get(ch); } cout转载 2013-12-25 19:29:01 · 497 阅读 · 0 评论 -
Sample 5.12:comstr2.cpp
#include#includeint main(){ using namespace std; string word = "?ate"; for(char ch = 'a';word != "mate";char++){ cout << word << endl; word[0] = ch; } cout << "转载 2013-12-25 19:25:43 · 515 阅读 · 0 评论 -
Sample 5.11:comstr1.cpp
#include#includeint main(){ using namespace std; char word[5] = "?ate"; for(char ch = 'a';strcmp(word,"mate");ch++){ cout << word << endl; word[0] = ch; } cout转载 2013-12-25 19:25:03 · 600 阅读 · 0 评论 -
Sample 5.20:nested.cpp
#includeconst int Cities = 5;const int Years = 4;int main(){ using namespace std; const char * cities[Cities] = { "Gribble City", "Gribbletown",转载 2013-12-25 19:30:17 · 559 阅读 · 0 评论 -
Sample 5.17:textin2.cpp
#includeint main(){ using namespace std; char ch; int count = 0; cout << "Enter characters; enter # to quit:\n"; cin.get(ch); while(ch != '#') { cout << ch;转载 2013-12-25 19:28:25 · 536 阅读 · 0 评论 -
Sample 5.16:textin1.cpp
#includeint main(){ using namespace std; char ch; itn count = 0; cout << "Enter characters; enter # to quit:\n"; cin >> ch; while(char != '#'){ cout << ch; ++转载 2013-12-25 19:27:59 · 656 阅读 · 1 评论 -
Sample 5.15:dowhile.cpp
#includeint main(){ using namespace std; int n; cout << "Enter numbers in the range 1-10 to find "; cout << "my favorite number\n"; do{ cin >> n; }while(n != 7);转载 2013-12-25 19:27:25 · 440 阅读 · 0 评论 -
Sample 5.13:while.cpp
#includeconst int ArSize = 20;int main(){ using namespace std; char name[ArSize]; cout << "Your first name,please:"; cin >> name; cout << "Here is your name, verticalize转载 2013-12-25 19:26:26 · 481 阅读 · 0 评论 -
Sample 4.17:use_new.cpp
#includeint main(){ using namespace std; int * pt = new int ; *pt = 1001; cout << "int "; cout << "value = " << *pt << ": location = " << pt << endl; double * pd = new doubl转载 2013-12-02 22:07:08 · 542 阅读 · 0 评论 -
Sample 4.15:pointer.cpp
#includeint main(){ using namespace std; int updates = 6; int * p_updates; p_updates = &updates; cout << "Values: updates = " << updates; cout << ", p_updates = " << *p_upd转载 2013-12-02 22:05:42 · 421 阅读 · 0 评论 -
Sample 4.9:strtype3.cpp
#include#include#includeint main(){ using namespace std; char charr1[20]; char charr2[20] = "jaguar"; string str1; string str2 = "panther"; str1 = str2; ctrcpy(charr1,转载 2013-12-02 22:01:52 · 450 阅读 · 0 评论 -
Sample 4.8:strtype2.cpp
#include#includeint main(){ using namespace std; string s1 = "penguin"; string s2,s3; cout << "You can assign one string object to another: s2 = s1\n"; s2 = s1; cout << "s1:转载 2013-12-02 22:01:10 · 442 阅读 · 0 评论 -
Sample 4.3:instr1.cpp
#includeint main(){ using namespace std; const int ArSize = 20; char name[ArSize]; char dessert[ArSize]; cout << "Enter your name: \n"; cin >> name; cout << "Enter your转载 2013-12-02 21:58:08 · 525 阅读 · 0 评论 -
Sample 4.1:arrayone.cpp
#includeint main(){ using namespace std; int yams[3]; yams[0] = 7; yams[1] = 8; yams[2] = 6; int yamcosts[3] = {20, 30, 5}; cout << "Total = "; cout << yams[0] + ya转载 2013-12-01 19:58:07 · 480 阅读 · 0 评论 -
Sample 5.10: equal.cpp
#includeint main(){ using namespace std; int quizscores[10] = { 20,20,20,20,20,19,20,18,20,20 }; cout << "Doing it right: \n"; int i ; for(i = 0;quizs转载 2013-12-08 21:35:33 · 446 阅读 · 0 评论 -
关于看C++ Primer Plus的建议
这本书事无巨细,虽然从水平上来说,并没有很高超的技巧,但是,是基础中的基础这本书不要仅仅想着看一、两遍就放那,一定要做到,所有的范例敲一遍,所有的习题自己做一遍!不要追求高速看完这本书,好菜慢慢吃,好书细细品。加油,奋斗!原创 2013-11-29 20:11:53 · 1910 阅读 · 0 评论 -
Sample 3.7: bondini.cpp
转义字符的使用,在cout中使用#includeint main(){ using namespace std; cout << "\aOperation \"HyperHype\" is now activated!\n"; cout << "Enter your agent code:________\b\b\b\b\b\b\b\b"; long cod转载 2013-11-27 21:20:32 · 518 阅读 · 0 评论 -
Sample 3.6:morechar.cpp
#includeint main(){ using namespace std; char ch = 'M'; int i = ch; cout << "The ASCII code for " << ch << " is " << i << endl; cout << "Add one to the character code:" << e转载 2013-11-27 21:14:32 · 474 阅读 · 0 评论 -
Sample 3.5:chartype.cpp
第一次使用char类型的范例#includeint main(){ using namespace std; char ch; cout << "Enter a character: " << endl; cin >> ch; cout << "Holla! "; cout << "Thank you for the " << ch转载 2013-11-27 20:56:46 · 428 阅读 · 0 评论 -
Sample 3.4:hexoct2.cpp
#includeint main(){ using namespace std; int chest = 42; int waist = 42; int inseam = 42; cout << "Monsieur cuts a striking figure!" << endl; cout << "chest = " << chest <<转载 2013-11-27 20:50:45 · 517 阅读 · 0 评论 -
Sample 3.3:hexoct.cpp
#includeint main(){ using namespace std; int chest = 42; int waist = 0x425; int inseam = 042; cout << "Monsieur cuts a striking figure!\n"; cout << "chest = " << chest << "转载 2013-11-27 20:44:04 · 575 阅读 · 0 评论 -
Sample 3.2:exceed.cpp
#include#define ZERO 0#includeint main(){ using namespace std; short sam = SHRT_MAX; unsigned short sue = sam; cout << "Sam has " << sam << " dollars and Sue has " << sue; cou转载 2013-11-25 23:55:22 · 482 阅读 · 0 评论