当前位置: 首页 > news >正文

双城网站建设哪家好爱战网关键词工具

双城网站建设哪家好,爱战网关键词工具,网站建设维护公司排名,wordpress dashboardC语言设计期末知识点附示例代码。 1. 基础语法 变量和数据类型: int a 10; // 整型 float b 5.25f; // 单精度浮点型 double c 5.25; // 双精度浮点型 char d A; // 字符型 bool e true; // 布尔型 const int PI 3.14; // 常量输入输出&…

C++语言设计期末知识点附示例代码。

1. 基础语法

  • 变量和数据类型

    int a = 10;       // 整型
    float b = 5.25f;  // 单精度浮点型
    double c = 5.25;  // 双精度浮点型
    char d = 'A';     // 字符型
    bool e = true;    // 布尔型
    const int PI = 3.14;  // 常量
    
  • 输入输出

    #include <iostream>
    using namespace std;int main() {int num;cout << "Enter a number: ";cin >> num;cout << "You entered: " << num << endl;return 0;
    }
    

2. 流程控制

  • 条件语句

    if (a > b) {cout << "a is greater than b";
    } else if (a == b) {cout << "a is equal to b";
    } else {cout << "a is less than b";
    }switch (a) {case 1: cout << "a is 1"; break;case 2: cout << "a is 2"; break;default: cout << "a is neither 1 nor 2";
    }
    
  • 循环语句

    // for loop
    for (int i = 0; i < 5; ++i) {cout << i << " ";
    }// while loop
    int i = 0;
    while (i < 5) {cout << i << " ";++i;
    }// do-while loop
    int j = 0;
    do {cout << j << " ";++j;
    } while (j < 5);
    

3. 函数

  • 函数定义与声明

    int add(int a, int b);  // 函数声明int main() {cout << add(5, 3);  // 调用函数return 0;
    }int add(int a, int b) {  // 函数定义return a + b;
    }
    
  • 函数重载

    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }int main() {cout << add(5, 3) << endl;          // 调用 int 版本cout << add(5.0, 3.0) << endl;      // 调用 double 版本return 0;
    }
    
  • 递归

    int factorial(int n) {if (n == 1) return 1;return n * factorial(n - 1);
    }int main() {cout << factorial(5);  // 输出 120return 0;
    }
    

4. 数组和指针

  • 数组

    int arr[5] = {1, 2, 3, 4, 5};  // 一维数组for (int i = 0; i < 5; ++i) {cout << arr[i] << " ";
    }int arr2D[2][3] = {{1, 2, 3}, {4, 5, 6}};  // 二维数组
    
  • 指针

    int var = 10;
    int *ptr = &var;  // 指针指向变量的地址cout << "Value of var: " << *ptr << endl;  // 输出指针指向的值
    
  • 动态内存分配

    int *p = new int[5];  // 动态分配一个长度为 5 的整数数组
    delete[] p;           // 释放内存
    

5. 面向对象编程(OOP)

  • 类与对象

    class Person {
    private:string name;int age;public:// 构造函数Person(string n, int a) : name(n), age(a) {}void display() {cout << "Name: " << name << ", Age: " << age << endl;}
    };int main() {Person p("John", 25);p.display();return 0;
    }
    
  • 继承

    class Animal {
    public:void eat() { cout << "Animal is eating" << endl; }
    };class Dog : public Animal {  // 公有继承
    public:void bark() { cout << "Dog is barking" << endl; }
    };int main() {Dog d;d.eat();  // 基类的方法d.bark(); // 派生类的方法return 0;
    }
    
  • 多态性

    class Animal {
    public:virtual void sound() { cout << "Some animal sound" << endl; }
    };class Dog : public Animal {
    public:void sound() override { cout << "Bark" << endl; }
    };int main() {Animal* a = new Dog();a->sound();  // 输出 "Bark"delete a;return 0;
    }
    

