#include
#include
#include
#define NULL 0
struct student{
char name[100];
char xuehao[100];
char gradeandclass[100];
int Mathnumber;
int Mathscore;
int Englishnumber;
int Englishscore;
int Politicsnumber;
int Politicsscore;
int Coursesnumber;
int Coursesscore;
};
int main()
{
FILE *fp;
char a;
fp = fopen( "学籍管理系统.txt", "ab+" );
if( fp == NULL )
{
printf( "打开文件失败!\n" );
exit(1);
}
while(1)
{
int i;
int j;
a='y';
printf( "---------------------欢迎使用学籍管理系统-------------------------\n" );
printf( "|*| 请进行选择 |*|\n" );
printf( "|*| 1.录入学生信息 |*|\n" );
printf( "|*| 2.显示学生信息 |*|\n" );
printf( "|*| 3.查找学生信息 |*|\n" );
printf( "|*| 4.清除学生信息 |*|\n" );
printf( "|*| 5.退出管理系统 |*|\n" );
printf( "------------------------------------------------------------------\n" );
printf( "请选择操作的序号:" );
scanf( "%d", &i );
switch(i)
{
case 1:
{
while(a=='y'){
struct student *p = ( student* ) malloc ( sizeof( struct student ) );
if( p == NULL )
{
printf( "内存分配失败!\n" );
exit(1);
}
printf( "姓名:" );
scanf( "%s", p->name );
printf( "学号:" );
scanf( "%s", p->xuehao );
printf( "班级:" );
scanf( "%s", p->gradeandclass );
printf( "《数 学》编号:" );
scanf( "%d", &p->Mathnumber );
printf( "《数 学》成绩:" );
scanf( "%d", &p->Mathnumber );
printf( "《英 语》编号:" );
scanf( "%d", &p->Englishnumber );
printf( "《英 语》成绩:" );
scanf( "%d", &p->Englishscore );
printf( "《政 治》编号:" );
scanf( "%d", &p->Politicsnumber );
printf( "《政 治》成绩:" );
scanf( "%d", &p->Politicsscore );
printf( "《专业课》编号:" );
scanf( "%d", &p->Coursesnumber );
printf( "《专业课》成绩:" );
scanf( "%d", &p->Coursesscore );
printf("如果继续输入学籍信息,请输入y否则输入n \n");
getchar();
a=getchar();
fwrite( p, sizeof( struct student ), 1, fp );
free(p);
p = NULL;
}
}
system( "pause" );
system( "cls" );
break;
case 2:
{
struct student *p = ( student* ) malloc ( sizeof( struct student ) );
if( p == NULL )
{
printf( "内存分配失败!\n" );
exit(1);
}
rewind(fp);
while( !feof(fp) )
{
if( fread( p, sizeof( struct student ), 1, fp ) )
{
printf( "*****************************************\n");
printf( "姓名:%s 学号:%s 班级:%s\n", p->name, p->xuehao, p->gradeandclass );
printf( "----课程名称----课程编号----课程成绩----\n" );
printf( " 数 学 %8d %8d\n", p->Mathnumber, p->Mathnumber );
printf( " 英 语 %8d %8d\n", p->Englishnumber, p->Englishscore );
printf( " 政 治 %8d %8d\n", p->Politicsnumber, p->Politicsscore );
printf( " 专业课 %8d %8d\n", p->Coursesnumber, p->Coursesscore );
printf( "*****************************************\n");
printf( " " );
}
}
free(p);
p = NULL;
}
system( "pause" );
system( "cls" );
break;
case 3:{
printf("----欢迎进入查找单元!!---------\n");
printf("------请选择查找方式:\n");
printf("1.按姓名 -- 2.按学号 -- 3.按班级 ");
scanf("%d",&j);
switch(j){
case(1):
{
char number1[20];
int m=0;
printf("输入查找学生的姓名:");
scanf("%s",number1);
struct student *p = ( student* ) malloc ( sizeof( struct student ) );
if(p==NULL){
printf("内存分配失败!\n");
exit(1);
}
rewind(fp);
while(!feof(fp)){
if( fread( p, sizeof( struct student ), 1, fp ) ){
if(strcmp( p->name, number1 ) == 0 ){
m++;
printf( "*****************************************\n");
printf( "姓名:%s 学号:%s 班级:%s\n", p->name, p->xuehao, p->gradeandclass );
printf( "----课程名称----课程编号----课程成绩----\n" );
printf( " 数 学 %8d %8d\n", p->Mathnumber, p->Mathnumber );
printf( " 英 语 %8d %8d\n", p->Englishnumber, p->Englishscore );
printf( " 政 治 %8d %8d\n", p->Politicsnumber, p->Politicsscore );
printf( " 专业课 %8d %8d\n", p->Coursesnumber, p->Coursesscore );
printf( "*****************************************\n");
printf( " " );
}//end if
}//end if
}//end while
if(!m){
printf("信息不存在!!");
}
}
system( "pause" );
system( "cls" );
break;
case(2):
{
char number[20];
int n = 0;
// int count=0;
printf( "输入查找的学生学号:" );
scanf( "%s", number );
struct student *p = ( student* ) malloc ( sizeof( struct student ) );
if( p == NULL )
{
printf( "内存分配失败!\n" );
exit(1);
}
rewind( fp );
while( !feof(fp) )
{
if( fread( p, sizeof( struct student ), 1, fp ) )
{
// printf("循环次数:%d\n n的值:%d\n 地址p的值%d\n",count,n,p);
if( strcmp( p->xuehao, number ) == 0 )
{
n++;
printf( "*****************************************\n");
printf( "姓名:%s 学号:%s 班级:%s\n", p->name, p->xuehao, p->gradeandclass );
printf( "----课程名称----课程编号----课程成绩----\n" );
printf( " 数 学 %8d %8d\n", p->Mathnumber, p->Mathnumber );
printf( " 英 语 %8d %8d\n", p->Englishnumber, p->Englishscore );
printf( " 政 治 %8d %8d\n", p->Politicsnumber, p->Politicsscore );
printf( " 专业课 %8d %8d\n", p->Coursesnumber, p->Coursesscore );
printf( "*****************************************\n");
printf( " " );
}
}
}
if(!n)
printf( "信息不存在!\n" );
}//end case(2 j)
system( "pause" );
system( "cls" );
break;
case(3):
{ char number2[20];
int k=0;
printf("输入查找的学生班级:");
scanf("%s",number2);
struct student *p = ( student* ) malloc ( sizeof( struct student ) );
if(p==NULL){
printf( "内存分配失败!\n" );
exit(1);
}
rewind(fp);
while(!feof(fp)){
if( fread(p,sizeof( struct student ),1,fp) ){
if( strcmp( p->gradeandclass , number2)==0){
k++;
printf( "*****************************************\n");
printf( "姓名:%s 学号:%s 班级:%s \n", p->name, p->xuehao, p->gradeandclass );
printf( "----课程名称----课程编号----课程成绩----\n" );
printf( " 数 学 %8d %8d\n", p->Mathnumber, p->Mathnumber );
printf( " 英 语 %8d %8d\n", p->Englishnumber, p->Englishscore );
printf( " 政 治 %8d %8d\n", p->Politicsnumber, p->Politicsscore );
printf( " 专业课 %8d %8d\n", p->Coursesnumber, p->Coursesscore );
printf( "*****************************************\n");
printf( " " );
}//end if
}//end if
}//end while
if(!k){
printf("信息不存在!!!\n");
}
}//end case(3 j)
system( "pause" );
system( "cls" );
break;
}//end switch(j)
}//end case(3) i
system( "pause" );
system( "cls" );
break;
case(4):
{
printf("1.确定删除 -- 2.返回 \n");
int b;
scanf("%d",&b);
switch(b){
case(1):
{
fp = fopen( "学籍管理系统.txt", "w+" );
// break;
system( "cls" );
}
case(2):
{
break;
}
} //end Switch(b)
}//end case(4)
break;
case 5:
exit(0);
break;
default:printf("输入无效!\n");
system( "pause" );
system( "cls" );
}
}
fclose(fp);
return 0;
}
你还需要什么内容看着加就可以了。。
额。。。最近好多人要这个东东。。不明白是什么意思。。。我自己写了一个,你看看。。。
用C++ 的 模板写的。。。
不理解的地方咱继续交流。。。。
//book_class.h 代码如下:
#include
#include
#include
#include
#include
#include
using namespace std;
typedef struct book_class
{
string book_number;
string book_name;
string book_public_infor;
string book_type; //图书类型;
string book_pbulic_time;//出版时间;
}book;
class equal1
{
public:
string str;
equal1(string str1):str(str1)
{}
bool operator () (book & book1)
{
if(book1.book_name==str || book1.book_number==str || book1.book_public_infor==str || book1.book_type==str)
return true;
return false;
}
};
class book_manage
{
public:
list
public:
book_manage(){}
void sort();
void show();
void insert();
void erase();
void inquire();
void save(){};
void show(list
friend bool operator < (const book &book1,const book &book2)
{
return book1.book_name
friend ostream & operator << ( ostream &out,const book &book1)
{
out<
}
};
//book_class.cpp 实现文件内容如下:
#include "book_class.h"
void book_manage::sort()
{
int number;
if(this->book_store_list.size()==0)
{
cout<<"no book in the store!"<
}
loop: cout<<"input the information you want the book sort by:"<
cout<<" input the infor:"<
switch(number)
{
case 1:
this->book_store_list.sort();
cout<<"the information of book had been sort by book's name!"<
case 2:
break;
case 3:
break;
default:
cout<<"Ǹʲô"<
}
cout<<" this is the new sort!"<
}
void book_manage::show()
{
if(this->book_store_list.size()==0)
cout<<"no book in the store!"<
{
ostream_iterator
copy(this->book_store_list.begin(),this->book_store_list.end(), os);
}
system("pause");
return ;
}
void book_manage::insert()
{
book_class book1;
cout<<"input the new book's information:"<
this->book_store_list.push_back(book1);
cout<<"insert successfully!"<
}
void book_manage::erase()
{
string book_name;
cin>>book_name;
list
if(itr==this->book_store_list.end())
cout<<"can't find the book!"<
this->book_store_list.erase(itr);
}
void book_manage::inquire()
{
string book_infor;
bool find_flag=false;
cin>>book_infor;
list
if(itr==this->book_store_list.end())
{
cout<<"can't find the information you want!"<
}
while(itr!=this->book_store_list.end())
{
this->show(itr);
++itr;
itr=find_if(itr,this->book_store_list.end(),equal1 (book_infor));
}
}
void book_manage::show(list
{
cout<<"you may need it!"<
<<(*itr).book_pbulic_time<<" "<<(*itr).book_public_infor<<" "
<<(*itr).book_type<
//main.cpp 主文件如下:
#include "book_class.h"
using namespace std;
int main()
{
//ifstream infile("book.txt");
// book_manage store(infile);
book_manage store;
loop: cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "<
cout<<"\t\t1: show the information of book !"<
int chose;
cout<<"input your chose:";
cin>>chose;
switch(chose)
{
case 1:
system("cls");
store.show();
cout<<"press any key to continue!"<
goto loop;
case 2:
system("cls");
store.sort();
store.show();
system("cls");
goto loop;
case 3:
store.insert();
store.show();
system("cls");
goto loop;
case 4:
cout<<"input the book's name or num you want to erase:";
store.erase();
store.show();
system("cls");
goto loop;
case 5:
cout<<" you may input the book's number,or book's name or book's pulbic_type:";
cout<<" input the book's infor:"<
system("pause");
system("cls");
goto loop;
case 6:
store.save();
return 0;
default:
cout<<" Ǹʲô?"<
cout<<"press any key to chose again!"<
goto loop;
}
return 0;
}
我的博客里边 有一些 关于 C 和C++ 的东东。。。你感兴趣的话看看吧。。呵呵。。祝你好运
http://hi.baidu.com/sx_liang/blog
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "malloc.h"
typedef char ElemType;
#define OK 1
#define ERROR 0
#define OVER -1
typedef struct node
{
int number;
char name[20];
int chinese,math,english;
struct node *next;
} LinkList;
LinkList *InitList()
{
LinkList *H;
H=(LinkList *)malloc(sizeof(LinkList));
H->next=NULL;
return(H);
}
int Length_list(LinkList *H)
{
LinkList *p;
int j=0;
p=H;
while(p->next!=NULL)
{ p=p->next;
j++;
}
return j;
}
void CreateList(LinkList *H,int n)
{
int i;
LinkList *s,*last;
char ch;
last=H;
for(i=1;i<=n;i++)
{ s=(LinkList *)malloc(sizeof(LinkList));
printf("\n请输入第%d个学生的学号:",i);
scanf("%d",&s->number);
printf("\n请输入第%d个学生的姓名:",i);
scanf("%s",&s->name);
printf("\n请输入第%d个学生的语文、数学和英语成绩:",i);
scanf("%d%d%d",&s->chinese,&s->math,&s->english);
s->next=NULL;
last->next=s;
last=s;
}
}
LinkList *Locate(LinkList *H,int num)
{
LinkList *p;
p=H->next;
while(p!=NULL&&p->number!=num)
p=p->next;
return p;
}
LinkList *GetList(LinkList *H,int i)
{
LinkList *p;
int j=0;
p=H;
while(p->next!=NULL &&j{
p=p->next;
j++;
}
if(j==i)
return p;
else
return NULL;
}
int InsList(LinkList *p,LinkList x)
{
LinkList *s;
s=(LinkList *)malloc(sizeof(LinkList));
s->number=x.number;
strcpy(s->name,x.name);
s->chinese=x.chinese;
s->math=x.math;
s->english=x.english;
s->next=p->next;
p->next=s;
return OK;
}
int Ins_List(LinkList *H,int i,LinkList x)
{
LinkList *p;
p=GetList(H,i-1);
if(p!=NULL)
{
InsList(p,x);
return OK;
}
else
return ERROR;
}
int DelList(LinkList *p,LinkList *x)
{
LinkList *s;
s=p->next;
x->number=s->number;
strcpy(x->name,s->name);
x->chinese=s->chinese;
x->math=s->math;
x->english=s->english;
p->next=s->next;
free(s);
return OK;
}
int Del_List(LinkList *H,int i,LinkList *x)
{
LinkList *p;
p=GetList(H,i-1);
if(p!=NULL&&p->next!=NULL)
{
DelList(p,x);
return OK;
}
else
return ERROR;
}
out()
{
printf("\n*****************************************");
printf("\n请输入序号(0-4)选择要进行的操作:");
printf("\n0-------退出");
printf("\n1-------建立一个学生信息表");
printf("\n2-------插入一个学生信息");
printf("\n3-------删除一个学生信息");
printf("\n4-------查找一个学生是否在该学生信息表中");
printf("\n*****************************************\n");
}
void DisLinkList(LinkList *H)
{
LinkList *p;
printf("\n所有学生的信息如下:");
printf("\n 学号 姓名 语文 数学 英语\n");
p=H->next;
while(p!=NULL)
{
printf("%2d%10s%9d%9d%9d\n",p->number,p->name,p->chinese,p->math,p->english);
p=p->next;
}
}
void main()
{
LinkList *H,*p,*q,x;
int i,n,menux,flag,num;
//clrscr();
out();
H=InitList();
scanf("%d",&menux);
do{switch(menux)
{
case 0: exit(0); break;
case 1:
printf("\n请输入要生成学生信息表的元素各数:");
scanf("%d",&n);
CreateList(H,n);
printf("建立的学生信息表为:\n");
DisLinkList(H);
break;
case 2:
printf("\n请输入要插入的学生位置:");
scanf("%d",&i);
printf("\n请输入要插入的学生信息:");
printf("\n请输入学生的学号:");
scanf("%d",&x.number);
printf("\n请输入学生的姓名:");
scanf("%s",&x.name);
printf("\n请输入学生的语文 数学和英语成绩:");
scanf("%d%d%d",&x.chinese,&x.math,&x.english);
flag=Ins_List(H,i,x);
if(flag)
{
printf("\n插入后的学生信息表为:");
DisLinkList(H);
}
break;
case 3:
printf("请输入要删除的学生的位置:");
scanf("%d",&i);
flag=Del_List(H,i,&x);
if(flag)
{
printf("\n删除第%d个学生后,表中信息为:",i);
DisLinkList(H);
}
break;
case 4:
printf("\n请输入查找的学生学号:\n");
scanf("%d",&num);
if((q=Locate(H,num))!=NULL)
{
printf("\n在学生信息表中存在着学号为%d的学生!",num);
printf("\n学号 姓名 语文 数学 英语\n");
printf("%2d%10s%9d%9d%9d",q->number,q->name,q->chinese,q->math,q->english);
}
else
printf("\n在学生信息表中不存在着学号为%d的学生!",num);
break;
default:
printf("\n输入选项错误,请重新输入(0-4)!");
}
out();
scanf("%d",&menux);
}while(1);
}
student.h
#include
class CHAIN{
public:
long num;
char name[30];
char sex;
int age;
CHAIN*link;
};
class STUDENT{
public:
STUDENT();
~STUDENT();
void add();
void amend();
void taxis();
void det();
void show();
void search();
private:
CHAIN*top;
};