日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

2020 我的C++学习之路 C++PrimerPlus第五章课后习题

發(fā)布時間:2025/3/20 c/c++ 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2020 我的C++学习之路 C++PrimerPlus第五章课后习题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

以C++ Primer Plus為參考書籍,自身歸納知識點,加深記憶。僅供參考,DEV C++已通過編譯運行
。
練習1

#include<iostream>int main() {int integer1, integer2,temp;int sum = 0;std::cout << "Enter minimum integer: ";std::cin >> integer1;std::cout << "Enter maximum integer: ";std::cin >> integer2;for (temp = integer1; temp <= integer2; temp++)sum += temp;std::cout << "Sum of " << integer1 << "~" << integer2;std::cout << " is: " << sum << std::endl;return 0; }

練習2

#include<iostream> #include<array> const int ArSize = 101;int main() {using namespace std;//cout.setf(ios_base::fixed, ios_base::floatfield);//去除科學計數(shù)法顯示array<long double, ArSize>factorials;factorials[0] = factorials[1] = 1.0; 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; }

練習3

#include<iostream>int main() {using namespace std;int integer, sum;sum = 0;cout << "Enter an integer(0 to quit): ";cin >> integer;while (integer)//integer != 0即為integer = true {sum += integer;cout << "Enter an integer(0 to quit): ";cin >> integer;}cout << "Sum of integer is: " << sum << endl;return 0; }

練習4

#include<iostream> const double beneda = 0.1; const double benec = 0.05; int main() {using std::cout;using std::endl;double daphne, cleo, temp;daphne = cleo = 100.0;temp = daphne * beneda;int count = 1;while (cleo <= daphne){daphne += temp;cleo += cleo * benec;cout << count << " " << daphne << " " << cleo << endl;count++;}cout << "Atleat " << count << " years";cout << "Cleo will beat Daphne." << endl;cout << count << " years latter,Daphne has " << daphne;cout << " dallors,Cleo has " << cleo << " dallors" << endl;return 0; }

練習5

#include<iostream> const int month = 12;int main() {using namespace std;const char* Month[month] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"};int* salenum = new int[month];int count = 1;int sum = 0;while (count <= month){cout << "Enter salenum in month " << Month[count-1] << " : ";//Month[]這里需要注意數(shù)組的序號問題cin >> salenum[count];sum += salenum[count];count++;}cout << "This Year sales " << sum << endl;delete []salenum;return 0; }

練習6

#include<iostream> const int month = 12; const int year = 3;int main() {using namespace std;int salenum[year][month];int cnty, cntm;//行列計數(shù)器int sumyear, sum;//每年總結以及總數(shù)總結sum = 0;for (cnty = 0; cnty < year; ++cnty){cout << "Enter year " << cnty + 1 << "'s salenum per month" << endl;for (cntm = sumyear = 0; cntm < month; ++cntm)//注意每年sum需要重置0{cout << "No." << cntm + 1 << " month's salenum is:";cin >> salenum[cnty][cntm];sumyear += salenum[cnty][cntm];}cout << cnty + 1 << "year's salenu sum = " << sumyear << endl;sum += sumyear;}cout << cnty + 1 << " years later, salesnum is : " << sum << endl;return 0; }

練習7

#include<iostream> #include<string> using namespace std;struct Car {string name;int year; };int main() {int num, cnt;cout << "How many car do you wish to catalog: ";cin >> num;cin.get();//此處有個換行符Car* car = new Car[num];for (cnt = 0; cnt < num;++cnt){cout << "Car #" << cnt+1 << ":" << endl;cout << "Please enter the make:";getline(cin, car[cnt].name);cout << "Please enter the year made:";cin >> car[cnt].year;cin.get();//此處也有個換行符}cout << "Here is your collection:" << endl;for (cnt = 0; cnt < num; ++cnt){cout << car[cnt].year << " " << car[cnt].name << endl;}delete[]car;return 0; }

練習8

#include<iostream> #include<cstring>int main() {using namespace std;char word[15];int count = 0;cout << "Enter words(to stop ,type the word done):" << endl;cin >> word;while (strcmp(word, "done")){++count;cin >> word;}cout << "You entered a total of " << count << " words." << endl;return 0; }

練習9

#include<iostream> #include<string>int main() {using namespace std;string word;int count = 0;cout << "Enter words(to stop ,type the word done):" << endl;cin >> word;while (word != "done"){++count;cin >> word;}cout << "You entered a total of " << count << " words." << endl;return 0; }

練習10

#include<iostream>int main() {using namespace std;int row,col,cntc,star;//row表示行,col表示列,cntc計數(shù)器,star星星個數(shù)cout << "Enter number of rows: ";cin >> row;col = row;;for (star = 1; star <= row; ++star)//構造單行{for (cntc = 1; cntc < col; ++cntc)cout << "." ;//單行循環(huán)輸出“?!?/span>for (; cntc <= row; ++cntc)cout << "*";//接“?!焙蟮男切?/span>--col;//每一行遞減一個“?!?/span>cout << endl;}return 0}

總結

以上是生活随笔為你收集整理的2020 我的C++学习之路 C++PrimerPlus第五章课后习题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。