06 2018 档案

摘要:1 //设计一个double类型的数组Array 2 //1.可定义下界下标和上届上标 3 //2.可对下标越界进行检查 4 //3.可重置数组大小 5 //4.可知道数组的长度 6 //5.数组类的对象可以使用赋值运算符=和下标运算符[] 7 8 #include 9 #include 10 class Array{ 11 privat... 阅读全文

posted @ 2018-06-29 19:11 孙悟空son_ku_kong 阅读(144) 评论(0) 推荐(0)

摘要:1 //设计运算符重载的复数类 2 #include 3 4 class Complex{ 5 private: 6 double real;//实部 7 double image;//虚部 8 public: 9 Complex(){ 10 real=0; 11 ... 阅读全文

posted @ 2018-06-29 19:09 孙悟空son_ku_kong 阅读(133) 评论(0) 推荐(0)

摘要:1 //设计运算符重载的复数类 2 #include 3 4 class Complex{ 5 private: 6 double real;//实部 7 double image;//虚部 8 public: 9 Complex(){ 10 real=0; 11 ... 阅读全文

posted @ 2018-06-29 19:08 孙悟空son_ku_kong 阅读(144) 评论(0) 推荐(0)

摘要:1 //友元分为友元类和友元成员函数和友元函数 2 //设计A类是B类的友元类 3 //那么A类可以访问B类的所有成员(公有、私有、保护成员),同理,友元类和友元函数也是一样 4 #include 5 class B{ 6 friend class A; 7 private: 8 int topSecret; 9 public: 10 ... 阅读全文

posted @ 2018-06-29 19:05 孙悟空son_ku_kong 阅读(134) 评论(0) 推荐(0)

摘要:1 //static成员的学习 2 #include 3 #include 4 5 class Employee{ 6 private: 7 char name[30]; 8 float salary; 9 static float allSalary; 10 public: 11 Employe... 阅读全文

posted @ 2018-06-29 18:51 孙悟空son_ku_kong 阅读(145) 评论(0) 推荐(0)

摘要:1 //内部类的学习 2 #include 3 class Line{ 4 class Point{ 5 public: 6 int x; 7 int y; 8 Point(int x=0,int y=0){ 9 this->x=x; 10 ... 阅读全文

posted @ 2018-06-29 18:50 孙悟空son_ku_kong 阅读(145) 评论(0) 推荐(0)

摘要:1 //析构函数的学习 2 #include 3 class Point{ 4 private: 5 int x; 6 int y; 7 public: 8 Point(){} 9 Point(int x,int y){ 10 this->x=x; 11 ... 阅读全文

posted @ 2018-06-29 18:49 孙悟空son_ku_kong 阅读(120) 评论(0) 推荐(0)

摘要:1 //设计一个线段类 2 #include 3 class Point{ 4 private: 5 int x; 6 int y; 7 public: 8 Point(){} 9 Point(int x,int y){ 10 this->x=x; 11 ... 阅读全文

posted @ 2018-06-29 18:36 孙悟空son_ku_kong 阅读(148) 评论(0) 推荐(0)

摘要:1 //设计一个简单的动态数组类 2 #include 3 #include 4 class Array{ 5 private: 6 double *arr; 7 int size; 8 public: 9 Array(int sz=100); 10 ~Array(); 11 }; 12 13 A... 阅读全文

posted @ 2018-06-29 18:34 孙悟空son_ku_kong 阅读(127) 评论(0) 推荐(0)

摘要:1 //用类实现复数的加减功能 2 #include 3 class Complex{ 4 private: 5 float real;//虚部 6 float img;//实部 7 public: 8 Complex(float real,float img){ 9 this->real=... 阅读全文

posted @ 2018-06-29 18:29 孙悟空son_ku_kong 阅读(135) 评论(0) 推荐(0)

摘要:1 //利用动态数组保存字符串"Data Structure"程序 2 #include 3 int main(){ 4 char *str,s[]="Data Structure"; 5 int length=14;//字符串的长度 6 str=new char[sizeof(s)+1]; 7 int i; 8 for(i=0;i<len... 阅读全文

posted @ 2018-06-29 15:11 孙悟空son_ku_kong 阅读(103) 评论(0) 推荐(0)

摘要:1 //命名空间的使用 2 #include 3 namespace module{ 4 void f1(){ 5 cout<<"这是f1()函数"<<endl; 6 } 7 void f2(){ 8 cout<<"这是f2()函数"<<endl; 9 } 10 double s=1.0; 11 } 12 ... 阅读全文

