C++語法學習的主要內容

?

科技特長生方向,主要學習的內容為?

一,《C++語法》

二,《數據結構》

三,《算法》

四,《計算機基礎知識》

五,《初高中的數學知識》

其中,《C++語法》學習的主要內容如下:

1,cout輸出語句和鍵盤的基本操作

#include <iostream>
int main()
{std::cout << "dsaffd\n";
}

2,int整數變量的定義和加減運算

#include <iostream>
int main()
{int a;a = 10;int b = 20;int c;c = a + b;std::cout << "c=" << c << std::endl;
}

3,cin輸入和if else 判斷語句的使用

#include <iostream>
int main()
{int a, b;std::cin >> a >> b;if (a > b){std::cout << "a大" << std::endl;}else {std::cout << "b大" << std::endl;}
}

4,float變量的定義和使用

#include <iostream>
using namespace std;
int main()
{cout << "計算器程序 加法輸入1 減法輸入2"<<endl;int a;cin >> a;if (a == 1){float b, c, d;cout << "請輸入第1個數 然后按回車" << endl;cin >> b;cout << "請輸入第2個數 然后按回車" << endl;cin >> c;d = b + c;cout << "兩個數的和是" << d << endl;}    else if (a == 2){float b, c, d;cout << "請輸入第1個數 然后按回車" << endl;cin >> b;cout << "請輸入第2個數 然后按回車" << endl;cin >> c;d = b - c;cout << "兩個數的差是" << d << endl;}
}

5,int 一維數據的定義和使用

#include <iostream>
using namespace std;
int main()
{int x[3] = {5,3,2};cout << "數組中第1個數是" << x[0] << endl;cout << "數組中第2個數是" << x[1] << endl;cout << "數組中第3個數是" << x[2] << endl;cout << "第2和第3個數的和是" << x[1]+x[2] << endl;x[0] = 12;cout << "數組中第1個數 修改后是" << x[0] << endl;
}

6,++運算符的使用

#include <iostream>
using namespace std;
int main()
{int a=0;cout << a << endl;a++;cout << a << endl;a++;cout << a << endl;a++;cout << a << endl;a++;cout << a << endl;a++;cout << a << endl;a++;cout << a << endl;a++;cout << a << endl;a++;
}

7,for 循環語句的使用

#include <iostream>
using namespace std;
int main()
{for (int a=0;a<=100;a++){cout << a << endl;}
}

8,while循環語句的使用

#include <iostream>
using namespace std;
int main()
{int a = 0;while (a<=100){cout << a << endl;a++;}
}

9,無返回值 函數的定義和使用

#include <iostream>
using namespace std;
void 輸出()
{cout << "fdsafs" << endl;
}
void 循環輸出()
{for (int a = 0; a <= 100; a++){cout << a << endl;}
}
int main()
{輸出();循環輸出();
}

10,返回值 函數的定義和使用

#include <iostream>
using namespace std;
void 輸出()
{cout << "fdsafs" << endl;
}
int 加法(int a, int b)
{int x;x = a + b;return x;
}
int 減法(int a, int b)
{int x;x = a - b;return x;
}
int main()
{輸出();int x;x = 加法(2, 3);cout << "x=" << x << endl;
}

11,C++ 類

#include <iostream>
class A
{int a;//默認是私有數據,類外部無法調用 
private: //私有的 數據int b;
protected://protected 是介于 private 和 public 之間的一種可見性修飾符。protected 成員既不能被外部對象直接訪問,但可以被派生類(繼承類)訪問int c;
public:  //公共的 數據int d;void ax(){a = 1008;std::cout << "ax函數:" << std::endl;}
};
int main()
{A m;m.d = 10;std::cout << m.d << std::endl;m.ax();
}

12,C++語法之類的繼承一

#include <iostream>
class A
{
public:A(){a = 10;b = 20;}int a, b; void ax(){std::cout << "ax函數:"<< std::endl;}
};
class B :public A
{
public:void bx(){std::cout << "bx函數:" << std::endl;}
};int main()
{A m;m.ax();B n;n.ax();n.bx();
}

13,C++類的構造函數和析構函數

