void main() { cout << "< CREATE DBMS >" << endl; Database database; database.GetInfo(); // 현재 라인 수 체크 int check; cin >> check; cin.ignore(1,'\n'); //cin 과 cin.getline의 \n 사용 방식이 다르므로 넣어줌. cin 으로 남아있는 \n 제거 if(check == 1) { char column1[30], column2[30]; cout << "첫번째 값을 입력하세요 : "; cin.getline(column1,30); /* for(int i = 0; i < 30; i++) { if(strcmp(column1[i],"")) { column1[i] = '\0'; } } */ // 비교 for(int i = 0; i < 30; i++) { column1[i] = '\0'; column2[i] = '\0'; } cout << endl << "두번째 값을 입력하세요 : "; cin.getline(column2,30); database.Insert(column1,column2); } else if(check == 2) { database.View(); } }
int main() { Database db; while(true) { cout << "A simple database program\n" << endl; cout << "(1) Add a record" << endl; cout << "(2) Show all record" << endl; cout << "(3) Search student(s) by name" << endl; cout << "(4) Output records to a text file" << endl; cout << "(5) Input records from a text file" << endl; cout << "(6) Exit the program" << endl << endl; cout << "Please select a function...>"; int opt=0; cin >> opt; system("cls"); switch(opt) { case 1: //add record { if(!db.isFull()) { cout << "Please input the required values:" << endl << endl; string name; cout << "Name (no space): "; cin >> name; char gender; cout << "Gender(M/F): "; cin >> gender; int age; cout << "Age: "; cin >> age; int scores[Student::MAX_SCORES]={0}; cout << Student::MAX_SCORES << " Scores: "; for(int i=0;i<Student::MAX_SCORES;++i) cin >> scores[i]; Student s(name, gender, age, scores); db.Insert(s); cout << endl << "Successfully add a record!" << endl << endl; } else cout << "Database is full." << endl; break; } case 2: //show record { cout << "There are " << db.size() << " records." << endl << endl; cout << db << endl; break; } case 3: //search name { string name; cout << "Please input the name of the student...>"; cin >> name; cout << endl; cout << "If the length of name is too long, it may ignore part sequence to fit the name field when searching." << endl << endl; Database result = db.Select(name); cout << "There is/are " << result.size() << " \"" << name << "\":" << endl << endl; cout << result << endl; break; } case 4: //output file { cout << "Out all records to a text file." << endl << endl; cout << "Note that the original data in the file will be lost after writing to the file. Are you sure that you want to continue? (Y/N)...>"; char ch='N'; cin >> ch; if(ch=='Y'||ch=='y') { cout << "Please input the name of the file...>"; string filename; cin >> filename; db.Export(filename); cout << endl << "Successfully export data to \"" << filename << "\"." << endl << endl; } else