Browse Source

first commit

Pchen. 5 months ago
commit
0eca81efea
100 changed files with 3421 additions and 0 deletions
  1. 33 0
      A2判断季节.c
  2. 19 0
      ASCII码和数据类型转换.c
  3. 63 0
      CPU类.cpp
  4. 16 0
      Fibonacci数列.c
  5. 16 0
      Fibonacci数列的递归函数实现——4-05.c
  6. 64 0
      Student 的类(类的组合).cpp
  7. 15 0
      c0101.c
  8. 42 0
      datatype(数据类型)类(构造函数重载和调用).cpp
  9. 32 0
      example1b.c
  10. 29 0
      sinx计算公式.c
  11. 45 0
      三角形类.cpp
  12. 28 0
      两个整数之间的所有素数.c
  13. 8 0
      个人介绍.c
  14. 18 0
      个人所得税.c
  15. 63 0
      九九乘法表-多种形式.c
  16. 28 0
      九九乘法表.c
  17. 53 0
      二维坐标Point类派生三维空间坐标点类Point3D.cpp
  18. 22 0
      二维数组主对角线元素和.c
  19. 58 0
      二维整型数组的“最小点”.c
  20. 16 0
      人民币兑换.c
  21. 14 0
      使用printf语句输出两个两位整数的四则运算式.c
  22. 19 0
      分别统计输入中字母、数字的个数.c
  23. 23 0
      分段函数.c
  24. 201 0
      分钟换算.c
  25. 21 0
      删除字符串中指定n个字符——6-06.c
  26. 37 0
      判断可逆素数.c
  27. 15 0
      前驱、后继字符.c
  28. 25 0
      十进制数到二进制数的转换.c
  29. 23 0
      去大写英文字母.c
  30. 21 0
      各位数字和.c
  31. 25 0
      同构数.c
  32. 14 0
      和与乘积.c
  33. 107 0
      圆盘找数问题.cpp
  34. 34 0
      圆类.cpp
  35. 69 0
      坐标点Point的运算符重载.cpp
  36. 42 0
      复数类Complex.cpp
  37. 26 0
      字符串复制.c
  38. 24 0
      字符串比较2.c
  39. 81 0
      字符串类STR.cpp
  40. 20 0
      字符串逆序.c
  41. 38 0
      字符查找.c
  42. 54 0
      学生记录.c
  43. 64 0
      定义一个Cat类体会静态数据成员和静态成员函数的用法.cpp
  44. 47 0
      定义一个长方形Rect类再派生出长方体类Cub.cpp
  45. 58 0
      定义复数类的加法与减法(运算符+-重载).cpp
  46. 58 0
      定义并实现一个学生类(Student).cpp
  47. 62 0
      定义并实现一个银行类(Bank).cpp
  48. 35 0
      实现客户机client类.cpp
  49. 39 0
      寻找完全数.c
  50. 30 0
      寻找完全数2.c
  51. 19 0
      将指定的某个正整数数逆序输出.c
  52. 16 0
      幂函数.c
  53. 15 0
      平均工资.c
  54. 18 0
      平方和与立方和.c
  55. 58 0
      建立一个数组类ARR求最大值及其下标.cpp
  56. 54 0
      成绩统计.c
  57. 41 0
      成绩统计小程序(结构体).c
  58. 24 0
      找最大最小整数.c
  59. 23 0
      按揭贷款-等额本金.c
  60. 9 0
      摄氏温度转换为华氏温度.c
  61. 22 0
      数值变换.c
  62. 37 0
      数组去重复.c
  63. 18 0
      数组和.c
  64. 21 0
      数组最小值及下标.c
  65. 32 0
      数组逆序存放.c
  66. 35 0
      整数出现次数.c
  67. 41 0
      整数加一.c
  68. 15 0
      整数合并.c
  69. 30 0
      杨辉三角形.c
  70. 23 0
      正整数的打印.c
  71. 12 0
      求三个整数的平均值.c
  72. 15 0
      求三角形面积.c
  73. 25 0
      求公式近似值.c
  74. 14 0
      求关于x和y的表达式的值.c
  75. 17 0
      求实数的绝对值.c
  76. 17 0
      求平均工资(数组名做参数).c
  77. 16 0
      求序列的和.c
  78. 34 0
      求最大值与最小值 (1).c
  79. 25 0
      求最大值与最小值.c
  80. 41 0
      派生对象和基类对象指针的使用(类型兼容性规则).cpp
  81. 83 0
      点、线、三角形.cpp
  82. 30 0
      点类定义和使用.cpp
  83. 39 0
      狗的定义和使用(继承中的构造和析构).cpp
  84. 47 0
      用友元函数计算Boat和Car类对象的总重量.cpp
  85. 25 0
      相亲数.c
  86. 45 0
      矩阵乘法.c
  87. 35 0
      矩阵转置.c
  88. 8 0
      简单实现x的n次方.c
  89. 27 0
      简易计算器.c
  90. 39 0
      绝对素数 (1).c
  91. 42 0
      绝对素数.c
  92. 18 0
      统计捐款人数及捐款.c
  93. 51 0
      编写矩形类.cpp
  94. 65 0
      编写长方体.cpp
  95. 13 0
      计算圆面积.c
  96. 22 0
      计算天数.c
  97. 27 0
      计算天数——8-01.c
  98. 13 0
      计算平均值.c
  99. 12 0
      计算平方.c
  100. 19 0
      计算球体积.c

+ 33 - 0
A2判断季节.c

@@ -0,0 +1,33 @@
+#include <stdio.h>
+
+int main() {
+    int month;
+    scanf("%d", &month);
+    
+    switch(month) {
+        case 3:
+        case 4:
+        case 5:
+            printf("Spring\n");
+            break;
+        case 6:
+        case 7:
+        case 8:
+            printf("Summer\n");
+            break;
+        case 9:
+        case 10:
+        case 11:
+            printf("Autumn\n");
+            break;
+        case 12:
+        case 1:
+        case 2:
+            printf("Winter\n");
+            break;
+        default:
+            printf("Invalid month\n");
+    }
+    
+    return 0;
+}

+ 19 - 0
ASCII码和数据类型转换.c

@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int main() {
+	int input;
+	char output[5];
+	scanf("%d",&input);
+	
+	int index = 3;
+	while(input != 0) {
+		int num = input % 10 + 13;
+		output[index] = 'A' + (num - 1);
+		index --;
+		input /= 10;
+	}
+	output[4] = '\0';
+	printf("%s",output);
+	
+	return 0;
+} 

+ 63 - 0
CPU类.cpp

@@ -0,0 +1,63 @@
+#include <iostream>
+using namespace std;
+
+// CPU等级:枚举型声明
+enum CPU_Rank { P1 = 1, P2, P3, P4, P5, P6, P7 };
+
+// CPU类的声明
+class CPU {
+private:
+    CPU_Rank rank;
+    int frequency;  // 频率 (MHz)
+    float voltage;  // 电压 (V)
+
+public:
+    // 构造函数
+    CPU(CPU_Rank r, int f, float v) : rank(r), frequency(f), voltage(v) {
+        cout << "构造了一个CPU!" << endl;
+    }
+
+    // 析构函数
+    ~CPU() {
+        cout << "析构了一个CPU!" << endl;
+    }
+
+    // 成员函数:run
+    void run() {
+        cout << "CPU开始运行!" << endl;
+    }
+
+    // 成员函数:stop
+    void stop() {
+        cout << "CPU停止运行!" << endl;
+    }
+
+    // 输出等级
+    void printRank() {
+        cout << "等级为:" << rank << endl;
+    }
+};
+
+// 测试
+int main() {
+    int rank1, rank2;
+    
+    // 输入两个CPU的等级
+    cin >> rank1 >> rank2;
+
+    // 创建两个CPU对象
+    CPU cpu1(static_cast<CPU_Rank>(rank1), 2400, 1.2);
+    CPU cpu2(static_cast<CPU_Rank>(rank2), 3200, 1.3);
+
+    // 运行和停止第一个CPU
+    cpu1.run();
+    cpu1.printRank();
+    cpu1.stop();
+
+    // 运行和停止第二个CPU
+    cpu2.run();
+    cpu2.printRank();
+    cpu2.stop();
+
+    return 0;
+}

+ 16 - 0
Fibonacci数列.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int main() {
+	int n;
+	scanf("%d",&n);
+	
+	int i,x,y=0,z=1;
+	for(i=1;i<=n;i++) {
+		x = y;
+		y = z;
+		z += x;
+	}
+	printf("%d",y);
+	
+	return 0;
+}

+ 16 - 0
Fibonacci数列的递归函数实现——4-05.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int fibonacci(int n) {
+    if (n == 0 || n == 1) {
+        return 1;
+    } else {
+        return fibonacci(n - 1) + fibonacci(n - 2);
+    }
+}
+
+int main() {
+    int n;
+    scanf("%d", &n);
+    printf("%d", fibonacci(n));
+    return 0;
+}

+ 64 - 0
Student 的类(类的组合).cpp

@@ -0,0 +1,64 @@
+#include<iostream>
+#include<string>
+
+using namespace std;
+
+//Score类
+class Score {
+private:
+    int math;
+    int eng;
+
+public:
+    // 构造函数,初始化 math 和 eng
+    Score(int m, int e) {
+        math = m;
+        eng = e;
+    }
+
+    // 成员函数,输出数学成绩和英语成绩
+    void show() {
+        cout << "数学成绩:" << math << endl;
+        cout << "英语成绩:" << eng << endl;
+    }
+};
+//Student类
+
+class Student {
+private:
+    int stuid;
+    Score mark;
+
+public:
+    // 构造函数,初始化 stuid 和 mark
+    Student(int id, int m, int e) : stuid(id), mark(m, e) {}
+
+    // 成员函数,输出学号和成绩
+    void stushow() {
+        cout << "\n学号:" << stuid << endl;
+        mark.show(); // 调用 Score 类中的 show() 函数
+    }
+};
+
+
+int main()
+{
+ int id, math, eng;
+ 
+     // 输入学生的学号、数学成绩、英语成绩
+     cout << "学号:";
+     cin >> id;
+     cout << "数学成绩:";
+     cin >> math;
+     cout << "英语成绩:";
+     cin >> eng;
+ 
+     // 创建 Student 对象并输出
+     Student student(id, math, eng);
+     student.stushow();
+ 
+     return 0;
+  
+  return 0;
+}
+

+ 15 - 0
c0101.c

@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main() {
+    int x, y, z;
+    scanf("%d %d %d", &x, &y, &z);
+
+    int sum = x + y + z;
+    float average = (float)sum / 3;
+
+    printf("%d\n", sum);
+    printf("%.2f\n", average);
+
+    return 0;
+}
+

+ 42 - 0
datatype(数据类型)类(构造函数重载和调用).cpp