#include <iostream>
class A
{
public:int a;A(){a = 0;std::cout << "A的 不帶參數的 構造函數:" << std::endl;}A(int b){a = b;std::cout << "A的 帶參數的 構造函數:" << std::endl;}~A(){std::cout << "A的 析構函數:" << std::endl;}void ax(){std::cout << "ax函數:" << std::endl;}};
int main()
{std::cout << "測試一\n\n\n";A m;m.ax();std::cout << "\n\n測試二\n\n";A n(2);n.ax();
}

14,C++語法之類的繼承中的構造函數

#include <iostream>
class A
{
public:A(){std::cout << "A的 構造函數:" << std::endl;}~A(){std::cout << "A的 析構函數:" << std::endl;}void ax(){std::cout << "ax函數:" << std::endl;}};
class B :public A
{
public:B(){std::cout << "B的 構造函數:" << std::endl;}~B(){std::cout << "B的 析構函數:" << std::endl;}
};int main()
{B m;m.ax();
}

15,指針的定義和使用

#include <iostream>
using namespace std;
int main()
{int a = 10;int* p;p = &a;cout << "a=" << a << endl;cout << "&a=" << &a << endl;cout << "p=" << p << endl;cout << "*p=" << *p << endl;*p = 20;cout << "a=" << a << endl;cout << "&a=" << &a << endl;cout << "p=" << p << endl;cout << "*p=" << *p << endl;}

16,C++語法之類的this指針

#include <iostream>
class A
{
public:A(){a = 10;b = 20;}int a, b; void add(int a, int b){int c= a + b;std::cout << "add:"<<c << std::endl;}void add2(int a, int b){int c = this->a + this->b;std::cout << "add2:" << c << std::endl;}void add3(int a, int b){       std::cout << "add3:" << std::endl;this->add(a,b);this->add2(a,b);}
};int main()
{A m;m.add(2, 3);m.add2(2, 3);m.add3(2, 3);
}

17,C++語法之命名空間一

#include <iostream>
namespace a
{void 輸出(){std::cout << "命名空間a里的輸出函數" << std::endl;}
};
namespace b
{void 輸出(){std::cout << "命名空間b里的輸出函數" << std::endl;}
};
using namespace a;//這里引入命名空間
int main()
{輸出();
}
#include <iostream>
namespace a
{void 輸出(){std::cout << "命名空間a里的輸出函數" << std::endl;}
};
namespace b
{void 輸出(){std::cout << "命名空間b里的輸出函數" << std::endl;}
};int main()
{a::輸出();//用命名空間調用函數
}

18,C++語法之命名空間二

A.h頭文件中代碼:

namespace a
{void 輸出();
};


A.cpp源文件中代碼:

#include <iostream>
#include "A.h"
void a::輸出()
{std::cout << "A.h里的輸出函數" << std::endl;
}


B.h頭文件中代碼:

namespace b
{void 輸出();
};


B.cpp源文件中代碼:

#include <iostream>
#include "B.h"
void b::輸出()
{std::cout << "B.h里的輸出函數" << std::endl;
}


主函數所在源文件代碼1:引入命名空間 b

#include <iostream>
#include "A.h"
#include "B.h"
using namespace b;
int main()
{輸出();
}


運行結果 : B.h里的輸出函數

19,char變量和char數組和字符串

#include <iostream>
using namespace std;
int main()
{char a = 'x';cout << "a的值為" << a << endl;char x[3] = { 'a','b','c' };cout << "x[0]=" << x[0] << endl;cout << "x[1]=" << x[1] << endl;cout << "x[2]=" << x[2] << endl;char y[3] = { 'a','b','\0' };cout << "y[0]=" << y[0] << endl;cout << "y[1]=" << y[1] << endl;cout << "y[2]=" << y[2] << endl;cout << "y的值為" << y << endl;cout << "x的值為" << x << endl;
}

20,字符串相關函數

#include <iostream>
#include <cstring>using namespace std;int main ()
{char str1[13] = "runoob";char str2[13] = "google";char str3[13];int  len ;// 復制 str1 到 str3strcpy( str3, str1);cout << "strcpy( str3, str1) : " << str3 << endl;// 連接 str1 和 str2strcat( str1, str2);cout << "strcat( str1, str2): " << str1 << endl;// 連接后,str1 的總長度len = strlen(str1);cout << "strlen(str1) : " << len << endl;return 0;
}

21,結構體struct

#include <iostream>
#include <cstring>using namespace std;// 聲明一個結構體類型 Books 
struct Books
{char  title[50];char  author[50];char  subject[100];int   book_id;
};int main( )
{Books Book1;        // 定義結構體類型 Books 的變量 Book1Books Book2;        // 定義結構體類型 Books 的變量 Book2// Book1 詳述strcpy( Book1.title, "C++ 教程");strcpy( Book1.author, "Runoob"); strcpy( Book1.subject, "編程語言");Book1.book_id = 12345;// Book2 詳述strcpy( Book2.title, "CSS 教程");strcpy( Book2.author, "Runoob");strcpy( Book2.subject, "前端技術");Book2.book_id = 12346;// 輸出 Book1 信息cout << "第一本書標題 : " << Book1.title <<endl;cout << "第一本書作者 : " << Book1.author <<endl;cout << "第一本書類目 : " << Book1.subject <<endl;cout << "第一本書 ID : " << Book1.book_id <<endl;// 輸出 Book2 信息cout << "第二本書標題 : " << Book2.title <<endl;cout << "第二本書作者 : " << Book2.author <<endl;cout << "第二本書類目 : " << Book2.subject <<endl;cout << "第二本書 ID : " << Book2.book_id <<endl;return 0;
}

22,C++ 數據類型

