Sie sind auf Seite 1von 4

104 H34019011

This code can be compiled and run ok.


usage:
ContactType.h : provides the type of contact info about Family, Friends, Others.
ContactRec.h : provides the stucture of contact info about name, email, phone number and type.
Contact.cpp : provides the function for hw3.cpp, includes GetContactInfo(), PrintContactInfo(), Menu(),
GetOption().
hw3.cpp : provide users to use GetOption() to select five options :
(1) Add a new record about Name, Email, Phone
(2) Display the entire database from outData
(3) Display the database of Family
(4) Display the database of Friends
(5) Leave the program
Makefile : the file of compiling
Input file:
outData.txt : records the data about users Name, Email, Phone Number, Type
Output file:
outData.txt : records the data about users Name, Email, Phone Number, Type
compile:
make

pseudocode
//ContactType.h
enum ContactType {Family, Friends, Others};

//ContactRec.h
Create a stucture, including four variables name, email, tel, type;
Create an operator overloading of out.

//Contact.cpp
ContactRec GetContactInfo(){
Open the data file
Let users input name, email, and phone number, then check the format of email and phone number.
If their formats are wrong, ask users to input again.
Let users input type of record.
switch(the first character of type){
If it is F, and the second character of type is a, then the type of structure is Family, otherwise, it
is Friends.
If it is O, then the type of structure is Others.
}
Write these data into data file.
}
104 H34019011
void PrintContactInfo(int type){
Open the data file.
Judge the type in GetOption() that users input.
If type equals 0, set flag is 0; type equals 1, set flag is 1; type equals 2, set flag
is 2.
Read data into record.
While( if there is data){
If(the end of file) break;
Else{
Separate the record into name, email, phone, and Typ.
If type equals -1, print the entire database;
Else if Typ equals type, print the data of Family or Friends;
Read data into record.
}
}
}

int Menu(){
Provide five options to let users choose, and return the option.
}

void GetOption(){
Set a variable flag to store the value that Menu() return;
While(flag is not equal 5){
If flag equals 1, then call GetContactRec();
Else if flag equals 2, then call PrintContactRec(-1);
Else if flag equals 3, then call PrintContactRec(0);
Else if flag equals 4, then call PrintContactRec(1);
Set a variable flag to store the value that Menu() return;
}
}

//hw3.cpp
int main(){
Call GetOption();
}





104 H34019011
//Makefile
all: hw3.o
g++ hw3.o -o hw3 -llibboost_regex-mt
hw3.o: hw3.cpp
g++ -c hw3.cpp
clean:
rm -rf *.o

Test Case


104 H34019011




coded by Ting-Hui Fang(), ID: H34019011, email: H34019011@mail.ncku.edu.tw
date: 2013.3.13

Das könnte Ihnen auch gefallen