1、图书管理系统图书管理系统设计(C+)实习报告 学号: 班级: 姓名: 用C+设计一个小型的图书管理系统一、目的 1、学会在自己的软件工程中利用STL提供的成熟数据类型(class),这里主要要用的类有:ostream(包括两个对象cin与cout,以及读文件类ifstream与写文件类ofstream等)、string istringstream等;2、掌握冒泡法。掌握数据类型大小(operator )的重载,进而利用冒泡法对数据进行排序。3、重点学习文件读写方式。4、了解开发简单应用程序的全过程,包括:分析、设计、编程、调试和编写报告。二、摘要 1.可以预览所有图书的所有内容. 2.可以向系
2、统的任意地方插入图书. 3.可以删除任意一本图书. 4.可以用多种方试查找所耐须要的图书. 5.将图书信息保存到到文本文件中三、系统设计用记事本新建一文本文件,文件名为:“book.txt”,将某图书信息输入到这个文件中菜单系统图书管理系统保存删除退出添加查找预览 退出书名作者编号系统实现启动系统之后,出现如下界面:1 预览文本文件“book.txt”中的内容运行程序后,选择1(显示文本文件“book.txt”中的内容)2.查找运行程序后, 选择2进行查找.3添加、保存运行程序后,选择3进行添加并保存到”book.txt”中保存此时”book.txt”中的内容为5. 删除、保存程序如下1、图书
3、类: (1) 书籍类头文件内容#pragma once#include #include #include using namespace std;class CBookpublic: string ID; string name; string author; string press; string public_time; float price; CBook *next; friend ostream& operator (istream& input,CBook &book);(2) 书籍类实现文件内容#include stdafx.h#include CBook.hostream&
4、 operator (ostream& output, CBook&book) outputbook.ID setiosflags(ios:left)setw(8)book.name book.author book.presstsetw(12)book.public_time (istream& input,CBook &book) inputbook.ID book.name book.author book.press book.public_time book.price ; return input;2链表1) 链表类的头文件#include CBook.hclass Link CB
5、ook *head; CBook *p;public: int creat();/创建一个链表 int insert();/插入一本书 int del();/删除一本书 void find();/查找一本书 void show();/显示所有图书 void menu();/总菜单 void del_menu();/删除菜单 void insert_menu();/插入菜单 void find_menu();/查找菜单 void put_into_file();/写入文本文件中;2) 链表的实现#include stdafx.h#include Link.h#include CBook.h#in
6、clude #include #include #include using namespace std;int Link:creat () /创建一个链表 head=new CBook; p=head; char str255; ifstream infile(book.txt); if(!infile) cerropen error!*p; p-next =new CBook; p=p-next ; p-next =0; p=head; infile.close (); return 0;int Link:insert () /插入一本书 int num; while(1) insert_
7、menu(); CBook *q=new CBook; cinnum; if(num=1) cout*q; q-next =head; p=q; else if(num=2) cout*q; coutstr; while(p-name !=str) p=p-next ; q-next =p-next ; p-next =q; p=head; else break; p=head; return 0;int Link:del () /删除一本书 int num; while(1) del_menu(); cinnum; if(num=1) p=p-next ; else if(num=2) co
8、utstr; p=head; while(p-next-ID !=str) p=p-next ; CBook *q; q=p-next ; p-next =q-next ; p=head; else break; p=head; return 0;void Link:find () /查找一本书 int num; while(1) find_menu(); cinnum; if(num=1) coutstr; bool prime=false; while(p-next !=0) if(p-ID=str) prime=true; cout*pnext ; if(prime=false) cou
9、terror!this book is not exit!n; else if(num=2) coutstr; bool prime=false; while(p-next !=0) if(p-name =str) prime=true; cout*pnext ; if(prime=false) couterror!this book is not exit!n; else if(num=3) coutstr; bool prime=false; while(p-next !=0) if(p-author =str) prime=true; coutnext ; if(prime=false)
10、 couterror!this book is not exit!n; else if(num=4) coutstr; bool prime=false; while(p-next !=0) if(p-press =str) prime=true; cout*pnext ; if(prime=false) couterror!this book is not exit!n; else if(num=5) coutstr; bool prime=false; while(p-next !=0) if(p-public_time=str) prime=true; cout*pendl; p=hea
11、d; if(prime=false) couterror!this book is not exit!n; else if(num=0) break; else coutoperate error!next !=0) cout*pnext ; p=head; void Link:menu () cout*图书管理系统*n; cout*1.预览2.查找3.添加 4.保存 5.删除 0.退出endl; cout*n; coutendl; void Link:insert_menu() cout-按什么方式添加-n; cout*1.从头添加 2.从中间或末尾添加 0.退出添加n ; cout-n;
12、void Link:del_menu () cout-按什么方式删除-n; cout*1.从头删除 2.从中间或末尾删除 0.退出删除n ; cout-n; void Link:find_menu () cout-按什么方式查找-n; cout*1.编号.书名.作者.出版社.出版时间 0.退出查找endl; cout-n; void Link:put_into_file() ofstream outfile(book.txt); outfile.seekp (0,ios:beg ); outfile编号 书名 作者 出版社 出版时间 next -next !=0) outfile*pnext
13、; outfile*p; p=head; outfile.close (); 3.主函数/ 2008程序设计.cpp : 定义控制台应用程序的入口点。/#include stdafx.h#include CBook.h#include Link.h#include using namespace std;Link CB;int _tmain(int argc, _TCHAR* argv) CB.creat (); while(1) CB.menu (); coutnum; if(num=1) CB.show (); else if(num=2) CB.find (); else if(num=3) CB.insert (); else if(num=4) CB.put_into_file (); else if (num=5) CB.del (); else if(num=0) break; else couterror!endl; break; return 0;1. 将类的声明和成员函数的定义分离,体现封装性,也便于调试和改正。2. 用动态链表将不同的书连接起来,以便进行插入和删除等操作
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1