?? 學生學籍信息管理系統.txt
字號:
題目:學生學籍信息管理系統
一:需求分析
通過此系統可以實現如下功能:
1、錄入:
可以錄入學生情況(數據可以存儲在一個數據文件中,數據結構、具體數據自定)
2、查詢:
可以查詢某個學生的情況(如,輸入學生號,查詢學生信息時間,學生數量);
3、修改:修改學生信息內容;
4、刪除:刪除相關學生信息;
5、打印:打印出學生的相關信息;
6、顯示結果。
根據以上功能說明,設計具體的存儲結構,要求程序要有一個可供用戶選擇的簡單操作界面。操作前要有簡單的提示,設計程序完成功能。
二:概要設計
為實現上述程序功能,應該將程序分成五個模塊:
1、主程序模塊:
void main()
{
輸入學生的學號、姓名、分數;
查找學生的信息;
更改學生的信息;
刪除學生的信息;
打印結果;
}
2、輸入學生信息模塊:輸入學生的相關信息;
3、 查找信息模塊:查找相關學生的信息;
4、更改信息模塊:更改指定學生的信息;
5、打印模塊:在屏幕上輸出結果。
三:源程序
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#include<fstream.h>
class student
{
int no;
char name[10];
int score;
public:
student(){}
student(int n,char na[],int s)
{
no=n;
strcpy(name,na);
score=s;
}
char *getname()
{
return name;
}
void creat()
{
cout<<"-----------------------"<<endl;
cout<<"輸入新的學號:"<<endl;
cin>>no;
cout<<"-----------------------"<<endl;
cout<<"輸入新的姓名:"<<endl;
cin>>name;
cout<<"-----------------------"<<endl;
cout<<"輸入新的分數:"<<endl;
cin>>score;
}
void disp()
{
cout<<"****************************"<<endl;
cout<<"學號: ";
cout<<no<<endl;
cout<<"姓名: ";
cout<<name<<endl;
cout<<"分數: ";
cout<<score<<endl;
cout<<"****************************"<<endl;
}
};
int comp(char s1[],char s2[])
{
int i=0;
while(s1[i]!='\0'&&s2[i]!='\0'&&s1[i]==s2[i])
i++;
if(s1[i]=='\0'||s2[i]=='\0')
return 1;
else
return 0;
}
void find(student st[])
{
char sname[10];
int i;
ofstream file("e:\\stud.txt");
for(i=0;i<6;i++)
file.write((char *)&st[i],sizeof(student));
cout<<"輸入查找姓名:"<<endl;
cin>>sname;
cout<<"學生情況結果:"<<endl;
cout<<setiosflags(ios::left)<<"學號"<<'\t'<<"姓名"<<'\t'<<"分數"<<endl;
ifstream infile;
for( i=0;i<6;i++)
{
infile.open("e:\\stud.txt");
infile.read((char *)&st[i],sizeof(student));
if(comp(st[i].getname(),sname)==1)
st[i].disp();
}
file.close();
}
void display(student st[])
{
ifstream infile;
for(int j=0;j<6;j++)
{
infile.open("e:\\stud.txt");
infile.read((char *)&st[j],sizeof(student));
st[j].disp();
}
infile.close();
}
void change(student st[])
{
char sname_m[10];
cout<<"請輸入你要更改的姓名:"<<endl;
cout<<"-----------------------------"<<endl;
cin>>sname_m;
ofstream file;
for(int i=0;i<6;i++)
{
file.open("e:\\stud.txt");
if(comp(st[i].getname(),sname_m)==1)
st[i].creat();
file.write((char *)&st[i],sizeof(student));
}
file.close();
}
void main()
{
cout<<"***************歡迎進入小功能學籍管理系統*****************"<<endl;
student st[]={ student(1,"xiaoli",89),student(2,"xiaohua",78),
student(3,"xiaozhang",92),student(4,"xiaowang",65),
student(5,"xiaopeng",88),student(6,"xiaogang",65)};
int chorces;
while(chorces!=0)
{
cout<<"------------------------------------"<<endl;
cout<<" 1 查找 "<<endl;
cout<<" 2 更改 "<<endl;
cout<<" 3 全顯 "<<endl;
cout<<" 0 退出 "<<endl;
cout<<"**************************************"<<endl;
cout<<"請輸入你要的服務項:"<<endl;
cout<<"**************************"<<endl;
cin>>chorces;
cout<<"**************************"<<endl;
switch(chorces)
{
case 1:
find(st);
break;
case 2:
change(st);
break;
case 3:
display(st);
break;
}
}
}
四:用戶手冊
1、本程序運行環境為DOS 操作系統和C++系統,執行文件為test.exe
2、進入本程序后,如下圖所示
***************歡迎進入小功能學籍管理系統*****************
1 查找
2 更改
3 全顯
0 退出
**************************************
請輸入你要服務項:
**************************************
3、此次程序是直接在屏幕上打印出程序的運行結果,用戶將在屏幕上看到程序功能顯示的結果。
五:調試、顯示
***************歡迎進入小功能學籍管理系統*****************
1 查找
2 更改
3 全顯
0 退出
**************************************
請輸入你要服務項:
**************************************
1
xiaozhang
學號:3
姓名:xiaozhang
分數:92
2
xiaozhang
3
學號:1
姓名:xiaocui
分數:89
學號:2
姓名:xiaosun
分數:92
學號:3
姓名:xiaozhang
分數:92
學號:4
姓名:xiaowang
分數:65
學號:5
姓名:xiaopeng
分數:88
學名:6
姓名:xiaogang
分數:65
六:附錄
class student //創建一個類
void creat()/void disp() //創建學生信息的函數
void main() //主函數
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -