C++學習筆記(2小時由C入門C++)

https://www.bilibili.com/video/av40959422?p=3

從C到C++快速入門(2019版C++程序設計)

科技演講·公開課

https://hwdong.net/2019/01/26/C%E5%88%B0C++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-2019%E7%89%88%E6%9C%AC/  2019

https://hwdong.net/2019/01/26/2%E5%B0%8F%E6%97%B6%E4%BB%8EC%E5%88%B0C++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/   2018

1.

條件編譯 

#if 1

#if 0

#endif   ?

2.

3.標準名字空間std

std::cout     

using namespace std;

cout<<XX; //輸出

cin>> XX; //輸入

#include <fstream> 
#include <iostream> 
#include <string> 
using namespace std;

int main() {
	ofstream oF("test.txt");
	oF << 3.14 << " " << "hello world\n";
	oF.close();
	ifstream iF("test.txt");
	double d;
	string str;
	iF >> d >> str;
	cout<<d <<" "<< str<<endl;

	return 0;
}

4.文件輸入輸出流

5.引用變量  

類似指針,但不是指針

 

 

 

5.函數的默認形參 

 

 

6.函數重載

7.函數模板

 

 

 

8.string 

 

 

 

 

 

 

 

9.vector

 

 

 

 

 

10.動態內存分配

 

 

11.面向對象編程

12.作業

 

/* 輸入一組學生成績(姓名和分數),輸出:平均成績、最高分和最低分。 當然,也要能輸出所有學生信息 */
#include <iostream> 
#include <string> 
#include <vector> 
using namespace std;
struct student{
	string name;
	double score;
	void print();
};
void student::print() {
	cout << name << " " << score << endl;
}
int main() {
/* student stu; stu.name = "Li Ping"; stu.score = 78.5; stu.print(); */

	vector<student> students;	
	while (1) {
		student stu;
		cout << "請輸入姓名 分數:\n";
		cin >> stu.name >> stu.score;
		if (stu.score < 0) break;
		students.push_back(stu);
	}
	for (int i = 0; i < students.size(); i++)
		students[i].print();

	double min = 100, max=0, average = 0;
	for (int i = 0; i < students.size(); i++) {
		if (students[i].score < min) min = students[i].score;
		if (students[i].score > max) max = students[i].score;
		average += students[i].score;
	}
	average /= students.size();
	cout << "平均分、最高分、最低分:" 
		<< average << " " << max << " " << min << endl;
}

13.

14

15

16

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章