日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

立志10天学会C++基础应用—day01

發布時間:2025/3/15 c/c++ 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 立志10天学会C++基础应用—day01 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 前言
  • 第一天感覺很實用的快捷鍵
  • 一、常識
    • A01打印c++HelloWorld.cpp
    • A02變量.cpp
    • A03常量.cpp
    • A04標識符命名規則.cpp
    • A05整型.cpp
    • A06sizeof的用法.cpp
    • A07實型.cpp
    • A08字符型.cpp
    • A09轉義字符.cpp
    • A10字符串類型.cpp
    • A11布爾類型.cpp
    • A12數據的輸入.cpp
  • 二、算術運算符
    • A13算術運算符.cpp
    • A14賦值運算符.cpp
    • A15比較運算符.cpp
    • A16邏輯運算符.cpp
  • 三、選擇結構
    • A17選擇結構.cpp
    • A18選擇結構的應用.cpp
    • A19三目運算符.cpp
    • A20switch語句.cpp
  • 總結

前言

??下面的文章小王留著以后復盤用,比較通俗易懂了屬于是。考完研已經快一個月了,小王必須盡快恢復狀態,不開心的就讓他過去吧,學業一定不可以落下,縱有疾風起,人生不言棄,與諸君共勉!

第一天感覺很實用的快捷鍵

第一次用vs
(自動對齊)快捷鍵:Ctrl+K+D(三個鍵同時按下)
注釋:Ctrl + K + C
取消注釋:Ctrl + K + U

一、常識

注:一個工程下面不可兩個及以上cpp文件中出現main函數,也就是你只能在一個cpp里有main函數

A01打印c++HelloWorld.cpp

#include <iostream> using namespace std;/*1月24日,今天是不開心的一天,但也是開心的一天不開心的是還是會想不開心的人 時間是一種解藥 一定可以走出來噠!開心的是考完研到現在已經墮落快一個月了,不過現在振作了估計是考研花光了那半年的所有力氣,導致現在干啥都沒勁 */// main只能有一個,因為做人不能三心二意 int main() {//在屏幕中輸出helloworldcout << "helloworld" << endl;system("pause");return 0;}

https://blog.csdn.net/hanhanwanghaha寶藏女孩的成長日記 歡迎您的關注!
歡迎關注微信公眾號:寶藏女孩的成長日記 讓這個可愛的寶藏女孩在努力的道路上與你一起同行! 如有轉載,請注明出處(如不注明,盜者必究)

A02變量.cpp

#include <iostream> using namespace std;int main() {//創建變量的語法:數據類型 變量名 = 變量初始值int num = 10;//num在內存中為10cout << "num為" << num << endl;system("pause");return 0;}

A03常量.cpp

#include <iostream> using namespace std;/*常量作用:用于記錄程序中不可更改的數據定義方式有兩種:注意后面不要加“;”1、#define 宏常量1、const 修飾的變量 *///第一種定義方式:年齡為23 #define age 23int main() {/*常量不可以改變,否則會報錯age = 18;*/cout << "目前我的年齡為:" << age << endl;//第二種定義方式const int mouth = 12;/*常量不可以改變,否則會報錯mouth = 18;*/cout << "一年有多少個月" << mouth << endl;system("pause");return 0;}

A04標識符命名規則.cpp

#include <iostream> using namespace std;/*標識符命名規則1、標識符不可以是關鍵字2、標識符是字母,數字,下劃線構成3、標識符第一個字母只能是字母、下劃線組成4、標識符是區分大小寫的 */int main() {//1、標識符不可以是關鍵字//int int 10;//2、標識符是字母,數字,下劃線構成int _aaa = 888;int aaa = 666;//3、標識符第一個字母只能是字母、下劃線組成,要是以數字開頭要報錯//int 1kk = 33;//4、標識符是區分大小寫的,輸出時就不能用AAA//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 短整形 2個字節 (-2的15次方到2的15次方-1)超過這個范圍會報錯short num1 = 32768;//int整形 4個字節 (-2的31次方到2的31次方-1)超過這個范圍會報錯int num2 = 32769;//long長整形 4個字節 (-2的31次方到2的31次方-1)超過這個范圍會報錯long num3 = 32770;//long long長整形 8個字節 (-2的63次方到2的63次方-1)超過這個范圍會報錯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(2字節) int(4字節) long(windows:4字節 linux32位:4字節;linux64位:8字節) //longlong(8字節)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() {/* 1、單精度 float2、雙精度 double; */cout <<"默認情況下,輸入一個小數最多會顯示6位有效數字" << endl;float f1 = 3.1415926;cout << "f1=" << f1 << endl;double d1 = 1.1415927;cout << "d1=" << d1 << endl;//用sizeof來統計float和double占用的內存空間cout << "float的內存占用空間為" << sizeof(float) << endl;cout << "double的內存占用空間為" << sizeof(double) << endl;//科學技術法(不要求掌握,但是遇到了會認出這是什么)float f2 = 3e2; //3*10的2次方cout << "f2為" << f2 << endl;float f3 = 3e-2; //3*0.1的2次方cout << "f3為" << f3 << endl;system("pause");return 0;}

A08字符型.cpp

#include <iostream> using namespace std;int main() {//1、字符型變量創建方式char ch = 'B';cout << "ch為" << ch << endl;//2、字符型變量所占內存大小cout << "char字符變量所占內存為" << sizeof(char) << endl;//3、字符變量常見錯誤//char ch2 = "c";//創建字符型變量的時候,要用單引號//char ch3 = 'jbgdjsnixc';//創建字符變量時,單引號內只能有一個字符//4、字符變量對應的ASCLL編碼//a-97 A-65 剩下的可以推 例如 B-66cout << "ch對應ASCLL編碼為" << (int)ch << endl;system("pause");return 0;}

