The first programming job - Address Book

github repository Address:

https://github.com/fzugame/071708131.git

PSP table:

PSP2.1

Personal Software Process Stages

Estimated time consuming (minutes)

The actual time-consuming (minutes)

Planning

plan

 10

 10

· Estimate

• Estimate how much time this task requires

 10

 20

Development

Develop

 20

 30

· Analysis

· Needs analysis (including learning new technologies)

 320

 640

· Design Spec

Generate design documents

 20

 20

· Design Review

· Design Review

 60

 30

· Coding Standard

· Code specifications (development of appropriate norms for the current development)

10

 10

· Design

· Specific design

 60

 50

· Coding

· Specific coding

 560

 660

· Code Review

· Code Review

 30

 40

· Test

· Test (self-test, modify the code, submit modifications)

 90

 120

Reporting

report

 60

 60

· Test repor

· testing report

20

 20

· Size Measurement

· Computing workload

 10

 10

· Postmortem & Process Improvement Plan

· Hindsight, and propose process improvement plan

 10

 10

 

· Total

 1290

 1730

Program interface: 

       The computer reads the name of the country by municipalities, and regions manually processing files downloaded from the Internet to facilitate and document transcoding to Utf-8 encoding (Unicode rule). Setting a class to build cities index (province names are in the first few lines, a few lines below the province is the province under the city). Setting a class to store five address structure, create a class by class inheritance again to store seven address. Next row reads the input file name and phone number to give to get. When processing addresses, extract the word after the comma as the name of the file provinces than, than the success of the assignment complete province name (four municipalities directly assigned to the municipal units), followed by similar city name. District-level addresses based on the keyword "district or county" and other keyword matching, township, village, house number similar approach. 3 levels of difficulty incomplete missing parts, not implemented in the program, because of the need to call Maps API, which still has not learned.

The process as shown below:

 

The key functions and features

 

Person1::getaddress_simple 处理五级地址的函数
Person2::getaddress_left 处理剩余的三级地址
Indexes::Indexes 建立索引,便于比对
print_to_file 转码输出文件
change_to_w UTF-8转UNICODE

 

计算模块接口部分性能改进:

 

     这张图是性能改进后的截图,可以看到print_to_file这个函数做占用的时间是最多的因为print_to_file这个函数承担着将答案从Unicode编码转换到utf-8编码方式,并且打开文件按json格式输出,最后再关闭文件等功能,但是这些占用时间是正常的。在性能未改进前建立索引的时间是最长既 index类内按索引读取文件的函数,其次才是输出函数priint_to_file,最后我采用增加内存占用的方式来减少性能消耗即将全国省市区名称文件内容都存储在一个wstring数组内不仅不需要频繁的开关文件而且还加快了比对速度。改进后的函数如下:

Indexes::Indexes()
{
    wnum = 0;
    int p[34] = { 0,3,17,29,47,57,69,87,91,94,
        106,118,131,146,156,170,189,204,219,241,
        256,259,267,289,299,316,324,335,350,359,
        365,381,386,391 };
    for (int i = 0; i < 34; i++)
    {
        province[i] = p[i];
    }
    ifstream fin(FILENAME);
    string str;
    while (!fin.eof())
    {
        //cout << "1" << endl;
        getline(fin, str);
        pc[wnum++] = change_to_w(str);
    }
    fin.close();
    fin.clear();

}

 

 计算模块单元测试:

因为cpp评测工具两次导致电脑奔溃死机,所以就没有列出详细的数据,这里我贴出我的运行程序运行结果与答案对比

 

 

 可以看到答案对比基本正确说明程序的正确性。

处理地址的函数如下:

void Person1::getaddress_simple(wstring& wstr, char* argv, const Indexes& sone)
{
    int i = 2, mark = 0;
    while (wstr[i] != L',')i++;
    int len = (int)wstr.size();
    wstring result = L"\"地址\":[\"";

    //开始处理省级单位
    i++;
    int flag = 0;
    province = L"";
    while (flag < 2)
    {
        if (wstr[i] != L'!')
        {
            province = province + wstr[i];
            flag++;
        }
        i++;
    }
    if (province == L"北京" || province == L"重庆" || province == L"上海" || province == L"天津")
    {
        //cout << "hello" << endl;
        city = province + L"";
        while (wstr[i] == L'!' || wstr[i] == L'')
        {
            i++;
        }

    }
    else
    {
        wstring lin = L"";
        int j;
        for (j = 0; j < pnum; j++)
        {
            lin = lin + pc[sone.province[j]][0] + pc[sone.province[j]][1];
            if (province == lin)
            {
                //cout << "yes there is"<<endl;
                province = pc[sone.province[j]];
                break;
            }
            lin = L"";
        }
        mark = j;
        int len = (int)province.size();
        j = 2;
        while (j < len || wstr[i] == L'!')
        {
            if ((wstr[i] != L'!') && (wstr[i] != province[j]))break;
            else if ((wstr[i] != L'!') && (wstr[i] == province[j])) { j++; i++; }
            else i++;
        }

        //开始处理市级单位
        city = L"";
        city = city + wstr[i];
        i++;
        city = city + wstr[i];
        flag = 0;
        for (j = sone.province[mark] + 1; j < sone.province[mark + 1]; j++)
        {
            lin = L"";
            lin = lin + pc[j][0];
            lin = lin + pc[j][1];
            if (lin == city)
            {
                flag = 1;
                len = 0;
                city = L"";
                while (pc[j][len] != L':')
                {
                    city = city + pc[j][len];
                    len++;
                }
                break;
            }
        }

计算模块部分异常处理说明:

 异常情况就是在处理电话号码时如果电话号码在门牌号后面就会得到错误的电话,而且会出现程序异常终止的清况,最后我在处理电话号码的模块中加入判断机制如果没有11位就再次寻找直到找到正确的号码 最后成功解决了此项问题。

     

 

Guess you like

Origin www.cnblogs.com/xhongj/p/11608596.html