贩母案考视频:要求用C与C++做个小系统

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 20:45:21
要求用C与C++做个小系统

欢迎进入学生管理系统
1添加学生信息
2查询学生信息
3删除学生信息
4退出
要求:(其中学生信息包括姓名,性别,专业,学号.)还要有原代码,注释.

/*此程序为线性表的插入,删除,查询程序。此程序原形及主函数功能未做变化,我只将菜单
显示作些调整,但总体思路未做变动,此程序于2006年6月10日写完,
将原程序中的错误进行纠正,一期目标已经完成。调试任务二:将主函数功能进行完善,即
显示插入,删除后顺序表的总状态,显示数组中的数据,任务三:添加菜单项,使之具有任务
二的功能。任务三:使此表能以文件的方式进行存储和调用。任务四:增强程序的纠错能力。
完毕。
/*****************预处理区,定义结构体,函数声明及头函数调用*********************/

/*******任务三未完成******/
//调用头函数
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>

//自定义结构体
typedef int datatype;
#define MAXSIZE 256
typedef struct
{
char Name[10];
char Code[8];
datatype Subject1_Score[MAXSIZE];
datatype Subject2_Score[MAXSIZE];
datatype Subject3_Score[MAXSIZE];
datatype Subject4_Score[MAXSIZE];
datatype Average_Score[MAXSIZE];
int last;
}seqlist;

//是否第一次运行程序是否初始化判断变量
int justify=-1;

//声明附属功能函数区
void cls(void); //声明清屏函数
int menuface(void); //声明菜单界面及选择函数
void menu(seqlist *,FILE *); //声明菜单选择函数
void PressAnyKeyToCountiune(void); //声明暂停函数

//声明主功能函数区
seqlist *Init_Seqlist(void); //初始化线性表
void Insert_Seqlist(seqlist *,int,datatype); //线性表插入
int Delete_Seqlist(seqlist *,int); //线性表删除
int Location_Seqlist(seqlist *,datatype); //线性表查询
void List_Seqlist(seqlist *); //线性表内存状况
seqlist *Sort_Seqlist(seqlist *);

//声明过程函数
int Identify(seqlist *L); //声明判断是否初始化顺序表函数
//void ReadSeqlistFromFile(seqlist *);
//void SaveSeqlistToFile(seqlist *);
FILE *KillData(void);

/******************************主函数区****************************************/
main()
{
/**************调用指定文件,如果指定文件存在,则从中调用数据,加到指定变量中,
如果文件不存在,则新建此文件,并将初始化变量justify定为-1*********************/
seqlist *L;
FILE *fp1,*fp2;
int i;
if((fp1=fopen("seqsave.sav","r+"))!=NULL)
{
L=Init_Seqlist();
justify=0;
fscanf(fp1,"%d\n",&(L->last));
for(i=0;i<=L->last;i++)
{
fscanf(fp1,"%10s\t",&(Name));
fscanf(fp1,"%8s\t",&(Code));
fscanf(fp1,"%4d\t",&(Subject1_Score[MAXSIZE]));
fscanf(fp1,"%4d\t",&(Subject2_Score[MAXSIZE]));
fscanf(fp1,"%4d\t",&(Subject3_Score[MAXSIZE]));
fscanf(fp1,"%4d\t",&(Subject4_Score[MAXSIZE]));
fscanf(fp1,"%4d\t\n",&(Average_Score[MAXSIZE]));
}
printf("加载文件成功!\n\n\n");
fclose(fp1);
PressAnyKeyToCountiune();
}
fp2=KillData();
menu(L,fp2); //调用菜单函数
fclose(fp2);
return 0;
}

/***********************************函数定义区****************************************/

/*-----------------------菜单界面及选择(附属函数定义)---------------------------*/

//建立清屏函数
void cls(void)
{
system("cls");
}
//定义一个暂停方式
void PressAnyKeyToCountiune(void)
{ printf("\n\n\n\n\n");
printf("\n按任意键继续....");
cin.get();
}
//定义菜单界面函数
int menuface(void)
{
int choise,xx;
cls();
printf("学生工作室演示程序:\n\n"); //菜单界面效果
printf("\n\t\t\t****************************\n");
printf("\t\t\t** 选择菜单 **\n"
"\t\t\t** 1.初始化数据表 **\n"
"\t\t\t** 2.学生信息插入 **\n"
"\t\t\t** 3.学生信息删除 **\n"
"\t\t\t** 4.学生数据查询 **\n"
"\t\t\t** 5.学生信息状态显示 **\n"
"\t\t\t** 6.学生数据排序整理 **\n"
"\t\t\t** 7.退出程序 **\n"
"\t\t\t**************************\n\n");
printf("\t ");
for(xx=0;xx<=54;xx++)
printf("*");
printf("\n\t\t请选择!");
scanf("%d",&choise);
return choise;
}

