目 录
1 题目内容及设计要求............................................................ 1
2 总体设计................................................................................. 1
2.1 总体功能框图.................................................................. 1
2.2 类的设计说明................................................................ 1
2.3 主要算法流程图........................................................... 1
3 程序清单及注释..................................................................... 1
4 运行结果与分析..................................................................... 1
5 总结.......................................................................................... 2
6 参考文献.................................................................................. 2
1 题目内容及设计要求
题目:会议记录管理系统
内容:
定义会议信息类class Conference
会议信息包括:会议编号,会议名称、部门名称、会议地点,会议日期,会议主持人,
会议记录人,出席人员,会议摘要。会议信息以二进制形式存储在文件中。
(1) 添加会议记录
(2) 浏览所有会议记录信息
(3) 按不同字段(会议编号,会议名称等)查询会议记录
(4) 修改会议记录
(5) 删除会议记录
2 总体设计
2.1 总体功能框图
图2-1 总体功能框图
2.2 类的设计说明
定义类为struck Meetinglist
使用Struck 不仅可用于C++也可兼容于C上。
而且struct可直接默认所有属性和方法为public。
void Add ( fstream ) //添加会议记录
void modification ( fstream ) ; //修改会议记录
void Delete ( fstream ) ; //删除会议记录
void Inquire( fstream ); //按不同字段(会议编号)查询会议记录和浏览所
有会议记录信息
2.3 主要算法流程图
图2-2 主算法流程图
图2-3 添加会议算法流程图
图2-3 修改会议算法流程图
图2-4 删除会议算法流程图
3 程序清单及注释
#include
#include
#include
#include
struct Meetinglist //定义类 Meetinglist
{
char name[10] ;
char number[50] ;
char department[40] ;
char address[40] ;
char time[15] ;
char moderator[20] ;
char recoder [15] ;
char presentmembers [300] ;
char digest[500];
};
void Add ( fstream ) ; //添加会议记录
void modification ( fstream ) ; //修改会议记录
void Delete ( fstream ) ; //删除会议记录
void Inquire( fstream ); //按不同字段(会议编号)查询会议记录和浏
览所有会议记录信息
void main ( )
{ int choice ;
fstream field ( "F:\\aaa.dat" , ios::in|ios::out|ios::binary ) ;
if(!field)
{cerr<<"文件不能打开"<
return;
}
while ( choice )
{ cout << "**会议记录管理系统**\n" ;
cout << "1.添加会议记录:\n"
<< "2.修改会议记录:\n"
<< "3.删除会议记录:\n"
<< "4.按不同字段(会议编号)查询会议记录和浏览所有会议记录信息:\n"
<< "0.退出!\n" ;
do
{
cin >> choice ;
}
while ( choice != 0 && choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice !=5 ) ;
switch ( choice )
{
case 1 : Add ( field ) ; break ;
case 2 : modification ( field ) ; break ;
case 3 : Delete ( field ) ; break ;
case 4 : Inquire ( field ) ; break ;
case 0 : cout << "退出系统!\n" ; return ;
default:cout<<"输入错误,请重新输入\n";
}
}
field.close ( ) ;
}
void Add ( fstream f )
{
Meetinglist list ;
cout << "请输入会议名称:\n" ;
cin >> list.name ;
cout << "请输入会议编号(3位):\n" ;
cin >> list.number ;
cout << "請输入部门名称:\n" ;
cin >> list.department ;
cout << "请输入会议地点:\n" ;
cin >> list.address ;
cout << "请输入会议日期:\n" ;
cin >> list.time ;
cout << "请输入会议主持人:\n" ;
cin >> list.moderator ;
cout << "请输入会议记录人:\n" ;
cin >> list.recoder ;
cout << "请输入出席人员:\n" ;
cin >> list.presentmembers ;
cout << "请输入会议摘要:\n" ;
cin >> list.digest ;
f.write ( ( char* ) & list , sizeof ( Meetinglist ) ) ;
}
void modification ( fstream f )
{
Meetinglist List ;
int a = 0 ;
int m = 0 ;
int choice ;
char num[50] ;
char information[50] ;
f.seekg ( 0 , ios::end ) ;
long posEnd = f.tellg ( ) ;
f.seekg ( 0 , ios::beg ) ;
cout << "*请输入要修改会议记录的编号:*\n" ;
cin >> num ;
do
{
f.read ( ( char* ) & List , sizeof ( Meetinglist ) ) ;
for ( int i = 0 ; i < 50 ; i++ )
{
if ( num[i] == List.number[i] )
m++ ;
if ( num[i] != List.number[i] )
{
m = 0 ;
break ;
}
}
}
while ( m != 50 && posEnd != f.tellg ( ) ) ;
if ( m <= 50 )
cout << "*找到这个会议*\n"
<< "1.修改会议名称:\n"
<< "2.修改会议编号:\n"
<< "3.修改部门名称:\n"
<< "4.修改会议地点:\n"
<< "5.修改会议日期:\n"
<< "6.修改会议主持人:\n"
<< "7.修改会议记录人:\n"
<< "8.修改出席人员:\n"
<< "9.修改会议摘要:\n"
<< "0.退出:\n" ;
if ( m != 50 )
{
cout << "*没有这个会议*!\n" ;
return ;
}
while ( choice )
{
do
{
cin >> choice ;
}
while ( choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 5 &&
choice != 6 && choice != 7 && choice != 8 && choice != 9 && choice != 0 ) ;
switch ( choice )
{
case 1 : cin >> information ;
for ( a = 0 ; a < sizeof(List.name) ; a++ )
List.name[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 2 : cin >> information ;
for ( a = 0 ; a < sizeof(List.number) ; a++ )
List.number[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 3 : cin >> information ;
for ( a = 0 ; a < sizeof(List.department) ; a++ )
List.department[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 4 : cin >> information ;
for ( a = 0 ; a < sizeof(List.address) ; a++ )
List.address[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 5 : cin >> information ;
for ( a = 0 ; a < sizeof(List.time) ; a++ )
List.time[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 6 : cin >> information ;
for ( a = 0 ; a < sizeof(List.moderator) ; a++ )
List.moderator[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 7 : cin >> information ;
for ( a = 0 ; a < sizeof(List.recoder) ; a++ )
List.recoder[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 8 : cin >> information ;
for ( a = 0 ; a < sizeof(List.presentmembers) ; a++ )
List.presentmembers[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 9 : cin >> information ;
for ( a = 0 ; a < sizeof(List.digest) ; a++ )
List.digest[a]=information[a] ;
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & List , sizeof ( List ) ) ;
return ;
case 0 : cout << "退出!\n" ; return ;
}
}
}
void Delete ( fstream f )
{
Meetinglist list ;
int m = 0 ;
char a ;
char num[50] ;
char Fill[80] = { ' ' } ;
cout << "*请输入要删除的会议的编号Y/N:*" << endl ;
cin >> num ;
f.seekg ( 0 , ios::end ) ;
long posEnd = f.tellg ( ) ;
f.seekg ( 0 , ios::beg ) ;
do
{
f.read ( ( char* ) & list , sizeof ( Meetinglist ) ) ;
for ( int i = 0 ; i < 50 ; i++ )
{
if ( num[i] == list.number[i] )
m++ ;
if ( num[i] != list.number[i] )
{
m = 0 ;
break ;
}
}
}
while ( m != 50 && posEnd != f.tellg ( ) ) ;
if ( m <= 50 )
cout << "*找到这个会议*\n" ;
if ( m !=50 )
{
cout << "*没有这个会议!*\n" ;
return ;
}
cout << "*确定删除这个会议?*" << endl ;
do
{
cin >> a ;
}
while ( a != 'Y' && a != 'N' && a != 'y' && a != 'n') ;
if ( a == 'Y' || a == 'y' )
{
for ( int i = 0 ; i < sizeof(list.name) ; i++ )
{
list.name[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.number) ; i++ )
{
list.number[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.department) ; i++ )
{
list.department[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.address) ; i++ )
{
list.address[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.time) ; i++ )
{
list.time[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.moderator) ; i++ )
{
list.moderator[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.recoder) ; i++ )
{
list.recoder[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.presentmembers) ; i++ )
{
list.presentmembers[i] = Fill[i] ;
}
for ( i = 0 ; i < sizeof(list.digest) ; i++ )
{
list.digest[i] = Fill[i] ;
}
f.seekp(-long (sizeof(Meetinglist)),ios::cur) ;
f.write ( ( char* ) & list , sizeof ( list ) ) ;
return ;
}
if ( a == 'N' || a == 'n' )
return ;
}
void Inquire ( fstream f )
{int choice;
Meetinglist list ;
char num[50];
f.seekg( 0 , ios::end );
long posEnd = f.tellg();
cout<<"**查询会议资料**\n";
while (1)
{cout<<"请输入操作选项\n"
<<"1:按会议编号查询\t"
<<"2:浏览\t"
<<"0:退出\n";
cin>>choice;
switch ( choice )
{case 1:
{f.seekg( 0 , ios::beg );
cout<<"会议编号:\n";
cin>>num;
do
{f.read( (char*) & list , sizeof ( Meetinglist ) ) ;
} while (list.number !=num && f.tellg() != posEnd );
if (list.number == num)
cout<<list.number<<'\t'
<<list.name<<'\t'
<<list.department<<'\t'
<<list.address<<'\t'
<<list.time<<'\t'
<<list.moderator<<'\t'
<<list.recoder<<'\t'
<<list.presentmembers<<'\t'
<<list.digest<<endl;
else
{cout<<"*会议编号输入错误*\n";
continue;
}
break;
}
case 2:
{f.seekg ( 0 , ios::beg );
do
{f.read( (char*) & list , sizeof ( Meetinglist ) ) ;
cout<<list.number<<'\t'
<<list.name<<'\t'
<<list.department<<'\t'
<<list.address<<'\t'
<<list.time<<'\t'
<<list.moderator<<'\t'
<<list.recoder<<'\t'
<<list.presentmembers<<'\t'
<<list.digest<<endl;
}
while (list.number != num && f.tellg() != posEnd );
break;
}
case 0 : return;
}
}
}
4 运行结果与分析
图4-1 运行结果图(添加会议)
图4-2 运行结果图(按编号查询会议)
通过会议编号查询编号为2的会议
将编号为2的会议中 会议日期从2013.5.25改为2013.6.20
通过编号查询编号为2的会议记录
图4-3、4、5 运行结果图(修改会议记录)
图4-6 运行结果图(浏览所有会议记录)
图4-7 运行结果图(删除编号为2的会议记录)
5 总结
(课程设计过程中出现的问题及其解决方案,可扩充的功能及设计等。)
6 参考文献
[1]李爱华,程磊著. 面向对象程序设计(C++语言) .北京:清华大学出版社,2010
[2]刘振安,刘燕君著. C++程序设计课程设计. 北京: 机械工业出版社,2004
[3]谭浩强著. C++程序设计实践指导. 北京:清华大学出版社,2005