#include<iostream>  
#include <limits>using namespace std;  int main()  
{  cout << "type: \t\t" << "************size**************"<< endl;  cout << "bool: \t\t" << "所占字節數:" << sizeof(bool);  cout << "\t最大值:" << (numeric_limits<bool>::max)();  cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;  cout << "char: \t\t" << "所占字節數:" << sizeof(char);  cout << "\t最大值:" << (numeric_limits<char>::max)();  cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;  cout << "signed char: \t" << "所占字節數:" << sizeof(signed char);  cout << "\t最大值:" << (numeric_limits<signed char>::max)();  cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;  cout << "unsigned char: \t" << "所占字節數:" << sizeof(unsigned char);  cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();  cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;  cout << "wchar_t: \t" << "所占字節數:" << sizeof(wchar_t);  cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();  cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;  cout << "short: \t\t" << "所占字節數:" << sizeof(short);  cout << "\t最大值:" << (numeric_limits<short>::max)();  cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;  cout << "int: \t\t" << "所占字節數:" << sizeof(int);  cout << "\t最大值:" << (numeric_limits<int>::max)();  cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;  cout << "unsigned: \t" << "所占字節數:" << sizeof(unsigned);  cout << "\t最大值:" << (numeric_limits<unsigned>::max)();  cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;  cout << "long: \t\t" << "所占字節數:" << sizeof(long);  cout << "\t最大值:" << (numeric_limits<long>::max)();  cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;  cout << "unsigned long: \t" << "所占字節數:" << sizeof(unsigned long);  cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();  cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;  cout << "double: \t" << "所占字節數:" << sizeof(double);  cout << "\t最大值:" << (numeric_limits<double>::max)();  cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;  cout << "long double: \t" << "所占字節數:" << sizeof(long double);  cout << "\t最大值:" << (numeric_limits<long double>::max)();  cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;  cout << "float: \t\t" << "所占字節數:" << sizeof(float);  cout << "\t最大值:" << (numeric_limits<float>::max)();  cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;  cout << "size_t: \t" << "所占字節數:" << sizeof(size_t);  cout << "\t最大值:" << (numeric_limits<size_t>::max)();  cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;  cout << "string: \t" << "所占字節數:" << sizeof(string) << endl;  // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;  cout << "type: \t\t" << "************size**************"<< endl;  return 0;  
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/75550.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/75550.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/75550.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

3、孿生網絡/連體網絡(Siamese Network)

目的: 用Siamese Network (孿生網絡) 解決Few-shot learning (小樣本學習)。 Siamese Network并不是Meta Learning最好的方法, 但是通過學習Siamese Network,非常有助于理解其他Meta Learning算法。 這里介紹了兩種方法:Siamese Network (孿生網絡)、Trplet Loss Siam…

從零構建大語言模型全棧開發指南:第二部分:模型架構設計與實現-2.2.1從零編寫類GPT-2模型架構(規劃模塊與代碼組織)

?? 點擊關注不迷路 ?? 點擊關注不迷路 ?? 點擊關注不迷路 文章大綱 2.2.1 從零編寫類GPT-2模型架構(規劃模塊與代碼組織)1. 模型架構設計規劃1.1 架構核心組件2. 模塊化設計實現2.1 輸入處理模塊2.1.1 分詞與嵌入2.1.2 位置編碼2.2 解碼塊設計2.2.1 多頭注意力子層2.2.…

消息隊列(Kafka及RocketMQ等對比聯系)

目錄 消息隊列 一、為什么使用消息隊列&#xff1f;消息隊列有什么優點/缺點&#xff1f;介紹下Kafka、ActiveMQ、RabbitMQ、RocketMQ有什么優點缺點&#xff0c;如何取舍&#xff1f; 1.公司業務場景是什么&#xff0c;這個業務場景有什么挑戰&#xff0c;如果不用MQ有什么麻…

Android 13系統定制實戰:基于系統屬性的音量鍵動態屏蔽方案解析

1. 需求背景與實現原理 在Android 13系統定制化開發中&#xff0c;需根據設備場景動態屏蔽音量鍵&#xff08;VOLUME_UP/VOLUME_DOWN&#xff09;功能。其核心訴求是通過系統屬性&#xff08;persist.sys.roco.volumekey.enable&#xff09;控制音量鍵的響應邏輯&#xff0c;確…

解鎖DeepSeek潛能:Docker+Ollama打造本地大模型部署新范式

&#x1f407;明明跟你說過&#xff1a;個人主頁 &#x1f3c5;個人專欄&#xff1a;《深度探秘&#xff1a;AI界的007》 &#x1f3c5; &#x1f516;行路有良友&#xff0c;便是天堂&#x1f516; 目錄 一、引言 1、什么是Docker 2、什么是Ollama 二、準備工作 1、操…

uv - Guides 指南 [官方文檔翻譯]

文章目錄 Guides 指南概述安裝 Python入門安裝特定版本重新安裝 Python查看 Python 安裝自動 Python 下載使用現有的 Python 版本 運行腳本在沒有依賴的情況下運行腳本運行帶有依賴的腳本創建一個Python腳本聲明腳本依賴使用替代包索引鎖定依賴提高可重復性使用不同的 Python 版…

根據模板將 Excel 明細數據生成 PDF 文檔 | PDF實現郵件合并功能

在日常辦公中&#xff0c;我們常常會面臨這樣的需求&#xff1a;依據特定的模板&#xff0c;把 Excel 里的每一條數據轉化為單獨的 PDF 文檔&#xff0c;且這些 PDF 文檔中的部分內容會根據 Excel 數據動態變化。這一功能不僅能高效完成任務&#xff0c;還支持圖片的動態替換&a…

apache安裝腳本使用shell建立

注意防火墻&#xff0c;yum&#xff0c;網絡連接等 以下是具體的apache安裝腳本 #!/bin/bash # Set Apache version to install ## author: yuan # 檢查外網連接 echo "檢查外網連接..." ping www.baidu.com -c 3 > /dev/null 2>&1 if [ $? -eq 0 ]; …

wordpress主題使用中常見錯誤匯總

在WordPress主題的使用過程中&#xff0c;開發者可能會遇到各種問題。下面是一些常見錯誤的匯總&#xff0c;并給出了相應的解決方法。 一、主題安裝與激活錯誤 無法激活主題&#xff1a;檢查主題文件是否完整&#xff0c;以及是否符合WordPress的主題規范。 激活主題后出現…

如何設計一個訂單號生成服務?應該考慮那些問題?

如何設計一個訂單號生成服務&#xff1f;應該考慮那些問題&#xff1f; description: 在高并發的電商系統中&#xff0c;生成全局唯一的訂單編號是關鍵。本文探討了幾種常見的訂單編號生成方法&#xff0c;包括UUID、數據庫自增、雪花算法和基于Redis的分布式組件&#xff0c;并…

Springboot 集成 Flowable 6.8.0

1. 創建 Spring Boot 項目 通過 Spring Initializr&#xff08;https://start.spring.io/ &#xff09;創建一個基礎的 Spring Boot 項目&#xff0c;添加以下依賴&#xff1a; Spring WebSpring Data JPAMySQL DriverLombok&#xff08;可選&#xff0c;用于簡化代碼&#x…

《TCP/IP網絡編程》學習筆記 | Chapter 22:重疊 I/O 模型

《TCP/IP網絡編程》學習筆記 | Chapter 22&#xff1a;重疊 I/O 模型 《TCP/IP網絡編程》學習筆記 | Chapter 22&#xff1a;重疊 I/O 模型理解重疊 I/O 模型重疊 I/O本章討論的重疊 I/O 的重點不在于 I/O 創建重疊 I/O 套接字執行重疊 I/O 的 WSASend 函數進行重疊 I/O 的 WSA…

搭建Redis哨兵集群

停掉現有的redis集群 因為這篇文章我是在 搭建完redis主從集群之后寫的&#xff0c;如果要是沒有搭建過這些&#xff0c;可以直接略過。要是從我上一篇 搭建redis主從集群過來的&#xff0c;可以執行下。 docker compose down 查找下redis相關進程 ps -ef | grep redis 可以看…

MySQL中,聚集索引和非聚集索引到底有什么區別?

文章目錄 1. 數據存儲方式2. 索引結構3. 查詢效率4. 索引數量5. 適用場景6. 示例說明7. 總結 在MySQL中&#xff0c;聚集索引和非聚集索引&#xff08;也稱二級索引&#xff09;的區別主要體現在數據存儲方式、索引結構和查詢效率等方面。以下是詳細對比&#xff1a; 1. 數據存…

看 MySQL InnoDB 和 BoltDB 的事務實現

BoltDB 事務實現 BoltDB 支持多讀單寫方式的并發級別 事務操作會鎖表 它的 MVCC 為 2 個版本&#xff0c;當前版本和正在寫的版本 多讀&#xff1a;可以并發讀當前版本 單寫&#xff08;串行寫&#xff09;&#xff1a;寫時拷貝當前 B 樹&#xff0c;構建新 B 樹&#xff…

08_JavaScript數據操作方法_數組

目錄 一、創建一個數組 1.1 數組如何創建 字面量創建 構造函數創建 1.2 數組的長度 數組名.length 1.3 數組的索引 1.4 數組如何循環遍歷 for 循環遍歷 for in for of 二、數組的常用方法 &#xff08;重點 面試&#xff09; push 方法 unshift 方法 pop shif…

2025.3.25總結

工作&#xff1a;這兩天工作都沒啥產出&#xff0c;主要是工作狀態不太好&#xff0c;周日晚上兩點睡&#xff0c;周一晚上一點睡。熬夜傷身&#xff0c;但就是控制不住自己&#xff0c;睡前總要刷刷手機。本來想睡前看會書的&#xff0c;但這行為及其不穩定&#xff0c;抖音也…

《Python實戰進階》第33集:PyTorch 入門-動態計算圖的優勢

第33集&#xff1a;PyTorch 入門-動態計算圖的優勢 摘要 PyTorch 是一個靈活且強大的深度學習框架&#xff0c;其核心特性是動態計算圖機制。本集將帶您探索 PyTorch 的張量操作、自動求導系統以及動態計算圖的特點與優勢&#xff0c;并通過實戰案例演示如何使用 PyTorch 實現…

初識哈希表

一、題意 給定一個整數數組 nums 和一個目標值 target&#xff0c;要求你在數組中找出和為目標值的那兩個整數&#xff0c;并返回它們的數組下標。你可以假設每種輸入只會對應一個答案。但是&#xff0c;數組中同一個元素不能使用兩遍。 示例&#xff1a; 給定 nums [2, 7, …

23種設計模式-創建型模式-單例

文章目錄 簡介問題1. 確保一個類只有一個實例2. 為該實例提供全局訪問點 解決方案示例重構前&#xff1a;重構后&#xff1a; 拓展volatile 在單例模式中的雙重作用 總結 簡介 單例是一種創建型設計模式&#xff0c;它可以確保一個類只有一個實例&#xff0c;同時為該實例提供…