C++ Primer Plus(第6版) 第5章 编程练习
2013-05-31 08:40
417 查看
#include <iostream> //#include <array> #include <string> #include <cstring> typedef struct { std ::string manufacturer; int p_year; } Car; typedef Car * CarPtr; /*----------------------- exercise 1 -----------------------------*/ //int main(void) //{ // using namespace std; // // int head; // int tail; // int sum = 0; // // cout << "Please enter two interger:"; // cin >> head; // cin >> tail; // // for (int i = head; i < tail + 1; i++){ // sum += i; // } // // cout << "sum = " << sum << endl; //} /*----------------------- exercise 2 -----------------------------*/ //int main(void) //{ // using namespace std; // // const int ArSize = 101; // array<long double, ArSize> factorials; // factorials[0] = factorials[1] = 1; // // for (int i = 2; i < ArSize; i++){ // factorials[i] = i * factorials[i - 1]; // } // // for (int i = 0; i < ArSize; i++){ // cout << i << "! = " << factorials[i] << endl; // } // // return 0; //} // /*----------------------- exercise 3 -----------------------------*/ //int main(void) //{ // using namespace std; // // cout << "Enter 0 to quit!" << endl; // cout << "Please enter the numbers : "; // // int num; // int sum = 0; // // cin >> num; // while (0 != num){ // sum += num; // cout << "Sum = " << sum << endl; // cout << "Please enter the numbers : "; // cin >> num; // } // return 0; //} /*----------------------- exercise 4 -----------------------------*/ //int main(void) //{ // using namespace std; // // const double ori_deposit_daphne = 100; // const double ori_deposit_cleo = 100; // double cur_deposit_daphne = ori_deposit_daphne; // double cur_deposit_cleo = ori_deposit_cleo; // double interest_daphne = 0; // double interest_cleo = 0; // int year = 0; // // do{ // interest_daphne = ori_deposit_daphne * 0.1; // interest_cleo = cur_deposit_cleo * 0.05; // cur_deposit_daphne += interest_daphne; // cur_deposit_cleo += interest_cleo; // year++; // }while (cur_deposit_cleo <= cur_deposit_daphne); // // cout << year << " Years later Cleo's income surpass Daphne's income" << endl; // cout << "Deposit of Daphne is " << cur_deposit_daphne << endl; // cout << "Deposit of Cleo is " << cur_deposit_cleo << endl; // return 0; //} /*----------------------- exercise 5 -----------------------------*/ //int main(void) //{ // using namespace std; // // const string mounth[12] = {"January", "February", "March", "April", "May", "June", // "July", "August", "September", "October", "November", "December"}; // int sales[12]; // int TotalSales = 0; // // for (int i = 0; i < 12; i++){ // cout << mounth[i] << "'s sales is : "; // cin >> sales[i]; // TotalSales += sales[i]; // } // // cout << "Total sales are : " << TotalSales << endl; // return 0; //} /*----------------------- exercise 7 -----------------------------*/ //int main(void) //{ // using namespace std; // // cout << "How many cars do you wish to catalog ? "; // // int c_cars; // // cin >> c_cars; // cin.get(); // CarPtr car = new Car [c_cars]; // // int num = 1; // while (c_cars > 0){ // cout << "\"Car #" << num << '\"' << endl; // cout << "Please enter the make: "; // getline(cin, car[num-1].manufacturer); // cout << "Please enter the year made :"; // cin >> car[num-1].p_year; // cin.get(); // num++; // c_cars--; // } // // cout << car[0].manufacturer << car[0].p_year << endl; // cout << car[1].manufacturer << car[1].p_year << endl; // delete [] car; // // return 0; //} /*----------------------- exercise 8 -----------------------------*/ //int main(void) //{ // using namespace std; // // char word[20]; // int c_word = 0; // // cout << "Enter words(to stop,type the word done):" << endl; // // while ((cin >> word) && strcmp(word, "done")){ // c_word++; // } // // cout << "You entered a total of " << c_word << " words" << endl; // return 0; //} /*----------------------- exercise 9 -----------------------------*/ //int main(void) //{ // using namespace std; // // string word; // int c_word = 0; // // cout << "Enter words(to stop,type the word done):" << endl; // // while ((cin >> word) && (word != "done")){ // c_word++; // } // // cout << "You entered a total of " << c_word << " words" << endl; // return 0; //} /*----------------------- exercise 10 -----------------------------*/ //int main(void) //{ // using namespace std; // // int c_row; // int cur_row; // // cout << "Enter number of rows: "; // cin >> c_row; // // for (cur_row = 1; cur_row <= c_row; cur_row++){ // for (int i = 0; i < c_row - cur_row; i++){ // cout << '.'; // } // // for (int i= 0; i < cur_row; i++){ // cout << '*'; // } // // cout << endl; // } // // return 0; //}水平有限,若有错误之处还请指教,谢谢!
本文出自 “谭智伟的博客” 博客,请务必保留此出处http://longtzw.blog.51cto.com/7219689/1213528
相关文章推荐
- C++ Primer Plus 第6版 中文版 第5章编程练习
- 《C++ Primer Plus(第6版)》编程练习代码 Chapter 8
- c++ primer plus(第6版)中文版 第四章编程练习答案
- c++ primer plus(第6版)中文版 第九章编程练习答案
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习9
- C++ Primer Plus(第6版) 第7章 编程练习
- C++ Primer Plus(第6版) 第2章编程练习
- C++ Primer Plus(第6版) 第6章 编程练习
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习2
- C++ Primer Plus 第6版 中文版 第6章编程练习
- 《C++ Primer Plus(第6版)》编程练习代码 Chapter 3
- C++ Primer Plus 第6版 中文版 第7章编程练习
- c++ primer plus(第6版)中文版 第十三章编程练习答案
- 《C++ Primer Plus (第6版)》3.7 编程练习
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习4
- 《C++ Primer Plus (第6版)》2.7 编程练习
- C++ Primer Plus (第6版)编程练习 代码-----第五章
- c++ primer plus(第6版)中文版 第十一章编程练习答案
- 《C++ Primer Plus (第6版)》6.10 编程练习
- C++ Primer Plus 第6版 中文版 第4章编程练习