靠,,,什么都不懂,,,,
Palm os 程序设计课程设计题目
设计一个学生成绩表,数据库包含:学生姓名(name), 成绩(mark)
并且在文档中写明设计思路,流程,以及各个函数的作用
用C语言写,要求就这么简单
要去吃饭了,编译错误都解决了,还剩下一个连接错误.
吃完了再帮你解决(最好你自己去搞顶).
思路在注释里面很清楚了,自己拿出来就可以把文档完成.
这靠你自己去搞.
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define NULL 0 //定义NULL宏
#define LEN sizeof(struct student) //定义LEN宏,替代struct student类型的长度
struct student //声明了struct student的类型
{
char name[15]; //学生姓名
float score; //学生成绩
struct student *next; //定义的指向下一个学生的指针
};
/*********一般的建个学生链表有以下几个函数就应该可以了*********/
struct student *creat(void); //创建 一个学生链表,返回一个指向链表头的指针
void print(struct student *head); //打印出学生链表
struct student *del(struct student *head,char name[]); //删除名称为name的学生
struct student *insert(struct student *head, struct student *stud); //插入新的学生信息
int n; //n为全局变量,对表中结点的个数进行掌控
struct student *create(void)
{
struct student *head;
struct student *p1,*p2;
n = 0;
p1 = p2 = (struct student*)malloc(LEN); //开辟的第一个单元,并却强制转换其类型
scanf("%s,%f",&p1->name,&p1->score);
head = NULL;
while(p1 ->name != 0)
{
n = n+1;
if(n == 1)
head = p1;
else
p2->next = p1;
p1 = p2;
p1 = (struct student*)malloc(LEN);
scanf("%s,%f",&p1->name,&p1->score);
}
p2->next = NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("now ,these %d records are:\n",n);
p = head;
if(head != NULL)
do
{
printf("%s,%f\n",p->name,p->score);
p = p->next;
}while(p != NULL);
}
struct student *del(struct student *head,char name[])
{
struct student *p1,*p2;
if(head == NULL)
{
printf("\n list null!");
}
p1 = head;
while(strcmp(name,p1->name) != 0 && p1->next != NULL)
//p1指向的不是所要的结点,却后面还有结点
{
p2 = p1;
p1 = p1->next;
}
if(strcmp(name,p1->name) == 0) //找到了
{
if(p1 == head)
head = p1->next;
else
p2->next = p1->next;
printf("delete:%s\n",name);
n = n-1;
}
else printf("can not been found!");
return head;
}
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(strcmp(p0->name,p1->name) > 0&&(p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(strcmp(p0->name,p1->name)<0)
{
if(head == p1)
head = p0;
else
p2 ->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next =NULL;
}
}
n = n+1;
return(head);
}
void main()
{
struct student *head,stu;
char name[20];
printf("input records:\n");
head = creat();
print(head);
printf("\ninput the deleted number:");
scanf("%s",name);
head = del(head,name);
print(head);
printf("\ninput the insert records:");
scanf("%s,%f",&stu.name,&stu.score);
head = insert(head,&stu);
print(head);
}
Palm os 程序设计课程设计题目
设计一个学生成绩表,数据库包含:学生姓名(name), 成绩(mark)
并且在文档中写明设计思路,流程,以及各个函数的作用
用C语言写,要求就这么简单
要去吃饭了,编译错误都解决了,还剩下一个连接错误.
吃完了再帮你解决(最好你自己去搞顶).
思路在注释里面很清楚了,自己拿出来就可以把文档完成.
这靠你自己去搞.
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define NULL 0 //定义NULL宏
#define LEN sizeof(struct student) //定义LEN宏,替代struct student类型的长度
struct student //声明了struct student的类型
{
char name[15]; //学生姓名
float score; //学生成绩
struct student *next; //定义的指向下一个学生的指针
};
/*********一般的建个学生链表有以下几个函数就应该可以了*********/
struct student *creat(void); //创建 一个学生链表,返回一个指向链表头的指针
void print(struct student *head); //打印出学生链表
struct student *del(struct student *head,char name[]); //删除名称为name的学生
struct student *insert(struct student *head, struct student *stud); //插入新的学生信息
int n; //n为全局变量,对表中结点的个数进行掌控
struct student *create(void)
{
struct student *head;
struct student *p1,*p2;
n = 0;
p1 = p2 = (struct student*)malloc(LEN); //开辟的第一个单元,并却强制转换其类型
scanf("%s,%f",&p1->name,&p1->score);
head = NULL;
while(p1 ->name != 0)
{
n = n+1;
if(n == 1)
head = p1;
else
p2->next = p1;
p1 = p2;
p1 = (struct student*)malloc(LEN);
scanf("%s,%f",&p1->name,&p1->score);
}
p2->next = NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("now ,these %d records are:\n",n);
p = head;
if(head != NULL)
do
{
printf("%s,%f\n",p->name,p->score);
p = p->next;
}while(p != NULL);
}
struct student *del(struct student *head,char name[])
{
struct student *p1,*p2;
if(head == NULL)
{
printf("\n list null!");
}
p1 = head;
while(strcmp(name,p1->name) != 0 && p1->next != NULL)
//p1指向的不是所要的结点,却后面还有结点
{
p2 = p1;
p1 = p1->next;
}
if(strcmp(name,p1->name) == 0) //找到了
{
if(p1 == head)
head = p1->next;
else
p2->next = p1->next;
printf("delete:%s\n",name);
n = n-1;
}
else printf("can not been found!");
return head;
}
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(strcmp(p0->name,p1->name) > 0&&(p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(strcmp(p0->name,p1->name)<0)
{
if(head == p1)
head = p0;
else
p2 ->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next =NULL;
}
}
n = n+1;
return(head);
}
void main()
{
struct student *head,stu;
char name[20];
printf("input records:\n");
head = creat();
print(head);
printf("\ninput the deleted number:");
scanf("%s",name);
head = del(head,name);
print(head);
printf("\ninput the insert records:");
scanf("%s,%f",&stu.name,&stu.score);
head = insert(head,&stu);
print(head
/*
对上面的进行了修改,连接能够通过,还存在思想上的错误,一时搞不顶,凑合着用吧!
老师应该看不出来的,这也是仿潭的程序
*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define NULL 0 //定义NULL宏
#define LEN sizeof(struct student) //定义LEN宏,替代struct student类型的长度
struct student //声明了struct student的类型
{
char name[15]; //学生姓名
float score; //学生成绩
struct student *next; //定义的指向下一个学生的指针
};
/*********一般的建个学生链表有以下几个函数就应该可以了*********/
struct student *create(void); //创建 一个学生链表,返回一个指向链表头的指针
void print(struct student *head); //打印出学生链表
struct student *del(struct student *head,char name[]); //删除名称为name的学生
struct student *insert(struct student *head, struct student *stud); //插入新的学生信息
int n; //n为全局变量,对表中结点的个数进行掌控
struct student *create(void)
{
struct student *head;
struct student *p1,*p2;
n = 0;
p1 = p2 = (struct student*)malloc(LEN); //开辟的第一个单元,并却强制转换其类型为struct student*
scanf("%s,%f",&p1->name,&p1->score);
head = NULL;
while(strcmp(p1 ->name ,"0") != 0)
{
n = n+1;
if(n == 1)
head = p1;
else
p2->next = p1;
p1 = p2;
p1 = (struct student*)malloc(LEN);
scanf("%s,%f",&p1->name,&p1->score);
}
p2->next = NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("now ,these %d records are:\n",n);
p = head;
if(head != NULL)
do
{
printf("%s,%f\n",p->name,p->score);
p = p->next;
}while(p != NULL);
}
struct student *del(struct student *head,char name[])
{
struct student *p1,*p2;
if(head == NULL)
{
printf("\n list null!");
}
p1 = head;
while(strcmp(name,p1->name) != 0 && p1->next != NULL)
//p1指向的不是所要的结点,却后面还有结点
{
p2 = p1;
p1 = p1->next;
}
if(strcmp(name,p1->name) == 0) //找到了
{
if(p1 == head)
head = p1->next;
else
p2->next = p1->next;
printf("delete:%s\n",name);
n = n-1;
}
else printf("can not been found!");
return head;
}
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(strcmp(p0->name,p1->name) > 0&&(p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(strcmp(p0->name,p1->name)<0)
{
if(head == p1)
head = p0;
else
p2 ->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next =NULL;
}
}
n = n+1;
return(head);
}
void main()
{
struct student *head,stu;
char name[15];
printf("input records:\n");
head = create();
print(head);
printf("\ninput the deleted name:");
scanf("%s",name);
head = del(head,name);
print(head);
printf("\ninput the insert records:");
scanf("%s,%f",&stu.name,&stu.score);
head = insert(head,&stu);
print(head);
}