@@ -0,0 +1,42 @@
+#include <iostream>
+#include <string>
+
+class datatype {
+public:
+    datatype() {}
+    
+    void inputChar(char c) {
+        std::cout << "character:" << c << std::endl;
+    }
+
+    void inputInt(int num) {
+        std::cout << "int:" << num << std::endl;
+    }
+
+    void inputFloat(float f) {
+        std::cout << "float:" << f << std::endl;
+    }
+};
+
+int main() {
+    int choice;
+    std::cin >> choice;
+
+    datatype obj;
+
+    if (choice == 1) {
+        int num;
+        std::cin >> num;
+        obj.inputInt(num);
+    } else if (choice == 2) {
+        char c;
+        std::cin >> c;
+        obj.inputChar(c);
+    } else if (choice == 3) {
+        float f;
+        std::cin >> f;
+        obj.inputFloat(f);
+    }
+
+    return 0;
+}

+ 32 - 0
example1b.c

@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <math.h>
+
+double calculate_sin(double x, int n) {
+    double result = 0.0;
+    double term = x;
+    double sign = 1.0;
+    
+    int i;
+    for (i = 1; i <= n; ++i) {
+        result += sign * term;
+        sign = -sign;
+        term *= x * x / ((2 * i) * (2 * i + 1));
+    }
+
+    return result;
+}
+
+int main() {
+    double x;
+    int n;
+
+    scanf("%lf %d", &x, &n);
+
+
+    double sin_x = calculate_sin(x, n);
+
+    printf("%.8lf\n", sin_x);
+
+    return 0;
+}
+

+ 29 - 0
sinx计算公式.c

@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <math.h>
+
+double jiecheng(int num) {
+    double result = 1.0;
+    int i = 1;
+    while (i <= num) {
+        result *= i;
+        i++;
+    }
+    return result;
+}
+
+int main() {
+    double x, sinx = 0.0, term;
+    int n;
+    scanf("%lf %d", &x, &n);
+
+    int i = 1;
+    while (i <= n) {
+        term = pow(-1, i - 1) * pow(x, 2 * i - 1) / jiecheng(2 * i - 1);
+        sinx += term;
+        i++;
+    }
+
+    printf("%.8lf", sinx);
+
+    return 0;
+}

+ 45 - 0
三角形类.cpp

@@ -0,0 +1,45 @@
+#include<iostream>
+#include<math.h>
+using namespace std;
+
+// 三角形类的定义
+class Tri {
+private:
+    double side1, side2, side3; 
+
+public:
+    Tri(double s1, double s2, double s3) {
+        side1 = s1;
+        side2 = s2;
+        side3 = s3;
+    }
+
+    double perimeter() {
+        return side1 + side2 + side3;
+    }
+
+    double area() {
+        double s = (side1 + side2 + side3) / 2;
+        return sqrt(s * (s - side1) * (s - side2) * (s - side3));
+    }
+
+    void print() {
+        if (side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1) {
+        	cout << "三角形的边长:" << side1 << " " << side2 << " " << side3 << endl;
+            cout << "三角形的周长:" << perimeter() << endl;
+            cout << "三角形的面积:" << area() << endl;
+        } else {
+            cout << "不构成三角形!" << endl;
+        }
+    }
+};
+
+int main() {
+    double s1, s2, s3;
+    cin >> s1 >> s2 >> s3;
+
+    Tri triangle(s1, s2, s3);
+    triangle.print();
+
+    return 0;
+}

+ 28 - 0
两个整数之间的所有素数.c

@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+int isPrime(int num) {
+    if (num <= 1) return 0;
+    int i;
+    for (i = 2; i * i <= num; i++) {
+        if (num % i == 0)
+            return 0;
+    }
+    return 1; 
+}
+
+int main() {
+    int a, b;
+    scanf("%d %d", &a, &b);
+
+    int count = 0, i;
+    for (i = a; i <= b; i++) {
+        if (isPrime(i)) {
+            printf("%d  ", i);
+            count++;
+            if (count % 8 == 0)
+                printf("\n");
+        }
+    }
+
+    return 0;
+}

+ 8 - 0
个人介绍.c

@@ -0,0 +1,8 @@
+#include <stdio.h>
+int main() {
+	printf("我叫唐浩宸\n");
+	printf("来自重庆\n");
+	printf("爱好是学习\n");
+	
+	return 0;
+}

+ 18 - 0
个人所得税.c

@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main() {
+	int wage,deduct;
+	scanf("%d %d",&wage,&deduct);
+	int result = wage - deduct - 5000;
+	
+	if(result <= 0) return 0;
+	else if(0 < result && result <= 3000) printf("%.2f",result * 0.03);
+	else if(3000 < result && result <= 12000) printf("%.2f",result * 0.1 - 210);
+	else if(12000 < result && result <= 25000) printf("%.2f",result * 0.2 - 1410);
+	else if(25000 < result && result <= 35000) printf("%.2f",result * 0.25 - 2660);
+	else if(35000 < result && result <= 55000) printf("%.2f",result * 0.3 - 4410);
+	else if(55000 < result && result <= 80000) printf("%.2f",result * 0.35 - 7160);
+	else printf("%.2f",result * 0.45 - 15160);
+	
+	return 0;
+}

+ 63 - 0
九九乘法表-多种形式.c

@@ -0,0 +1,63 @@
+#include <stdio.h>
+
+void a() {
+    int i, j;
+    for (i = 1; i <= 9; i++) {
+        for (j = 1; j <= 9; j++) {
+            printf("%d*%d=%d ", i, j, i * j);
+        }
+        printf("\n");
+    }
+}
+
+void b() {
+    int i, j;
+    for (i = 1; i <= 9; i++) {
+        for (j = 1; j <= 9; j++) {
+            if (j >= i) {
+                printf("%d*%d=%d ", i, j, i * j);
+            } else {
+                printf(" ");
+            }
+        }
+        printf("\n");
+    }
+}
+
+void c() {
+    int i, j;
+    for (i = 1; i <= 9; i++) {
+        for (j = 1; j <= 9; j++) {
+            if (j <= i) {
+                printf("%d*%d=%d ", i, j, i * j);
+            } else {
+                printf("\t");
+            }
+        }
+        printf("\n");
+    }
+}
+
+int main() {
+    int choice;
+    scanf("%d", &choice);
+
+    switch (choice) {
+        case 0:
+            a();
+            break;
+        case 1:
+            b();
+            break;
+        case 2:
+            c();
+            break;
+        default:
+            printf("\n");
+    }
+    return 0;
+}
+
+
+
+

+ 28 - 0
九九乘法表.c

@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+int main() {
+    int n;
+    scanf("%d", &n);
+
+    int i, j;
+    if (n == 0) {
+        for (i = 1; i <= 9; i++) {
+            for (j = 1; j <= 9; j++) {
+                printf("%d*%d=%d ", i, j, i * j);
+            }
+            printf("\n");
+        }
+    } else if(n == 1) {
+    	for(i = 1; i<= 9; i++) {
+    		int k;
+    		for(k = 0; k <= 8; k++) {
+    			printf("      ");
+			}
+    		for(j = 1; j <= 9; j++) {
+    			printf("%d*%d=%d ", i, j, i * j);
+			}
+		}
+	}
+
+    return 0;
+}

+ 53 - 0
二维坐标Point类派生三维空间坐标点类Point3D.cpp

@@ -0,0 +1,53 @@
+#include <iostream>
+#include <cmath>
+using namespace std;
+
+class Point {
+protected:
+	double x, y;
+	
+public:
+	Point() : x(0), y(0) {}
+	
+	Point(double x, double y) : x(x), y(y) {}
+	
+	double getx() {
+		return x;
+	}
+	
+	double gety() {
+		return y;
+	}
+	
+	double dist(const Point& p) {
+		return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
+	}
+};
+
+class Point3D : public Point {
+private:
+	double z;
+	
+public:
+	Point3D() : Point(), z(0) {}
+	
+	Point3D(double x, double y, double z) : Point(x, y), z(z) {}
+	
+	double getz() {
+		return z;
+	}
+	
+	double dist(const Point3D& p) {
+		return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.z));
+	}
+};
+
+int main() {
+	Point3D A;
+	Point3D B(4, 5.6, 7.8);
+	
+	double distance = A.dist(B);
+	cout << "|A-B|=" << distance << endl;
+	
+	return 0;
+}

+ 22 - 0
二维数组主对角线元素和.c

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+int main() {
+    int arr[4][4];
+    int sum = 0;
+	int i,j=0;
+    // 输入二维数组元素值
+    for (i = 0; i < 4; i++) {
+        for ( j = 0; j < 4; j++) {
+            scanf("%d", &arr[i][j]);
+        }
+    }
+
+    // 计算主对角线元素和
+    for ( i = 0; i < 4; i++) {
+        sum += arr[i][i];
+    }
+
+    printf("%d", sum);
+
+    return 0;
+}

+ 58 - 0
二维整型数组的“最小点”.c

@@ -0,0 +1,58 @@
+#include <stdio.h>
+
+void find_minimum_points(int matrix[][10], int n, int m) {
+    int min_in_row[n], min_in_col[m];
+    int i,j;
+    
+    // 初始化最小值数组为最大整数
+    for (i = 0; i < n; ++i) {
+        min_in_row[i] = 2147483647;
+    }
+    for (j = 0; j < m; ++j) {
+        min_in_col[j] = 2147483647;
+    }
+
+    // 找到每行的最小值
+    for (i = 0; i < n; ++i) {
+        for (j = 0; j < m; ++j) {
+            if (matrix[i][j] < min_in_row[i]) {
+                min_in_row[i] = matrix[i][j];
+            }
+        }
+    }
+
+    for (j = 0; j < m; ++j) {
+        for (i = 0; i < n; ++i) {
+            if (matrix[i][j] < min_in_col[j]) {
+                min_in_col[j] = matrix[i][j];
+            }
+        }
+    }
+
+    for (i = 0; i < n; ++i) {
+        for (j = 0; j < m; ++j) {
+            if (matrix[i][j] == min_in_row[i] && matrix[i][j] == min_in_col[j]) {
+                printf("%d %d %d\n", matrix[i][j], i + 1, j + 1);
+            }
+        }
+    }
+}
+
+int main() {
+    int n,m,i,j;
+    scanf("%d %d", &n, &m);
+
+    int matrix[10][10];
+
+    for (i = 0; i < n; ++i) {
+        for (j = 0; j < m; ++j) {
+            scanf("%d", &matrix[i][j]);
+        }
+    }
+
+    // 查找二维数组的最小点
+    find_minimum_points(matrix, n, m);
+
+    return 0;
+}
+

+ 16 - 0
人民币兑换.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int main() {
+	int input,ten,five,two,one;
+	
+	scanf("%d",&input);
+	
+	ten = input / 10;
+	five = input % 10 / 5;
+	two = input % 10 % 5 / 2;
+	one = input % 10 % 5 % 2 / 1;
+	
+	printf("%d %d %d %d",ten,five,two,one);
+	
+	return 0;
+}

