
c语言课程设计报告电子版.doc
36页C 语言课程设计报告姓名:张林班级:计算 11—1 班学号:1106010124(1、 )A 类基本题1、围绕着山顶有 10 个圆形排列的洞,狐狸要吃兔子,兔子说:“可以,但必须先找到我,我就藏身于这十个洞中的某个洞你从1号洞找,下次隔1个洞(即 3 号洞)找,第三次隔2个洞(即 6 号洞)找,再隔 3 个…以后在这个圆圈中如此类推,次数不限 ”但狐狸从早到晚进进出出了 1000 次,仍没有找到兔子问兔子究竟藏在哪个洞里?#includeint main(){int i,m=0,k=1;int a[10];for(i=0;i10)m=m%10;if(m==a[m-1])a[m-1]=0;}for(i=0;i#includechar * strdup(char t[]) {char *p;int i;p=(char *)malloc(6*sizeof(char));for(i=0;i6*sizeof(char))return 0;else{for(i=0;istruct student{int num;float English,math,Computer;struct student *next;};int search(struct student *head,int num){struct student *p1; if(head==NULL) {printf("\nlist null!\n");return 0;}p1=head;while(num!=p1->num && p1->next!=NULL){p1=p1->next;}if(num==p1->num)printf("\nnum:%d\nEglish:%f\nmath:%f\nComputer:%f\n",p1->num,p1->English,p1->math,p1->Computer);else printf("\n%d not been found!\n",num);return 0;}void main(){int num;struct student a,b,c,d,*head,*p;a.num=01;a.English=79;a.math=79;a.Computer=77;b.num=02;b.English=97;b.math=89;b.Computer=68;c.num=03;c.English=52;c.math=99;c.Computer=54;//输入三个学生信息head=a.next=b.next=c.next=NULL;p=head;//连接do {printf("%d %f %f %f\n",p->num,p->English,p->math,p->Computer);p=p->next;}while(p!=NULL);printf("please input the number:\n");//输出scanf("%d",search(head,num);//查找学生}4、设计一个学生类(CStudent),它具有私有数据成员是:学号、姓名、数学、外语和计算机课程的成绩。
要求能实现求三门课总成绩和平均成绩,并能设置和显示学生信息 (类声明和成员函数定义分离)设计一个友元函数,按照成绩从高到低的顺序输出姓名、学号和成绩信息includeusing namespace std;class lei;class student{private:int num;char name[20];int math;int english;int computer;int pingjun;int chengji;public:void paixu();//友元函数void input();void average();void zongchengji();void display();}a[8];//student 类建立void student::paixu(){int i,j;for(j=4;j>name;cout>num;cout>math;cout>english;cout>computer;}//输入成绩void student::average(){pingjun=chengji/3;}//平均成绩void student::zongchengji(){chengji=computer+english+math;}//总成绩void student::display(){cout#includeusing namespace std;class Animal{private:string name;float m;public:Animal(string str,float d){name=str;m=d;}virtual string who()const{return name;}virtual float weight()const{return m;}virtual string sound() const=0;};// 基类 ANIMALclass Sheep:public Animal{ public:Sheep(string str,float d):Animal(str,d){}virtual string sound() const{return "mei";};};//SHEEP 派生类class Dog:public Animal{public:Dog(string str,float d):Animal(str,d){}virtual string sound() const{return "wan";};};//DOG 派生类class Cow:public Animal{public:Cow(string str,float d):Animal(str,d){}virtual string sound() const{return "mo";};};//COW 派生类class Zoo{public:Animal *p[50];void out(int n);};void Zoo::out (int n){int i;for(i=0;i#include#define LEN sizeof(struct student)struct student{long num; char name[10];char ad[20]; long tel;struct student *next;};int n;struct student *creat(void){struct student *head;struct student *p1,*p2;n=0;p1=p2=(struct student *)malloc(LEN);scanf("%ld,%s,%s,%ld",head=NULL;while(p1->num!=0){n=n+1;if(n==1) head=p1;else p2->next=p1;p2=p1;p1=(struct student *)malloc(LEN);scanf("%ld,%s,%s,%ld",}p2->next=NULL;return (head);}void print(struct student *head){struct student *p;printf("\nNow,These %d records are:\n",n);p=head;if(head!=NULL) do{printf("%-10ld %-10s %-20s %-20ld\n",p->num,p->name,p->ad,p->tel);p=p->next;}while(p!=NULL);}struct student *del(struct student * head,long num){struct student *p1,*p2;if(head==NULL) {printf("\nlist null!");return head;}p1=head;while(num!=p1->num && p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num ){if(p1==head) head=p1->next;else p2->next=p1->next;printf("delete:%ld\n",num);n=n-1;}else printf("%ld not been found! \n",num);return head;}int search(struct student *head,long num){struct student *p1;if(head==NULL) {printf("\nlist null!\n");return 0;}p1=head;while(num!=p1->num && p1->next!=NULL){p1=p1->next;}if(num==p1->num)printf("%-10ld %-10s %-20s %-20ld\n",p1->num,p1->name,p1->ad,p1->tel);else printf("\n%d not been found!\n",num);return 0;}struct student *insert(struct student *head,struct student *stud){struct student *p0,*p1,*p2;p1=head;p0=stud;if(head==NULL){head=p0;p0->next=NULL; }else{while((p0->num>p1->num)&&(p1->next !=NULL)){p2=p1;p1=p1->next;}if(p0->numnum){if(head==p1) head=p0;else p2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}n=n+1;return head;}int change(struct student *head,long t){struct student *p1;if(head==NULL) {printf("\nlist null!\n");return 0;}p1=head;while(t!=p1->num && p1->next!=NULL){p1=p1->next;} if(t==p1->num){printf("%-10ld %-10s %-20s %-20ld\n",p1->num,p1->name,p1->ad,p1->tel);printf("改为:\n");scanf("%ld,%s,%s,%ld",}else printf("\n%d not been found!\n",t);return 0;}void main(){long dn,num,ch;struct student *head,*stu;printf("请输入学生数据,按 0 结束输入:\n");head=creat();print(head);printf("请输入要删除的学生学号,按 0 结束删除:\n");scanf("%ld",while(dn!=0){head=del(head,dn);print(head);printf("请输入要删除的学生学号,按 0 结束删除:\n");scanf("%ld",} printf("请输入要找的学生学号,按 0 结束寻找:\n");scanf("%ld",while(num!=0){ search(head,num);printf("请输入要找的学生学号,按 0 结束寻找:\n");scanf("%。












