第一次编程作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/SE
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy/SE/homework/10283
这个作业的目标 中文语言编译器
作业正文 如下
其他参考文献 百度
Github链接地址 https://github.com/users/1458008768/projects/1

1.记录自己的代码行数,需求分析时间,编码时间。
行数:100行
分析时间:不详
编码时间:不详
对于以上作业很可能存在BUG,请谅解

2.分解需求的思路,分解成多个模块,并阐述为什么这么分,优势在哪,可以附上代码片段。

include

include

include

include

include

include

using namespace std;
int toint(string value) {
int len = value.size(), a = 0;
for (int i = 0; i < len; i+=2) {
if (value.substr(i, 2) == "零") a = a10 + 0;
if (value.substr(i, 2) == "一") a = a
10 + 1;
if (value.substr(i, 2) == "二") a = a10 + 2;
if (value.substr(i, 2) == "三") a = a
10 + 3;
if (value.substr(i, 2) == "四") a = a10 + 4;
if (value.substr(i, 2) == "五") a = a
10 + 5;
if (value.substr(i, 2) == "六") a = a10 + 6;
if (value.substr(i, 2) == "七") a = a
10 + 7;
if (value.substr(i, 2) == "八") a = a10 + 8;
if (value.substr(i, 2) == "九") a = a
10 + 9;
if (value.substr(i, 2) == "十") a = a10 + 10;
}
return a;
}
int main() {
map mp;
string var, value, word, oper, cmp, other;
string num[12] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
while (cin >> word) {
if (word == "整数") {
cin >> var >> other >> value;
mp[var] = toint(value);
} else if (word == "看看") {
cin >> var;
if (!mp.count(var)) {
if (var[0] == '"' && var[var.size()-1] == '"')
cout << var.substr(1,var.size()-2) << endl;
continue;
}
int temp = abs(mp[var]);
if (mp[var] < 0) cout << "负";
if (temp <= 10) {
cout << num[temp] << endl;
} else {
int ssum = 0, cnt = 0;
while (temp) {
ssum = ssum
10 + temp % 10;
temp /= 10;
++cnt;
}
while (cnt--) {
cout << num[ssum%10];
ssum /= 10;
}
cout << endl;
}
} else if (word == "如果") {
string digit, then, s1, s2, s3, s4, s5;
cin >> var >> cmp >> digit;
cin >> then >> s1 >> s2 >> s3 >> s4 >> s5;
if (s1 == "看看") {
int len1 = s2.size()-2;
int len2 = s5.size()-2;
if (cmp == "大于") {
if (mp[var] > toint(digit)) cout << s2.substr(1, len1) << endl;
else cout << s5.substr(1, len2) << endl;
} else if (cmp == "小于") {
if (mp[var] < toint(digit)) cout << s2.substr(1, len1) << endl;
else cout << s5.substr(1, len2) << endl;
}
} else {
if (cmp == "大于") {
if (mp[var] > toint(digit)) {
if (s2 == "减少") {
mp[s1] -= toint(s3);
} else if (s2 == "增加") {
mp[s1] += toint(s3);
}
} else;
} else if (cmp == "小于") {
if (mp[var] < toint(digit)) {
if (s2 == "减少") {
mp[s1] -= toint(s3);
} else if (s2 == "增加") {
mp[s1] += toint(s3);
}
} else;
}
}
} else if (mp.count(word)) {
cin >> oper >> value;
if (oper == "减少") {
mp[word] -= toint(value);
} else if (oper == "增加") {
mp[word] += toint(value);
}
}
}
return 0;
}

3.不足之处
编程能力较差,能力有限,无法依靠自己完成题目要求,求助同学和百度搜索。
github desktop还不会使用。
希望开学老师可以详细讲解,拜托了。

你可能感兴趣的:(第一次编程作业)