- 博客(8)
- 收藏
- 关注
原创 【C++程序设计】补6.3 strcmp实现
#include using namespace std;#define MIN(a,b) (a<b?a:b)int strCmp(const char * str1, const char *str2){ int minLen=MIN(strlen(str1),strlen(str2)); for(int i=0;i<=minLen;i++){ if(str1[i]>str2[i]
2013-12-03 13:29:24
724
原创 【C++程序设计】补6.2 排序算法
排序方法有很多,例如冒泡排序、插入排序、归并排序、快速排序等等...... 我就介绍最简单的冒泡排序吧!1. 比较相邻的元素。如果第一个比第二个大,就交换他们两个。2. 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。在这一点,最后的元素应该会是最大的数。3. 针对所有的元素重复以上的步骤,除了最后一个。4. 持续每次对越来越少的元素重复上面的步骤,直到没有任何
2013-12-03 13:15:30
680
原创 【C++程序设计】补6.1 输出数组最大值及其下标
#define MAX(a,b) (a>b?a:b) int _tmain(int argc, _TCHAR* argv[]){ int arr[]={34,91,83,56,29,93,56,12,88,72}; int max=0, index=0, len=sizeof(arr)/sizeof(int); while(len--) { max=MAX(max,arr[len-1
2013-12-03 12:23:15
2270
原创 【C++程序设计】P123_4-9 Rectangle类
#include #include using namespace std;class Point{private: double x,y;public: Point(int xx,int yy){x=xx;y=yy;} double getX(){return x;} double getY(){return y;}};class Rectangle{private:
2013-11-15 16:25:09
914
原创 【C++程序设计】P123_4-8 Dog类
#include using namespace std;class Dog{private: char* name; int age; int weight;public: Dog(){name="";age=0;weight=0;} Dog(char* name, int age, int weight){ this->name=name; this->age=ag
2013-11-15 16:09:46
1233
原创 【C++程序设计】P123_4-10 设计一个用于人事管理的"人员“ 类
#include using namespace std;class Date{public: int year,month,day; Date(){} Date(int y,int m,int d){ year=y;month=m;day=d; }};enum SEX{MALE,FEMAL};class Person{private: int ID; SEX se
2013-11-15 15:58:41
7101
1
原创 【C++程序设计】P61_2-37 输出九九乘法表
题目:RT解答: for(int i=1;i<10;i++){ for(int j=1;j<=i;j++) cout<<i<<'*'<<j<<'='<<i*j<<'\t'; cout<<endl; }
2013-10-22 12:43:25
702
原创 【C++程序设计】P61_2-31 穷举法寻找质数
问题:用穷举法找出1~100的质数并显示出来。分别使用while、do-while、for循环语句实现。解答:1.while方法:int i=1,j;while( i++,j=1,i<=100){ while(j++,j<i) if(!(i%j)) break; if(i==j) cout<<i<<endl;}2.do-while方法:int i=2,j
2013-10-22 12:29:03
1919
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人