博文

[置顶] 代做作业(2009-04-27 22:28:00)

摘要:本论坛长期从事如下业务: 1、作业 2、课程设计 3、毕业设计 4、个人软件定制 5、网站开发 6、C、C++、VB+数据库开发 论坛地址: http://cplus.5d6d.com/forum-7-1.html qq:356153065......

阅读全文(1220) | 评论:0

将一个偶数分解成质数和(2011-11-13 18:34:00)

摘要:#include<iostream.h> #include<math.h> #include <windows.h> //判断是否是素数 int IsSushu(int num) { int i; int temp; temp = sqrt(num); for (i=2;i<=temp;i++) { if(num%i==0) { return 0; } } if(i>temp) return 1; } //主函数开始,正常返回1,异常返回0 int main() {     int num; cout<<"input a num: "<<endl; cin>>num; //num=100; if(num<3||num%2!=0) { cout<<"数字非法,10秒后关闭程序"<<endl; _sleep(10000); return 0; } int i,temp; temp = num/2; cout<<" 程序运行结果如下所示:"<<endl; for (i=2;i<=temp;i++) { if(!IsSushu(i)) continue; else { if(!IsSushu(num-i)) continue; else { cout<<num<<"="<<i<<"+"<<num-i<<endl; } } } cout<<"程序运行结束,10秒后关闭程序"<<endl;   _sleep(10000);    return 1; } 程序不解释,大家自己看哇......

阅读全文(1989) | 评论:0

字符串处理的两个函数(2009-12-11 20:12:00)

摘要:包含头文件:string.h 函数原型:      char *strdup(const char *)  作用:         复制字符串 函数原型:    char *strrchr(const char *,int) 作用:取得某字符最后出现处起的字符串。 测试代码: #include "stdafx.h" int main(int argc, char* argv[]){ char *sstr="It's a test/hello"; char *dstr; char *mstr; dstr=strdup(sstr); printf("dstr=%s\n",dstr); mstr=strrchr(sstr,'/'); printf("mstr=%s\n",mstr); return 0;}......

阅读全文(2129) | 评论:0

c++中模板使用的一个小例子(2009-10-18 10:10:00)

摘要:#include<iostream.h>#include<iomanip.h> /*声明模板函数*/template<class T> void Swap(T &x,T &y);/*   Write :2009年10月17日  */ /*定义结构体数据类型*/struct STU{ int number; char name[3]; float score;};int main(){ /*定义两个成员变量*/ STU s1={1001,"s1",90}; STU s2={1002,"s2",89}; /*模板的引用*/ Swap(s2,s1); cout<<"s1:"<<setw(6)<<s1.number<<setw(6)<<s1.name<<setw(6)<<s1.score<<endl; cout<<"s2:"<<setw(6)<<s2.number<<setw(6)<<s2.name<<setw(6)<<s2.score<<endl; cin.get(); return 0;} /*定义模板函数*/template <class T> void Swap(T &x,T &y){ T temp; temp=x; x=y; y=temp;} 注意:在使用setw()函数定义输出格式时要在开始添加#include<iomanip.h>头文件......

阅读全文(2827) | 评论:0

友元类使用的一个小例子(2009-10-14 17:11:00)

摘要:// teacher.h //student's classclass STUDENT{private: //do add variable of students char Gradu_name[10]; char Gradu_direction[20]; char Gradu_class[10];public: //do add method of student STUDENT(){}; STUDENT(char name[],char direction[],char _class[]); void SetStu(char name[],char direction[],char _class[]); ~STUDENT(){}; friend class TEACHER;};class TEACHER{ private:  //do add variable  char Teacher_name[10]; public:  //do add method  TEACHER(){};  TEACHER(char name[]);  ~TEACHER(){};  void ListStudent(TEACHER teacher,STUDENT stu[],int num);};   //teacher.cpp #include <iostream.h>#include <string.h>#include "Teacher.h"STUDENT::STUDENT(char name[],char direction[],char _class[]){ strcpy(Gradu_name,name); strcpy(Gradu_direction,direction); strcpy(Gradu_class,_class);}void STUDENT::SetStu(char name[],char direction[],char _cl......

阅读全文(4578) | 评论:0

vc6.0++Zthread库添加于编译(2009-09-23 15:13:00)