6. 运算符重载

  • 加法运算符重载
    class Complex {
    private:int real, imag;public:Complex(int r = 0, int i = 0) : real(r), imag(i) {}Complex operator + (const Complex& obj) {Complex temp;temp.real = real + obj.real;temp.imag = imag + obj.imag;return temp;}void display() { cout << real << " + i" << imag << endl; }
    };int main() {Complex c1(5, 3), c2(2, 4);Complex c3 = c1 + c2;c3.display();  // 输出 "7 + i7"return 0;
    }
    

7. 标准模板库(STL)

  • vector 使用
    #include <iostream>
    #include <vector>
    using namespace std;int main() {vector<int> vec = {1, 2, 3, 4, 5};vec.push_back(6);  // 添加元素for (int i : vec) {cout << i << " ";  // 遍历 vector}return 0;
    }
    

8. 异常处理

  • 异常捕获
    #include <iostream>
    using namespace std;int main() {try {int age = -1;if (age < 0) {throw "Invalid age!";}} catch (const char* msg) {cout << "Error: " << msg << endl;}return 0;
    }
    

9. 文件操作

  • 文件读写
    #include <iostream>
    #include <fstream>
    using namespace std;int main() {// 写入文件ofstream outFile("example.txt");outFile << "Hello, World!" << endl;outFile.close();// 从文件读取string line;ifstream inFile("example.txt");if (inFile.is_open()) {while (getline(inFile, line)) {cout << line << endl;}inFile.close();}return 0;
    }
    

10. 预处理器与宏

  • 宏与条件编译
    #define PI 3.14#include <iostream>
    using namespace std;int main() {cout << "PI is: " << PI << endl;return 0;
    }#ifdef DEBUGcout << "Debug mode" << endl;
    #endif
    

11. 名字空间(namespace)

  • 使用名字空间
    #include <iostream>
    using namespace std;namespace myNamespace {int x = 10;
    }int main() {cout << myNamespace::x << endl;return 0;
    }
    

12. 动态内存管理

  • 智能指针
    #include <iostream>
    #include <memory>
    using namespace std;int main() {shared_ptr<int> p1 = make_shared<int>(10);cout << *p1 << endl;return 0;}
http://www.tj-hxxt.cn/news/16773.html

相关文章:

  • 杭州做网站哪家公司好香港百度广告
  • 济宁做网站的企业靠网络营销火起来的企业
  • 无形资产 网站建设百度快照替代
  • 做淘宝客为什么要做网站百度指数是啥
  • 有专门做检验的视频网站吗手机端关键词排名优化
  • 嘉兴网站建设网址台州优化排名推广
  • 大连建设工业产品网站百度高级搜索指令
  • 网站建设主要包括两个方面杭州千锋教育地址
  • 滕州网站建设哪家好深圳疫情最新消息
  • 成都兼职做网站百度网页版登录入口
  • 不让人看出wordpress建的站职业培训机构需要什么资质
  • 百度怎么对网站处罚外包公司和劳务派遣
  • 3d网站建设制作百度推广登录后台登录入口
  • 军队网站建设方案seo优化论坛
  • 网站怎么发内容优化品牌运营策略有哪些
  • 装修设计公司起名seo是广告投放吗
  • 建站工具缺点国内优秀个人网站欣赏
  • 大连专业手机自适应网站建设维护卡点视频免费制作软件
  • 高清做网站插图宽带营销策略
  • 网站开发服务公司站外推广免费网站
  • 自适应网站建设都找全网天下网址导航推广
  • 网站售后维护seo优化服务公司
  • 色调网站百度地图疫情实时动态
  • 怎样登入网站后台如何建网址
  • 自开发网站中国站长之家网站
  • 江门做网站哪家好北京百度总部
  • 广告传媒网站模板软件推广接单平台
  • 贵阳制作网站网络推广渠道公司
  • wordpress学校网站neotv
  • 好看的wordpress文章模板下载seoul是什么国家