posted @ 2018-06-29 15:06 孙悟空son_ku_kong 阅读(143) 评论(0) 推荐(0)

摘要:1 //编写个人通讯录管理系统,实现以下功能 2 //1.管理系统提供菜单 3 //2.将通讯录存入文件中,并且命名为PersonInfo.txt 4 //3.管理系统将执行以下操作 5 //(1)查看通讯录的所有信息 6 //(2)输入要查找的姓名,查找通讯录,如果找到则显示相关信息 7 //(3 阅读全文

posted @ 2018-06-28 17:47 孙悟空son_ku_kong 阅读(284) 评论(0) 推荐(0)

摘要:1 //ferror函数的作用是检查文件中是否有错误,如果有错,则返回非0,否则返回0 2 //ferror(文件指针) 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 if((fp=fopen("file_data.txt","r"))==NULL){ 8 printf("打开文件失败\n");... 阅读全文

posted @ 2018-06-28 17:46 孙悟空son_ku_kong 阅读(196) 评论(0) 推荐(0)

摘要:1 //feof函数的作用是判断文件指针是否在文件末尾,如果在文件末尾,返回非0,否则返回0 2 //feof(文件指针) 3 #include<stdio.h> 4 #include<stdlib.h> 5 int main(){ 6 FILE *fp; 7 char c; 8 if((fp=fo 阅读全文

posted @ 2018-06-28 17:45 孙悟空son_ku_kong 阅读(141) 评论(0) 推荐(0)

摘要:1 //ftell函数的作用是返回文件位置指针的位置,给出当前位置指针相对于文件头的字节数 2 //返回值为long,当函数调用出错时,函数返回-1L 3 //ftell(文件指针) 4 #include 5 #include 6 int main(){ 7 FILE *fp; 8 long i; 9 if((fp=fopen("file_data.tx... 阅读全文

posted @ 2018-06-28 17:44 孙悟空son_ku_kong 阅读(181) 评论(0) 推荐(0)

摘要:1 //fseek函数的作用是将文件的位置指针移到指定位置 2 //fseek(文件指针,位移量,起始点) 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char s[]="abcdefghijklmnopqrstuvwxyz"; 8 char c; 9 if((fp=fopen("file_... 阅读全文

posted @ 2018-06-28 17:43 孙悟空son_ku_kong 阅读(161) 评论(0) 推荐(0)

摘要:1 //rewind函数的作用是使位置指针重新返回指定文件的开头 2 #include 3 #include 4 int main(){ 5 FILE *fp; 6 char s[]="abcdefghijklmnopqrstuvwxyz"; 7 char c; 8 if((fp=fopen("file_data.txt","w+"))==NULL... 阅读全文

posted @ 2018-06-28 17:42 孙悟空son_ku_kong 阅读(203) 评论(0) 推荐(0)

摘要:1 //fread函数的作用是从指定文件中读入指定长度的数据块 2 //fread(buffer,size,count,文件指针) 3 #include 4 #include 5 int main(){ 6 struct Book_Type{ 7 char name[10]; 8 int price; 9 char aut... 阅读全文

posted @ 2018-06-28 17:41 孙悟空son_ku_kong 阅读(141) 评论(0) 推荐(0)

摘要:1 //fwrite函数的作用是将指定长的数据写入文件中 2 //fwrite(fp,size,count,文件指针) 3 #include<stdio.h> 4 #include<stdlib.h> 5 int main(){ 6 struct Book_Type{ 7 char name[10] 阅读全文

posted @ 2018-06-28 17:38 孙悟空son_ku_kong 阅读(135) 评论(0) 推荐(0)

摘要:1 //fscanf函数从指定的文件中按指定格式读入数据,与scanf函数作用类似,scanf从键盘输入,fscanf从文件输入 2 #include 3 #include 4 int main(){ 5 FILE *fp; 6 int i,j; 7 double m,n; 8 char s1[100],s2[100],s3[100],s4[100... 阅读全文

posted @ 2018-06-28 17:33 孙悟空son_ku_kong 阅读(144) 评论(0) 推荐(0)

摘要:1 //fprintf函数将数据按指定格式写入指定文件中,与printf函数相似 2 //形式为 fprintf(文件指针,格式字符串,输出列表) 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 int i=10,j=12; 8 double m=1.5,n=2.345; 9 char s[]=... 阅读全文

posted @ 2018-06-28 17:24 孙悟空son_ku_kong 阅读(167) 评论(0) 推荐(0)

