
C++ Primer Plus习题
黑眼圈的意志
自我学习的地方
展开
-
Exercise 2.3
#includeusing namespace std;void output1(){ cout << "Three blind mice" << endl; return;}void output2(){ cout << "See how they run" << endl; return;}int main(){ output1原创 2013-11-22 23:02:34 · 492 阅读 · 0 评论 -
Exericse 4.1
#includeusing namespace std;int main(){ const int ArSize = 20; char firstname[ArSize]; char lastname[ArSize]; char mark; int age; cout << "What is your first name?"; ci原创 2013-12-04 21:26:58 · 602 阅读 · 0 评论 -
Exercise 4.2
#include#includeint main(){ using namespace std; string name; string dessert; cout << "Enter your name: \n"; getline(cin,name); cout << "Enter your favorite dessert: \n";原创 2013-12-04 21:29:42 · 452 阅读 · 0 评论 -
Exercise 4.3
#include#includeusing namespace std;int main(){ char firstname[20]; char name[40]; cout << "Enter your first name:"; cin.getline(firstname,20); cout << "Enter your last name:";原创 2013-12-04 21:35:56 · 568 阅读 · 0 评论 -
Exercise 4.6
#includeusing namespace std;struct CandyBar{ char pinpai[20]; float weight; int ka;};int main(){ CandyBar snack[3] = { { "Mocha Munch1", 2.3,原创 2013-12-04 21:50:29 · 508 阅读 · 0 评论 -
Exercise 4.7
#includeusing namespace std;struct pizza{ char name[20]; float length; float weight;};int main(){ pizza a_pizza; cout << "请输入公司名称:"; cin.getline(a_pizza.name,20); c原创 2013-12-04 21:57:14 · 559 阅读 · 0 评论 -
Exercise 4.4
#include#includeusing namespace std;int main(){ string firstname; string name; cout << "Enter your first name:"; getline(cin,firstname); cout << "Enter your last name:"; ge原创 2013-12-04 21:40:57 · 476 阅读 · 0 评论 -
Exercise 4.8
这是一个不错的练习,最起码是一个掌握get()处理换行技巧的练习#includeusing namespace std;struct pizza{ char name[20]; float length; float weight;};int main(){ pizza *a_pizza = new pizza; cout << "请输原创 2013-12-05 20:38:08 · 579 阅读 · 0 评论 -
Exercise 4.9
#includeusing namespace std;struct CandyBar{ char pinpai[20]; float weight; int ka;};int main(){ int n; cout << "请输入糖果种数:"; (cin >> n).get(); CandyBar *snack = new C原创 2013-12-05 20:51:58 · 556 阅读 · 0 评论 -
Exercise 5.6
#include#define ArSize 50using namespace std;struct car{ char productor[ArSize]; int year;};int main(){ int n; cout << "How many cars you wish to catalog?"; cin >> n; c原创 2013-12-25 20:06:56 · 534 阅读 · 0 评论 -
Exercise 5.5
#include#includeusing namespace std;int main(){ string Months[12] = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",原创 2013-12-25 19:41:56 · 457 阅读 · 0 评论 -
Exercise 5.8
#include#includeusing namespace std;int main(){ string word; int number = 0; cout << "Enter words (to stop, type the word done):" << endl; while(cin >> word && word != "done")原创 2013-12-28 07:57:20 · 521 阅读 · 0 评论 -
Exercise 5.9
#includeusing namespace std;int main(){ cout << "Enter number of rows:"; int n; cin >> n; for(int i = 0;i < n;i++) { for(int k = 0;k < n - i - 1;k++) cout原创 2013-12-28 08:02:30 · 588 阅读 · 0 评论 -
Exercise 5.7
#include#include#define ArSize 50using namespace std;int main(){ char word[ArSize]; int number = 0; int x; cout << "Enter words (to stop, type the word done):" << endl; whil原创 2013-12-28 07:16:13 · 532 阅读 · 0 评论 -
Exercise 4.5
#includeusing namespace std;struct CandyBar{ char pinpai[20]; float weight; int ka;};int main(){ CandyBar snack = { "Mocha Munch", 2.3, 350 };原创 2013-12-04 21:47:19 · 500 阅读 · 0 评论 -
Exercise 5.1
#includeint main(){ using namespace std; int m,n; cout << "请输入较小的整数:"; cin >> m; cout << "请输入较大的整数:"; cin >> n; int sum = 0; for(;m <= n;m++){ sum += m; }原创 2013-12-08 21:04:31 · 460 阅读 · 0 评论 -
Exercise 3.5
#includeint main(){ using namespace std; cout << "请输入驱车里程(英里):"; float mile,jialun; cin >> mile; cout << "请输入使用的汽油量(加仑):"; cin >> jialun; cout << "每加仑的汽油可以行驶" << mile / j原创 2013-12-01 19:18:14 · 561 阅读 · 0 评论 -
Exercise 2.1
#includeint main(){ cout << "我叫黑眼圈的意志,家住中国!" << endl; return 0;}原创 2013-11-22 22:07:25 · 589 阅读 · 0 评论 -
Exercise 2.2
#includeint main(){ using namespace std; int lang; cout << "请输入浪的值:"; cin >> lang; cout << lang << "浪 = " << lang * 140 << "码" << endl; return 0;}原创 2013-11-22 22:27:06 · 518 阅读 · 0 评论 -
Exercise 2.5
#includeusing namespace std;float exchange(float l){ return l * 63240;;}int main(){ cout << "Enter the number of light years:"; float light,unit; cin >> light; unit = excha原创 2013-11-25 23:12:18 · 417 阅读 · 0 评论 -
Exercise 2.4
#includeusing namespace std;void exchange(float t){ cout << t << "degrees Celsius is " << 1.8 * t + 32.0 << " degrees Fahrenheit." << endl; return;}int main(){ cout << "Please ente原创 2013-11-25 23:05:49 · 650 阅读 · 0 评论 -
Exercise 2.6
#includeusing namespace std;void show(int h,int m){ cout << "Time:" << h << ":" << m << endl; return;}int main(){ cout << "Enter the number of hours:"; int hour,minute; cin原创 2013-11-25 23:18:09 · 409 阅读 · 0 评论 -
Exercise 3.1
#includeusing namespace std;int main(){ const int rate = 12; cout << "Enter the your height in inch:____\b\b\b\b"; int inch; cin >> inch; cout << "Your height is " << inch / rat原创 2013-11-28 22:44:54 · 421 阅读 · 0 评论 -
Exercise 3.2
#includeusing namespace std;int main(){ const int rate_inch_foot = 12; const float rate_inch_meter = 0.0254; const float rate_pound_kg = 2.2; cout << "Enter the foot your height:___原创 2013-11-28 22:53:35 · 495 阅读 · 0 评论 -
Exercise 3.3
#includeint main(){ using namespace std; const int rate = 60; cout << "Enter a latitude in degrees, minutes, and seconds:" << endl; cout << "First, enter the degrees:" float degr原创 2013-11-29 21:21:51 · 532 阅读 · 0 评论 -
Exercise 3.4
#includeint main(){ using namespace std; cout << "Enter the number of seconds:"; long second; cin >> second; int minute,hour,day; minute = second / 60; second %= 60;原创 2013-11-29 21:38:39 · 533 阅读 · 0 评论 -
Exercise 5.2
#includeint main(){ using namespace std; int m; int n = 0; cout << "请输入一个整数(0结束):"; while(cin >> m && m != 0){ n += m; cout << "目前为止,所有输入整数的和为:" << n << endl;原创 2013-12-08 21:08:30 · 413 阅读 · 0 评论 -
Exercise 5.3
#includeint main(){ using namespace std; double Daphne_rate = 0.1; double Cleo_rate = 0.05; double Daphne = 100; double Cleo = 100; int i = 0; while(Cleo <= Daphne) {原创 2013-12-08 21:20:52 · 562 阅读 · 0 评论 -
Exercise 5.4
#include#includeint main(){ using namespace std; string Months[12] = { "January", "February", "March", "April", "May", "June", "J原创 2013-12-08 21:27:28 · 471 阅读 · 0 评论 -
Exercise 3.6
#includeint main(){ using namespace std; cout << "请输入汽车的百公里耗油量:"; float hyl; //耗油量 cout << "美式表达:" << (hyl / 3.875) / (100 / 0.6214) << "mpg" << endl; re原创 2013-12-01 19:38:32 · 573 阅读 · 0 评论 -
Sample 6.1:if.cpp
#includeint main(){ using namespace std; char ch; int spaces = 0; int total = 0; cin.get(ch); while(ch != '.') { if(ch == ' ') ++spaces; ++tot转载 2013-12-28 08:09:14 · 613 阅读 · 0 评论