202103226-1 编程作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/computer-science-class1-2018
这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-science-class1-2018/homework/11877
这个作业的目标 理解软件工程在实际项目开发当中的使用
作业正文
其他参考文献 https://github.com/chjw8016/alibaba-java-style-guide/https://files-cdn.cnblogs.com/files/juking/腾讯Cplusplus编码规范.pdf/https://www.python.org/dev/peps/pep-0008/

1.Gitee仓库地址

https://gitee.com/hezhichao69/project-c/tree/master/

2.PSP表格

3.解题思路描述

看到这个题目,先处理文本文档输入输出,然后去掉不需要的汉字这个时候我们可以开始统计字符行了,只有汉字的因为去掉了所以没有了,当空行处理,然后就是把字符串分成一个一个的单词并且统计,当然有一个非常重要的事情就是,我们需要一个统计每一个的单词的数量以及在字典里面的顺序。

4.代码规范制定链接

https://gitee.com/hezhichao69/project-c/blob/master/codestyle.md

5.基本代码

#include <iostream>  
#include<sstream> 
#include <fstream>
#include <vector>
#include <string>

using namespace std;

string RemoveChinese(char* str);
int CharacterValue(vector<string> str);
int Validline(vector<string> str);


int main()
{
	vector<string> a;

	int words = 0;
	int sum = 0;
	char buffer[2560];
	string buyfferString; 

	ifstream in("input.txt");
	if (!in.is_open())
	{
		cout << "Error opening file"; exit(1);
	}
	while (!in.eof())
	{
		in.getline(buffer, 100);
		cout << RemoveChinese(buffer) << endl;

		a.push_back(RemoveChinese(buffer));

		if (RemoveChinese(buffer) != "")
		{
			sum++;
		}

		istringstream is(RemoveChinese(buffer));
		string s;
		while (is >> s)
		{
			words++;
		}
	}
	ofstream mycout("output.txt");
	cout << sum << endl;

	mycout << "characters:" << words << endl;

	mycout << "words:" << CharacterValue(a) << endl;

	mycout << "lines:" << a.size() << endl;

	mycout.close();

	return 0;
}

string RemoveChinese(char* str)
{
	string qwe;
	for (int i = 0; i < strlen(str); i++)
	{
		if (str[i] - '' >= 0 && str[i] - '' <= 127)
			qwe += str[i];
	}
	return qwe;
}

int CharacterValue(vector<string> str)
{
	int sum = 0;
	for (int i = 0; i < str.size(); i++)
	{
		sum += str[i].length();
	}
	return sum;
}

6.性能测试


我暂时没有写出单词的统计所以没有性能

7. 心路历程与收获

怎么说呢,这一次作业跟之前的作业比较,是有一定难度的,花了非常多的时间,并且让我看到我自己目前的水平,也遇到了非常多的问题,不断百度资料。

原文地址:https://www.cnblogs.com/he932206959/p/14607886.html