C++ 信息学奥赛总复习题答案解析(第一章)
第一章 答案解析
填空题
1.cpp
2.main()
3./* */ ,//
4.int a;
5.cout
知识点:
1.C++ 源文件的命名规范
2.C++ 程序的入口函数
3.C++ 注释的两种形式
4.变量声明的语法
5.输出语句的关键字
判断题
1.√
2.×
3.×
4.√
5.√
知识点:
1.C++ 是大小写敏感的语言
2.C++ 程序必须有一个 main 函数
3.注释不会被编译,不影响程序运行速度
4.变量使用前必须声明
5.输出语句中可以使用转义字符如 \n
选择题
1.C
2.A
3.A
4.D
5.C
知识点:
1.标识符的命名规则(以字母或下划线开头,由字母、数字、下划线组成)
2.cout 输出语句的正确用法
3.变量声明可以放在作用域内的任何位置
4.abc 不是 C++ 关键字
5.C++ 语句以分号结束
编程题
1.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"Hello,C++";
return 0;
}
知识点:基本的输入输出语句和程序结构
2.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
int a=10,b=20;
cout<<a+b;
return 0;
}
知识点:变量声明、赋值和算术运算
3.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
char s;
cin>>s;
cout<<int(s); //数据类型转换
return 0;
}
知识点:字符型数据的输入输出及 ASCII 码值的获取
4.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
int m=0;
for(int i=1;i<=100;i++){
m+=i;
}
cout<<m;
return 0;
}
知识点:for 循环的使用和累加运算
5.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<(a+b)/2;
return 0;
}
知识点:浮点型数据的输入输出和平均值计算