




已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SEMIIC+作业:资料库管理系统 代码清单1、在TC+中编写以下代码文件Library.CPP,并运行工程;#include #include #include #include / The base class for books in the library.class book_clprotected:int book_cd;char book_nm30;char publisher30;public:/* Function to accept the details common to both books and periodicals. It takes the last book code as a parameter. */void getdata(int lcd)char check;cout nntADD NEW BOOK/PERIODICAL DETAILS endl;book_cd=lcd+1;cout nnBook code: book_cd endl;/ Verify that the book name is not left blank.check=n;while(check=n)cout endl Enter Book/Periodical name: ;cin.getline(book_nm, 30);if(strlen(book_nm)=0)cout nntBook/Periodical name must be entered.;elsecheck=y;/ Verify that the publisher name is not left blank.check=n;while(check=n)cout nEnter Publisher name: ;cin.getline(publisher, 30);if(strlen(publisher)=0)cout nntPublisher name must be entered.;elsecheck=y;/ Function to display the details common to books and periodicals.void dispdata(void)cout nCode: book_cd;cout tName: book_nm;/ The derived class for books in the library.class book:public book_clprotected:char author_nm30;char pubdate8;float price;char status;public:/* Function to accept the book specific details. It takes the last book code as a parameter. */void getdata(int lcode)char check;/ Invoke the function in the base class.book_cl:getdata(lcode);/ Verify that the author name is not left blank.check=n;while(check=n)cout nEnter Author Name: ;cin.getline(author_nm, 30);if(strlen(author_nm)=0)cout nntAuthor name must be entered.;elsecheck=y;cout pubdate;cin.ignore();/ Verify that the price is greater than 0.check=n;while(check=n)cout price;cin.ignore();if(price=0)cout nntBook price must be greater than 0.;elsecheck=y;/ Set the new books status as available. status=A;/ Function to display the details specific to books.void dispdata(void)book_cl:dispdata();cout tAuthor: author_nm;/ Function that returns the book getcode(void)return book_cl:book_cd;/ Function to set the book status to the value received as a parameter.void setstatus(char pstatus)status=pstatus;/ Function that returns the book status.char getstatus(void)return status;/ The derived class for periodicals in the library.class periodical:public book_clprotected:char periodicity;public:/* Function to accept the periodical specific details. It takes the last periodical code as a parameter. */void getdata(int lcode)char check;/ Invoke the function in the base class.book_cl:getdata(lcode);/ Verify that a valid periodicity is entered.check=n;while(check=n)cout periodicity;if(periodicity=a & periodicity=z)periodicity=periodicity-32;if(periodicity!=F & periodicity!=M & periodicity!=S & periodicity!=Y)cout nntPeriodicity must be entered as F for Fortnightly, M for Monthly,S for Six-monthly, and Y for Yearly;elsecheck=y;/ Function that returns the book getcode(void)return book_cl:book_cd;/ Function that returns the book name.char *getname(void)return book_cl:book_nm;/ The class for periodical issues in the library.class perissueprotected:int percode;int issno;char issdate8;float price;char status;public:/* Function to accept the details of an issue for a periodical.It takes the periodical code and issue number as parameters. */void getdata(int pcode, int issuenum)char check;percode=pcode;issno=issuenum;cout issdate;/ Verify that the price is greater than 0.check=n;while(check=n)cout price;if(price=0)cout nntIssue price must be greater than 0.;elsecheck=y;/ Set the new issues status as available. status=A;/* Function to display the details of the issue. It takes the periodical name as a parameter. */void dispdata(char *fbooknm)cout nCode: percode;cout tName: fbooknm;cout tIssue: issno;cout tIssue date: issdate;/ Function that returns the issue getissno(void)return issno;/ Function that returns the periodical getpercd(void)return percode;/ Function that returns the availability status of the issue.char getstatus(void)return status;/ Function to set the issue status to the value received as a parameter.void setstatus(char pstatus)status=pstatus;void main(void)int choice=0;/ Function declarations.void addbook(void);void addper(void);void issueret(void);void delissue(void);void viewavail(void);/ Loop to display the menu.while(choice!=6)system(cls);cout nntLIBRARY MANAGEMENT SYSTEM;cout nn1. Add new Book details;cout n2. Add new Periodical details;cout n3. Record Issue/Return details;cout n4. Delete old Periodical Issue details;cout n5. View Available Books/Periodicals;cout n6. Exit;cout choice;cin.ignore();/ Check user input menu choice and invoke appropriate function.if(choice=1)addbook();else if(choice=2)addper();else if(choice=3)issueret();else if(choice=4)delissue();else if(choice=5)viewavail();else if(choice=6)return;elsecout nntINVALID CHOICE! Valid choices are 1 to 6.;/ Function to accept and add new book details to the Book.dat file.void addbook(void)/ Declare objects of the book class.book book1, book2;int lastcode;system(cls);/ Open Book.dat file for reading.fstream finout(Book.dat, ios:in);if(!finout)cout Could not open Book.dat file.;return;/ Obtain the book code of the last book in the file.finout.seekg(0);while(finout.read(char *)&book1, sizeof(book1)lastcode=book1.getcode();/* If the details of the first book are being entered, set last book code to 0.*/if(lastcode0)lastcode=0;/ Close the file.finout.close();/* Invoke the function to accept book details and pass the last book code as a parameter to it. */book2.getdata(lastcode);/ Reopen Book.dat file for adding the new record.finout.open(Book.dat, ios:app);if(!finout)cout Could not open Book.dat file.;return;/ Write the new record to the file.finout.write(char *)&book2, sizeof(book2);/ Close the file.finout.close();return;/* Function to accept and add new periodical details to the Periodical.dat file, or new issue details to the Issue.dat file. */void addper(void)char reply, check;system(cls);/ Accept whether Periodical of Issue details are being input.check=n;while(check=n)cout reply;cin.ignore();if(reply!=P & reply!=I & reply!=p & reply!=i)cout nntPlease enter P for periodical entry or I for Issue entry.;elsecheck=y;if(reply=P | reply=p)/ Declare objects of the class periodical.periodical per1, per2;int lastcode;/ Open Periodical.dat file for reading.fstream finout(Periodical.dat, ios:in);if(!finout)cout Could not open Periodical.dat file.;return;/ Obtain the periodical code of the last periodical in the file.finout.seekg(0);while(finout.read(char *)&per1, sizeof(per1)lastcode=per1.getcode();/* If the details of the first periodical are being entered, set last book code to 0.*/if(lastcode0)lastcode=0;/ Close the file.finout.close();/* Invoke the function to accept periodical details and pass the last periodical code as a parameter to it. */per2.getdata(lastcode);/ Reopen Periodical.dat file for adding the new record.finout.open(Periodical.dat, ios:app);if(!finout)cout Could not open Periodical.dat file.;return;/ Write the new record to the file.finout.write(char *)&per2, sizeof(per2);/ Close the file.finout.close();return;else/ Declare objects of the class perissue and periodical.perissue issue1, issue2;periodical per1;int issnum1, issnum2, percd1, percd2;char check=n;fstream finout1, finout2;/ Open Periodical.dat file for reading.finout1.open(Periodical.dat, ios:in);if(!finout1)cout Could not open Periodical.dat file.;return;/* Accept the periodical code for which the issue details are being entered and ensure that it exists in Periodical.dat. */while(check=n)cout percd1;finout1.seekg(0);int j=0;while(finout1.read(char *)&per1, sizeof(per1)j+; percd2=per1.getcode();if(percd1=percd2)check=y;break;if(j=0)check=y;if(check=n)cout nntINVALID PERIODICAL CODE! Please re-enter.;/ Close the Periodical.dat file.finout1.close();/ Open Issue.dat file for reading.finout2.open(Issue.dat, ios:in);if(!finout2)cout Could not open Issue.dat file.;return;/* Accept the issue number and ensure that the issue details for the specified periodical do not exist in Issue.dat. */check=n;while(check=n)cout issnum1;finout2.seekg(0);int i=0;while(finout2.read(char *)&issue1, sizeof(issue1)i+;issnum2=issue1.getissno();percd2=issue1.getpercd();if(percd1=percd2 & issnum1=issnum2)check=n;break;elsecheck=y;if(i=0)check=y;if(check=n)cout nntISSUE DETAILS ALREADY EXIST! Please re-enter.;/ Close the Issue.dat file.finout2.close();/* Invoke the function to accept issue details and pass the inputperiodical code and issue number as parameters. */issue2.getdata(percd1, issnum1);/ Reopen Issue.dat file for adding the new record.finout2.open(Issue.dat, ios:app);if(!finout2)cout Could not open Issue.dat file.;return;/ Write the new record to the Issue.dat file.finout2.write(char *)&issue2, sizeof(issue2);/ Close the file.finout2.close();return;/* Function to record details of books or periodicals issued to library members */void issueret()char issueret, bookper, check=n;system(cls);/* Ask user whether the transaction is an issue or a return transaction. */while(check=n)cout nnRECORD ISSUE/RETURN;cout issueret;if(issueret!=I & issueret!=i & issueret!=R & issueret!=r)cout nntINVALID ENTRY. Enter I for Issue or R for Return.;elsecheck=y;/* Ask user whether the transaction is for a book or a periodical. */check=n;while(check=n)cout nnRECORD ISSUE DETAILS;cout bookper;if(bookper!=B & bookper!=b & bookper!=P & bookper!=p)cout nntINVALID ENTRY. Enter B for Book issue or P for Periodical Issue.;elsecheck=y;if(bookper=B | bookper=b)/ Declare object array of the book class to read data from the file.book bookarr100;int vbookcd1, vbookcd2, i,j, mesgflag;char vstatus;/ Open Book.dat for reading.fstream finout(Book.dat, ios:in);if(!finout)cout Could not open Book.dat file for reading.;return;finout.seekg(0);/ Read the book records into the object array.for(i=0;(finout.read(char *)&bookarri, sizeof(bookarri);i+) check=n;while(check=n)/ Accept the book code.cout vbookcd1;/ Loop to process the object array.for(j=0, mesgflag=0;ji;j+) / Obtain the book code of each object.vbookcd2=bookarrj.getcode();/ Check whether it matches the input book code.if(vbookcd1=vbookcd2)/ If it matches, obtain its availability status.vstatus=bookarrj.getstatus();/ If the book is being issued, display a message if it is not available.if(issueret=I | issueret=i)if(vstatus=I)cout nntThis book has been issued. Please reenter book code.;mesgflag=1;elsebookarrj.setstatus(I);check=y;/ If the book is being returned, display a message if it is already available.elseif(vstatus=A)cout nntThis book has not been issued. Please reenter book code.;mesgflag=1;elsebookarrj.setstatus(A);check=y;break;/ If the input book code is not found, display message.if(check=n & mesgflag=0)cout nntINVALID BOOK CODE! Please re-enter.;/ Close the Book.dat file.finout.close();/ Reopen the file for overwriting existing content.finout.open(Book.dat, ios:out);if(!finout)cout Could not open Book.dat file for updating.;return;/ Write the object array back to the file.for(j=0;ji;j+)finout.write(char *)&bookarrj, sizeof(bookarrj);/ Close the file.finout.close();else/ Declare object array of the perissue class to read data from the file.perissue issuearr100;int vpercd1, vpercd2, vissnum1, vissnum2, i,j, mesgflag;char vstatus;/ Open Issue.dat for reading.fstream finout(Issue.dat, ios:in);if(!finout)cout Could not open Issue.dat file for reading.;return;finout.seekg(0);/ Read the issue records into the object array.for(i=0;(finout.read(char *)&issuearri, sizeof(issuearri);i+) check=n;while(check=n)/ Accept the periodical code and issue number.cout vpercd1;cout vissnum1;/ Loop to process the object array.for(j=0, mesgflag=0;ji;j+) / Obtain the periodical code and issue number of each object.vpercd2=issuearrj.getpercd();vissnum2=issuearrj.getissno();/ Check whether both values match the input values.if(vpercd1=vpercd2 & vissnum1=vissnum2)/ If they match, obtain the availability status.vstatus=issuearrj.getstatus();/ If the periodical is being issued, display a message if it is not available.if(issueret=I | issueret=i)if(vstatus=I)cout nntThis Periodical has been issued. Please reenter Periodical code and Issue number.;mesgflag=1;elseissuearrj.setstatus(I);check=y;/ If the periodical is being returned, display a message if it is already available.elseif(vstatus=A)cout nntThis Periodical has not been issued. Please reenter Periodical code and Issue number.;mesgflag=1;elseissuearrj.setstatus(A);check=y;break;/ If the input periodical code and issue number is not found, display message.if(check=n & mesgflag=0)cout nntINVALID PERIODICAL CODE OR ISSUE NUMBER! Please re-enter.;/ Close the Issue.dat file.finout.close();/ Reopen the file for overwriting existing content.finout.open(Issue.dat, ios:out);if(!finout)cout Could not open Issue.dat file for updating.;return;/ Write the object array back to the file.for(j=0;ji;j+)finout.write(char *)&issuearrj, sizeof(issuearrj);/ Close the file.finout.close();/* Function that deletes outdated periodical issues from the Issue.dat file. */void delissue(void)/ Declare object array of the perissue class to read data from the file.perissue issuearr100;int vpercd1, vpercd2, vissnum1, vissnum2, i,j, delctr;/ Open Issue.dat for readin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年影视行业报告:工业化制作流程与质量控制关键节点解析
- 节后复工培训课件
- 教师招聘之《小学教师招聘》能力测试备考题及参考答案详解
- 教师招聘之《小学教师招聘》通关试卷提供答案解析附答案详解(基础题)
- 教师招聘之《幼儿教师招聘》模拟题库讲解及答案详解【全优】
- 演出经纪人之《演出经纪实务》模拟考试高能及完整答案详解(夺冠)
- 教师招聘之《小学教师招聘》提分评估复习及答案详解(全优)
- 2025年教师招聘之《幼儿教师招聘》练习题库包(含答案详解)
- 2025年教师招聘之《幼儿教师招聘》模拟题库完整答案详解
- 2025年教师招聘之《幼儿教师招聘》考前冲刺练习题库附参考答案详解(典型题)
- 耳鼻喉科眼科门诊临床技术操作规范2022版
- 党章党纪党规知识竞赛案例分析30题(含答案)
- 火力发电厂节水导则DLT783-2023年
- 艾滋病梅毒丙肝检测与解释
- GB/T 22076-2008气动圆柱形快换接头插头连接尺寸、技术要求、应用指南和试验
- GB/T 12325-2008电能质量供电电压偏差
- CJJ28-2014城镇供热管网工程施工及验收规范
- 新《高等教育学》考试复习题库450题(含各题型)
- 三字经全文带拼音注释打印版
- 产品技术规格书模板
- 《绿色建筑评价标准》解读
评论
0/150
提交评论