侵刪;
1.1 注釋
1.2 變數
1.3 常量
關鍵字識別符號命名
命名要求:
1.4 資料型別
1.4.1 整型
1.4.2 浮點型
1.4.3 字元型
1.4.4 字串型
1.4.5 布林型bool
1.5資料輸入
cin>>變數;//變數需要提前定義
1.6 運算子
1.7 程式流程結構
1.7.1 if語句
1.7.2 三目運算子: 判斷? 表示式1:表示式2;
1.7.3 switch語句:c=(a>b? a:b);
//返回的是變數可以繼續賦值
(a>b? a:b)=10;
1.7.4 while迴圈語句switch(表示式)
1.7.5 案例1:猜數遊戲while (迴圈條件)//只要迴圈條件為真,就執行迴圈語句
do while(條件)//先執行後判斷
1.7.6 案例2:水仙花數#include#include using namespace std;
int main()
else if (val < num)
else
system("pause");
}
1.7.7 for迴圈語句#includeusing namespace std;
int main()
num++;
} while (num < 1000);
system("pause");
return 0;
}
1.8 陣列
#include using namespace std;
int main() ;
int len_s = sizeof(arr) / sizeof(arr[0]);
int len = len_s;
int tempo;
for (int i = 0; i <= (len_s - 1); i++)
for (int i = 0; i <= (len - 1); i++)
} for (int i = 0; i <= (len_s - 1); i++)
} }for (int i = 0; i <= (len_s - 1); i++)
system("pause");
return 0;
}
1.9 函式
返回值型別 函式名 (引數列表)
函式的呼叫
函式名(引數1,引數2);
引數傳遞(無指標時):形參,實參
函式的常見樣式
函式宣告可以多次,但是定義只有一次
函式的分檔案編寫:讓**結構更加清晰
1.10 指標
const修飾指標
const int* const p = &b;
//指標指向的值和指向都不可以修改
指標作為函式的引數
1.11 結構體int func1(int* a,int * b)
int main()
結構體陣列
結構體指標
//建立學生結構體變數
student s = ;
//通過指標指向結構體變數
student* p = &s;
//通過指標訪問結構體變數中的資料
cout << " 姓名:" << p->name<<" 年齡: "
<< p->age <<" 分數: "<< p->score << endl;
結構體巢狀結構體
//定義結構體
struct student ;
//巢狀結構體
struct teacher ;
//結構圖巢狀
teacher t;
t.id = 100000;
t.name = "老張";
t.age = 50;
t.stu.name = "小王";//巢狀結構體的屬性
t.stu.age = 20;
t.stu.score = 60;
cout << "老師姓名: " << t.name << " 老師編號: " << t.id << " 老師年齡: "
<< t.age << " 老師輔導學生的姓名: " << t.stu.name << " 學生年齡: "
<< t.stu.age << " 學生的考試成績: " << t.stu.score << endl;
結構體做函式引數
void printstudent(struct student s)
//位址傳遞
void printstudent1(struct student* s)
//建立學生結構體變數
student s = ;
printstudent(s);
printstudent1(&s);
結構體內使用const使用結構
void printstudent1(const struct student* s)
結構體案例
#include #includeusing namespace std;
struct student ;
struct teacher ;
void allocatespace(struct teacher tarray, int len) }}
//列印所有資訊
void printinfo(struct teacher tarray, int len) }}
int main()
案例:通訊錄管理系統
#include#includeusing namespace std;
//聯絡人結構體
struct person ;
//通訊錄位址
struct addressbooks ;
void showmenu()
//1 新增聯絡人
void addpeerson(addressbooks* abs)
else
}//2 顯示聯絡人
void showperson(addressbooks* abs)
else
} system("pause");
system("cls");
}//刪除聯絡人
//檢測聯絡人是否存在,如果存在,返回聯絡人所在陣列的具體位置,不存在返回-1
//傳遞的引數 通訊錄,對比的姓名
int i***ist(addressbooks* abs, string name)
} return -1;
}//3 刪除指定聯絡人
void deleteperson(addressbooks* abs)
abs->m_size--;//更新通訊錄中的人員數
cout << "刪除成功!" << endl;
} system("pause");
system("cls");
}//查詢聯絡人
void findperson(addressbooks* abs)
else //未找到聯絡人
system("pause");
system("cls");
}//5 修改聯絡人
void modifyperson(addressbooks* abs)
}else
}}
機器學習 1 概述入門篇
本週任務 1.python基礎的準備 本課程擬採用python做為機器演算法應用的實現語言,所以請確保 1 安裝好python開發環境,pycharm 或 anaconda等都可以,按個人習慣喜好。2 基本庫的安裝,如numpy pandas scipy matplotlib 3 具備一定的pyth...
web前端基礎學習入門篇
web前端基礎學習入門篇 一 1 xhtml css 標記語言 一 web標準的概念及組成 w3c制定的結構和表現的標準 結構 xhtml xml 主要是網頁的基本結構 表現 css 主要對網頁樣式進行修飾 ecma制定的行為的標準 行為 dom ecmascript 主要是在網頁上加一些動態的效果...
NumPy學習筆記 入門篇
numpy學習筆記 收集者 keengle 最近在學習scipy。在理解scipy之前,numpy作為scipy基本的模組之一,是不得不去理解掌握的。先總結一下numpy部分的內容吧。接下來學習scipy,最後是pylab和matplotlib。介紹numpy是乙個python的擴充套件模組,通過使...