資源簡介
c++項目開發全程實錄 隨書源代碼 劉志銘
代碼片段和文件信息
#include?“Book.h“
#include?
#include?
#include?
#include?
using?namespace?std;
CBook::CBook(char*?cNamechar*?cIsbnchar*?cPricechar*?cAuthor)
{
strncpy(m_cNamecNameNUM1);
strncpy(m_cIsbncIsbnNUM1);
strncpy(m_cPricecPriceNUM2);
strncpy(m_cAuthorcAuthorNUM2);
}
char*?CBook::GetName()
{
return?m_cName;
}
void?CBook::SetName(char*?cName)
{
strncpy(m_cNamecNameNUM1);
}
char*?CBook::GetIsbn()
{
return?m_cIsbn;
}
void?CBook::SetIsbn(char*?cIsbn)
{
strncpy(m_cIsbncIsbnNUM1);
}
char*?CBook::GetPrice()
{
return?m_cPrice;
}
void?CBook::SetPrice(char*?cPrice)
{
strncpy(m_cPricecPriceNUM2);
}
char*?CBook::GetAuthor()
{
return?m_cAuthor;
}
void?CBook::SetAuthor(char*?cAuthor)
{
strncpy(m_cAuthorcAuthorNUM2);
}
void?CBook::WriteData()
{
ofstream?ofile;
ofile.open(“book.dat“ios::binary|ios::app);
try
{
ofile.write(m_cNameNUM1);
ofile.write(m_cIsbnNUM1);
ofile.write(m_cPriceNUM2);
ofile.write(m_cAuthorNUM2);
}
catch(...)
{
throw?“file?error?occurred“;
ofile.close();
}
ofile.close();
}
void?CBook::GetBookFromFile(int?iCount)
{
char?cName[NUM1];
char?cIsbn[NUM1];
char?cPrice[NUM2];
char?cAuthor[NUM2];
ifstream?ifile;
ifile.open(“book.dat“ios::binary);
try
{
ifile.seekg(iCount*(NUM1+NUM1+NUM2+NUM2)ios::beg);
ifile.read(cNameNUM1);
if(ifile.tellg()>0)
strncpy(m_cNamecNameNUM1);
ifile.read(cIsbnNUM1);
if(ifile.tellg()>0)
strncpy(m_cIsbncIsbnNUM1);
ifile.read(cPriceNUM2);
if(ifile.tellg()>0)
strncpy(m_cIsbncIsbnNUM2);
ifile.read(cAuthorNUM2);
if(ifile.tellg()>0)
strncpy(m_cAuthorcAuthorNUM2);
}
catch(...)
{
throw?“file?error?occurred“;
ifile.close();
}
ifile.close();
}
void?CBook::DeleteData(int?iCount)
{
long?respos;
int?iDataCount=0;
fstream?file;
fstream?tmpfile;
ofstream?ofile;
char?cTempBuf[NUM1+NUM1+NUM2+NUM2];
file.open(“book.dat“ios::binary|ios::in|ios::out);
tmpfile.open(“temp.dat“ios::binary|ios::in|ios::out|ios::trunc);
file.seekg(0ios::end);
respos=file.tellg();
iDataCount=respos/(NUM1+NUM1+NUM2+NUM2);
if(iCount?0?&&?iCount?>?iDataCount)
{
throw?“Input?number?error“;
}
else
{
file.seekg((iCount)*(NUM1+NUM1+NUM2+NUM2)ios::beg);
for(int?j=0;j<(iDataCount-iCount);j++)
{
memset(cTempBuf0NUM1+NUM1+NUM2+NUM2);
file.read(cTempBufNUM1+NUM1+NUM2+NUM2);
tmpfile.write(cTempBufNUM1+NUM1+NUM2+NUM2);
}
file.close();
tmpfile.seekg(0ios::beg);
ofile.open(“book.dat“);
ofile.seekp((iCount-1)*(NUM1+NUM1+NUM2+NUM2)ios::beg);
for(int?i=0;i<(iDataCount-iCount);i++)
{
memset(cTempBuf0NUM1+NUM1+NUM2+NUM2);
tmpfile.read(cTempBufNUM1+NUM1+NUM2+NUM2);
ofile.write(cTempBufNUM1+NUM1+NUM2+NUM2);
}
}
tmpfile.close();
ofile.close();
remove(“temp.dat“);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2931??2010-02-24?20:52??C++項目開發全程實錄\01\Book.cpp
?????文件???????1068??2013-01-10?16:35??C++項目開發全程實錄\01\book.dat
?????文件????????550??2010-02-24?20:49??C++項目開發全程實錄\01\Book.h
?????文件???????4865??2010-02-24?21:15??C++項目開發全程實錄\01\main.cpp
?????文件????????277??2010-03-23?13:28??C++項目開發全程實錄\01\readme.txt
?????文件???????4396??2010-02-19?21:16??C++項目開發全程實錄\01\Sample.dsp
?????文件????????535??2010-02-12?14:53??C++項目開發全程實錄\01\Sample.dsw
?????文件???????4508??2012-12-20?15:40??C++項目開發全程實錄\02\13.1\13.1.cpp
?????文件????7884800??2012-12-20?16:18??C++項目開發全程實錄\02\13.1\13.1.sdf
?????文件????????874??2012-12-20?14:50??C++項目開發全程實錄\02\13.1\13.1.sln
?????文件??????17408??2012-12-20?16:18??C++項目開發全程實錄\02\13.1\13.1.suo
?????文件???????4521??2012-12-20?15:08??C++項目開發全程實錄\02\13.1\13.1.vcxproj
?????文件???????1668??2012-12-20?15:08??C++項目開發全程實錄\02\13.1\13.1.vcxproj.filters
?????文件????????143??2012-12-20?14:50??C++項目開發全程實錄\02\13.1\13.1.vcxproj.user
?????文件????????236??2012-12-20?16:17??C++項目開發全程實錄\02\13.1\buyRecord.txt
?????文件????????402??2012-12-20?15:08??C++項目開發全程實錄\02\13.1\commodity.cpp
?????文件????????865??2012-12-20?15:17??C++項目開發全程實錄\02\13.1\commodity.h
?????文件?????147968??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.exe
?????文件????????406??2012-12-20?15:17??C++項目開發全程實錄\02\13.1\Debug\13.1.exe.em
?????文件????????472??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.exe.em
?????文件????????381??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.exe.intermediate.manifest
?????文件?????807108??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.ilk
?????文件????????102??2012-12-20?16:15??C++項目開發全程實錄\02\13.1\Debug\13.1.lastbuildstate
?????文件????????960??2012-12-20?16:15??C++項目開發全程實錄\02\13.1\Debug\13.1.log
?????文件?????360507??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.obj
?????文件????1179648??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.pch
?????文件????1354752??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\13.1.pdb
?????文件????????198??2012-12-20?15:17??C++項目開發全程實錄\02\13.1\Debug\13.1_manifest.rc
?????文件???????5986??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\cl.command.1.tlog
?????文件??????46826??2012-12-20?16:09??C++項目開發全程實錄\02\13.1\Debug\CL.read.1.tlog
............此處省略1114個文件信息
- 上一篇:C++大作業學生信息管理系統
- 下一篇:C+++編程藝術(教程+源碼)
評論
共有 條評論