📄 right3-7.htm
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 3 章</title>
<base target="rbottom">
<style>
<!--
.右标题 { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容 { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin:
0 }
-->
</style>
</head>
<body>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><font size="2"><img border="0" src="1.gif" width="63" height="70"></font></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"> </font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left"><font size="2">
<span style="background-color: #CCFF99">第 3 章 </span>><span style="background-color: #CCFF99"> 第
7 节 </span>><span style="background-color: #CCFF99"> 3.7 习题</span></font></p>
<hr color="#008000" size="1">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1.
<font FACE="??ì?,SimSun" LANG="ZH-CN">面向对象程序设计的特点是什么?</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2.
<font FACE="??ì?,SimSun" LANG="ZH-CN">定义一个满足如下要求的</font>CDate<font FACE="??ì?,SimSun" LANG="ZH-CN">类。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">①</font>
<font FACE="??ì?,SimSun" LANG="ZH-CN">可以设置日期。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">②</font>
<font FACE="??ì?,SimSun" LANG="ZH-CN">日期的输出格式为:日</font>/<font FACE="??ì?,SimSun" LANG="ZH-CN">月</font>/<font FACE="??ì?,SimSun" LANG="ZH-CN">年。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">③</font>
<font FACE="??ì?,SimSun" LANG="ZH-CN">可进行在日期上加一天的运算。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">3.
<font FACE="??ì?,SimSun" LANG="ZH-CN">定义一个时间类</font>CTime<font FACE="??ì?,SimSun" LANG="ZH-CN">,编写成员函数设置和输出由时、分、秒组成的时间。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">4.
<font FACE="??ì?,SimSun" LANG="ZH-CN">定义一个字符串类</font>CString<font FACE="??ì?,SimSun" LANG="ZH-CN">,编写成员函数实现类的初始化,字符串对象的赋值,输出字符串等操作。并将类的定义和函数成员的定义放在不同的文件中。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">5.
<font FACE="??ì?,SimSun" LANG="ZH-CN">写出下列程序的输出结果。</font></font></p>
<blockquote>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include<iostream.h></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include<string.h></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int
i=1;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">class
Abc</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ </font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">char
a[10];</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int*p1,*p2;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">public:</font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Abc(
)</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ </font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout<<"constructor...i="<<i<<endl;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">strcpy(a,"ShangHai");</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">p1=new
int; *p1=100+i;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">p2=new
int; *p2=200+i;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">++i;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">~Abc(
)</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ </font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout<<"destructor...
";</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout<<"*p1="<<*p1<<"
*p2="<<*p2<<endl;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">delete
p1; delete p2;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">void
print( )</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ </font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout<<"a="<<a<<"
*p1="<<*p1<<" *p2="<<*p2<<endl;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">};</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int
main( )</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Abc
a1,a2; //<font FACE="??ì?,SimSun" LANG="ZH-CN">执行构造函数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">a1.print(
); a2.print( );</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return
0; //<font FACE="??ì?,SimSun" LANG="ZH-CN">执行析构函数</font></font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
</blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">6.
<font FACE="??ì?,SimSun" LANG="ZH-CN">创建一个</font>CWorker<font FACE="??ì?,SimSun" LANG="ZH-CN">类,该类中由字符数组表示姓名、街道地址、城市、省和邮政编码。将构造函数、</font>ChangeName(
)<font FACE="??ì?,SimSun" LANG="ZH-CN">、</font>Display( )<font FACE="??ì?,SimSun" LANG="ZH-CN">的函数原型放在类定义中,其中构造函数初始化每个数据成员,</font>ChangeName(
)<font FACE="??ì?,SimSun" LANG="ZH-CN">用以更改姓名,</font>Display( )<font FACE="??ì?,SimSun" LANG="ZH-CN">用于将完整的对象数据打印出来。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">7.
<font FACE="??ì?,SimSun" LANG="ZH-CN">写出下列程序的运行结果。</font></font></p>
<blockquote>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include<iostream.h></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include<stdio.h></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">class
A{ </font></p>
<blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -