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

做电子相册的网站模板建设网站

做电子相册的网站,模板建设网站,温州品牌网站建设,巴顿品牌设计C语言设计期末知识点附示例代码。 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.yayakq.cn/news/67865/

相关文章:

  • 网站后台密码怎么修改架设一个网站需要多少钱
  • 安徽城乡建设部网站首页企业信用信息公示系统湖北
  • 比较有名的公司网站英文网站域名注册
  • 大型网站建设企业白银区住房和城乡建设局网站
  • 最好的微网站建设公司推荐广州外贸网络推广
  • 宝坻集团网站建设专业门户网站开发
  • 网站建设代码标签大全一流的盐城网站建设
  • 400电话 网站建设经典软文案例100例
  • 深圳英文网站建设公司WordPress太臃肿了
  • 怎样评价一个网站做的好与不好制作网页动态效果
  • 在线学习网站建设响应式布局怎么实现
  • .net做的学校网站网站建设维护合同范本
  • 公众号做微网站公司部门设置
  • 在线网站建设联系人天津注册公司多少钱
  • 网站seo外包价格网站必须做ssl认证
  • 设计模板免费网站网络推广员是什么
  • ps做图下载网站有哪些品牌高端网站建设公司
  • 获得网站所有关键字网站内部的信息安全建设
  • 平谷营销型网站建设专业的网站建设科技公司
  • 自适应网站是什么手机在线图片编辑器
  • 站长工具5118百度提交收录
  • 商商业网站建设网站建设 风险防控
  • 做个游戏网站多少钱注册广告公司名字
  • 南昌网站建设 南昌做网站公司医程通 网站做的太
  • 叫别人做网站需要注意什么谷歌浏览器搜索引擎入口
  • 怎么查那些人输入做网站app推广拉新
  • wordpress流量站高端网站建设的方案
  • 网站 做百度推广有没有效果怎么样网站空间信息查询
  • 建站之星官方网站多商户海外商城源码下载
  • html5建设的网站美术馆网站建设要求