摘要:1 //fgets函数的作用是从指定文件中读取n-1个字符,然后在最后添加一个'\0'字符作为字符串结束的标志 2 //如果在读完n-1个字符之前遇到一个换行符或者EOF,则读入结束 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char str[100]; 8 int n; 9 if( (f... 阅读全文

posted @ 2018-06-28 17:23 孙悟空son_ku_kong 阅读(184) 评论(0) 推荐(0)

摘要:1 //fputs函数是把字符串写入指定文件中 2 #include 3 #include 4 int main(){ 5 FILE *fp; 6 char str[20]; 7 if((fp=fopen("file_data.txt","w"))==NULL ){ 8 printf("打开文件失败\n"); 9 exit... 阅读全文

posted @ 2018-06-28 17:22 孙悟空son_ku_kong 阅读(122) 评论(0) 推荐(0)

摘要:1 //fgetc函数 2 //fgetc函数的作用是从指定的文件读入一个字符 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char ch; 8 if( (fp=fopen("file_data.txt","r"))==NULL ){ 9 printf("打开文件失败\n"); 10... 阅读全文

posted @ 2018-06-28 17:14 孙悟空son_ku_kong 阅读(184) 评论(0) 推荐(0)

摘要:1 //fputc函数 2 //将一个字符写进一个文件中 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char ch; 8 if( (fp=fopen("file_data.txt","w"))==NULL ){ 9 printf("打开文件失败\n"); 10 ... 阅读全文

posted @ 2018-06-28 17:13 孙悟空son_ku_kong 阅读(121) 评论(0) 推荐(0)

摘要:1 //typedef应用举例 2 #include 3 typedef int INTEGER; 4 typedef struct{ 5 int year; 6 int month; 7 int day; 8 }DATE; 9 10 typedef int COUNT[10]; 11 12 int main(){ 13 INTEGER i;... 阅读全文

posted @ 2018-06-28 17:08 孙悟空son_ku_kong 阅读(141) 评论(0) 推荐(0)

摘要:1 //枚举 2 //1.枚举值对应的整数值默认情况从0开始,可以在枚举类型声明中自定义 3 //2.枚举值不是字符串,不能用printf("%s",a);输出 4 //3.不用枚举也能实现此程序,但是用枚举类型更加直观 5 #include 6 enum weekday{sun=7,mon=1,tue,wed,thu,fri,sat}; 7 int main(){ 8 ... 阅读全文

posted @ 2018-06-28 17:03 孙悟空son_ku_kong 阅读(144) 评论(0) 推荐(0)

摘要:1 //链表的学习 2 #include 3 #include 4 #define LEN sizeof(struct student) 5 struct student{ 6 int num; 7 float score; 8 struct student *next; 9 }; 10 int n;//这个是链表节点的个数 11 ... 阅读全文

posted @ 2018-06-28 11:38 孙悟空son_ku_kong 阅读(159) 评论(0) 推荐(0)

摘要://指向指针的结构体 #include struct student{ int num; char name[20]; }student1={1001,"xiaoming"}; int main(){ struct student *p; p=&student1; printf("学生的号数\t学生的名字\t\n"); printf("%d\t%... 阅读全文

posted @ 2018-06-28 11:33 孙悟空son_ku_kong 阅读(127) 评论(0) 推荐(0)

摘要:1 //用指向指针的指针输出若干字符串 2 #include 3 int main(){ 4 char *name[]={"Basic","Visual Basic","C","Visual C++","Pascal","Delphi"}; 5 char **p; 6 p=name; 7 for(int i=0;i<6;i++){ 8 ... 阅读全文

posted @ 2018-06-28 11:30 孙悟空son_ku_kong 阅读(123) 评论(0) 推荐(0)

摘要:1 //输入一个1-7的整数,输出对应的星期名,通过调用指针函数实现 2 #include 3 char name[8][20]={"Illegal day","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}; 4 char *day_name(int n){ 5 if(n7){ 6... 阅读全文

posted @ 2018-06-28 11:29 孙悟空son_ku_kong 阅读(164) 评论(0) 推荐(0)

摘要:1 #include 2 int max(int x,int y){ 3 if(x>y){ 4 return x; 5 } 6 return y; 7 } 8 9 int min(int x,int y){ 10 if(x<y){ 11 return x; 12 } 13 return y; 14... 阅读全文

posted @ 2018-06-28 11:28 孙悟空son_ku_kong 阅读(161) 评论(0) 推荐(0)

摘要:1 //用字符串指针作为函数参数,试下字符串的复制 2 #include 3 void cpystr(char *pss,char *pds){ 4 while( (*pds=*pss)!='\0' ){ 5 pss++; 6 pds++; 7 } 8 } 9 10 int main(){ 11 char *pss="... 阅读全文