//定义菜单选择函数
void menu(seqlist *L,FILE *fp2)
{
int choice,choisewrong=0; //声明错误选择变量
int i,success; //声明子函数运行成功变量
datatype x;

while((choice=menuface())!=7) //调用菜单界面及用户选择
{
switch(choice)
{
case 1: //初始化线性表
{
cls();
L=Init_Seqlist();
choisewrong=0;
break;
}
case 2: //插入操作
{
cls();
if(Identify(L)==-1) //判断第一次运行程序是否初始化
break;
if(L->last==MAXSIZE-1) //如果插入操作中表满提示表满不能插入数据
{
printf("表已满,不能再插入数据!\n\n");
break;
}
if(L->last==-1) //第一次运行程序则提示为空表
{
printf("这是一个空表!\n"
"请输入起始数据:");
i=1; //在第一个位置上插入数据
}
else
{
printf("请输入需要插入的位置(1~%d):",L->last+2); //限定用户的插入范围
//并给以提示
scanf("%d",&i);
if(i<1||i>(L->last+2))
{
printf("插入的位置错误!\n\n");
break;
}
printf("请输入需要插入的数据:"); //机器提示插入的数据
}
scanf("%d",&x);
Insert_Seqlist(L,i,x); //调用插入子函数完成插入操作
printf("\n插入操作完成!\n\n");
choisewrong=0;
break;
}
case 3: //运行删除操作
{
cls();
if(Identify(L)==-1) //判断是否初始化
break;
if(L->last==-1)
{
printf("这是一张空表,没有可删除的数据\n\n\n\n\n");
break;
}
printf("请输入需要删除的位置(1~%d):",L->last+1); //机器提示删除的位置
scanf("%d",&i);
success=Delete_Seqlist(L,i); //调用删除子函数判断结果返回success
if(success==1)
printf("\n已删除表中的数据!\n\n");
else
printf("\n删除操作失败!\n\n");
choisewrong=0;
break;
}
case 4: //运行查询子函数
{
cls();
if(Identify(L)==-1) //判断是否初始化
break;
if(L->last==-1)
{
printf("这是一张空表,没有可查找的数据\n\n\n\n\n");
break;
}
printf("请输入你要查询的数据:");
scanf("%d",&x);
success=Location_Seqlist(L,x);
if(success==-1)
{
printf("\n未找到该数据!\n\n");
}
else
{
printf("\n查到您要的数据!\n\n");
printf("您查询的数据是: 第 %d 个位置的数据 %d\n\n",success+1,x);
}
choisewrong=0;
break;
}
case 5: //运行显示状态子函数
{
cls();
if(Identify(L)==-1)
break;
List_Seqlist(L);
choisewrong=0;
break;
}
case 6: //排列顺序更替原先位置
{
cls();
if(Identify(L)==-1)
break;
if(L->last==-1)
{
printf("这是一张空表,不能重新排列数据\n\n\n\n\n");
break;
}
if(L->last==0)
{
printf("表中数据最少在两个或两个以上。");
break;
}
L=Sort_Seqlist(L);
printf("\n顺序更替成功!\n\n");
choisewrong=0;
break;
}
default: //如果用户选择错三次,则自动退出
{
choisewrong++;
printf("\n\t\t错误的选择!\n\n");
if(choisewrong==3)
{
fclose(fp2);
exit(0);
}
}
}//end switch
PressAnyKeyToCountiune(); //调用暂停子函数
}//end while
if(justify==-1||L->last==-1)
{
fclose(fp2);
system("del seqsave.sav");
exit(0);
}
fprintf(fp2,"%d\n",L->last); //变量L->last存入文件
for(i=0;i<=L->last;i++) //数组中的数值存入文件
{
fprintf(fp2,"%d\n",L->data[i]);
}
}//end menu

/*-------------------初始化,插入,删除,查询函数(主功能函数定义)-----------------*/

//线性表初始化函数
seqlist *Init_Seqlist(void)
{
seqlist *L;
L=(seqlist *)malloc(sizeof(seqlist));
L->last=-1;
justify=0;
printf("\n\n初始化完毕!\n\n\n");
return L;
}
//线性表的插入函数
void Insert_Seqlist(seqlist *L,int i,datatype x)
{
int j;
for(j=L->last;j>=i-1;j--)
L->data[j+1]=L->data[j];
L->data[i-1]=x;
L->last++;
}
//线性表的删除函数
int Delete_Seqlist(seqlist *L,int i)
{
int j;
if(i<1||i>(L->last+1))
{
printf("所删除的数据位置错误!\n\n");
return 0;
}
for(j=i;j<=L->last;j++)
L->data[j-1]=L->data[j];
L->last--;
return 1;
}
//线性表的查询函数
int Location_Seqlist(seqlist *L,datatype x)
{
int i=0;
while(i<=L->last&&L->data[i]!=x)
i++;
if(i>L->last)
return -1;
else return i;
}
//线性表内数据显示
void List_Seqlist(seqlist *L)
{
int i;
printf(" \t序号 \t\t成员名\t\t\t数据\t\t 地址\n\n");
for(i=0;i<=L->last;i++)
printf("\t%3d\t\tdata[%3d]\t\t%4d\t\t%p\n",i+1,i,L->data[i],&L->data[i]);
printf("\n\n");
}
//顺序表顺序重排
seqlist *Sort_Seqlist(seqlist *L)
{
int i,pass;
datatype hold;
printf("顺序正在按数值由小到大进行重排......\n\n\n\n");
for(pass=0;pass<=L->last-1;pass++)
{
for(i=0;i<=L->last-1;i++)
{
if(L->data[i]>=L->data[i+1])
{
hold=L->data[i];
L->data[i]=L->data[i+1];
L->data[i+1]=hold;
}//end if
}//end for i
}//end for pass
return L;
}

//定义判断是否初始化顺序表函数
int Identify(seqlist *L)
{
if(justify==-1)
{
printf("线性表还未初始化,先初始化。\n\n");
return -1;
}
else
return 0;
}
//清空原文件中的数据
FILE *KillData(void)
{
FILE *fp1;
system("del seqsave.sav");
if((fp1=fopen("seqsave.sav","w+"))==NULL)
{
printf("文件创建错误!\n\n");
exit(0);
}
return fp1;
}

又是这个作业,那个学校那么没水平啊,去看数据结构的书,基本的原代码都有,给你个提示
struct student{
string name,object;
bool sex;
unsigned int num;
};
add,search,delet,exit四个功能么,四个函数实现就可以了