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.mzph.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;同时为该实例提供…