教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

C++期末考试试卷答案(2)

来源:网络收集 时间:2026-09-01
导读: cout的距离是:d(p1,p2)endl; } 点(2,3)到点(4,5)的距离是:2.82843 5、将下列程序的运行结果写在右边空白位置 #includeiostream.h class T { public: T( int x) { a=x; b+=x;}; static void display( T c) {couta=c.

cout<<"的距离是:"<<d(p1,p2)<<endl; }

点(2,3)到点(4,5)的距离是:2.82843

5、将下列程序的运行结果写在右边空白位置

#include<iostream.h> class T { public:

T( int x) { a=x; b+=x;}; static void display( T c)

{cout<<"a="<<c.a<<'\t'<<"b="<<c.b<<endl;} private: int a;

static int b; };

int T::b=5; void main() { T A(3),B(5); T::display(A); T::display(B); }

a=3 b=13 a=5 b=13

四、程序设计题(4小题,每小题10分,共40分)

1、输入某学生成绩,若成绩在通常情况下85分以上输出"very good",若成绩在60分到85分之间输出"good",若成绩低于60分输出"no good"。 #include<iostream> using namespace std; void main() { }

int score;

cout<<"输入分数:"; cin>>score;

if(score>=85)cout<<"very good!"; else if(score>=60)cout<<"good!"; else cout<<"no good!";

2、编写一个程序,包含三个重载的display函数和一个主函数。要求第一个函数输出double 值,前面用字符串“a double:”引导,第二个函数输出 一个int值,前面用字符串“a int:”引导,第三个函数输出一个char字符值,前面用字符串“a char:”引导,在主函数中分别

计算机 c语言 c++ 期末考试真题

用double、int 和char型变量作为实参调用display函数。 #include<iostream> using namespace std; void display(double x) { }

cout<<"a double:"<<x;

void display(int x) { }

void display(char x) { }

void main() { display(1.345);cout<<endl;

display(3);cout<<endl; display('a');cout<<endl; cout<<"a char:"<<x; cout<<"a int:"<<x;

}

3、编写程序,按照指定长度生成动态数组,用随机数对数组元素赋值,然后逆置该数组元素。输出逆置前后的数组元素序列。要求逆置时不使用辅助数组。 #include<iostream> #include<ctime> #include<cstdlib> #include<iomanip> using namespace std; void main() {

int n;

cout<<"输入数组长度:"; cin>>n;

int *p=new int[n]; srand(unsigned(time(0))); for(int *a=p;a<p+n;++a) {

*a=rand()%n;

cout<<setw(3)<<*a;

} cout<<endl;

for(int i=0;i<n/2;++i)

计算机 c语言 c++ 期末考试真题

{

int t; t=*(p+i); *(p+i)=*(p+n-1-i); *(p+n-1-i)=t; }

for(int *b=p;b<p+n;++b) }

4、定义一个Student类,在该类定义中包括:一个数据成员score(分数) 及两个静态数据成员total(总分)和学生人数count;成员函数scoretalcount(float s)用于设置分数、求总分和累计学生人数;静态成员函数sum用于返回总分;静态成员函数average用于求平均值。

#include<iostream> #include<ctime> #include<cstdlib> #include<iomanip> using namespace std; class Student {

float score;

static float total; static int count; { }

cout<<setw(3)<<*b;

public: void scoretalcount(float s)

{ }

score=s; total+=s; ++count;

static float sum() {return total;}

static float average() {return total/count;} };

int Student::count=0; float Student::total=0; void main() {

Student s1,s2,s3;

s1.scoretalcount(80); s2.scoretalcount(70);

计算机 c语言 c++ 期末考试真题

}

s3.scoretalcount(60);

cout<<"总成绩为:"<<Student::sum(); cout<<endl;

cout<<"平均分为:"<<Student::average();

计算机 c语言 c++ 期末考试真题

《C++语言程序设计》答题纸

班级: 学号: 姓名:

1、 2、 3、 4、 5、

三、程序分析题:给出下面各程序的输出结果。 (5小题,每小题4 分,共20分 ) 1、 2、 3、 4、

一、单项选择题(用铅笔在正确的选项上涂黑)。

5、

计算机 c语言 c++ 期末考试真题

四、程序设计题(4小题,每小题10分

…… 此处隐藏:449字,全部文档内容请下载后查看。喜欢就下载吧 ……
C++期末考试试卷答案(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/90851.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)