前言
??下面的文章小王留着以后复盘用,比较通俗易懂了属于是。考完研已经快一个月了,小王必须尽快恢复状态,不开心的就让他过去吧,学业一定不可以落下,纵有疾风起,人生不言弃,与诸君共勉!
第一天感觉很实用的快捷键
第一次用vs (自动对齐)快捷键:Ctrl+K+D(三个键同时按下) 注释:Ctrl + K + C 取消注释:Ctrl + K + U
一、常识
注:一个工程下面不可两个及以上cpp文件中出现main函数,也就是你只能在一个cpp里有main函数
A01打印c++HelloWorld.cpp
#include <iostream>
using namespace std;
int main() {
cout << "helloworld" << endl;
system("pause");
return 0;
}
https://blog.csdn.net/hanhanwanghaha宝藏女孩的成长日记 欢迎您的关注! 欢迎关注微信公众号:宝藏女孩的成长日记 让这个可爱的宝藏女孩在努力的道路上与你一起同行! 如有转载,请注明出处(如不注明,盗者必究)
A02变量.cpp
#include <iostream>
using namespace std;
int main() {
int num = 10;
cout << "num为" << num << endl;
system("pause");
return 0;
}
A03常量.cpp
#include <iostream>
using namespace std;
#define age 23
int main() {
cout << "目前我的年龄为:" << age << endl;
const int mouth = 12;
cout << "一年有多少个月" << mouth << endl;
system("pause");
return 0;
}
A04标识符命名规则.cpp
#include <iostream>
using namespace std;
int main() {
int _aaa = 888;
int aaa = 666;
cout << aaa << endl;
int num1 = 10;
int num2 = 56;
int sum = num1 + num2;
cout << sum << endl;
system("pause");
return 0;
}
A05整型.cpp
#include <iostream>
using namespace std;
int main() {
short num1 = 32768;
int num2 = 32769;
long num3 = 32770;
int num4 = 32771;
cout << num1 << endl;
cout << num2 << endl;
cout << num3 << endl;
cout << num4 << endl;
system("pause");
return 0;
}
A06sizeof的用法.cpp
#include <iostream>
using namespace std;
int main() {
short num1 = 888;
cout << "short所长字节为:" << sizeof(num1) << endl;
int num2 = 999;
cout << "short所长字节为:" << sizeof(999) << endl;
long num3 = 666;
cout << "long所长字节为:" << sizeof(666) << endl;
long long num4 = 966;
cout << "short所长字节为:" << sizeof(long long) << endl;
system("pause");
return 0;
}
https://blog.csdn.net/hanhanwanghaha 宝藏女孩的成长日记 欢迎您的关注! 欢迎关注微信公众号:宝藏女孩的成长日记 让这个可爱的宝藏女孩在努力的道路上与你一起同行! 如有转载,请注明出处(如不注明,盗者必究)
A07实型.cpp
#include <iostream>
using namespace std;
int main() {
cout <<"默认情况下,输入一个小数最多会显示6位有效数字" << endl;
float f1 = 3.1415926;
cout << "f1=" << f1 << endl;
double d1 = 1.1415927;
cout << "d1=" << d1 << endl;
cout << "float的内存占用空间为" << sizeof(float) << endl;
cout << "double的内存占用空间为" << sizeof(double) << endl;
float f2 = 3e2;
cout << "f2为" << f2 << endl;
float f3 = 3e-2;
cout << "f3为" << f3 << endl;
system("pause");
return 0;
}
A08字符型.cpp
#include <iostream>
using namespace std;
int main() {
char ch = 'B';
cout << "ch为" << ch << endl;
cout << "char字符变量所占内存为" << sizeof(char) << endl;
cout << "ch对应ASCLL编码为" << (int)ch << endl;
system("pause");
return 0;
}
A09转义字符.cpp
#include <iostream>
using namespace std;
int main() {
cout << "hello world\n";
cout << "\\" << endl;
cout << "aaaaa\thello world" << endl;
cout << "aaa\thello world" << endl;
cout << "a\thello world" << endl;
system("pause");
return 0;
}
A10字符串类型.cpp
#include <iostream>
using namespace std;
#include <string>
int main() {
string str1 = "hello \nworld \n换了个行哈哈哈哈哈哈";
cout << str1 << endl;
system("pause");
return 0;
}
A11布尔类型.cpp
#include <iostream>
using namespace std;
int main() {
bool flag = true;
cout << flag << endl;
flag = false;
cout << flag << endl;
cout << "bool类型所占空间为:" << sizeof(bool) << endl;
system("pause");
return 0;
}
A12数据的输入.cpp
#include <iostream>
using namespace std;
#include <string>
int main() {
int num1 = 0;
cout << "请给整型变量num1赋值" << endl;
cin >> num1;
cout << "赋值后的整型变量为" << num1 << endl;
float f = 3.14f;
cout << "请给浮点型f赋值" << endl;
cin >> f;
cout << "赋值后的f为:" << f << endl;
char ch = 'a';
cout << "请给字符型ch赋值" << endl;
cin >> ch;
cout << "赋值后的ch为:" << ch << endl;
string str1 = "sweety";
cout << "请给字符串型str1赋值" << endl;
cin >> str1;
cout << "赋值后的str1为:" << str1 << endl;
bool flag = "flase";
cout << "请给布尔类型flag赋值" << endl;
cin >> flag;
cout << "赋值后的flag为:" << flag << endl;
system("pause");
return 0;
}
二、算术运算符
A13算术运算符.cpp
加减乘除与取模、自增和自减
#include <iostream>
using namespace std;
int main() {
int num1 = 6;
int num2 = 6;
cout << num1 + num2 << endl;
cout << num1 - num2 << endl;
cout << num1 * num2 << endl;
cout << num1 / num2 << endl;
int a = 10;
int b = 20;
cout << a / b << endl;
int c = 9;
int d = 0;
double e = 0.01;
double f = 0.3;
cout << e / f << endl;
int g = 8;
int h = 3;
cout << "8%3的余数为" << g % h << endl;
cout << "\n前置和后置++及其区别\n" << endl;
int A1 = 7;
++A1;
cout << "前置定增后的A1为" << A1 << endl;
int A2 = 7;
A2++;
cout << "后置定增后的A1为" << A2 << endl;
cout << "前置递增是先让变量加1,再进行表达式的运算" << endl;
int A3 = 5;
int B3 = ++A3 * 2;
cout << "A3=" << A3 << endl;
cout << "B3=" << B3 << endl;
cout << "后置递增是先进行表达式的运算,再让变量加1" << endl;
int A4 = 5;
int B4 = A4++ * 2;
cout << "A4=" << A4 << endl;
cout << "B4=" << B4 << endl;
system("pause");
return 0;
}
A14赋值运算符.cpp
#include <iostream>
using namespace std;
int main() {
int a = 2;
a = 999;
cout << "a的值为" << a << endl;
int b = 4;
b += 4;
cout << "b的值为" << b << endl;
int c = 10;
c -= 2;
cout << "c的值为" << c << endl;
int d = 33;
d *= 2;
cout << "d的值为" << d << endl;
int e = 81;
e /= 9;
cout << "e的值为" << e << endl;
int f = 13;
f %= 7;
cout << "f的值为" << f << endl;
system("pause");
return 0;
}
A15比较运算符.cpp
#include <iostream>
using namespace std;
int main() {
int a = 6;
int b = 8;
cout << (a == b) << endl;
cout << (a != b) << endl;
cout << (a > b) << endl;
cout << (a < b) << endl;
cout << (a >= b) << endl;
cout << (a <= b) << endl;
system("pause");
return 0;
}
A16逻辑运算符.cpp
#include <iostream>
using namespace std;
int main() {
int a = 9;
int b = 6;
cout << (a && b) << endl;
a = 9;
b = 0;
cout << (a && b) << endl;
a = 0;
b = 0;
cout << (a && b) << endl;
int c = 6;
int d = 6;
cout << (c||d) << endl;
c = 0;
d = 6;
cout << (c || d) << endl;
c = 6;
d = 0;
cout << (c || d) << endl;
c = 0;
d = 0;
cout << (c || d) << endl;
int e = 9;
cout << !e << endl;
cout << !!e << endl;
system("pause");
return 0;
}
三、选择结构
A17选择结构.cpp
#include <iostream>
using namespace std;
int main() {
int score = 0;
cout << "请输入您的高考分数" << endl;
cin >> score;
cout << "您输入的分数为" << score << endl;
if (score >= 550) {
cout << "恭喜您!您可以选择很多一本的大学" << endl;
if (score > 650) {
cout << "建议直接报考顶尖985" << endl;
}
else if (score > 600) {
cout << "并且您可以选择很多985 211" << endl;
}
}
else if (score > 500)
{
cout << "您的分数在500到550之间,可以选择二本的大学" << endl;
}
else if (score > 470) {
cout << "您的分数在470到500之间,可以选择民办院校" << endl;
if (score > 490) {
cout << "您还可以看看好一点的民办院校" << endl;
}
}
else {
cout << "亲亲,这边建议您复读" << endl;
}
system("pause");
return 0;
}
}
A18选择结构的应用.cpp
#include <iostream>
using namespace std;
int main() {
int score1 = 89;
int score2 = 95;
int score3 = 93;
cout << "请输入第一个娃娃的成绩" << endl;
cin >> score1;
cout << "请输入第二个娃娃的成绩" << endl;
cin >> score2;
cout << "请输入第三个娃娃的成绩" << endl;
cin >> score3;
cout << "第一个娃娃的成绩为" << score1 << endl;
cout << "第二个娃娃的成绩为" << score2 << endl;
cout << "第三个娃娃的成绩为" << score3 << endl;
if (score1 > score2) {
if (score1 > score3) {
cout << "第一个娃娃成绩最好" << endl;
}
else if(score1 > score3) {
cout << "第三个娃娃成绩最好" << endl;
}
else {
cout << "第一个和第三个娃娃成绩相等,且都大于第二个娃娃的成绩" << endl;
}
}
else if(score1<score2) {
if (score2 > score3) {
cout << "第二个娃娃成绩最好" << endl;
}
else if(score2 < score3) {
cout << "第三个娃娃成绩最好" << endl;
}
else {
cout << "第二个和第三个娃娃成绩相等,且都大于第一个娃娃的成绩" << endl;
}
}
else {
if (score2 > score3) {
cout << "第一个和第二个娃娃成绩相等,且都大于第三个娃娃的成绩" << endl;
}
else if (score2 < score3) {
cout << "第一个和第二个娃娃成绩相等,且都大于第三个娃娃的成绩" << endl;
}
else {
cout << "三个娃娃成绩相等" << endl;
}
}
system("pause");
return 0;
}
A19三目运算符.cpp
#include <iostream>
using namespace std;
int main() {
int a = 10;
int b = 90;
int c = 0;
c = (a > b ? a : b);
cout << "ab中最大的值c为" << c << endl;
(a > b ? a : b) = 100;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
system("pause");
return 0;
}
A20switch语句.cpp
#include <iostream>
using namespace std;
int main() {
cout << "请您录入成绩等级" << endl;
char score = 'A';
cin >> score;
cout << "您输入的成绩为"<<score << endl;
switch (score)
{
case 'A':
cout << "顶呱呱了你,快去重高报名吧!" << endl;
break;
case 'B':
cout << "一般的学校可以读!" << endl;
break;
case 'C':
cout << "有学上。" << endl;
break;
case 'D':
cout << "复读吧,,,???????????" << endl;
break;
default:
cout << "别搞笑" << endl;
break;
}
system("pause");
return 0;
}
总结
https://blog.csdn.net/hanhanwanghaha宝藏女孩的成长日记 欢迎您的关注! 欢迎关注微信公众号:宝藏女孩的成长日记 让这个可爱的宝藏女孩在努力的道路上与你一起同行! 如有转载,请注明出处(如不注明,盗者必究)、
C++大部分和C Python java的语法是差不多的,反正语言都是有贯通性的 ,但还是有一些语法上的差别感觉, 而且很多都是离散数学学过的吧, 第一天接触的都是很基础的东西 明天加大分量。终于干完咯!去看武林外传啦!!!
|