posted @ 2018-06-28 11:27 孙悟空son_ku_kong 阅读(122) 评论(0) 推荐(0)

摘要:1 //输出字符串中第n个字符后的所有字符 2 #include 3 int main(){ 4 int n=10; 5 char *str="This is a book"; 6 str=str+n; 7 printf("%s\n",str); 8 return 0; 9 } 阅读全文

posted @ 2018-06-28 11:26 孙悟空son_ku_kong 阅读(82) 评论(0) 推荐(0)

摘要:1 //利用指针的方式输出二位数组的值 2 #include 3 int main(){ 4 int arr[3][4]={ 5 {0,1,2,3}, 6 {4,5,6,7}, 7 {8,9,10,11} 8 }; 9 int (*p)[4]; 10 p=arr; 11 for(int i=... 阅读全文

posted @ 2018-06-28 11:25 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)

摘要:1 //使用指针法,利用数组名计算地址引用数字元素 2 #include 3 int main(){ 4 int a[10]; 5 for(int i=0;i<10;i++){ 6 *(a+i)=i; 7 } 8 for(int j=0;j<10;j++){ 9 printf("%4d",*(a+j)); 10 ... 阅读全文

posted @ 2018-06-28 10:56 孙悟空son_ku_kong 阅读(103) 评论(0) 推荐(0)

摘要:1 //编写用指针变量做参数的函数,将输入的两个整数按从大到小顺序输出 2 #include 3 void swap(int *p1,int *p2){ 4 int temp; 5 temp=*p1; 6 *p1=*p2; 7 *p2=temp; 8 } 9 int main(){ 10 int a,b; 11 int *p1,*... 阅读全文

posted @ 2018-06-28 10:55 孙悟空son_ku_kong 阅读(125) 评论(0) 推荐(0)

摘要:1 //用指针,输入整数a和b,按从大到小的顺序输出a和b 2 #include 3 int main(){ 4 int *p1,*p2,*p,a,b; 5 printf("请输入两个数字\n"); 6 scanf("%d %d",&a,&b); 7 printf("%d %d\n",a,b); 8 p1=&a; 9 p2=&b;... 阅读全文

posted @ 2018-06-28 10:53 孙悟空son_ku_kong 阅读(115) 评论(0) 推荐(0)

摘要:下面是文件file.cpp的源代码 下面是文件main.cpp的源代码 阅读全文

posted @ 2018-06-28 10:52 孙悟空son_ku_kong 阅读(115) 评论(0) 推荐(0)

摘要:1 //static的用法 2 #include 3 void f(int a){ 4 static int b=2; 5 b=a+b; 6 printf("a=%d,b=%d\n",a,b); 7 } 8 9 int main(){ 10 int a=1,i; 11 for(i=1;i<=3;i++){ 12 f(a)... 阅读全文

posted @ 2018-06-28 10:50 孙悟空son_ku_kong 阅读(97) 评论(0) 推荐(0)

摘要:1 //利用递归求!n 2 #include 3 double fact(int n){ 4 double s; 5 if(n==0 || n==1){ 6 s=1; 7 }else{ 8 s=n*fact(n-1); 9 } 10 return s; 11 } 12 13 int main(){ 14 ... 阅读全文

posted @ 2018-06-28 10:49 孙悟空son_ku_kong 阅读(111) 评论(0) 推荐(0)

摘要:1 //输入N个字符,查找最大的字符串 2 #include 3 #include 4 int main(){ 5 char s[6][100]; 6 printf("请输入6个字符串\n"); 7 for(int j=0;j<6;j++){ 8 gets(s[j]); 9 } 10 int max=0; 11 f... 阅读全文

posted @ 2018-06-28 10:48 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)

摘要:1 //统计字符串中的英文单词的数目 2 #include 3 #include 4 int main(){ 5 char s[100]; 6 printf("请输入字符串\n"); 7 gets(s); 8 int i=0,word=0,num=0; 9 for(;s[i]!='\0';i++){ 10 if(s[i]=... 阅读全文

posted @ 2018-06-28 10:46 孙悟空son_ku_kong 阅读(93) 评论(0) 推荐(0)

摘要:1 //判断回文 2 #include 3 #include 4 int main(){ 5 char s1[100]; 6 printf("请输入字符串\n"); 7 gets(s1); 8 int n=0; 9 for(;s1[n]!='\0';n++){ 10 11 } 12 n--; 13 int fla... 阅读全文

posted @ 2018-06-28 10:45 孙悟空son_ku_kong 阅读(125) 评论(0) 推荐(0)

摘要:1 //比较两个字符串 2 #include 3 #include 4 int main(){ 5 char s1[100],s2[100]; 6 int i; 7 printf("请输入字符串1\n"); 8 gets(s1); 9 printf("请输入字符串2\n"); 10 gets(s2); 11 if(strc... 阅读全文

posted @ 2018-06-28 10:44 孙悟空son_ku_kong 阅读(134) 评论(0) 推荐(0)

摘要:1 //运用strcat函数 2 #include<stdio.h> 3 #include<string.h> 4 int main(){ 5 char s1[100]="Tianjing,",s2[]="How are you"; 6 strcat(s1,s2); 7 puts(s1); 8 re 阅读全文

posted @ 2018-06-27 18:43 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 //char s1[100],s2[]="How are you!" 2 //s1=s2;错误!因为s1表示数组的第0个元素的地址,它为常量,不能被赋值 3 #include 4 #include 5 int main(){ 6 char s1[100],s2[]="How are you"; 7 strcpy(s1,s2); 8 puts(s1)... 阅读全文

posted @ 2018-06-27 18:42 孙悟空son_ku_kong 阅读(118) 评论(0) 推荐(0)

摘要:1 #include 2 #include 3 int main(){ 4 char s[100]; 5 gets(s); 6 printf("原字符串:%s\n",s); 7 printf("变大写字符串%s\n",strupr(s)); 8 printf("变小写字符串%s\n",strlwr(s)); 9 return ... 阅读全文

posted @ 2018-06-27 18:41 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 #include 2 #include 3 int main(){ 4 char s1[100]; 5 gets(s1); 6 puts(s1); 7 printf("字符串长度:%d\n",strlen(s1)); 8 return 0; 9 } 阅读全文

posted @ 2018-06-27 18:40 孙悟空son_ku_kong 阅读(133) 评论(0) 推荐(0)

摘要:1 #include <stdio.h> 2 int main(){ 3 char s1[1]; 4 gets(s1); 5 puts(s1); 6 printf("%d\n",sizeof(s1)); 7 printf("%c\n",s1[1]); 8 return 0; 9 } 阅读全文

posted @ 2018-06-27 18:39 孙悟空son_ku_kong 阅读(121) 评论(0) 推荐(0)

摘要://字符串数组 #include int main(){ char s1[]={"I am a boy"}; char s2[]={"I am a boy\0 and a student"};//遇到\0字符串结束 printf("%s\n",s1); printf("%s\n",s2); return 0; } 阅读全文

posted @ 2018-06-24 10:46 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 //判断一个数字是否是素数(素数只能被1和它自己整除) 2 #include 3 #include 4 int main(){ 5 int num; 6 int flag=0; 7 printf("输入一个数字:\n"); 8 scanf("%d",&num); 9 for(int i=2;i<=sqrt(num);i++){ 1... 阅读全文

posted @ 2018-06-24 10:45 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)

摘要://利用格里高利公式π/4=1-1/3+1/5-1/7+...,求圆周率,要求最后一行绝对值小于10e-6 #include #include int main(){ double sum=1,k=1,m=1,t=0; do{ m=-m; k+=2; t=m/k; sum=sum+t; }while(fabs(t)>=0.000001); printf("%lf\n"... 阅读全文

posted @ 2018-06-24 10:33 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 //输出Fibonacci数列1,1,2,3,5,8,13,21,...的前40项 2 //经过观察,我们可以得出结论后一项是前两项之和 3 #include <stdio.h> 4 int main(){ 5 int a,b,c; 6 a=1; 7 b=1; 8 c=a+b; 9 int su 阅读全文

posted @ 2018-06-24 10:31 孙悟空son_ku_kong 阅读(121) 评论(0) 推荐(0)

摘要://求s=10!,即求10的阶乘 start #include int main(){ int s=1; for(int i=1;i<=10;i++){ s=s*i; } printf("%d",s); return 0; } 阅读全文

posted @ 2018-06-24 10:30 孙悟空son_ku_kong 阅读(107) 评论(0) 推荐(0)

摘要:#include int main(){ char c1,c2,c3; c1=getchar(); c2=getchar(); c3=getchar(); putchar(c1); putchar(c2); putchar(c3); return 0; } 阅读全文

posted @ 2018-06-24 10:28 孙悟空son_ku_kong 阅读(132) 评论(0) 推荐(0)

导航