摘要:这两天都在搞Zthread库,因为要学习C++并发,现在我把我搞的结果写出来和大家分享。 1、从www.zthread.sourceforge.net下载Zthread源文件 2、将include\下的zthread文件夹考到vc安装目录下,如:\Microsoft Visual Studio\VC98\Include 3、新建一个vc静态库的工程,将src文件下的.cxx文件导入到工程中去。注意:在src文件夹下还有其他文件夹,不要将这些文件夹里的.cxx  文件导入到工程中去,以免与src文件下的cxx文件冲突 4、打开“工程\设置\c/c++\code gerenation中的use run timeliberty,选择多线程 5、编译 6,将zthread.lib考到vc安装目录下,如:Microsoft Visual Studio\VC98\Lib 7,从www.zthread.sourceforge.net下载测试代码进行测试。 注:如果上面的又什么问题大家请不要小气,指出来我好修改。谢谢啦。......

阅读全文(4082) | 评论:2

c++模板学习笔记(1)(2009-09-13 15:48:00)

摘要:今天在学习C++的时候遇到一个问题,就是编译的时候总是提示一个一个错误,错误信息如下:  error C2087: '<Unknown>' : missing subscript 源代码如下: #include<iostream.h>#include<stddef.h>template<int R,int C,typename T>int init(T a[R][C]){  for(int i=0;i<R;i++)  for(int j=0;j<C;j++)   a[i][j]=i*j;    for(int k=0;k<R;k++)  for(int l=0;l<C;l++)  {   cout<<"k="<<k<<"l="<<l<<endl;   cout<<a[k][l]<<endl;  } return 1;}int main(){ int a[10][20]; init<10,20,int>(a); cin.get(); return 0;} 检查了半天才发现是因为编译器不支持动态数组的缘故,函数在应用时参数要采用指针的格式。 现将代码修改如下: #include<iostream.h>#include<stddef.h>template<int R,int C,typename T>int init(T (*a)[C]){  for(int i=0;i<R;i++)  for(int j=0;j<C;j++)   a[i][j]=i*j;    for(int k=0;k<R;k++)  for(int l=0;l<C;l++......

阅读全文(2013) | 评论:0

保龄球计分统计(2009-04-27 22:32:00)

摘要:#include<stdio.h>#include<stdlib.h>struct strike{ int frist; int second; struct strike *next;};struct strike *creat(void){ struct strike *head; struct strike *p,*q; int i; /*if(head) {  free(head); }*/ p=head=(struct strike *)malloc(sizeof(struct strike)); head->frist=head->second=0; for(i=1;i<=10;i++) {  q=(struct strike *)malloc(sizeof(struct strike));  q->frist=0;q->second=0;  p->next=q;  p=q; } p->next=NULL; if(!head) {  printf("error");  exit(1); } return head;}int setScore(struct strike *head){ int i; struct strike *p; p=head; for(i=0;i<11&&p!=NULL;i++) {  printf("请输入第%d次击倒的瓶子数:",i+1);  scanf("%d",&p->frist);  getchar();  printf("%d次的分数:%d\n",i+1,p->frist);  printf("\n");  if(i==9)......

阅读全文(1244) | 评论:0

二叉树接点总数(2008-01-07 11:01:00)

摘要:int  binnumber(T *h) {      if(h==null)             return 0;      else    return binnumber(h->left)+binnumber(h->right)+1; }......

阅读全文(2153) | 评论:1

学生成绩查询系统(2008-01-07 10:56:00)

摘要:/*课程链表结构定义*/ typedef struct course {   char cour[30];   int  score;   char  teacher[10];   struct course *next; }C_COURSE; /*学生链表结构定义*/ typedef struct student {   int num;   char name[10];   char dep[20];   float ave;   C_COURSE *link;   struct student *next;   }S_STUDENT;/*从键盘上输入信息并创建课程结构结点实例*//*分数为-1时,输入结束*//*返回所创建的接点地址,若输入结束返回NULL*/C_COURSE *creatcoursenode(){   C_COURSE *p=(C_COURSE*)malloc(sizeof(C_COURSE));   printf("course=");   scanf("%s",p->cour);   printf("teacher=");   scanf("%s",p->teacher);   printf("score=");   scanf("%d",&p->score);   if(p->score==-1){      free(p);   return NULL;   }   else return p;}/*在课程链表中插入一个学生所学的所有课程*//*插入课程的成绩进行比较,并按照从高到低的顺序进行排列*//*h:课程链表的头接点的地址;course:要插入的接点*/v......

阅读全文(6234) | 评论:0