自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(19)
  • 收藏
  • 关注

原创 迭代公式求x的n次方根,求16的4次方根等于2

#include <iostream>using namespace std; #include <math.h>double mySqrt(int m) //定义求解公式 { double x1,x0;//定义两个数当这两个数相等时就是我们要求的值 x0=m ;//任意定义x0的值,也可以等于二分之一m x1=(3*x0/4)+m/(4*x0*x0*x0...

2020-03-15 17:34:00 732

原创 c++,将一个字符串交叉插入到另一个字符串中(假定两字符串不等长)。例如将字符串 "abcde" 交叉插入字符串“ABCDEFG"的结果为“aAbBcCdDeEFG"

#include<iostream>#include<string.h>using namespace std;class KB{ private: char str1[60];//被插入的数组 char str2[60];//插入的数组 char str3[120];//插入后的数组 public: KB(const char *s1,c...

2020-03-15 17:14:19 2904

原创 将一维整型数组中各元素排序,排序的方法是:根据去掉最高位数字后余下的数值 按从小到大的顺序对原数据排序,最后显示排序后的原数据。,20数组( 134, 4029)最后输出(4029,134)

#include<iostream>using namespace std;class KB{ private: int a[5] ;//待排序的数组。 int n;//成员数组a实际元素个数 public: KB(int t[],int n1)//构造函数,初始化数据成员。 { n=n1; for(int i=0;i<n;i++) a[...

2020-03-13 00:49:49 1135

原创 c++删除一串数字中相同的数字并且输出

#include <iostream>using namespace std;int main(){ int n; int i=0,j,m=0; int a[10],b[10]; cout<<"输入数字:"; cin>>n; while(n) { a[i++]=n%10; n=n/10; }//结束循环后a[i]数组将从尾到头储存...

2020-03-13 00:31:55 1349

原创 一维数组(一串数字)从小到大进行排序

#include <iostream>using namespace std;int main(){ int a[6]={32,4,6,5,87,99}; int k; for(int i=0;i<5;i++) for(int j=i+1;j<6;j++) if(a[i]>a[j]) { k=a[i];a[i]=a[j];a[j]=...

2020-03-10 19:28:55 5135 1

原创 建立一个矩阵类,对矩阵左下角包括对角线的元素进行两个操作。若该元素不是素数则保持不变,若该元素是素数则用比这个数大的最小素数来替代这个数

#include<iostream>using namespace std;class KB{ private: int x[4][4]; int count; public: KB(int xx[4][4]) { for(int i=0;i<4;i++) for(int j=0;j<4;j++) x[i][j]=xx[i][j]...

2020-03-10 19:25:06 871

原创 c++,把一个字符串中的数字提取出来成为一个整数

#include<iostream>#include<string.h>using namespace std;class KB{ private: char *s; int num; public: KB(char *ss) { s=new char[strlen(ss)+1]; strcpy(s,ss); } void f...

2020-03-10 18:50:21 5058

原创 c++,判断一个字符串是不是标识符,标识符由数字,字母,下划线组成,而且不能是数字开头

#include<iostream>#include<string.h>using namespace std; class KB{ private: char *s; int k; public: KB(const char *ss) { s=new char[strlen(ss)+1]; strcpy(s,ss); } i...

2020-03-10 00:38:22 3068

原创 c++,从正方体、球体和圆柱体的各种运算中抽象出一个公共基类container为抽象,计算正方体、球体和圆柱体的体积和表面积

#include<iostream>#include<string.h>using namespace std; class container{ protected: double radius; public: container(double r) { radius=r; } virtual double area()=...

2020-03-09 12:56:12 3654 1

原创 c++连接字符串(重载运算符+=)

#include<iostream>#include<string.h>using namespace std;class KB{ private: char *s;//字符串 public: KB(const char *p=0) { s=new char[strlen(p)+1]; strcpy(s,p); } frie...

2020-03-09 12:47:24 3761 3

原创 c++,判断两个集合是否相同,即元素相同的,但序号可以不相同

#include<iostream>#include<string.h>using namespace std;class KB{ private: int *s;//储存整数数组 int len;//数组长度 public: KB(int *ss,int le) { len=le; s=new int[len];//给数组指针开...

2020-03-09 01:41:25 2531 1

原创 c++,把一个字符串中的数字字符提取出来成为一个整数

#include<iostream>#include<string.h>using namespace std;class KB{ char *s; public: KB(const char *ss) { s=new char[strlen(ss)+1]; strcpy(s,ss); } void fun...

2020-03-08 23:26:37 2284

原创 c++,对于一个有正数和负数的数组,将其中所有小于0的元素放到所有大于0的元素的前面。使用的算法 是:从左右两个方向扫描数组,从左向右找到大于等于0的元素,从右向左找到小于0的元素,将两 者交换.

#include<iostream>using namespace std;class KB{ private: int n; int a[100]; public: KB(int aa[],int size) { n=size; for(int i=0;i<n;i++) a[i]=aa[i]; } void print() ...

2020-03-08 22:48:38 1153

原创 c++,定义基类和派生类,求长方体的表面积和体积。一,基类的指针指向派生类的对象 二,在基类中定义了虚函数。这样用基类的指针去访问同名函数时 ,即可访问派生类的成员函数

#include<iostream>using namespace std;class KB{ protected: double x,y;//分别表示长方形的长和宽。 public: KB(double x1,double y1) { x=x1; y=y1; } virtual double area()//虚函数,计算长方形的面积,计算公式...

2020-03-06 22:33:54 2018 1

原创 c++,两个字符串连接并且排序

#include <iostream>#include <string.h>using namespace std; class KB{ private: char s1[50],s2[50];//存放两个字符串 char s3[100];//存放连接好的字符串 public: KB(char a1[],char a2[])//因为私有数据定义时...

2020-03-06 15:21:34 1083

原创 将两个字符串拼接删除空格并且排序输出。用到删除空格函数,字符串的排序函数

#include <iostream>#include <string.h>using namespace std; class String{ char * str1,* str2; char *str;public: String(const char*ptr1,const char*ptr2)//构造函数进行初始化 { str1=new cha...

2020-03-06 00:00:09 322

原创 数字往后移动两格,并且在空出来的位置上填充数字。用char类型的数组储存数字

#include<iostream>#include<string.h>using namespace std;class KB{ private: char a[19];//存放15位身份证号 public: KB(char *aa) { strcpy(a,aa); } void fun() { char...

2020-03-05 16:35:16 159

原创 由一个已知一维数组派生出另一个-维数组的派生规则如下:新数组的每一元素等 于原始数组的对应元素及其相邻两元素的平均值。其中第0个元素的左邻元素约定为最后一个元素,最后一个元素的右邻 元素约定为第一个

#include<iostream>using namespace std;class KB{ private: double a[10],b[10];//分别用来存放原始数组和派生数组 public: KB(double aa[10]) //构造函数进行初始化 { for(int i=0;i<10;i++) a[i]=aa[i]; ...

2020-03-05 15:25:00 1428

原创 用c++两个分数相加并且化简成最简形式,通过类来完成。思想是:求出两个数的最大公约数用来化简和求最大公倍数,具体公式代码中见

#include<iostream>using namespace std;class KB{ private: int fz,fm;//fz代表分子,fm代表分母 public: KB(int a=0,int b=1)//构造函数,分别用a和b对分子分母进行初始化 { fz=a,fm=b; } int gys(int m,int n);//求两...

2020-03-05 10:47:34 3298

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除