⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 right4-3.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<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>第 4 章</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                              
&nbsp;&nbsp;&nbsp; <span style="background-color: #CCFF99">第 4 章&nbsp; </span>&gt;<span style="background-color: #CCFF99"> 第   
3 节 </span>&gt;<span style="background-color: #CCFF99">    
 4.3 习题 </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></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></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></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include&lt;iostream.h&gt;</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include&lt;stdio.h&gt;</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include&lt;string.h&gt;</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">class   
    people //<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">{&nbsp;</font></p>
    <blockquote>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">long   
      number; //<font FACE="??ì?,SimSun" LANG="ZH-CN">身份证号</font>(<font FACE="??ì?,SimSun" LANG="ZH-CN">假设</font>long<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">char   
      name[20],sex; //<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">public:</font></p>
    <blockquote>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">people(long 
      num=0,char* n=&quot;\0&quot;,char s='m')</font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{   
      number=num; strcpy(name,n),sex=s; } //<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">void   
      p_show( )</font></p>  
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ 
      cout&lt;&lt;&quot;people: number=&quot;&lt;&lt;number;</font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout&lt;&lt;&quot; 
      name=&quot;&lt;&lt;name&lt;&lt;&quot; sex=&quot;&lt;&lt;sex&lt;&lt;endl; }</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">class   
    student:public people //<font FACE="??ì?,SimSun" LANG="ZH-CN">学生类,具有基类</font>people<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">{&nbsp;</font></p>
    <blockquote>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int   
      s_num; //<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">public:</font></p>
    <blockquote>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int   
      s_class; //<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">student(long   
      n,char* na,char s='m',int sn=0,int sc=0):people(n,na,s)</font></p>  
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{   
      s_num=sn; s_class=sc; } //<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">void   
      s_show( )</font></p>  
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ 
      cout&lt;&lt;&quot;student: &quot;&lt;&lt;endl;;</font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">p_show( 
      );</font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout&lt;&lt;&quot; 
      s_num=&quot;&lt;&lt;s_num&lt;&lt;&quot; 
      s_class=&quot;&lt;&lt;s_class&lt;&lt;endl; }</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">class   
    member:public people //<font FACE="??ì?,SimSun" LANG="ZH-CN">教工类,具有基类</font>people<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">{&nbsp;</font></p>
    <blockquote>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int   
      m_num; //<font FACE="??ì?,SimSun" LANG="ZH-CN">工号</font>---<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">public:</font></p>
    <blockquote>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">char   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -