Loading

小测反思:Exam 5 - Control Statement

问题

其他几道题都没有什么问题,基本都正确。主要问题出在第一道题:

1、(Question) /*
Find the sum of the first n items of the following score sequence,
2/1, 3/2, 5/3, 8/5, 13/8, 21/13, ...
*/

#include <iostream>
using namespace std;
int main(){
	【1】 ; //defined and initialize the a and b.
	float t=0, sum=0;
	int n=0;
	cout<<"Please enter the value of n:";
	cin>>n;
	for(int i=1; 【2】 ; i++){
		【3】 ; //Find the value of a
		b=a-b;
		t=a/b;
		sum=sum+t;
	}
	cout<<"sum="<<sum<<endl;
	return 0;
}

我的作答是:

【1】float a=2.0,b=1.0
【2】i<=n+1
【3】a=a+i-1

实际上,这样的输出是:

2/1
3/2
5/3
8/5
12/7
17/10
23/13
...

和预期的输出并不一样。主要原因是没有注意到这个级数本身的性质,分子等于前一项的分子和分母之和。考试时间太短,很紧张。

反思和总结

前面几次小测主要是结果判断题和结果输出题,答案的可预期性比较强,但是今天出题中有程序填空的题目,在短时间内测试紧张的情况下,没读懂程序本身的逻辑,非常容易出错。

启示接下来的高级语言学习中:

  • 善用ide
  • 要多复习常用、常考的代码片段(质数判断、从cin持续获取多个数字的输入、计算最小公倍数、最大公因数)
  • 多做 C++ 大学教程上面的练习题,多复习小测、作业、实验考过的题目
  • 小测的时候要带草稿纸和笔来教室……考试的时候是不能用ide的
posted @ 2025-10-21 11:45  kozumi  阅读(9)  评论(0)    收藏  举报