- 博客(8)
- 资源 (1)
- 收藏
- 关注
原创 类中运算符的重载及利用友元函数同等实现
#include<iostream>using namespace std;class complex {private: double real; double imag;public: complex operator +(complex& c2); complex add(complex& c); complex(double r, double i) { real = r; imag = i;} void output(); friend compl
2020-08-10 15:48:11 200
原创 利用链表,依次输出信息
struct t { char g; int num; struct t *next;}t1,t2,t3;struct t* head;int main(){ t1.g ='m'; t1.num = 1; t2.g ='w' ;t2.num = 2; t3.g = 'm'; t3.num = 3; head = &t1; t1.next = &t2; t2.next = &t3; t3.next = NULL; for (; head != NULL;
2020-08-09 15:33:44 189
原创 利用结构体投票程序,输出票最多的名字和票数
#include<iostream>#include<cmath>using namespace std;struct t { char name[20]; int num;};t a[3] = { {"w",0},{"y",0},{"h",0} };int main(){ int b(int m, int n, int k); for (int i = 0; i < 10; i++) { char name[20]; cin >>
2020-08-09 15:12:40 342
原创 输入一个字符串,然后输出字符数量
#include<iostream>using namespace std;int main(){ int length(char str[]); char str[20]; cin.get(str,20); cout << length(str) << endl;} int length(char str[]){ int i = 0; while (str[i] != '\0') { i++; } return i
2020-08-06 23:16:58 909
原创 折半排序法,给定一数组,输入一个值找到该值在数组中第几个
#include<iostream>#include<cmath>using namespace std;int main(){ int a[10] = { 1,4,6,8,9,12,14,15,18,23 }; int n; int find(int a[],int key); cout << "a num" << endl; cin >> n; cout << "第" << find(a, n)+1
2020-08-06 21:28:17 273
原创 给定一组确定序列数值(从小到大),再随机输入一个数,插入到合适的位置按序输出
#include<iostream>using namespace std;int main(){int a[5] = { 2,6,12,16 }; int num, end; cout << "Please enter a number and I will insert " << endl; cin >> num; end = a[3]; if (num >= end) a[4] = end; else
2020-08-05 19:04:14 365
原创 二维矩阵输入和元素相加
#include<iostream>#include<cmath>using namespace std;int main(){int a[3][3], sum1=0,sum2=0;for(int i=0;i<3;i++) for (int j = 0; j < 3; j++) { cin >> a[i][j]; }for (int k = 0; k < 3; k++) sum1 += a[k][k];for (int i =
2020-08-05 17:06:10 317
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人