/**************************************************************************************** * KYU BAE project#3 * 212-04-5868 * * MembList.CPP * Definitons of memb.cpp * *****************************************************************************************/ #include "Memb.h" #include #include #include #include #include #include // global constants: const int MaxMember=25; const int STRG_SZ=4; /*************************************************************************************** * Constructor * Initialize the data member to zero. ****************************************************************************************/ ClubMember::ClubMember() { SetSurname ("00000"); SetFirstName ('0'); SetState ("00"); SetDate (00000000); SetJoinCode ('0'); SetContestNum(00000); SetAmountPaid(00.00); SetCategory ('0'); SetCodeNum (000000); SetArtist ("000000000"); SetTitle ("000000000"); } /**************************************************************************************** * Set function * Set the values of my data members * they returns nothing *****************************************************************************************/ void ClubMember::SetSurname(char SurnameIn[]) { strcpy(Surname,SurnameIn); } void ClubMember::SetFirstName(char FirstNameIn) { FirstName=FirstNameIn; } void ClubMember::SetState(char StateIn[]) { strcpy(State,StateIn); } void ClubMember::SetDate(long int DateIn) { Date=DateIn; } void ClubMember::SetJoinCode(char JoinCodeIn) { JoinCode=JoinCodeIn; } void ClubMember::SetContestNum(long int ContestNumIn) { ContestNum=ContestNumIn; } void ClubMember::SetAmountPaid(float AmountPaidIn) { AmountPaid=AmountPaidIn; } void ClubMember::SetCategory(char CategoryIn) { Category=CategoryIn; } void ClubMember::SetCodeNum(long int CodeNumIn) { CodeNum=CodeNumIn; } void ClubMember::SetArtist(char ArtistIn[]) { strcpy(Artist,ArtistIn); } void ClubMember::SetTitle(char TitleIn[]) { strcpy(Title,TitleIn); } /**************************************************************************************** * Get functions * These returns the values of data members *****************************************************************************************/ char* ClubMember::GetSurname( void) { return Surname; } char ClubMember::GetFirstName( void) { return FirstName; } char* ClubMember::GetState(void) { return State; } long int ClubMember::GetDate(void) { return Date; } char ClubMember::GetJoinCode(void) { return JoinCode; } long int ClubMember::GetContestNum(void) { return ContestNum; } float ClubMember::GetAmountPaid(void) { return AmountPaid; } char ClubMember::GetCategory(void) { return Category; } long int ClubMember::GetCodeNum(void) { return CodeNum; } char* ClubMember::GetArtist(void) { return Artist; } char* ClubMember::GetTitle(void) { return Title; } /**************************************************************************************** * File IO Function * Purpose: Read records from a file name entered from command line * Class: MemberList * ****************************************************************************************/ void MemberList::FileInput(char * fname) { ListSize = 0; MaxSize = MaxMember; ListPtr = new ClubMember[MaxSize]; ListTwoPtr= new ClubMember[MaxSize]; ifstream EntryFile(fname,ios::in,ios::nocreate); if (!EntryFile) { cout <<" File could not be opened!!!!\n"; cout <<"\n The program will end because you did n't provide data file names.\n"; cout <<" You must provide data file names at the command line!!!!\n\n"; exit (1); } else { int i = 0; char temp[81]; EntryFile.getline(temp,80,'\n'); while (!EntryFile.eof()) { ListPtr[i].SetSurname(temp); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetFirstName(temp[0]); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetState(temp); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetDate(atol(temp)); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetJoinCode(temp[0]); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetContestNum(atol(temp)); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetAmountPaid(atof(temp)); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetCategory(temp[0]); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetCodeNum(atol(temp)); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetArtist(temp); EntryFile.getline(temp,80,'\n'); ListPtr[i].SetTitle(temp); EntryFile.getline(temp,80,'\n'); i++; } ListSize = i; EntryFile.close(); } } /**************************************************************************************** * O FUNCTION: << * CLASS: Club Member * PURPOSE: Overload "<<" operator. print all record informations * RETURNS: ostream& ******************************************************************************************/ ostream& operator<< (ostream& output, const ClubMember& MemberRef) { output << setprecision(2) << setiosflags(ios::showpoint |ios::fixed) << setw(12) <=a;b--) { if(strcmp(ListTwoPtr[b-1].Surname,ListTwoPtr[b].Surname)>0) /*test if previous greater */ { temp=ListTwoPtr[b-1]; /* swap if adjacent are out of order */ ListTwoPtr[b-1]=ListTwoPtr[b]; /* swap pointers not the strings */ ListTwoPtr[b]=temp; } } } return; } /*************************************************************************************** * * Function: BinarySearch * Class: MemberList * search the arrays already sorted using the bubble sort. * Return integer ***************************************************************************************/ int MemberList::binarysearch(MemberList & Ref, char* searchkey, int low, int high, int size) { int middle; while (low <= high) { middle = (low + high)/2; if (strcmp(searchkey, ListTwoPtr[middle].Surname) ==0) //match return middle; else if (strcmp(searchkey, ListTwoPtr[middle].Surname) <0) high = middle -1; //searching low end of array else low = middle +1; //searching high end of array } return -1; } /***************************************************************************************** * Print functions: This function calls all outputs When called in dispaly function * Prints all records * Return: All Records entered *****************************************************************************************/ void MemberList::PrintAllRecord(MemberList & Storage) { char junk; cout <<"\n*********************" << endl; cout <<"* Records Entered: *" << endl; cout <<"*********************" << endl; cout <<"_____________________________________________________________________________" << endl; cout.precision(2); cout.setf(ios::showpoint | ios::fixed); cout < "; junk = cin.get(); cout <<"_____________________________________________________________________________" << endl; cout.precision(2); cout.setf(ios::showpoint | ios::fixed); cout <> * Class Clubmember * Overload ">>" enters record info by keyboard * returns : istream& ***************************************************************************************/ istream& operator>> (istream& input, ClubMember& MemberRef) { input.ignore(); cout << " Enter Last Name => "; //input>>MemberRef.Surname; input.getline(MemberRef.Surname, 80); if(!(MemberRef.Surname[0] =='\0')) { cout << " First Name Initial => "; input.get(MemberRef.FirstName); //input>>MemberRef.FirstName; input.ignore(); cout << " State => "; //input>>MemberRef.State; input.get(); input.getline(MemberRef.State,20); cout << " Date (YYYYMMDD) => "; input>>MemberRef.Date; //input.get(MemberRef.Date,20); cout << " JoinCode (Y/N) => "; input>>MemberRef.JoinCode; //input.getline(MemberRef.JoinCode,20); cout << " Amount Paid => $ "; input>>MemberRef.AmountPaid; //input.getline(MemberRef.AmountPaid, 20); cout << " Category (P, A, B, p, a, or b, etc.)=> "; input>>MemberRef.Category; //input.getline(MemberRef.Category,20); cout << " CodeNum => "; input>>MemberRef.CodeNum; //input.getline(MemberRef.CodeNum, 20); //input.ignore(); cout << " Artist => "; //input>>MemberRef.Artist; input.get(); input.getline(MemberRef.Artist,80); cout << " Title => "; //input.ignore(); //input>>MemberRef.Title; input.getline(MemberRef.Title,80); MemberRef.ContestNum=50000; } else strcpy (MemberRef.Surname, "NONE" ); return input; } /**************************************************************************************** * FUNCTION: MemberList() * CLASS: MemberList * PURPOSE: Constructor allocate the memory and tell you howmany records. * RETURNS: void. ******************************************************************************************/ MemberList::MemberList() { ListSize = 0; MaxSize = MaxMember; ListPtr = new ClubMember[MaxSize]; if (ListPtr == NULL) { exit(1); } } /**************************************************************************************** * FUNCTION: Enter() * CLASS: MemberList * PURPOSE: Enters records into database and this fuctions makes the output file name * calls "cdfile.dat". * RETURNS: void. *****************************************************************************************/ void MemberList::Enter() { int i=0; static long int _contestnum = 55555; char answer[STRG_SZ]; do { cin >> ListPtr[ListSize]; if (ListPtr[ListSize].Compare_Name("NONE")) { ListPtr[ListSize].SetContestNum(_contestnum+i); i++; ListSize++; } if (ListSize <= MaxSize) { cout << "\nDo you want to enter more names ?\n "; cin.getline(answer, STRG_SZ); } else { cout << "The list is full.\n"; answer[0] = 'n'; } } while (answer[0] != 'n'); ofstream outFile; outFile.open("cdfile.dat",ios::out); if(!outFile) { cerr<<"File could not be opened" <