https://www.bilibili.com/video/av40959422?p=3
从C到C++快速入门(2019版C++程序设计)
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