自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 c++Shape为抽象类 派生出其他类,并对其他类进行创建对象及求面积

#include<iostream>using namespace std;#define pi 3.1415926//抽象类Shapeclass Shape {public: virtual double getArea() = 0;};//派生类Circleclass Circle :public Shape {protected: double _radius;public: Circle() {}; Circle(int radius) { _radius

2021-03-21 14:56:58 442

原创 编写程序查找数组中是否存在某个指定元素;将数组a和数组b中的素数不重不漏地合并到 一个vector容器c中,然后按照下标访问的方式手动对容器c中的数据,按从小到大顺序重新排序

#include <iostream>#include <vector>#include <algorithm>#include <string>using namespace std;int main() { int a[5] = { 19,67,24,11,17 }, b[5] = { 2,3,9,17,59 }; //数组a为乱序数组,可以用顺序查找法查找 for (int m = 0;m < sizeof(a) / sizeof

2020-12-22 20:50:41 347

原创 1) 显示定义析构函数; 2) 获取分数的分子; 3) 获取分数的分母; 4) 实现分数的约分; 5) 实现对两个分数对象进行通分; 6) 使用 operator/操作符重载实现两个分数的除法运算。

#include<iostream>using namespace std;class Fraction { //数据成员,访问控制属性默认是私有 int m_numerator = 0; // 分子默认为0; C++11 int m_denominator = 1; //分母默认为1; public://公有成员函数 Fraction(int above = 0, int below = 1) : m_numerator(above), m_denominator(belo

2020-12-18 21:18:49 271 1

原创 c++辗转相除递归求最大公约数

#include <iostream>using namespace std;int main() { int GCD(int c, int d); int c, d; cout << "请输入两个数字" << endl; cin >> c >> d; cout << c << "和" << d << "的最大公约数为" << GCD(c, d) << endl;

2020-12-14 22:56:38 337

原创 约瑟夫

#include<iostream>#include<vector>using namespace std;int main(){ int m,n,k,p,number=0,i; cout << "请输入总人数m以及循环号码n:"; cin >> m >> n; k = m; vector<bool> left(m, 1); while (k > 1) { i = number; //i记录循环开始

2020-12-11 21:37:56 155 1

原创 c++广义回文判断

回文为:滤去所有非字母字符(包括空格)后,不考虑字母的大小写,从左向右和从右向左读都相同的词或短语。本代码可实现广义回文的判断功能#include <iostream>#include <string>#include <vector>using namespace std;int main() { string sentence; vector <char> n_s; int a,i,n,m; int is_palindrome = .

2020-12-11 11:54:20 168

原创 c++回文数判断

#include <iostream>using namespace std;const int SZ = 100;int main(){char carray[SZ];int is_palindrome = 1;cout << "Please input a string .." << endl;cin.get(carray, SZ);int len = strlen(carray);for (int i = 0; i < len/2; i++

2020-12-05 20:18:40 346

原创 c++已知一个方阵,存储在一个二维数组中。用指针访问数组元素的方法, 计算方阵中上三角所有元素的和、下三角所有元素的和,以及主对角线上的所有 元素和。

#include <iostream>using namespace std;int main() { int arr[3][3] = { {1,2,3,},{2,3,4,},{3,4,5,}}; int(*p) = *arr; int up_sum = 0, down_sum = 0, djx = 0; int a = 0, b=2; for (;a < 3;++a,b=2) { for (;a==0&&b >-1;--b) up_sum

2020-12-05 20:14:03 847

原创 c++已知一个矩阵,存储在一个二维数组中。将矩阵中和值为最大的那一行 元素与首行对换。

定义函数方法,便于后期维护#include <iostream>using namespace std;int max_2(int p, int q);int max_4(int p, int q, int s, int t);int first_line();int second_line();int third_line();int fourth_line();int main() { cout << "原矩阵" << endl; int arr

2020-12-05 19:37:20 367

原创 c++同构数判断