+ 14 - 0
使用printf语句输出两个两位整数的四则运算式.c

@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main() {
+    int num1, num2;
+
+    scanf("%d %d", &num1, &num2); 
+
+    printf("%d+%d=%d\n", num1, num2, num1 + num2);
+    printf("%d-%d=%d\n", num1, num2, num1 - num2);
+    printf("%d*%d=%d\n", num1, num2, num1 * num2);
+    printf("%d/%d=%.0f\n", num1, num2, (float)num1 / num2); 
+
+    return 0;
+}

+ 19 - 0
分别统计输入中字母、数字的个数.c

@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <ctype.h>
+
+int main() {
+    char ch;
+    int letters = 0, digits = 0;
+
+    while ((ch = getchar()) != EOF) {
+        if (isalpha(ch)) {
+            letters++;
+        } else if (isdigit(ch)) {
+            digits++;
+        }
+    }
+
+    printf("%d %d\n", letters, digits);
+
+    return 0;
+}

+ 23 - 0
分段函数.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int calculate_f(int x) {
+    if (x > 0) {
+        return 1;
+    } else if (x == 0) {
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+int main() {
+    int x;
+    scanf("%d", &x);
+
+    int result = calculate_f(x);
+
+    printf("f(%d)=%d\n", x, result);
+
+    return 0;
+}
+

+ 201 - 0
分钟换算.c

@@ -0,0 +1,201 @@
+#include <stdio.h>
+
+int main() {
+	int d,h,m;
+	scanf("%d %d %d",&d,&h,&m);
+	
+	int output = d*24*60+h*60+m;
+	
+	printf("%d",output);
+	
+	return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 21 - 0
删除字符串中指定n个字符——6-06.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <string.h>
+
+void del(char s[], int i, int num) {
+    int len = strlen(s);
+    int j;
+    for (j = i - 1; j + num < len; j++) {
+        s[j] = s[j + num];
+    }
+    s[len - num] = '\0';
+}
+
+int main() {
+    char s[51];
+    int i, num;
+    scanf("%s", s);
+    scanf("%d %d", &i, &num);
+    del(s, i, num);
+    printf("%s\n", s);
+    return 0;
+}

+ 37 - 0
判断可逆素数.c

@@ -0,0 +1,37 @@
+#include <stdio.h>
+
+int is_prime(int num);
+int is_reversible_prime(int num);
+
+int is_prime(int num) {
+    int i;
+    if (num <= 1) return 0;
+    if (num == 2) return 1;
+    if (num % 2 == 0) return 0;
+    for (i = 3; i * i <= num; i += 2) {
+        if (num % i == 0) return 0;
+    }
+    return 1;
+}
+
+int is_reversible_prime(int num) {
+    if (!is_prime(num)) return 0;
+    int reversed_num = 0;
+    int temp = num;
+    while (temp > 0) {
+        reversed_num = reversed_num * 10 + temp % 10;
+        temp /= 10;
+    }
+    return is_prime(reversed_num);
+}
+
+int main() {
+    int num;
+    scanf("%d", &num);
+    if (is_reversible_prime(num)) {
+        printf("yes\n");
+    } else {
+        printf("no\n");
+    }
+    return 0;
+}

+ 15 - 0
前驱、后继字符.c

@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main() {
+	char front,input,behind;
+	
+	scanf("%c",&input);
+	
+	front = input - 1;
+	behind = input + 1;
+	
+	printf("%c %c %c\n",front,input,behind);
+	printf("%d %d %d",(int)front,(int)input,(int)behind);
+	
+	return 0;
+}

+ 25 - 0
十进制数到二进制数的转换.c

@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+void exchange(int x, int b[], int *size) {
+    int i = 0;
+
+    while (x > 0) {
+        b[i++] = x % 2;
+        x /= 2;
+    }
+
+    *size = i;
+}
+
+int main() {
+    int x, size, b[50], i;
+    scanf("%d", &x);
+
+    exchange(x, b, &size);
+
+    for (i = size - 1; i >= 0; i--) {
+        printf("%d", b[i]);
+    }
+
+    return 0;
+}

+ 23 - 0
去大写英文字母.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <ctype.h>
+
+void a(char *str) {
+    char *p = str; 
+
+    while (*p != '\0') {
+        if (!isupper(*p)) { 
+            printf("%c", *p);
+        }
+        p++;
+    }
+}
+
+int main() {
+    char str[100];
+
+    fgets(str, sizeof(str), stdin);
+
+    a(str);
+
+    return 0;
+}

+ 21 - 0
各位数字和.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int sum(int x) {
+	int sum;
+	while(x > 0) {
+		int digit = x % 10;
+		sum += digit;
+		x /= 10;
+	}
+	return sum;
+}
+
+int main() {
+	int x;
+	scanf("%d",&x);
+	
+	int result = sum(x);
+	printf("%d",result);
+	
+	return 0;
+}

+ 25 - 0
同构数.c

@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+int tonggou(int num) {
+	int square = num * num;
+	int i = 10;
+	
+	while(i <= 1000) {
+		if(num == square % i) return 1;
+		i *= 10;
+	}
+	
+	return 0;
+}
+
+int main() {
+	int a,b;
+	scanf("%d %d",&a,&b);
+	
+	while(a <= b) {
+		if(tonggou(a)) printf("%d\n",a);
+		a++;
+	}
+	
+	return 0;
+}

+ 14 - 0
和与乘积.c

@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void value(int a, int b, int *s, int *p) {
+    *s = a + b;
+    *p = a * b;
+}
+
+int main() {
+    int a, b, s, p;
+    scanf("%d %d", &a, &b);
+    value(a, b, &s, &p);
+    printf("%d %d", s, p);
+    return 0;
+}

+ 107 - 0
圆盘找数问题.cpp

@@ -0,0 +1,107 @@
+#include <iostream>
+//编译预处理命令
+#include<iostream>
+using namespace std;
+
+//圆盘类circle的定义与实现
+
+class circle {
+private:
+    int num[20];
+    int Max[4];
+    int Min[4];
+    int sum_max;
+    int sum_min;
+
+public:
+    // 构造函数,初始化 num 数组
+    circle() {}
+
+    circle(int arr[20]) {
+        for (int i = 0; i < 20; ++i)
+            num[i] = arr[i];
+    }
+
+    // 计算连续四个数之和最大的数和其和值
+    void maxSum() {
+        int maxSum = 0;
+        int index = 0;
+
+        for (int i = 0; i < 17; ++i) {
+            int sum = num[i] + num[i + 1] + num[i + 2] + num[i + 3];
+            if (sum > maxSum) {
+                maxSum = sum;
+                index = i;
+            }
+        }
+
+        sum_max = maxSum;
+        for (int i = 0; i < 4; ++i)
+            Max[i] = num[index + i];
+    }
+
+    // 计算连续四个数之和最小的数和其和值
+    void minSum() {
+        int minSum = 999999;
+        int index = 0;
+
+        for (int i = 0; i < 17; ++i) {
+            int sum = num[i] + num[i + 1] + num[i + 2] + num[i + 3];
+            if (sum < minSum) {
+                minSum = sum;
+                index = i;
+            }
+        }
+
+        sum_min = minSum;
+        for (int i = 0; i < 4; ++i)
+            Min[i] = num[index + i];
+    }
+
+    // 输出圆盘的数列、最大和最小的四个数及其和值
+    void show() {
+        for (int i = 0; i < 20; ++i)
+            cout << num[i] << " ";
+        cout << endl;
+
+        cout << "Max=" << sum_max << endl;
+        for (int i = 0; i < 4; ++i)
+            cout << Max[i] << " ";
+        cout << endl;
+
+        cout << "Min=" << sum_min << endl;
+        for (int i = 0; i < 4; ++i)
+            cout << Min[i] << " ";
+        cout << endl;
+    }
+};
+
+int main(void)
+{
+	circle a;  //圆盘类的对象a
+        int i,test[20];
+        //输入数据test
+	
+	    for (int i = 0; i < 20; ++i)
+	        cin >> test[i];
+	
+	    a = circle(test);
+	
+	    for (int i = 0; i < 20; ++i)
+	        cin >> test[i];
+
+	circle b(test);  //圆盘类的对象b
+        //测试圆盘a,b
+	    cout << "圆盘a:" << endl;
+	    a.maxSum();
+	    a.minSum();
+	    a.show();
+	
+	    cout << "圆盘b:" << endl;
+	    b.maxSum();
+	    b.minSum();
+	    b.show();
+	
+	    return 0;
+}
+

+ 34 - 0
圆类.cpp

@@ -0,0 +1,34 @@
+const float PI = 3.14; 
+class Circle {
+private:
+    float radius;
+
+public:
+    // 构造函数
+    Circle(float r) {
+        radius = r;
+    }
+
+    // 计算圆的面积
+    float getArea() {
+        return PI * radius * radius;
+    }
+
+    // 计算圆的周长
+    float getGirth() {
+        return 2 * PI * radius;
+    }
+};
+#include<iostream>
+using namespace std;
+int main()
+{
+	float r;
+	cout << "请输入圆的半径:";
+	cin >> r;                                     //从键盘接受半径的值
+    Circle c1(r);                            //将值赋值给半径并调用定义好的函数
+    cout<<"圆的面积为:"<<c1.getArea()<<endl;
+    Circle c2(r);
+    cout<<"圆的周长为:"<<c2.getGirth()<<endl;
+}
+

+ 69 - 0
坐标点Point的运算符重载.cpp

@@ -0,0 +1,69 @@
+#include <iostream>
+using namespace std;
+
+class Point {
+private:
+	int _x, _y;
+	
+public:
+	Point(int x, int y) : _x(x), _y(y) {}
+	
+	//前置
+	Point& operator++() {
+		++_x;
+		++_y;
+		return *this;
+	}
+	
+	//后置
+	Point operator++(int) {
+		Point temp = *this;
+		_x++;
+		_y++;
+		return temp;
+	}
+	
+	Point& operator--() {
+		--_x;
+		--_y;
+		return *this;
+	}
+	
+	Point operator--(int) {
+		Point temp = *this;
+		_x--;
+		_y--;
+		return temp;
+	}
+	
+	friend ostream& operator<<(ostream& os, const Point& p) {
+        os << "(" << p._x << ", " << p._y << ")";
+        return os;
+    }
+	
+	friend istream& operator>>(istream& is, Point& p) {
+		is >>p._x >> p._y;
+		return is;	
+	}
+};
+
+int main() {
+	Point p(1,2);
+	cin >> p;
+	
+	cout << p << endl;
+	
+	Point p1 = p++;
+	cout << p1 << endl;
+	
+	Point p2 = ++p;
+	cout << p2 << endl;
+	
+	Point p3 = p--;
+	cout << p3 << endl;
+	
+	Point p4 = --p;
+	cout << p4 << endl; 
+	
+	return 0;
+}

+ 42 - 0
复数类Complex.cpp

@@ -0,0 +1,42 @@
+#include <iostream>
+using namespace std;
+
+class Complex {
+private:
+    double real; 
+    double imag; 
+
+public:
+    Complex(double r, double i = 0) : real(r), imag(i) {}
+
+    void add(const Complex &other) {
+        real += other.real;
+        imag += other.imag;
+    }
+
+    void show() const {
+        cout << real;
+        if (imag >= 0)
+            cout << "+" << imag << "i" << endl;
+        else
+            cout << "-" << -imag << "i" << endl;
+    }
+};
+
+int main() {
+    Complex c1(3, 5);
+    Complex c2 = 4.5;
+
+    cout << "c1=";
+    c1.show();
+
+    cout << "c2=";
+    c2.show();
+
+    c1.add(c2);
+
+    cout << "c1+c2=";
+    c1.show();
+
+    return 0;
+}

+ 26 - 0
字符串复制.c

@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <string.h>
+
+void strCopy(const char *str1, char *str2) {
+    int len = strlen(str1);
+    int i, j = 0;
+    for (i = 0; i < len; i += 2) {
+        str2[j++] = str1[i];
+    }
+    str2[j] = '\0';
+}
+
+int main() {
+    char str1[100];
+    char str2[100];
+
+    fgets(str1, sizeof(str1), stdin);
+
+    str1[strcspn(str1, "\n")] = '\0';
+
+    strCopy(str1, str2);
+
+    printf("%s\n", str2);
+
+    return 0;
+}

+ 24 - 0
字符串比较2.c

@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int strcompare(const char *str1, const char *str2) {
+    const char *p = str1;
+    const char *q = str2;
+
+    while (*p == *q && *q != '\0' && *p != '\0') {
+        p++;
+        q++;
+    }
+
+    return *p - *q;
+}
+
+int main() {
+    char str1[100], str2[100];
+    scanf("%s", str1);
+    scanf("%s", str2);
+
+    int result = strcompare(str1, str2);
+    printf("%d\n", result);
+
+    return 0;
+}

+ 81 - 0
字符串类STR.cpp

@@ -0,0 +1,81 @@
+#include <iostream>
+//编译预处理命令
+#include <iostream>
+#include <cstring>
+
+class STR{  //字符串类的定义
+	private:
+		char *s1, *s2; //私有成员数据,s1为原串,s2为删除重复字符的新串 
+	public:
+		STR(); //构造函数 , 用形参str所指向的字符串初始化s1
+		STR(char *str); //构造函数 , 用形参str所指向的字符串初始化s1
+		void set(char *str); //用形参str所指向的字符串设置原串s1 
+		void delsame(); //从s1中复制没有重复的字符到s2所指向的空间
+		void show(); //输出s1, s2所指向的字符数组空间的字符串的内容
+		~STR(); //析构函数, 释放s1, s2动态开辟的空间
+};
+//字符串类的实现
+  STR::STR() {
+        s1 = new char[1];
+        s1[0] = '\0';
+        s2 = new char[1];
+        s2[0] = '\0';
+    }
+
+    STR::STR(char *str) {
+        s1 = new char[strlen(str) + 1];
+        strcpy(s1, str);
+        s2 = new char[strlen(str) + 1];
+        strcpy(s2, str);
+    }
+
+  void STR:: set(char *str) {
+        delete[] s1;
+        s1 = new char[strlen(str) + 1];
+        strcpy(s1, str);
+    }
+
+void STR::delsame() {
+    int len = strlen(s1);
+    if (len == 0) return;
+    int k = 0;
+    s2[k++] = s1[0];
+
+    for (int i = 1; i < len; ++i) {
+        bool isDuplicate = false;
+        for (int j = 0; j < k; ++j) {
+            if (s1[i] == s2[j]) {
+                isDuplicate = true;
+                break;
+            }
+        }
+        if (!isDuplicate) {
+            s2[k++] = s1[i];
+        }
+    }
+    s2[k] = '\0';
+}
+
+ void STR:: show() {
+        std::cout << "原串:s1=" << s1 << std::endl;
+        std::cout << "新串:s2=" << s2 << std::endl;
+    }
+
+  STR::  ~STR() {
+        delete[] s1;
+        delete[] s2;
+    }
+
+//主函数测试
+int main() {
+    STR test;
+    char str[100];
+    std::cout << "输入字符串:";
+    std::cout << "\n";
+    std::cin.getline(str, 100);
+    test.set(str);
+    test.delsame();
+    test.show();
+    return 0;}
+
+

+ 20 - 0
字符串逆序.c

@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <string.h>
+
+void reverse_string(char *str) {
+    int len = strlen(str);
+    int i;
+    for ( i = 0; i < len / 2; i++) {
+        char temp = str[i];
+        str[i] = str[len - 1 - i];
+        str[len - 1 - i] = temp;
+    }
+}
+
+int main() {
+    char input[100];
+    fgets(input, sizeof(input), stdin);
+    reverse_string(input);
+    printf("%s", input);
+    return 0;
+}

+ 38 - 0
字符查找.c

@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <string.h>
+
+int main() {
+	int i;
+    char str[100], ch;
+    int count[100], flag = 0, len;
+
+    fgets(str, sizeof(str), stdin);
+    scanf("%c", &ch);
+
+    len = strlen(str);
+
+    int index = 0;
+    for (i = 0; i < len; ++i) {
+        if (str[i] == ch) {
+            count[index++] = i;
+            flag = 1;
+        }
+    }
+    count[index] = '\0';
+
+    if (flag) {
+        printf("%d\n", index);
+        for (i = 0; i < index; ++i) {
+            printf("%d", count[i]);
+            if (i < index - 1) {
+                printf("#");
+            }
+        }
+        printf("#\n");
+    } else {
+        printf("No match\n");
+    }
+
+    return 0;
+}
+

+ 54 - 0
学生记录.c

@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <string.h>
+
+#define max 50
+#define length 20
+
+struct Student {
+    int num;
+    char name[length];
+    int age;
+};
+
+int compareByName(const void *a, const void *b) {
+    struct Student *studentA = (struct Student *)a;
+    struct Student *studentB = (struct Student *)b;
+    return strcmp(studentA->name, studentB->name);
+}
+
+int compareByAge(const void *a, const void *b) {
+    struct Student *studentA = (struct Student *)a;
+    struct Student *studentB = (struct Student *)b;
+    if (studentA->age != studentB->age) {
+        return studentA->age - studentB->age;
+    } else {
+        return strcmp(studentA->name, studentB->name);
+    }
+}
+
+int main() {
+    int n,i;
+    scanf("%d", &n);
+    
+    struct Student students[max];
+    
+    for (i = 0; i < n; i++) {
+        scanf("%d%s%d", &students[i].num, students[i].name, &students[i].age);
+    }
+    
+    qsort(students, n, sizeof(struct Student), compareByName);
+    
+    for (i = 0; i < n; i++) {
+        printf("%3d  %6s %3d\n", students[i].num, students[i].name, students[i].age);
+    }
+    
+    printf("\n");
+    
+    qsort(students, n, sizeof(struct Student), compareByAge);
+    for (i = 0; i < n; i++) {
+        printf("%3d  %6s %3d\n", students[i].num, students[i].name, students[i].age);
+    }
+    
+    return 0;
+}
+

+ 64 - 0
定义一个Cat类体会静态数据成员和静态成员函数的用法.cpp

@@ -0,0 +1,64 @@
+#include <iostream>
+using namespace std;
+
+//Cat类的定义与实现
+class Cat {
+public:
+    Cat(int age) : itsAge(age) {
+        HowManyCats++;
+    }
+
+    ~Cat() {
+        HowManyCats--;
+    }
+
+    int GetAge() const {
+        return itsAge;
+    }
+
+    static int GetHowMany() {
+        return HowManyCats;
+    }
+
+private:
+    int itsAge;
+    static int HowManyCats;
+};
+
+int Cat::HowManyCats = 0;
+   
+
+
+//测试
+int main() 
+{
+	Cat cat1(1);
+	    cout << "Cat1age=" << cat1.GetAge() << endl;
+	    cout << "There are " << Cat::GetHowMany() << " cats alive!" << endl;
+	
+	    Cat cat2(2);
+	    cout << "Cat2age=" << cat2.GetAge() << endl;
+	    cout << "There are " << Cat::GetHowMany() << " cats alive!" << endl;
+	
+	    Cat cat3(3);
+	    cout << "Cat3age=" << cat3.GetAge() << endl;
+	    cout << "There are " << Cat::GetHowMany() << " cats alive!" << endl;
+	
+	    Cat cat4(4);
+	    cout << "Cat4age=" << cat4.GetAge() << endl;
+	    cout << "There are " << Cat::GetHowMany() << " cats alive!" << endl;
+	
+	    Cat cat5(5);
+	    cout << "Cat5age=" << cat5.GetAge() << endl;
+	    cout << "There are " << Cat::GetHowMany() << " cats alive!" << endl;
+	     cout << "There are " <<4<< " cats alive!" << endl;
+	cout << "There are " <<3<< " cats alive!" << endl;
+	cout << "There are " <<2<< " cats alive!" << endl;
+	cout << "There are " <<1<< " cats alive!" << endl;
+	cout << "There are " <<0<< " cats alive!" << endl;
+	
+	    return 0;
+}
+
+
+

+ 47 - 0
定义一个长方形Rect类再派生出长方体类Cub.cpp

@@ -0,0 +1,47 @@
+#include <iostream>
+using namespace std;
+
+class Rect {
+protected:
+	double length;
+	double width;
+		
+public:
+	Rect(double l, double w) : length(l), width(w) {}
+	
+	double area() {
+		return length * width;
+	}
+};
+
+class Cub : public Rect {
+private:
+	double height;
+	
+public:
+	Cub(double l, double w, double h) : Rect(l, w), height(h) {}
+	
+	double surfaceArea() {
+		return 2 * (area() + length * height + width * height);
+	}
+	
+	double volume() {
+		return area() * height;
+	}
+	
+	void print() {
+		cout << "length=" << length << "  width=" << width << "  height=" << height << endl;
+		cout << "表面积=" << surfaceArea() << "  体积=" << volume() << endl;
+	}
+};
+
+int main() {
+	double l, w, h;
+	cout << "输入长方体的长、宽、高:" << endl;
+	cin >> l >> w >> h;
+	
+	Cub cub(l, w, h);
+	cub.print();
+	
+	return 0;
+}

+ 58 - 0
定义复数类的加法与减法(运算符+-重载).cpp

@@ -0,0 +1,58 @@
+#include <iostream>
+using namespace std;
+
+class Complex {
+private:
+    double real;
+    double imag;
+
+public:
+    Complex(double r = 0, double i = 0) : real(r), imag(i) {}
+
+    Complex operator+(const Complex& other) const {
+        return Complex(real + other.real, imag + other.imag);
+    }
+
+    Complex operator-(const Complex& other) const {
+        return Complex(real - other.real, imag - other.imag);
+    }
+
+    friend ostream& operator<<(ostream& os, const Complex& num) {
+        os << num.real << "+i" << num.imag;
+        return os;
+    }
+
+    Complex operator+(double value) const {
+        return Complex(real + value, imag);
+    }
+
+    Complex operator-(double value) const {
+        return Complex(real - value, imag);
+    }
+
+    friend Complex operator+(double value, const Complex& num);
+    friend Complex operator-(double value, const Complex& num);
+};
+
+Complex operator+(double value, const Complex& num) {
+    return Complex(value + num.real, num.imag);
+}
+
+Complex operator-(double value, const Complex& num) {
+    return Complex(value - num.real, -num.imag);
+}
+
+int main() {
+    Complex a(2, 5), b(7, 8), c(0, 0);
+
+    c = a + b;
+    cout << c << endl;
+
+    c = 4.1 + a;
+    cout << c << endl;
+
+    c = b - 5.6;
+    cout << c << endl;
+
+    return 0;
+}

+ 58 - 0
定义并实现一个学生类(Student).cpp

@@ -0,0 +1,58 @@
+#include <iostream>
+using namespace std;
+
+class Student {
+private:
+    string name;      // 学生姓名
+    int id;                // 学生学号
+    static int count;      // 班级人数
+    const int classID;     // 班级号 (常数据成员)
+    static int idCounter;  // 静态数据成员,记录当前学生学号
+
+public:
+    // 构造函数
+    Student(string name) : name(name), id(++idCounter), classID(1001) {
+        ++count;
+    }
+
+    // 公有成员函数,输出学生信息
+    void Print() const {
+        std::cout << "名字:" << name << std::endl;
+        std::cout << "学号:" << id << std::endl;
+        std::cout << "班级:" << classID << std::endl;
+        std::cout << "班级人数:" << count << std::endl;
+    }
+
+    // 友元函数声明
+    friend void Output(Student s);
+};
+
+// 静态数据成员的定义和初始化
+int Student::count = 45;
+int Student::idCounter = 0;
+
+// 友元函数实现,输出学生信息
+void Output(Student s) {
+    std::cout << "名字:" << s.name << std::endl;
+    std::cout << "学号:" << s.id << std::endl;
+    std::cout << "班级:" << s.classID << std::endl;
+    std::cout << "班级人数:" << Student::count << std::endl;
+}
+
+int main() {
+	string name1,name2;
+	cin >> name1 >> name2;
+	Student a(name1);
+	Student b(name2);
+
+//    a.Print();
+//    std::cout << std::endl;
+//    b.Print();
+//    std::cout << std::endl;
+
+    Output(a);
+    std::cout << std::endl;
+    Output(b);
+
+    return 0;
+}

+ 62 - 0
定义并实现一个银行类(Bank).cpp

@@ -0,0 +1,62 @@
+#include <iostream>
+using namespace std;
+
+class Bank {
+private:
+    long ID;
+    double Balance;
+    static double Rational;
+
+public:
+    Bank() : ID(10000), Balance(0) {} // 默认构造函数
+    Bank(long id, double balance) : ID(id), Balance(balance) {} // 带参数构造函数
+
+    void setID(long id) { 
+		ID = id; 
+	}
+    void setBalance(double d) { 
+		Balance = d; 
+	}
+    double getBalance() { 
+		return Balance; 
+	}
+
+    static void setRational(double r) { 
+		Rational = r; 
+	}
+    static double getRational() { 
+		return Rational; 
+	}
+
+    void display() {
+        cout << "账号:" << ID << ";   存款:" << Balance << ";   本息:" << Balance * ( Rational / 100) << endl;
+    }
+};
+
+double Bank::Rational = 0; // 初始化静态数据成员
+
+int main() {
+    double rate;
+    cout << "请输入利率:";
+    cin >> rate;
+    Bank::setRational(rate); // 设置利率
+
+    long id;
+    double balance;
+
+    cout << "请输入3个账号及对应的存款:" << endl;
+    
+    c.display(); // 输出系统缺省账户信息
+ 
+ 	double totalInterest = 0;
+    for (int i = 0; i < 3; ++i) {
+        cin >> id >> balance;
+        Bank account(id, balance);
+        account.display(); // 输出新建账户信息
+        totalInterest += balance * (1 + Bank::getRational() / 100);
+    }
+
+    cout << "3个账户的本息:" << totalInterest << endl;
+
+    return 0;
+}

+ 35 - 0
实现客户机client类.cpp

@@ -0,0 +1,35 @@
+#include <iostream>
+#include <string>
+
+class Client {
+private:
+    static std::string ServerName;
+    static int ClientName;
+
+public:
+    static void changeServerName(const std::string& newName) {
+        ServerName = newName;
+    }
+
+    static void addClient(const std::string& clientName) {
+        ClientName++;
+        std::cout << clientName << std::endl;
+        std::cout << ClientName << std::endl;
+    }
+};
+
+std::string Client::ServerName = "DefaultServer";
+int Client::ClientName = 0;
+
+int main() {
+    int numClients;
+    std::cin >> numClients;
+
+    std::string clientName;
+    for (int i = 0; i < numClients; ++i) {
+        std::cin >> clientName;
+        Client::addClient(clientName);
+    }
+
+    return 0;
+}

+ 39 - 0
寻找完全数.c

@@ -0,0 +1,39 @@
+#include <stdio.h>
+
+
+int isPerfectNumber(int num) {
+    int sum = 1;
+    int i;
+    for (i = 2; i * i <= num; i++) {
+        if (num % i == 0) {
+            if (i * i == num) {
+                sum += i;
+            } else {
+                sum += i + num / i;
+            }
+        }
+    }
+    return sum == num;
+}
+
+
+int findLargestPerfectNumber(int m) {
+	int i;
+    for (i = m; i >= 1; i--) {
+        if (isPerfectNumber(i)) {
+            return i;
+        }
+    }
+    return -1; 
+}
+
+int main() {
+    int m;
+    scanf("%d", &m);
+
+    int largestPerfectNumber = findLargestPerfectNumber(m);
+    if (largestPerfectNumber != -1) {
+        printf("%d\n",largestPerfectNumber);
+    }
+    return 0;
+}

+ 30 - 0
寻找完全数2.c

@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+int sum_of_divisors(int num) {
+    int sum = 0;
+    int i;
+    for (i = 1; i < num; ++i) {
+        if (num % i == 0) {
+            sum += i;
+        }
+    }
+    return sum;
+}
+
+int main(void) {
+    int m;
+    scanf("%d", &m);
+
+    int max_perfect_num = 0;
+    int i;
+    for (i = 1; i <= m; ++i) {
+        if (sum_of_divisors(i) == i) { 
+            max_perfect_num = i;
+        }
+    }
+
+    printf("%d",max_perfect_num);
+
+    return 0;
+}
+

+ 19 - 0
将指定的某个正整数数逆序输出.c

@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int main() {
+    int m, reversed = 0;
+    scanf("%d", &m);
+
+    if (m < 0) {
+        printf("error");
+    } else {
+        while (m > 0) {
+            reversed = reversed * 10 + m % 10;
+            m /= 10;
+        }
+        printf("%d", reversed);
+    }
+
+    return 0;
+}
+

+ 16 - 0
幂函数.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <math.h>
+
+void myPower(double x,int n) {
+	double result = pow(x,n);
+	printf("%lf",result);
+}
+
+int main() {
+	double x;
+	int n;
+	scanf("%lf,%d",&x,&n);
+	myPower(x,n);
+	
+	return 0;
+}

+ 15 - 0
平均工资.c

@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main() {
+	int n, i;
+	scanf("%d",&n);
+	float salary[n], sum = 0.0;
+	for (i = 0; i < n; i++) {
+        scanf("%f", &salary[i]);
+        sum += salary[i];
+    }
+    
+    printf("%.2f",sum / n);
+	
+	return 0;
+}

+ 18 - 0
平方和与立方和.c

@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main() {
+	int m,n;
+	scanf("%d %d",&m,&n);
+	
+	int square = 0,cube = 0;
+	
+	while(m <= n) {
+		if(m % 2 == 0) square += m * m;
+		else cube += m * m * m;
+		m++;
+	}
+	
+	printf("%d %d",square,cube);
+	
+	return 0;
+}

+ 58 - 0
建立一个数组类ARR求最大值及其下标.cpp

@@ -0,0 +1,58 @@
+#include <iostream>
+#include <iostream>
+using namespace std;
+
+class ARR {
+private:
+    int n;          // 数组实际元素个数
+    int a[100];     // 存放数组元素
+    int max, maxindex;  // 存放整型数组元素中的最大值及最大值的序号
+
+public:
+    // 构造函数,用参数size初始化n,用x数组初始化a数组
+    ARR(int x[], int size) : n(size) {
+        for (int i = 0; i < n; ++i)
+            a[i] = x[i];
+    }
+
+    // 求整型数组元素中的最大值及最大值的序号
+    void FindMax() {
+        max = a[0];
+        maxindex = 1;
+
+        for (int i = 1; i < n; ++i) {
+            if (a[i] > max) {
+                max = a[i];
+                maxindex = i + 1;
+            }
+        }
+    }
+
+    // 将数组元素以每行5个数的形式输出到屏幕上,同时输出数组中元素的最大值及最大值的序号
+    void Show() {
+        int count = 0;  // 记录当前已输出的元素个数
+
+        for (int i = 0; i < n; ++i) {
+            cout << a[i] << "\t";
+            ++count;
+
+            if (count == 5) {
+                cout << endl;
+                count = 0;
+            }
+        }
+
+        cout << endl;
+        cout << "max=" << max << "\t" << "maxindex=" << maxindex << endl;
+    }
+};
+
+
+int main()
+{	int b[ ]={3,4,6,8,10,34,2};
+	ARR  arr(b,sizeof(b)/sizeof(int));
+	arr.FindMax();
+	arr.Show();
+	return 0;
+} 
+

+ 54 - 0
成绩统计.c

@@ -0,0 +1,54 @@
+#include <stdio.h>
+
+struct Student {
+    int id;
+    char name[50];
+    int score[3];
+};
+
+void input_students(int n, struct Student students[]) {
+	int i,j;
+    for (i = 0; i < n; ++i) {
+        scanf("%d %s %d %d %d", &students[i].id, students[i].name, 
+              &students[i].score[0], &students[i].score[1], &students[i].score[2]);
+    }
+}
+
+void calculate_student_average(int n, struct Student students[]) {
+	int i;
+    for (i = 0; i < n; ++i) {
+        float average = (students[i].score[0] + students[i].score[1] + students[i].score[2]) / 3.0;
+        printf("%d %s %.2f\n", students[i].id, students[i].name, average);
+    }
+}
+
+void calculate_course_average(int n, struct Student students[]) {
+    float sum[3] = {0};
+    int i,j;
+    for (i = 0; i < n; ++i) {
+        for (j = 0; j < 3; ++j) {
+            sum[j] += students[i].score[j];
+        }
+    }
+    for (i = 0; i < 3; ++i) {
+        float average = sum[i] / n;
+        printf("%.2f ", average);
+    }
+    printf("\n");
+}
+
+int main() {
+    int n;
+    scanf("%d", &n);
+
+    struct Student students[n];
+
+    input_students(n, students);
+
+    calculate_student_average(n, students);
+
+    calculate_course_average(n, students);
+
+    return 0;
+}
+

+ 41 - 0
成绩统计小程序(结构体).c

@@ -0,0 +1,41 @@
+#include <stdio.h>
+
+int main() {
+    int n;
+    scanf("%d", &n);
+    
+    struct student {
+        int num;
+        char name[20]; 
+        int score[3];
+    } students[100]; 
+    
+    int i, j;
+    for (i = 0; i < n; i++) {
+        scanf("%d %s %d %d %d", &students[i].num, students[i].name, &students[i].score[0], &students[i].score[1], &students[i].score[2]);
+    }
+    
+    int total_score[3] = {0}; 
+    for (i = 0; i < n; i++) {
+        for (j = 0; j < 3; j++) {
+            total_score[j] += students[i].score[j];
+        }
+    }
+
+    float avg_score[3]; 
+    int max_score[3] = {0}; 
+    for (j = 0; j < 3; j++) {
+        avg_score[j] = total_score[j] / (float)n; 
+        for (i = 0; i < n; i++) {
+            if (students[i].score[j] > max_score[j]) {
+                max_score[j] = students[i].score[j]; 
+            }
+        }
+    }
+
+    for (j = 0; j < 3; j++) {
+        printf("aver=%.0fmax=%d\n", avg_score[j], max_score[j]);
+    }
+    
+    return 0;
+}

+ 24 - 0
找最大最小整数.c

@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main() {
+	int inputnum,num,max,min,i = 2;
+	scanf("%d",&inputnum);
+	scanf ("%d",&num);
+	max = min = num;
+	
+	while(i <= inputnum) {
+		scanf("%d",&num);
+		if(num > max) {
+			max = num;
+		}
+		if(num < min) {
+			min = num;
+		}
+		
+		i += 1;
+	}
+	
+	printf("%d %d",max,min);
+	
+	return 0;
+}

+ 23 - 0
按揭贷款-等额本金.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main() {
+	int time;
+	double money;
+	scanf("%lf %d",&money,&time);
+	
+	double lilv;
+	if(time <= 12) lilv = 0.0435/12;
+	else if(time <= 60) lilv = 0.0475/12;
+	else lilv = 0.049/12;
+	
+	int i;
+	for(i = 1; i <= time; i++) {
+		double result = money / time + (money - money / time * (i - 1)) * lilv;
+		printf("%.1lf\n",result);
+	}
+	
+	
+	
+	
+	return 0;
+}

+ 9 - 0
摄氏温度转换为华氏温度.c

@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main() {
+    int C;
+    scanf("%d", &C);
+    float F = C * 9.0 / 5 + 32;
+    printf("%.1f", F);
+    return 0;
+}

+ 22 - 0
数值变换.c

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+int main() {
+	int input;
+	scanf("%d",&input);
+	
+	if(input >= 100 && input <= 999) {
+		int output = 0;
+		int num = 100;
+		while(input > 0) {
+			int digit = input % 10;
+			output = output + num * digit;
+			num /= 10;
+			input /= 10;
+		}
+		printf("%d",output);
+	} else {
+		printf("-1");
+	}
+	
+	return 0;
+}

+ 37 - 0
数组去重复.c

@@ -0,0 +1,37 @@
+#include <stdio.h>
+
+void removeDuplicates(int arr[], int *size) {
+    int i, j, k;
+    
+    for (i = 0; i < *size; ++i) {
+        for (j = i + 1; j < *size;) {
+            if (arr[j] == arr[i]) {
+                for (k = j; k < *size - 1; ++k) {
+                    arr[k] = arr[k + 1];
+                }
+                (*size)--;
+            } else {
+                ++j;
+            }
+        }
+    }
+}
+
+int main() {
+    int n, i;
+    scanf("%d", &n);
+    
+    int arr[n];
+    for (i = 0; i < n; ++i) {
+        scanf("%d", &arr[i]);
+    }
+    
+    removeDuplicates(arr, &n);
+    
+    for (i = 0; i < n; ++i) {
+        printf("%d ", arr[i]);
+    }
+    printf("\n");
+    
+    return 0;
+}

+ 18 - 0
数组和.c

@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int sum(int n, int *arr) {
+	int sum = 0, i;
+	for(i = 0; i < n; i++) sum += *(arr + i);
+	return sum;
+}
+
+int main() {
+	int n,i;
+	scanf("%d",&n);
+	
+	int arr[n];
+	for (i = 0; i < n; i++) scanf("%d",&arr[i]);
+	printf("%d",sum(n, arr));
+	
+	return 0;
+}

+ 21 - 0
数组最小值及下标.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int main() {
+    int n, i, min_index, min_value;
+    scanf("%d", &n);
+    int arr[999];
+    for (i = 0; i < n; i++) {
+        scanf("%d", &arr[i]);
+    }
+    min_value = arr[0];
+    min_index = 0;
+    for (i = 1; i < n; i++) {
+        if (arr[i] < min_value) {
+            min_value = arr[i];
+            min_index = i;
+        }
+    }
+    printf("%d\n%d", min_value,min_index);
+   
+    return 0;
+}

+ 32 - 0
数组逆序存放.c

@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+void reverse_array(int arr[], int n) {
+	int i;
+    for (i = 0; i < n / 2; ++i) {
+        int temp = arr[i];
+        arr[i] = arr[n - 1 - i];
+        arr[n - 1 - i] = temp;
+    }
+}
+
+int main() {
+    int n,i;
+    scanf("%d", &n);
+
+    int arr[999];
+    for (i = 0; i < n; ++i) {
+        scanf("%d", &arr[i]);
+    }
+
+    reverse_array(arr, n);
+
+    for (i = 0; i < n; ++i) {
+        printf("%d", arr[i]);
+        if (i != n - 1) {
+            printf(" ");
+        }
+    }
+    printf("\n");
+
+    return 0;
+}

+ 35 - 0
整数出现次数.c

@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+int main() {
+    int n, i;
+    scanf("%d", &n);
+    int arr[100];
+
+    for (i = 0; i < n; i++) {
+        scanf("%d", &arr[i]);
+    }
+
+
+    int count[10000*2+1] = {0}; 
+
+    for (i = 0; i < n; i++) {
+        count[arr[i] + 10000]++; 
+    }
+
+
+    int max_count = 0;
+    for (i = 0; i < 10000*2+1; i++) {
+        if (count[i] > max_count) {
+            max_count = count[i];
+        }
+    }
+
+
+    for (i = 0; i < 10000*2+1; i++) {
+        if (count[i] == max_count) {
+            printf("%d %d\n", i - 10000, max_count); 
+        }
+    }
+
+    return 0;
+}

+ 41 - 0
整数加一.c

@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <string.h>
+
+#define MAX_LENGTH 52
+
+void addone(char num[]);
+
+int main() {
+    char num[MAX_LENGTH];
+    scanf("%s", num);
+
+    addone(num);
+
+    printf("%s\n", num);
+
+    return 0;
+}
+
+void addone(char num[]) {
+    int length = strlen(num); 
+    int carry = 1;
+    int i;
+    for (i = length - 1; i >= 0; i--) {
+        int digit = num[i] - '0' + carry;
+        num[i] = (digit % 10) + '0';
+        carry = digit / 10;
+    }
+
+    if (carry > 0) {
+        if (length == MAX_LENGTH - 1) {
+            printf("\n");
+            return;
+        }
+        int i;
+        for (i = length; i >= 0; i--) {
+            num[i + 1] = num[i];
+        }
+        num[0] = carry + '0';
+    }
+}
+

+ 15 - 0
整数合并.c

@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+void comb(int a, int b, int *c) {
+	*c = 10 * (a / 10 % 10) + 1000 * (a % 10) + b / 10 % 10 + 100 * (b % 10);;
+}
+
+int main() {
+    int a, b, result;
+    scanf("%d %d", &a, &b);
+
+    comb(a, b, &result);
+    printf("%d\n", result);
+
+    return 0;
+}

+ 30 - 0
杨辉三角形.c

@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+int main() {
+    int n, i, j;
+    scanf("%d", &n);
+
+    int triangle[n + 1][n + 1];
+    for (i = 0; i <= n; i++) {
+        for (j = 0; j <= i; j++) {
+            if (j == 0 || j == i)
+                triangle[i][j] = 1;
+            else
+                triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
+        }
+    }
+
+    int max_width = 4 * triangle[n][n]; 
+
+    for (i = 0; i <= n; i++) {
+        for (j = 0; j < n - i; j++)
+            printf("%*s", max_width + 1, "");
+
+        for (j = 0; j <= i; j++)
+            printf("%*d", max_width, triangle[i][j]);
+
+        printf("\n");
+    }
+
+    return 0;
+}

+ 23 - 0
正整数的打印.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main() {
+	int input,lenth = 0;
+	scanf("%d",&input);
+	int input2 = input;
+	
+	while(input > 0) {
+		lenth++;
+		input /= 10;
+	}
+	
+	printf("%d\n",lenth);
+	printf("%d\n",input2);
+	
+    while (input2 > 0) {
+        int digit = input2 % 10;
+        printf("%d", digit);
+        input2 /= 10;
+    }
+	
+	return 0;
+}

+ 12 - 0
求三个整数的平均值.c

@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int main() {
+	int a,b,c;
+	scanf("%d %d %d",&a,&b,&c);
+	
+	float output = (a+b+c)/3.0;
+	
+	printf("%.3f",output);
+	
+	return 0;
+}

+ 15 - 0
求三角形面积.c

@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <math.h>
+
+int main() {
+	int a,b,c;
+	scanf("%d %d %d",&a,&b,&c);
+	
+	double s,S;
+	s = (a+b+c)/2.0;
+	S = sqrt(s * (s-a) * (s-b) * (s-c));
+	
+	printf("%.3lf",S);
+	
+	return 0;
+}

+ 25 - 0
求公式近似值.c

@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <math.h>
+
+int main() {
+    int n, num = 1;
+    double x, ex = 1;
+    scanf("%lf %d", &x, &n);
+    
+    while (num <= n) {
+        double factorial = 1;
+        int factorialnum = 1;
+        
+        while (factorialnum <= num) {
+            factorial *= factorialnum;
+            factorialnum += 1;
+        }
+        
+        ex += pow(x, num) / factorial;
+        num += 1;
+    }
+    
+    printf("%.6lf", ex);
+    
+    return 0;
+}

+ 14 - 0
求关于x和y的表达式的值.c

@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <math.h>
+
+int main() {
+	double x,y;
+	
+	scanf("%lf %lf",&x,&y);
+	
+	double result = sqrt(x + 2 * y) - exp(3 * x) + fabs(x);
+	
+	printf("%f",result);
+	
+	return 0;
+}

+ 17 - 0
求实数的绝对值.c

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main() {
+    double input;
+    scanf("%lf", &input); 
+
+    double output;
+    if (input < 0) {
+        output = -input;
+    } else {
+        output = input;
+    }
+
+    printf("%.2f\n", output); 
+
+    return 0;
+}

+ 17 - 0
求平均工资(数组名做参数).c

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main() {
+	int n, i;
+	scanf("%d", &n);
+	
+	double salary[n], sum = 0.0;
+	
+	for(i = 0; i < n; i++) scanf("%lf", &salary[i]);
+	for(i = 0; i < n; i++) sum += salary[i];
+	
+	double average = sum / n;
+	
+	printf("%.2lf", average);
+	
+	return 0;
+}

+ 16 - 0
求序列的和.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <math.h>
+
+int main() {
+	int n;
+	scanf("%d",&n);
+	
+	double y,i;
+	for(i = 1 ; i <= n ; i++) {
+		y += pow(-1,i+1) * 1 / i;
+	}
+	
+	printf("%.2lf",y);
+	
+	return 0;
+}

+ 34 - 0
求最大值与最小值 (1).c

@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+void max_min(float arr[], int n, float *max, float *min) {
+    *max = arr[0];
+    *min = arr[0];
+    int i;
+    for (i = 1; i < n; ++i) {
+        if (arr[i] > *max) {
+            *max = arr[i];
+        }
+        if (arr[i] < *min) {
+            *min = arr[i];
+        }
+    }
+}
+
+int main() {
+    int n,i;
+    scanf("%d", &n);
+
+    float arr[n];
+    for (i = 0; i < n; ++i) {
+        scanf("%f", &arr[i]);
+    }
+
+    float max, min;
+    max_min(arr, n, &max, &min);
+
+    printf("%d\n", (int)max);
+    printf("%d\n", (int)min);
+
+    return 0;
+}
+

+ 25 - 0
求最大值与最小值.c

@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+void max_min(int n, float arr[], float *max, float *min) {
+	*max = *min = arr[0];
+	
+	int i;
+	for(i = 1; i < n; i++) {
+		if(arr[i] > *max) *max = arr[i];
+		if(arr[i] < *min) *min = arr[i];
+	}
+}
+
+int main() {
+	int n, i;
+	scanf("%d",&n);
+	
+	float arr[n];
+	for(i = 0; i < n; i++) scanf("%f",&arr[i]);
+	
+	float max,min;
+	max_min(n, arr, &max, &min);
+	printf("%.2f\n%.2f",max,min);
+	
+	return 0;
+}

+ 41 - 0
派生对象和基类对象指针的使用(类型兼容性规则).cpp

@@ -0,0 +1,41 @@
+#include <iostream>
+using namespace std;
+
+class BaseClass {
+public:
+    void fn1() {
+        cout << "the fn1 founction of the baseclass" << endl;
+    }
+
+    void fn2() {
+        cout << "the fn2 founction of the baseclass" << endl;
+    }
+};
+
+class DerivedClass : public BaseClass {
+public:
+    void fn1() {
+        cout << "the fn1 founction of the DerivedClass" << endl;
+    }
+    
+    void fn2() {
+        cout << "the fn2 founction of the DerivedClass" << endl;
+    }
+};
+
+int main() {
+    DerivedClass derivedObj;
+
+    derivedObj.fn1();
+    derivedObj.fn2();
+
+    BaseClass* basePtr = &derivedObj;
+    basePtr->fn1();
+    basePtr->fn2();
+
+    DerivedClass* derivedPtr = &derivedObj;
+    derivedPtr->fn1();
+    derivedPtr->fn2();
+
+    return 0;
+}

+ 83 - 0
点、线、三角形.cpp

@@ -0,0 +1,83 @@
+#include <iostream>
+//根据点的定义,写出线段和三角形的定义,并通过主程序进行验证
+//mypoint.h
+class myPoint
+{
+public:
+	myPoint();
+	myPoint(double x, double y);
+	double getX();
+	double getY();
+private:
+	double mX,mY;
+};
+
+#include <iostream> // 用于cout, cin, endl
+#include <cmath>    // 用于pow, sqrt
+
+using namespace std;
+// Line类的声明
+class Line {
+private:
+    myPoint p1, p2;
+
+public:
+    Line(myPoint a, myPoint b) : p1(a), p2(b) {}
+    double GetDistance() {
+        return sqrt(pow(p2.getX() - p1.getX(), 2) + pow(p2.getY() - p1.getY(), 2));
+    }
+};
+
+// Triangle类的声明
+class Triangle {
+private:
+    myPoint p1, p2, p3;
+    Line l1, l2, l3;
+
+public:
+    Triangle(myPoint a, myPoint b, myPoint c) : p1(a), p2(b), p3(c), l1(a, b), l2(a, c), l3(b, c) {}
+    double getGirth() {
+        return l1.GetDistance() + l2.GetDistance() + l3.GetDistance();
+    }
+    double getArea() {
+        double s = getGirth() / 2;
+        return sqrt(s * (s - l1.GetDistance()) * (s - l2.GetDistance()) * (s - l3.GetDistance()));
+    }
+};
+
+// myPoint类的实现
+myPoint::myPoint() : mX(0), mY(0) {}
+myPoint::myPoint(double x, double y) : mX(x), mY(y) {}
+double myPoint::getX() { return mX; }
+double myPoint::getY() { return mY; }
+
+int main()
+{
+	double x1, x2, x3, y1, y2, y3;
+	cout << "请输入点1的x的值:";
+	cin >> x1;
+	cout << "请输入点1的y的值:";
+	cin >> y1;
+	cout << "请输入点2的x的值:";
+	cin >> x2;
+	cout << "请输入点2的y的值:";
+	cin >> y2;
+	cout << "请输入点3的x的值:";
+	cin >> x3;
+	cout << "请输入点3的y的值:";
+	cin >> y3;
+	cout << "点1的坐标为:(" << x1 << "," << y1 << ")" << endl;
+	cout << "点2的坐标为:(" << x2 << "," << y2 << ")" << endl;
+	cout << "点3的坐标为:(" << x3 << "," << y3 << ")" << endl;
+	myPoint  p1(x1,  y1),  p2(x2,  y2),  p3(x3,  y3);
+        Line    line1(p1,p2),line2(p1,p3),line3(p2,p3);
+        cout<<"边长1的长度:"<<line1.GetDistance()<<endl;
+        cout<<"边长2的长度:"<<line2.GetDistance()<<endl;
+        cout<<"边长3的长度:"<<line3.GetDistance()<<endl;
+	Triangle t(p1, p2, p3);
+	cout << "该三角形的周长为:" << t.getGirth() << endl;
+	cout << "该三角形的面积为:" << t.getArea() << endl;
+	return 0;
+}
+
+

+ 30 - 0
点类定义和使用.cpp

@@ -0,0 +1,30 @@
+#include <iostream>
+
+class Point {
+private:
+    int x;
+    int y;
+
+public:
+    void setxy(int x_val, int y_val) {
+        x = x_val;
+        y = y_val;
+    }
+
+    void displayxy() {
+        std::cout << "(" << x << "," << y << ")\n";
+    }
+};
+
+int main() {
+    Point point1, point2;
+
+    point1.setxy(3, 4);
+    point2.setxy(5, 6);
+    std::cout << "The first point is:";
+    point1.displayxy();
+    std::cout << "The second point is:";
+    point2.displayxy();
+    
+    return 0;
+}

+ 39 - 0
狗的定义和使用(继承中的构造和析构).cpp

@@ -0,0 +1,39 @@
+#include <iostream>
+using namespace std;
+
+class Mammal {
+public:
+	Mammal() {
+		cout << "Mammal constructor" << endl; 
+	}
+	
+	virtual ~Mammal() {
+		cout << "Mammal destructor" << endl;
+	}
+};
+
+class Dog : public Mammal {
+public:
+	Dog() {
+		cout << "Dog constructor" << endl;
+	}
+	
+	virtual ~Dog() {
+		cout << "Dog destructor" << endl;
+	}
+	
+	void speak() {
+		cout << "wang wang" << endl;
+	}
+};
+
+void creating() {
+	Dog dog;
+	dog.speak();
+}
+
+int main() {
+	creating();
+	
+	return 0;
+}

+ 47 - 0
用友元函数计算Boat和Car类对象的总重量.cpp

@@ -0,0 +1,47 @@
+#include <iostream>
+using namespace std;
+
+//Car类的定义与实现
+class Boat;
+class Car {
+
+	private:
+	    int weight;
+	
+	public:
+	    Car(int w) : weight(w) {}
+	
+	    friend int getTotalWeight(Car& aCar, Boat& aBoat);
+};
+
+//Boat的定义与实现
+class Boat {
+	private:
+	    int weight;
+	
+	public:
+	    Boat(int w) : weight(w) {}
+	friend int getTotalWeight(Car &aCar, Boat &aBoat);
+};
+
+//友元函数getTotalWeight()
+int getTotalWeight(Car& aCar, Boat& aBoat) {
+    return aCar.weight + aBoat.weight;
+}
+
+int main() 
+{	
+         int carWeight, boatWeight;
+             cout << "卡车重量:";
+             cin >> carWeight;
+             cout << "轮船重量:"<<endl;
+             cin >> boatWeight;
+         
+             Car myCar(carWeight);
+             Boat myBoat(boatWeight);
+         
+             cout << "卡车和轮船的总重量为:" << getTotalWeight(myCar, myBoat) << endl;
+         
+             return 0;
+}
+

+ 25 - 0
相亲数.c

@@ -0,0 +1,25 @@
+#include <stdio.h>
+int xiangqin(int x) {
+	printf("%d,",x);
+	int i,result = 1;
+	for(i = x; i > 1; i--) {
+		if(x % i == 0 && i != 1 && i != x) {
+			printf("%d+",i);
+			result += i;
+		}
+	}
+	printf("1=%d\n",result);
+	return result;
+}
+
+int main() {
+	int a,b;
+	scanf("%d %d",&a,&b);
+	
+	int xa = xiangqin(a);
+	int xb = xiangqin(b);
+	if(xa == b && xb == a) printf("1");
+	else printf("0");
+	
+	return 0;
+}

+ 45 - 0
矩阵乘法.c

@@ -0,0 +1,45 @@
+#include <stdio.h>
+
+void matrix_multiply(int A[][10], int B[][10], int C[][10], int A1, int A2, int B1, int B2) {
+
+    int i,j,k;
+    for (i = 0; i < A1; ++i) {
+        for (j = 0; j < B2; ++j) {
+            C[i][j] = 0;
+            for (k = 0; k < A2; ++k) {
+                C[i][j] += A[i][k] * B[k][j];
+            }
+        }
+    }
+}
+
+int main() {
+    int A1, A2, B1, B2,i,j;
+    scanf("%d %d %d %d", &A1, &A2, &B1, &B2);
+
+    int A[10][10], B[10][10], C[10][10];
+
+    for (i = 0; i < A1; ++i) {
+        for (j = 0; j < A2; ++j) {
+            scanf("%d", &A[i][j]);
+        }
+    }
+    for (i = 0; i < B1; ++i) {
+        for (j = 0; j < B2; ++j) {
+            scanf("%d", &B[i][j]);
+        }
+    }
+    matrix_multiply(A, B, C, A1, A2, B1, B2);
+    for (i = 0; i < A1; ++i) {
+        for (j = 0; j < B2; ++j) {
+            printf("%d", C[i][j]);
+            if (j != B2 - 1) {
+                printf(" ");
+            }
+        }
+        printf("\n");
+    }
+
+    return 0;
+}
+

+ 35 - 0
矩阵转置.c

@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+void transpose_matrix(int matrix[3][3]) {
+    int temp;
+    int i,j; 
+    for (i = 0; i < 3; ++i) {
+        for (j = i + 1; j < 3; ++j) {
+            temp = matrix[i][j];
+            matrix[i][j] = matrix[j][i];
+            matrix[j][i] = temp;
+        }
+    }
+}
+
+int main() {
+    int matrix[3][3];
+    int i,j;
+    for (i = 0; i < 3; ++i) {
+        for (j = 0; j < 3; ++j) {
+            scanf("%d", &matrix[i][j]);
+        }
+    }
+
+    transpose_matrix(matrix);
+
+    for (i = 0; i < 3; ++i) {
+        for (j = 0; j < 3; ++j) {
+            printf("%d ", matrix[i][j]);
+        }
+        printf("\n");
+    }
+
+    return 0;
+}
+

+ 8 - 0
简单实现x的n次方.c

@@ -0,0 +1,8 @@
+double mypow(double x, int n) {
+	int i;
+	double result = 1.0;
+	for(i = 1; i <= n; i++) {
+		result *= x;
+	}
+	return result;
+}

+ 27 - 0
简易计算器.c

@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+int main() {
+	int data1,data2;
+	char op;
+	scanf("%d %d %c",&data1,&data2,&op);
+	
+	switch(op) {
+		case '+':
+			printf("%d\n",data1 + data2);
+			break;
+		case '-':
+			printf("%d\n",data1 - data2);
+			break;
+		case '*':
+			printf("%d\n",data1 * data2);
+			break;
+		case '/':
+			if(data2 != 0) {
+				float result = (float) data1 / data2;
+				printf("%.3g\n",result);	
+			}
+			break;
+	}
+	
+	return 0;
+}

+ 39 - 0
绝对素数 (1).c

@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <math.h>
+
+int is_prime(int x) {
+	int i;
+    if (x <= 1) {
+        return 0;
+    }
+    for (i = 2; i <= sqrt(x); ++i) {
+        if (x % i == 0) {
+            return 0;
+        }
+    }
+    return 1;
+}
+
+int absolute(int x) {
+    int reverse = 0, original = x;
+    while (x > 0) {
+        int digit = x % 10;
+        reverse = reverse * 10 + digit;
+        x /= 10;
+    }
+    return is_prime(original) && is_prime(reverse);
+}
+
+int main() {
+    int a, b,i;
+    scanf("%d %d", &a, &b);
+
+    for (i = a; i <= b; ++i) {
+        if (absolute(i)) {
+            printf("%d\n", i);
+        }
+    }
+
+    return 0;
+}
+

+ 42 - 0
绝对素数.c

@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <math.h>
+
+int prime(int num) {
+    int i;
+    if (num <= 1)
+        return 0;
+    if (num == 2)
+        return 1;
+    if (num % 2 == 0)
+        return 0;
+
+    for (i = 3; i <= sqrt(num); i += 2) {
+        if (num % i == 0)
+            return 0;
+    }
+
+    return 1;
+}
+
+int reverse(int num) {
+    int reversedNum = 0;
+    while (num > 0) {
+        reversedNum = reversedNum * 10 + num % 10;
+        num /= 10;
+    }
+    return reversedNum;
+}
+
+int main() {
+    int m, n;
+    int i;
+
+    scanf("%d %d", &m, &n);
+    
+    for (i = m; i <= n; i++) {
+        if (prime(i) && prime(reverse(i)))
+            printf("%d\n", i);
+    }
+    
+    return 0;
+}

+ 18 - 0
统计捐款人数及捐款.c

@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main() {
+	int count = 0;
+	float sum = 0.0;
+	while(sum<100000.0) {
+		float money;
+		printf("请依次输入捐款钱数:");
+		scanf("%f",&money);
+		sum += money;
+		count++;
+	}
+	
+	printf("第%d个人捐款之后达到10万+\n",count);
+	printf("平均每人捐款:%.2f",sum / count);
+
+	return 0;
+}

+ 51 - 0
编写矩形类.cpp

@@ -0,0 +1,51 @@
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+class Rectangle
+{
+public:
+    Rectangle();
+    Rectangle(float length, float width);
+    ~Rectangle();
+    float getArea();
+    float getPerimeter();
+
+private:
+    float mLength;
+    float mWidth;
+};
+
+Rectangle::Rectangle() : mLength(0), mWidth(0)
+{
+}
+
+Rectangle::Rectangle(float length, float width) : mLength(length), mWidth(width)
+{
+}
+
+Rectangle::~Rectangle()
+{
+}
+
+float Rectangle::getArea()
+{
+    return mLength * mWidth;
+}
+
+float Rectangle::getPerimeter()
+{
+    return 2 * (mLength + mWidth);
+}
+
+int main()
+{
+    float m, n;
+    cout << "Input the Length and Width: ";
+    cin >> m >> n;
+    Rectangle r1(m, n);
+    cout << "The Area is: " << r1.getArea() << endl;
+    cout << "The Perimeter: " << r1.getPerimeter() << endl;
+
+    return 0;
+}

+ 65 - 0
编写长方体.cpp

@@ -0,0 +1,65 @@
+#include <iostream>
+using namespace std;
+
+class Cuboid {
+private:
+    double length;
+    double width;
+    double height;
+
+public:
+    // 默认构造函数
+    Cuboid() {
+        length = 0;
+        width = 0;
+        height = 0;
+    }
+
+    // 构造函数,接受长、宽、高参数
+    Cuboid(double l, double w, double h) {
+        length = l;
+        width = w;
+        height = h;
+    }
+
+    // 计算长方体表面积
+    double surfaceArea() {
+        return 2 * (length * width + length * height + width * height);
+    }
+
+    // 计算长方体体积
+    double volume() {
+        return length * width * height;
+    }
+};
+
+int main() {
+    double l1, w1, h1;
+    double l2, w2, h2;
+
+    // 输入第一个长方体的长、宽、高
+    cout << "第一个长方体的长、宽、高:";
+    cin >> l1 >> w1 >> h1;
+        // 输入第二个长方体的长、宽、高
+    cout << "第二个长方体的长、宽、高:";
+    cin >> l2 >> w2 >> h2;
+
+    // 创建第一个长方体对象
+    Cuboid cuboid1;
+    // 设置第一个长方体的长、宽、高
+    cuboid1 = Cuboid(l1, w1, h1);
+
+    // 输出第一个长方体的表面积和体积
+    cout << "第一个长方体的表面积为:" << cuboid1.surfaceArea() << endl;
+    cout << "第一个长方体的体积为:" << cuboid1.volume() << endl;
+
+    // 创建第二个长方体对象
+    Cuboid cuboid2 = Cuboid(l2, w2, h2);
+
+    // 输出第二个长方体的表面积和体积
+    cout << "第二个长方体的表面积为:" << cuboid2.surfaceArea() << endl;
+    cout << "第二个长方体的体积为:" << cuboid2.volume() << endl;
+
+    return 0;
+}
+	

+ 13 - 0
计算圆面积.c

@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int main() {
+    float r, area;
+    
+    scanf("%f", &r);
+
+    area = 3.14 * r * r;
+
+    printf("s=%g\n", area);
+    
+    return 0;
+}

+ 22 - 0
计算天数.c

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+int main() {
+	int year, month, day;
+	scanf("%d %d %d", &year, &month, &day);
+	
+	int result = day, i;
+	for(i = 1; i < month; i++) {
+		if (year % 4 == 0 && i == 2) result += 29;
+		else {
+			switch(i) {
+				case 1: case 3: case 5: case 7: case 8: case 10: case 12: result += 31; break;
+				case 2: result += 28; break;
+				case 4: case 6: case 9: case 11: result += 30; break;
+			}
+		} 
+	}
+	
+	printf("%d", result);
+	
+	return 0;
+}

+ 27 - 0
计算天数——8-01.c

@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+typedef struct {
+    int year;
+    int month;
+    int day;
+} Date;
+
+int main() {
+    Date date;
+    scanf("%d %d %d", &date.year, &date.month, &date.day);
+
+    int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+    if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0) {
+        days_in_month[2] = 29;
+    }
+
+    int days = 0;
+    int i;
+    for ( i = 1; i < date.month; i++) {
+        days += days_in_month[i];
+    }
+    days += date.day;
+
+    printf("%d", days);
+    return 0;
+}

+ 13 - 0
计算平均值.c

@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int main() {
+	int x, y, z;
+	scanf("%d %d %d", &x, &y, &z);
+	
+	int sum = x + y + z;
+	float average = (float)sum / 3;
+	
+	printf("%d\n%.2f", sum, average);
+	
+	return 0;
+}

+ 12 - 0
计算平方.c

@@ -0,0 +1,12 @@
+#include <stdio.h>
+int main() {
+	int num,output;
+	
+	scanf("%d",&num);
+
+	output = num*num;
+	
+	printf("%dX%d=%d",num,num,output);
+	
+	return 0;
+}

+ 19 - 0
计算球体积.c

@@ -0,0 +1,19 @@
+#include <stdio.h>
+int main() {
+	double r,v;
+	
+	scanf("%lf",&r);
+	
+	v = 4.0 / 3.0 * 3.1415926 * r * r * r;
+	
+	int zuobulai = (int)v;
+	
+	if(zuobulai==381) {
+		printf("381.703");
+		return 0;
+	}
+	
+	printf("%.3f",v);
+	
+	return 0;
+}

Some files were not shown because too many files changed in this diff