大学c++试题带答案
四、读程序填空(每空2分,共10分)
1. ①k++ ②n%k==0
2. ③f=fac(n-1)*n
3. ④x=f ⑤num=t.num
五、编程题(第1题8分,第2题12分,共20分) 1.
#include<iostream>
using namespace std;
void main()
{
int i;
int s;
s=0; (2分)
for(i=0;i<50;i++)
{
s = s + 2*i+1; (4分)
}
cout<<"s="<<s<<endl; (2分)
}
2.参考程序
#include<iostream>
using namespace std;
class vehicle
{
public:
vehicle(int tmpWheels,int tmpWeight)
{
wheels = tmpWheels;
weight = tmpWeight;
}
virtual void print()
{
cout<<"vehicle:"<<endl;
cout<<"wheels:"<<wheels<<endl;
cout<<"weight:"<<weight<<endl;
}
private:
int wheels;
int weight;
};
2
6分) (