教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

c++复习资料及答案(2)

来源:网络收集 时间:2026-08-29
导读: 是 。 18、int **p; 的含义是 。 四、简答题 1、请用C++语言的表达式表示下列代数式。 (1) x3sin55???d (2) ea?b (e=2.71828) (3) a?b2?h?a?h?tb4 13(4) ea?b?sin50? (e=2.71828) (5) ln 2、根据要求完成下列各题。

是 。 18、int **p; 的含义是 。 四、简答题

1、请用C++语言的表达式表示下列代数式。

(1) x3sin55???d

(2) ea?b (e=2.71828) (3)

a?b2?h?a?h?tb4

13(4) ea?b?sin50? (e=2.71828) (5) ln

2、根据要求完成下列各题。

(1) 用两种方法实现一个字符串str,并赋以初值”welcome to Nanjing !”。

(2) 定义结构体类型date, 该结构体包含的成员为year (整型)、month (整型)、day(整型),再使用typedef

将结构体类型date等价成DATE,最后使用DATE定义一个变

6

x(a??a?x2)5

量pdate。

五、程序分析题

1、写出下列程序运行结果:

(1) #include \ (4分) void main( ) {int x=5,y=8,*px,*py; px=&x,py=&y;

cout<<\ if(x

cout<<\ if(x

cout<<\ if(x

cout<<\ }

swap1(int a,int b) {int t; t=a; a=b; b=t;

cout<<\ }

7

swap2(int *p,int *q) {int *t; t=p; p=q; q=t;

cout<<\ }

swap3(int *p,int *q) {int t;

t=*p;*p=*q;*q=t;

cout<<\ }

(2) #include “iostream.h” (3分) main(int argc,char *argv[ ]) { int i;

cout<<”argc=”<

for(i=0;i<=argc-1;i++) cout<

若上面的程序编译`连接后生成可执行文件ABC.EXE,

若输入以下命令行 abc filel file2 (表示回车) 文件的路径可以不考虑

(3) #include (4分)

8

注: class A { int a, b; public: A(){a=b=0;}

A( int aa , int bb ) : a(aa),b(bb)

{cout <<”a=”<

void main( )

{ A x , y(2 , 3) ; } //对象x , y消亡后分别自动调用析构函数~A( )

2、试分析下列程序或函数的功能。(4分) (1) #include \ void main( ) { char str[81],*sptr; int i;

for(i=0; i<80; i++) { str[i]=cin.get( ); if(str[i]=='\\n') break; } str[i]=’\\0’;

9

sptr=str;

while(*sptr) cout<<(*sptr++); }

3、程序改错题:(4分)

从键盘输入一个分数(0~100),判断它属于哪个分数段,并输出分数段字母代号。

#include main( )

{int num; char grade; cout<<“please input num:”; cin>>num;

if((grade>=90)&&(grade<==100) grade=”A”; cout<<“The grade is:”<

if (grade>=80) grade=”B”; cout<<“The grade is:”<

if (grade>=70) grade=”C”; cout<<“The grade is:”<

if (grade>=60) grade=”D”; cout<<“The grade is:”<

else grade=”E”; cout<<“The grade

10

c++复习资料及答案(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/591528.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)