usage: hw1.cpp provide three options for users to use : (1) Add a new record about Name, Email, Phone (2) Display the entire database form outData (3) leave the program input file: outData.txt : records the data about users Name, Email, Phone Number output files: outData.txt : records the data about users Name, Email, Phone Number compile: g++ hw1.cpp -llibboost_regex-mt
pseudocode Menu (){ Provide three options: Add (), Display (), Exit cin >> flag; }
Add (){ // Provide user add a new data cin.ignore(100, \n); //cin getline(cin, name); // cin >> email; while(format of email is wrong) cin >> email; //check the format of email cin >> phone; while(format of phone is wrong) cin >> phone; //check the format of phone outData << name << email << phone << endl; }
Display (){ // Display the entire file while(inData){ /*check the inData is correct, then read it in if(inData.eof()) program; if read in the end, then break.*/ break; else{ if (inData) { //inData getline(inData, record); //inData cout << left << record; cout << endl; } } } 104 H34019011 } Main(){ Menu(); while(flag != 3){ /*user flag 3 if(flag == 1) Add(); */ else if(flag == 2) Display(); Menu(); } system("pause"); return 0; }
Test Case
104 H34019011
coded by Ting-Hui Fang(), ID: H34019011, email: H34019011@mail.ncku.edu.tw date: 2013.3.06