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

发布了57 篇原创文章 · 获赞 27 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ao_mike/article/details/104102229