講課內容 感性➡️理性➡️函數➡️指針等ios
做業練習 初級階段 ➡️正常做業練習c++
1954-1956——John Backus——FORTRAN(FORmula TRANslation)——數學計算領域編程
1960——Alan J. Perlis——A語言(Algol 60)——計算科學裏程碑編程語言
1963——劍橋大學——CPL(Combined Programming Language)——規模太大難以實現函數
1967——Matin Pichards——BCPL(Basic CPL)學習
1970——貝爾實驗室 Ken Thompson——B語言(簡化BCPL)——UNIXui
1972-1973——Dennis Ritchie& Ken Thompson——C語言(完善發展B語言)——重寫UNIXspa
1979——貝爾實驗室 Bjarne Stroustrup——給C加入面向對象的特性——C with Classes——C++設計
1985——The C++ Programming Language 初版指針
1998——C++國際標準
2011——C++2011標準
C++語言支持了C語言全部的特性,咱們要在C++環境中學習C語言的部分。
#include <iostream> using namespace std; int main() { int n;//n爲細菌的數量 int id[100];//細菌的編號 double rate[100];//細菌的繁殖率 cin>>n; for(int i = 0; i < n; i++) { int initial,final; cin >> id[i] >> initial >> final; rate[i] = (double)final / initial; } //排序 for (int i = 0; i < n; i++) { for(int j = 0; j < n - i - 1; j++) { if(rate[j+1] > rate[j]) { int tmpID = id[j]; id[j] = id[j+1]; id[j+1] = tmpID; double temRate = rate[j]; rate[j] = rate[j+1]; rate[j+1] = temRate; } } } //記錄最大的差和最大差的下標 double maxDiff = 0; int maxDiffIndex = 0; for (int i = 0; i < n - 1; i++) { double diff = rate[i] - rate[i + 1]; if(maxDiff < diff) { maxDiff = diff; maxDiffIndex = i; } } //輸出繁殖率較大的那組細菌 cout<< maxDiffIndex + 1 <<endl; for (int i = maxDiffIndex; i >=0 ; i--) { cout<<id[i]<<endl; } cout<< n - maxDiffIndex - 1 << endl; for (int i = n - 1; i >= maxDiffIndex + 1 ; i--) { cout<<id[i]<<endl; } return 0; }
#include <iostream> using namespace std; int main() { int numApple, bugSpeed, hour; cin>>numApple>>bugSpeed>>hour; int numEat = hour / bugSpeed; if(numEat - numApple > 0) cout<<"0"<<endl; else if (hour % bugSpeed == 0) cout<< numApple - numEat << endl; else cout<<numApple - numEat - 1 <<endl; return 0; }
#include <iostream> using namespace std; int main() { int height, radius; cin>>height>>radius; double volume = 3.1415926*radius*radius*height; int num = 20*1000 / volume; cout<<num + 1 << endl; return 0; }
#include <iostream> using namespace std; int main() { int numStu, stu[100]; cin>>numStu; for (int i = 0; i <numStu ; i++) { cin>>stu[i]; if(i != 0 && stu[i] > stu[0]) stu[0] = stu[i]; } cout<<stu[0]<<endl; }
#include <iostream> using namespace std; int main() { int num[6], maxOdd = 1, numAbs, minEven = 101; for (int i = 0; i < 6; i++) cin>>num[i]; for (int i = 0; i < 6; i++) { if(num[i] % 2 == 0 && num[i] < minEven) minEven = num[i]; if(num[i] % 2 == 1 && num[i] > maxOdd) maxOdd = num[i]; } if(maxOdd - minEven < 0) numAbs = minEven - maxOdd; else numAbs = maxOdd - minEven; cout << numAbs << endl; return 0; }
#include <iostream> using namespace std; int main() { int num,a,b,c; cin>>num; a = num / 100; b = (num - a * 100) / 10; c = num % 10; cout<<a<<"\n"<<b<<"\n"<<c<<endl; }