同构数,即这个数出现在他平方的右侧,比如5*5=25,5出现在25的右侧,则5为同构数本代码可以用来判断用户输入的数是否为同构数#include<iostream>using namespace std;int main() { int a, b,c; while (1) { cout << "请输入一个整数" << endl; cin >> a; b = a * a; if (a == b % 10)*//除10取余,判断个位数字

2020-11-21 13:06:06 3731 1

原创 迭代法求圆周率

#include <iostream><cmath>using namespace std;int main() { float a = 1, b = 1, c = 1; float sum = 0; //引用绝对值函数减少代码量 while ( fabs (c) >= 1.0E-12//精确度10^-12) { c = a / b; sum += c; a = -a; b += 2; } cout << sum * 4 &l

2020-11-17 22:30:34 1688

原创 c++循环打印菱形

#include<iostream>#include<cmath> using namespace std; int main() { int n, t, b, k, j; while (1) { cout << "请输入行数" << endl; cin >> n; t = (n + 1) / 2; for (k = 1;k <= n;k++) {.

2020-11-13 12:16:15 336

原创 c++200内素数矩阵输出

#include <iostream><cmath>using namespace std;int main() { int n=100,j,b,c=0,d=1; for (; n < 201; n++) { for (j=2; j <= n; j++) { b = n % j; if (b != 0) continue; if (j == n) { cout << j << "\t";

2020-11-13 12:15:21 158

原创 c++素数判断

#include <iostream>#include <cmath>using namespace std;int main() { int a, b, n = 2; cout << "请输入一个数" << endl; cin >> a; for (;n < a;n++) { b = a % n; if (b == 0) cout << a << "不是素数" << end

2020-11-13 12:14:22 137

原创 c++圆面积计算

#include <iostream>#include <cmath>using namespace std;int main() { double radius=1, area,pi=3.14; for (;radius < 11;radius++) { area = pi * radius*radius; if (area < 100) cout << area << endl; } return 0;}

2020-11-13 12:13:02 857

原创 c++10数字平均数&正数个数

#include <iostream>using namespace std;int main() { double a, sum = 0, n,average=0; for (n = 1 ;n <= 10; n++) { cout << "请输入第" << n << "个数" << endl; cin >> a; average += a; if (a > 0) sum += 1; els

2020-11-13 12:12:05 288

原创 c++4*5矩阵

#include<iostream>using namespace std;int main(){ int i, j, a; for (i = 1;i <5;i++) { for (j = 1;j <6;j++) { a = i * j; cout << a << "\t"; } cout << endl; } return 0;}

2020-11-13 12:10:59 482

原创 c++n项求和

#include <iostream>using namespace std;int main() { do { int a, n,b ; cout << "请输入一个数" << endl; cin >> a; if (a > 0) { n = (1 + a) * a / 2; cout << n << endl; } else break; cout << "要继续嘛

2020-11-13 12:09:41 683

原创 c++海伦公式

#include <iostream>#include <cmath>using namespace std;int main() { double a, b, c,p,s; cout << "请输入三角形三条边长" << endl; cin >> a >> b >> c; p = (a + b + c) / 2; s = p * (p - a) * (p - b) * (p - c); s = sqrt(

2020-11-13 12:08:22 1662

原创 c++如何实现排列三个数据

#include <iostream>using namespace std;int main() { int a, b, c, d; cout <<"请输入三个变量" << endl; cin >> a >> b >> c; if (a < b) d = a;a = b;b = d; if (a < c) d = a;a = c;c = d; if (b < c) d = b;b = c;

2020-11-13 12:06:57 404

原创 c++实现输出水仙花数

#include<iostream>using namespace std;int main() { int i; int a, b, c; for (i = 100;i <= 999;i++) { a = i / 100; b = (i / 10) % 10; c = i % 10; if (a * a * a + b * b * b + c * c * c == i) cout << "水仙花数为" << i <&

2020-11-13 12:03:58 223

空空如也

空空如也

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

TA关注的人

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