A09轉義字符.cpp

#include <iostream> using namespace std;int main() {//常用轉義字符//換行符: \ncout << "hello world\n";//反斜杠: \\ cout << "\\" << endl;//水平制表符: \t (作用:可以整齊輸出數據)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> //用C++風格的字符串時,需包含這個頭文件int main() {string str1 = "hello \nworld \n換了個行哈哈哈哈哈哈";cout << str1 << endl;system("pause");return 0;}

A11布爾類型.cpp

#include <iostream> using namespace std;int main() {//1、創建bool數據類型bool flag = true;//true代表真cout << flag << endl;flag = false;cout << flag << endl;//本質上 1代表真 0代表假//2、查看bool類型所占空間cout << "bool類型所占空間為:" << sizeof(bool) << endl;system("pause");return 0; }

A12數據的輸入.cpp

#include <iostream> using namespace std; #include <string>//string的頭文件int main() {//1、整型int num1 = 0;cout << "請給整型變量num1賦值" << endl;cin >> num1;cout << "賦值后的整型變量為" << num1 << endl;//2、浮點型float f = 3.14f;cout << "請給浮點型f賦值" << endl;cin >> f;cout << "賦值后的f為:" << f << endl;//3、字符型char ch = 'a';cout << "請給字符型ch賦值" << endl;cin >> ch;cout << "賦值后的ch為:" << ch << endl;//4、字符串型string str1 = "sweety";cout << "請給字符串型str1賦值" << endl;cin >> str1;cout << "賦值后的str1為:" << str1 << endl;//5、布爾類型 (點0或1)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;//兩個數相除,除數不可以為0,若為0,則會報錯,同理也取不了余數(本質就是除法)int c = 9;int d = 0;//cout << c / d << endl;//兩個小數可以相除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;//1、前置遞增int A1 = 7;++A1;//讓變量+1cout << "前置定增后的A1為" << A1 << endl;//2、后置遞增int A2 = 7;A2++;//讓變量+1cout << "后置定增后的A1為" << A2 << endl;//3、前置遞增和后置遞增的區別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;//0cout << (a != b) << endl;//1cout << (a > b) << endl;//0cout << (a < b) << endl;//1cout << (a >= b) << endl;//0cout << (a <= b) << endl;//1system("pause");return 0;}

A16邏輯運算符.cpp

#include <iostream> using namespace std;int main() {//邏輯運算:與&& (兩個為真才能為真,有一個不為真就是假)//在c++中,除了0都為真int a = 9;int b = 6;cout << (a && b) << endl;//兩個都為真,結果就是1a = 9;b = 0;cout << (a && b) << endl;//有一個不為真,那么結果就是假(0)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;//0cout << !!e << endl;//1system("pause");return 0;}

三、選擇結構

A17選擇結構.cpp

#include <iostream> using namespace std;int main() {//用戶輸入高考分數,如果分數大于550,考上重本int score = 0;cout << "請輸入您的高考分數" << endl;//1、用戶輸入分數cin >> score;//2、打印用戶輸入的分數cout << "您輸入的分數為" << score << endl;//3、判斷分數是否大于550,如果是,就輸出/*//選擇結構 單行if語句if (score >= 550) {cout << "您可以四川選擇一本的大學" << endl;}*///選擇結構 多行if語句(講人話:就是加了一個else)/*if(score >= 550) {cout << "您可以四川選擇一本的大學" << endl;}else {cout << "您的分數未達到550,走不了一本" << endl;}*/選擇結構 多條件if語句(講人話:就是加了一個或多個else if,最后再來個else)/*if (score >= 550) {cout << "您可以四川選擇一本的大學" << endl;}else if(score >500){cout << "您的分數在500到550之間,可以選擇二本的大學" << endl;}else if (score > 470) {cout << "您的分數在470到500之間,可以選擇民辦院校" << endl;}else {cout << "親親,這邊建議您復讀" << endl;}*///嵌套if語句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() {//1、創建三個娃娃成績的默認值int score1 = 89;int score2 = 95;int score3 = 93;//2、請用戶輸入三個娃娃的實際成績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() {//三目運算符//創建三個變量abc//ab作比較,將變量大的值賦值給cint a = 10;int b = 90;int c = 0;c = (a > b ? a : b);cout << "ab中最大的值c為" << c << endl;//在C++中三目運算符返回的是變量,可以繼續賦值(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() {//switch語句的學習:給中考某同學的期末等級做評價// A 頂呱呱了你,快去重高報名吧!// B 一般的學校可以讀!// C 有學上。// D 復讀吧,,,???????????//1、提示用戶輸入成績等級cout << "請您錄入成績等級" << endl;//2、錄入成績等級char score = 'A';cin >> score;cout << "您輸入的成績為"<<score << endl;//3、根據用戶輸入的分數來提示用戶最后的結果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;}/*總結:什么時候用if,什么時候用switchif表示一個區間,switch只能表示整型或者字符型*/system("pause");return 0; }

總結

https://blog.csdn.net/hanhanwanghaha寶藏女孩的成長日記 歡迎您的關注!
歡迎關注微信公眾號:寶藏女孩的成長日記 讓這個可愛的寶藏女孩在努力的道路上與你一起同行! 如有轉載,請注明出處(如不注明,盜者必究)、

C++大部分和C Python java的語法是差不多的,反正語言都是有貫通性的 ,但還是有一些語法上的差別感覺,
而且很多都是離散數學學過的吧, 第一天接觸的都是很基礎的東西 明天加大分量。終于干完咯!去看武林外傳啦!!!

總結

以上是生活随笔為你收集整理的立志10天学会C++基础应用—day01的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。