리펙토링 해야 하는데 귀찮아서리.....ㅡ.ㅡ;;;;
~cpp #include <iostream> #include <fstream> #include <cmath> #include <string> using namespace std; #include <vector> class UserInfo { private: string szName; // User's name unsigned int nSchoolNumber; // User's school number public: UserInfo() {} UserInfo( string szN, unsigned int nSN ) { szName = szN; nSchoolNumber = nSN; } unsigned int getSchoolNumber() { return nSchoolNumber; } string getName() { return szName; } }; class BookInfo { private: int nBookNumber; string szBookName; string szWriter; string szPublishingCompany; bool bLone; UserInfo * pLendPeople; public: BookInfo() {} BookInfo( int nBN, string szBName, string szW, string szPC ) { nBookNumber = nBN; szBookName = szBName; szWriter = szW; szPublishingCompany = szPC; bLone = false; } int getBookNumber() { return nBookNumber; } string getBookName() { return szBookName; } string getWriter() { return szWriter; } string getPublishingCompany() { return szPublishingCompany; } void lendBook(UserInfo * pUi) { pLendPeople = pUi; bLone = true; } }; class DataBase { private: int nNextBookNumber; vector <UserInfo *> userinfo; vector <BookInfo *> bookinfo; public: DataBase() { // Read the number of Book... ifstream f; f.open("BookNumber.dat"); string szNextNum; while (!f.eof()) getline(f, szNextNum); unsigned int nTNN; double nTNN2; for (int k = 0 ; k < szNextNum.size() ; k++) // convert 'char' into 'int' { nTNN += ( szNextNum[k] - 48 ) * pow(10.0, nTNN2); nTNN2--; } nNextBookNumber = nTNN; f.close(); // end // Read data from UserData file... ifstream fin; fin.open("UserData.dat"); string szTemp; vector <int> nT; unsigned int nTempNum = 0; double nTempNum2 = 0.0; while (!fin.eof()) { getline(fin, szTemp); for (int i = 0 ; i < szTemp.size() ; i++) { if ( szTemp[i] == ',' ) nT.push_back(i); } string szTempNum(szTemp.begin(), szTemp.begin() + nT[0]); string szTempName(szTemp.begin() + nT[0] + 1, szTemp.size()); nTempNum2 = szTempNum.size() - 1; for (int j = 0 ; j < szTempNum.size() ; j++) // convert 'char' into 'int' { nTempNum += ( szTempNum[j] - 48 ) * pow(10.0, nTempNum2); nTempNum2--; } UserInfo * ui = new UserInfo(szTempName , nTempNum); userinfo.push_back(ui); } fin.close(); // end // Read data from BookData file... ifstream fin2; fin2.open("BookData.dat"); string szTemp2; vector <int> nT2; nTempNum = 0; nTempNum2 = 0.0; while (!fin2.eof()) { getline(fin2, szTemp2); for (int i = 0 ; i < szTemp2.size() ; i++) { if ( szTemp2[i] == ',' ) nT2.push_back(i); } // string 변수(배열 시작, 배열 마지막); string szTemp2BookNum(szTemp2.begin(), szTemp2.begin() + nT2[0]); string szTemp2BookName(szTemp2.begin() + nT2[0] + 1, szTemp2.begin() + nT2[1]); string szTemp2Writer(szTemp2.begin() + nT2[1] + 1, szTemp2.begin() + nT2[2]); string szTemp2PublishingCompany(szTemp2.begin() + nT2[2] + 1, szTemp2.size()); nTempNum2 = szTemp2BookNum.size() - 1; for (int j = 0 ; j < szTemp2BookNum.size() ; j++) // convert 'char' into 'int' { nTempNum += ( szTemp2BookNum[j] - 48 ) * pow(10.0, nTempNum2); nTempNum2--; } BookInfo * bi = new BookInfo(nTempNum , szTemp2BookName , szTemp2Writer , szTemp2PublishingCompany); bookinfo.push_back(bi); } fin2.close(); // end } void insertUserData(UserInfo * ui) { userinfo.push_back(ui); } void deleteUserData(int nUserNum) { for (int i = 0 ; i < userinfo.size() ; i++) { if ( userinfo[i]->getSchoolNumber() == nUserNum ) { userinfo.erase(userinfo.begin()+i); return; } } } void insertBookData(BookInfo * bi) { bookinfo.push_back(bi); } void deleteBookData(int nBookNum) { for (int i = 0 ; i < bookinfo.size() ; i++) { if ( bookinfo[i]->getBookNumber() == nBookNum ) { bookinfo.erase(bookinfo.begin()+i); return; } } } int getNextBookNumber() { nNextBookNumber++; return nNextBookNumber; } void showAll() { } };
잡담 ¶
음. 근데 이거 스펙대로 한건가? 스펙에는 linked list 아니면, array 쓰라고 한것 같은뎅..-_-a - 임인택