姜子怡

计算与软件工程 作业四

作业四

作业要求

作业要求 https://edu.cnblogs.com/campus/jssf/infor_computation17-31/homework/10534
课程目标 深刻了解代码规范,通过组队进行结对编程
参考文献 https://blog.csdn.net/wdx1993/article/details/103654602 https://blog.csdn.net/wdx1993/article/details/103654602
作业正文

作业(1)

  • 截图

  • 总结
    什么样的代码是好代码,这个问题见仁见智,没有统一的标准去衡量,我认为主要有5个评价指标。代码的规模,执行效率,占用空间,可读性,扩展性。但由于我们是初学者追求的是简单,但往往如果程序规模较小的话,可读性就会相应的变差。代码规范被认为是评价代码的第一要素。对于我们来说养成良好的编写习惯至关重要,这对代码可读性有很大关系。当遇到代码量大的程序时,可以先以子功能为单位一点一点理解,静心研读。

作业(2) 结对编程

作业要求

  • 实现一个简单而完整的软件工具(中文文本文件人物统计程序):针对小说《红楼梦》要求能分析得出各个人物在每一个章回中各自出现的次数,将这些统计结果能写入到一个csv格式的文件。
  • 进行单元测试、回归测试、效能测试,在实现上述程序的过程中使用相关的工具。
  • 进行个人软件过程(PSP)的实践,逐步记录自己在每个软件工程环节花费的时间。
  • 使用源代码管理系统 (GitHub, Gitee, Coding.net, 等);
  • 针对上述形成的软件程序,对于新的文本小说《水浒传》分析各个章节人物出现次数,来考察代码。
    一开始只能单纯的统计单词词频出现的次数。
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include<cstdlib>
using namespace std;
//统计词频用map
void display_map(map<string,int> &wmap);
   
int main()
{
    using namespace std;
    string filename;
    cout << "Enter the file name : ";
    cin >> filename;
    cin.get();
    ifstream fin(filename.c_str());                    //  read  in  str[]
    string  temp;
    map<string,int> wmap;
    while(fin>>temp)
        wmap[temp]++;
    display_map(wmap);
   
    fin.close();
    cin.get();
    return 0;
}
   
void display_map(map<string,int> &wmap)
{
    map<string,int>::const_iterator map_it;
    for(map_it=wmap.begin();map_it != wmap.end();map_it ++)
    {
        cout << "(\"" << map_it->first << "\"," << map_it->second << ")" << endl;
    }
	system("pause");
}


通过网上搜寻发现有用java语言编写的程序

import jieba
list_12jinchai= ["黛玉", "宝钗", "元春", "探春", "惜春", "李纨","妙玉","凤姐", "秦可卿", "贾巧"]
list_yahuan = ["晴雯", "袭人", "麝月", "香菱", "司琪"]
list_jiafu = ["宝玉","贾敬", "贾赦", "贾政", "贾琏", "贾珍", "贾环"]
list_furen = ["贾母", "王夫人"]
lists = list_12jinchai + list_furen + list_jiafu + list_yahuan
for s in lists:
    jieba.add_word(s) # 目标分词
txt = open("红楼梦.txt", "r", encoding='utf_8').read() 
words = jieba.lcut(txt)
counts = {}
for word in words:
    if len(word) == 1: 
        continue
    elif word == "林妹妹" :
        rword == "黛玉"
    elif word == "老太太":
        rword == "贾母"
    else:
        rword = word
        counts[rword] = counts.get(rword,0) + 1
items = list(counts.items())
items1 = []
for s in items:
    if s[0] in lists:
        items1.append(s)  # 只显示目标人物  
items1.sort(key=lambda x:x[1], reverse=True)
for i in range(10):
    word, count = items1[i]
    print("{0:<10}{1:>5}".format(word, count))


但是自身没有运行出来。

关于水浒传的java程序,即将人物改成相应的《水浒传》主要人物即可。

  • 总结
    结对编程是一种敏捷软件开发的方法,两个程序员在一个计算机上共同工作,是极限编程的组成部分。一个人输入代码,称作驾驶员;另一个人负责审查工作,称作观察员(或导航员)。两人常互换角色。在结对编程中,观察员同时考虑工作的战略性方向,提出改进的意见,或将来可能出现的问题以便处理。整个项目的代码是团队共有,而不再是个人的。结对编程会带来纪律和时间管理的提升。

posted on 2020-04-04 20:01  ☆♡^O^  阅读(189)  评论(0编辑  收藏  举报

导航