C语言课程设计不少于200行代码
编程代码不少于200行,最基础的,包括函数,结构体,循环等功能等!很急,谢谢!
追问:请问有没有这个代码的设计报告
编程代码不少于200行,最基础的,包括函数,结构体,循环等功能等!很急,谢谢!
追问:请问有没有这个代码的设计报告
答案:#include "stdio.h"
#include"stdlib.h"
#include "conio.h"
#include"string.h"
struct SStudent
{
unsigned number;
char name[10];
char tele[12];
struct SStudent * link;
};
void main()
{
struct SStudent * CreateTable();
void AppendToTable(struct SStudent * stu);
void InsertToTable(struct SStudent * stu);
void QueryTable(struct SStudent * stu, unsigned number);
void SortTable(struct SStudent * stu);
void PrintTable(struct SStudent * stu);
void Save(struct SStudent * stu);
void Load(struct SStudent * stu);
void Help();
void modi(struct SStudent *h);
void search(struct SStudent *h);struct SStudent * student;
unsigned number;
char keyValue;
student = CreateTable();
//clrscr();
system("cls");
Help();
printf("\n= ");
while((keyValue = getche()) != 'q' && keyValue != 'Q' && keyValue != 27)
{
puts("");
switch(keyValue)
{
case 'l': case 'L':
PrintTable(student); break;
case 'd': case 'D':
printf("Please input the number you want delete: ");
scanf("%d", &number);
QueryTable(student, number);
break;
case 'a': case 'A':
AppendToTable(student); break;
case 'i': case 'I':
InsertToTable(student); break;
case 's': case 'S':
SortTable(student);
puts("Sort complished! Please use command L to list.");
break;
case 'f': case 'F':
search(student);
break;
case 'm': case 'M':
modi(student);
break;case 'v': case 'V':
Save(student); break;
case 'o': case 'O':
Load(student); break;
case 'h': case 'H':
Help(); break;
default: puts("Error command!");
}
printf("\n= ");
}
}
struct SStudent * CreateTable()
{
struct SStudent * stu;
stu = (struct SStudent *) malloc(sizeof(struct SStudent));
stu->number = 0;
stu->name[0] = '\0';
stu->tele[0] = '\0';
stu->link = NULL;
return(stu);
}
void AppendToTable(struct SStudent * stu)
{
struct SStudent * next, * last;
int number;
last = stu;
while(last->link) last = last->link;
printf("Please input the number (0 to quit): ");
scanf("%d", &number);
while(number)
{
next = (struct SStudent *) malloc(sizeof(struct SStudent));
next->number = number;
printf("Please input name: ");
scanf("%s", next->name);
printf("Please input tele: ");
scanf("%s", next->tele);
last->link = next;
last = last->link;
printf("\nPlease input the number (0 to quit): ");
scanf("%d", &number);
}
last->link = NULL;
}
void InsertToTable(struct SStudent * stu)
{
struct SStudent * next, * last;
int number;
printf("Please input the number (0 to quit): ");
scanf("%d", &number);
while(number)
{
next = (struct SStudent *) malloc(sizeof(struct SStudent));
next->number = number;
printf("Please input name: ");
scanf("%s", next->name);
printf("Please input tele: ");
scanf("%s", next->tele);
last = stu;
while(last->link)
{
if(last->link->number > next->number)
{
next->link = last->link;
last->link = next;
break;
}
else last = last->link;
}
printf("\nPlease input the number (0 to quit): ");
scanf("%d", &number);
}
}
void QueryTable(struct SStudent * stu, unsigned number)
{
struct SStudent * temp, * next;
next = stu;
while(next->link)
{
if(next->link->number == number)
{
temp = next->link;
next->link = next->link->link;
free(temp);
}
else next = next->link;
}
}
void PrintTable(struct SStudent * stu)
{
stu = stu->link;
if(!stu)
{
puts("The table is EMPTY!");
return;
}
printf("number\tname\ttele\n");
while(stu)
{
printf("%3d\t", stu->number);
printf("%-s\t", stu->name);
printf("%-s\t", stu->tele);
printf("\n");
stu = stu->link;
}
}
void SortTable(struct SStudent * stu)
{
struct SStudent * next, * last, * temp;
int flag;
last = stu;
while(last->link)
{
next = stu; flag = 1;
while(next->link != last->link)
{
if(next->link->number > last->link->number)
{
temp = last->link;
last->link = last->link->link;
temp->link = next->link;
next->link = temp;
flag = 0;
break;
}
else next = next->link;
}
if(flag) last = last->link;
}
}
void Save(struct SStudent * stu)
{
char filename[13];
FILE * fileSave;
printf("Please input the filename you want save in: ");
scanf("%s", filename);
if((fileSave = fopen(filename, "wb")) == 0)
{
printf("Cannot open file %s !\n", filename);
return;
}
puts("Saveing ...");
stu = stu->link;
while(stu)
{
fwrite(stu, sizeof(struct SStudent), 1, fileSave);
stu = stu->link;
}
puts("Saveing is finished!");
}
void Load(struct SStudent * stu)
{char filename[13];
FILE * fileLoad;
struct SStudent * temp;
while(stu->link)
{
temp = stu->link;
stu->link = stu->link->link;
free(temp);
}
temp = (struct SStudent *) malloc(sizeof(struct SStudent));
printf("Please input the filename you want load from: ");
scanf("%s", filename);
if((fileLoad = fopen(filename, "rb")) == 0)
{
printf("Cannot open file %s !\n", filename);
return;
}
puts("Loading ...");
while(fread(temp, sizeof(struct SStudent), 1, fileLoad))
{stu->link = temp;
stu = stu->link;
temp = (struct SStudent *) malloc(sizeof(struct SStudent));
}
stu->link = NULL;
puts("loading is finished!");
}
void Help()
{ puts(" *********************************************");
puts(" * System Command Help *");
puts(" *********************************************");
puts(" * L = List all records *");
puts(" * D = Delete a record seleced by number *");
puts(" * A = Append records *");
puts(" * I = Insert records *");
puts(" * S = Sort records *");
puts(" * F= Search records *");
puts(" * M= Modi records *");puts(" * H = Show this help message *");
puts(" * V = Save records to a file *");
puts(" * O = Load records from a file *");
puts(" * Q = Quit System *");
puts(" *********************************************");
}
void modi(struct SStudent *h)
{
struct SStudent *p; /* 移动指针*/
unsigned num; /*存放学号的变量*/
// clrscr(); /*清屏幕*/
system("cls");
printf("please enter number for modifi\n");
scanf("%d",&num); /*输入学号*/
p=h; /*将头指针赋给p*/
while( (p->number!=num)&&p!=NULL) /*当记录的姓名不是要找的,且指针不为空时*/
p=p->link; /*移动指针,指向下一结点*/
if(p==NULL) /*如果指针为空*/
printf("\nlist no %d student\n",num); /*显示没有该学生*/
else /*修改找到的记录信息*/
{
printf("Please input new name: ");
scanf("%s", p->name);
printf("Please input new tele: ");
scanf("%s", p->tele);
printf("|number | name | tel | \n");
printf("|----------|---------------|---------------|\n");
printf("|%6d|%-10s|%12s|\n", p->number,p->name,p->tele);}
}
void search(struct SStudent *h)
{
struct SStudent *p; /* 移动指针*/
char s[10]; /*存放姓名的字符数组*/
// clrscr(); /*清屏幕*/
sys
上一个:计算机专业课C语言该怎么学好?
下一个:c语言 试题 急求 简单一些的