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

📄 xt8.htm

📁 有关C++程序设计的复习资料
💻 HTM
📖 第 1 页 / 共 2 页
字号:
        <TBODY>
        <TR>
          <TD vAlign=top colSpan=2 height=30><IMG height=30 
            src="xt8.files/gai_02.gif" width=177></TD></TR>
        <TR>
          <TD width=41 height=4></TD>
          <TD width=134></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=left><A class=mb14 
            href="http://www.nuist.edu.cn/JSJ/syjx/sbcl.htm"> 申报材料</A></DIV></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=left><A class=mb14 
            href="http://www.nuist.edu.cn/JSJ/syjx/szll.htm"> 师资力量</A></DIV></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=center>
            <P align=left><A class=mb14 
            href="http://www.nuist.edu.cn/JSJ/syjx/jxcg.htm"> 教学成果</A></P></DIV></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=left><A 
            href="http://www.nuist.edu.cn/JSJ/syjx/jxkh.htm"> 教学考核</A></DIV></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=left><A class=mb14 
            href="http://www.nuist.edu.cn/JSJ/syjx/zwpj.htm"> 自我评价</A></DIV></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=left><A class=mb14 
            href="http://www.nuist.edu.cn/JSJ/syjx/jsgh.htm"> 建设规划</A></DIV></TD></TR>
        <TR>
          <TD height=26>
            <DIV align=right><IMG height=15 src="xt8.files/article_common.gif" 
            width=9></DIV></TD>
          <TD>
            <DIV align=left><A class=mb14 
            href="http://www.nuist.edu.cn/JSJ/syjx/jcxy.htm"> 教材选用</A></DIV></TD></TR>
        <TR>
          <TD height=2></TD>
          <TD></TD></TR></TBODY></TABLE></TD>
    <TD vAlign=top colSpan=2>
      <TABLE class=bg height=241 cellSpacing=0 cellPadding=0 width="100%" 
      border=0>
        <TBODY>
        <TR>
          <TD width="11%" height=33><IMG height=34 src="xt8.files/homedha.gif" 
            width=55><IMG height=34 src="xt8.files/homedhbg.gif" width=8></TD>
          <TD 
            width="89%"><!-- InstanceBeginEditable name="EditRegion4" --><SPAN 
            class=s14><STRONG>习题八</STRONG></SPAN><!-- InstanceEndEditable --></TD></TR>
        <TR>
          <TD colSpan=2><!-- InstanceBeginEditable name="EditRegion5" -->
            <TABLE cellSpacing=1 cellPadding=1 width="100%" border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV align=center>第8章 I/O流类库</DIV></TD></TR>
              <TR>
                <TD>
                  <P class=xt12>8.1 
                  文件的I/O由ifstream、ofstream和fstream提供。ifstream是istream的派生类,处理文件输入;ofstream是ostream的派生类,处理文件输出;fstream是iostream的派生类,可以同时处理文件的I/O。使用文件I/O类的程序需要包含头文件iostream.h</P>
                  <P class=xt12>8.2 若定义cin&gt;&gt;str; 当输入Object Windows 
                  Programming!,所得的结果是str=Object</P>
                  <P class=xt12>8.3 进行文件操作需要包括头文件fstream.h</P>
                  <P class=xt12>8.4 在磁盘文件操作中,打开磁盘文件的访问模式常量时, app 
是以追加方式打开文件的。</P>
                  <P class=xt12>8.5 关于getline()函数的下列描述中, 是错误的。<BR>A 
                  该函数是用来从键盘上读取字符串;<BR>B 该函数读取的字符串长度是受限制的;<BR>C 
                  该函数读取字符串时,遇到终止符时便停止;<BR>D 该函数中所使用的终止符只能是换行符;<BR>答:D</P>
                  <P class=xt12>8.6 下列关于read()函数的描述中, 是对的。<BR>A 
                  该函数是用来从键盘的输入获取字符串;<BR>B 该函数所获取的字符多少是不受限制的;<BR>C 
                  该函数只能用于文本文件的操作中;<BR>D 该函数只能按照规定读取所指定的字符串;<BR>答:D</P>
                  <P class=xt12>8.7 给出下列程序的执行结果<BR>#include 
                  &lt;iostream.h&gt;<BR>void 
                  main()<BR>{<BR> cout.fill(‘*’);<BR> cout.width(10);<BR> cout&lt;&lt;123.45&lt;&lt;endl;<BR> cout.width(8);<BR> cout&lt;&lt;123.45&lt;&lt;endl;<BR> cout.width(4);<BR> cout&lt;&lt;123.45&lt;&lt;endl;<BR>}<BR>答:****123.45<BR>**123.45<BR>123.45</P>
                  <P class=xt12>8.8 给出下列程序的执行结果。<BR>#include 
                  &lt;iostream.h&gt;<BR>#include &lt;fstream.h&gt;<BR>#include 
                  &lt;stdlib.h&gt;<BR>void main()<BR>{<BR> fstream 
                  file;<BR> file.open(“text1.dat”,ios::in|ios::out);<BR> if(!file)<BR> {<BR>  cout&lt;&lt;”text1.dat 
                  can’t open”&lt;&lt;endl;<BR>  abort();<BR> }<BR> char 
                  textline[]=”123456789\nabcdefghi\0”;<BR> for(int 
                  i=0;i&lt;sizeof(textline);i++)<BR> file.put(textline[i]);<BR> file.seekg(0);<BR> char 
                  ch;<BR> while 
                  (file.get(ch))<BR> cout&lt;&lt;ch;<BR> file.close();<BR>}</P>
                  <P class=xt12>答:123456789<BR>abcdefghi</P>
                  <P class=xt12>8.9 给出下列程序的执行结果<BR>#include 
                  &lt;iostream.h&gt;<BR>#include &lt;fstream.h&gt;<BR>#include 
                  &lt;stdlib.h&gt;<BR>void main()<BR>{<BR> char ch;<BR> fstream 
                  file;<BR> file.open(“abc.dat”,ios::out|ios::in|ios::binary);<BR> if(!file)<BR> {<BR>  cout&lt;&lt;”abc.dat文件不能打开”&lt;&lt;endl;<BR>  abort();<BR> }<BR> file&lt;&lt;”12 
                  34 
                  56”&lt;&lt;endl;<BR> file.seekg(0,ios::beg);<BR> while(!file.eof())<BR> {<BR>  streampos 
                  here=file.tellg();<BR>  file.get(ch);<BR>  if(ch==’ 
                  ’)<BR>  cout&lt;&lt;here&lt;&lt;” 
                  ”;<BR> }<BR> cout&lt;&lt;endl;<BR>}<BR>答:2 5</P>
                  <P class=xt12>8.10 
                  编写一个程序将data.dat文件中的内容在屏幕上显示出来并拷贝到data1.dat文件中。<BR>#include 
                  &lt;iostream.h&gt;<BR>#include &lt;fstream.h&gt;<BR>#include 
                  &lt;stdlib.h&gt;<BR>void main()<BR>{<BR> char ch;<BR> fstream 
                  infile,outfile;<BR> infile.open(“data.dat”,ios::in);<BR> if(!infliel)<BR> {<BR>  cout&lt;&lt;”data.dat文件不能打开”&lt;&lt;endl;<BR>  abort();<BR> }<BR> outfile.open(“data1.dat”,ios:out);<BR> if(!outfile)<BR> {<BR>  cout&lt;&lt;”data1.dat文件不能打开”&lt;&lt;endl;<BR>  abort();<BR> }<BR> while(infile.get(ch))<BR> {<BR>  cout&lt;&lt;ch;<BR>  outfile.put(ch);<BR> }<BR> cout&lt;&lt;endl;<BR> infile.close();<BR> outfile.close();<BR>}</P>
                  <P class=xt12>8.11 编写一个程序,统计文件abc.txt的字符个数<BR>#include 
                  &lt;iostream.h&gt;<BR>#include &lt;fstream.h&gt;<BR>#include 
                  &lt;stdlib.h&gt;<BR>void main()<BR>{<BR> fstream 
                  file;<BR> file.open(“abc.txt”,ios::in);<BR> if(!file)<BR> {<BR>  cout&lt;&lt;”abc.txt 
                  can’t be opened”&lt;&lt;endl;<BR>  abort();<BR> }<BR> char 
                  ch;<BR> int 
                  i=0;<BR> while(!file.eof())<BR> {<BR>  file.get(ch);<BR>  i++;<BR> }<BR> cout&lt;&lt;”文件字符个数:”&lt;&lt;i&lt;&lt;endl;<BR> file.close;<BR>}<BR>8.12 
                  编写一个程序,将abc.txt文件的所有行加上行号后写到abc1.txt文件中。<BR>#include 
                  &lt;iostream.h&gt;<BR>#include &lt;fstream.h&gt;<BR>#include 
                  &lt;stdlib.h&gt;<BR>void main()<BR>{<BR> fstream 
                  outfile,infile;<BR> infile.open(“abc.txt”,ios::in);<BR> if(!infile)<BR> {<BR>  cout&lt;&lt;”abc.txt 
                  can’t be 
                  opened!”&lt;&lt;endl;<BR>  abort();<BR> }<BR> outfile.open(“abc1.txt”,ios::out);<BR> if(!outfile)<BR> {<BR>  cout&lt;&lt;”abc1.txt 
                  can’t be created”&lt;&lt;endl;<BR>  abort();<BR> }<BR> char 
                  buf[80];<BR> int 
                  i=0;<BR> while(!infile.eof())<BR> {<BR>  infile.getline(buf,sizeof(buf));<BR>  outfile&lt;&lt;i++&lt;&lt;”:”&lt;&lt;buf&lt;&lt;endl;<BR> }<BR> cout&lt;&lt;”abc.txt=&gt;abc1.txt 
                  转换成功”&lt;&lt;endl;<BR> infile.close();<BR> outfile.close();<BR>}</P>
                  <P class=xt12>8.13 
                  编写一个程序对于上题建立的data.dat文件按照记录号进行查询并显示。<BR>#include 
                  &lt;iostream.h&gt;<BR>#include &lt;fstream.h&gt;<BR>#include 
                  &lt;stdlib.h&gt;<BR>struct student<BR>{<BR> int no;<BR> char 
                  name[10];<BR> double degree;<BR>};<BR>void main()<BR>{<BR> int 
                  i;<BR> student stud;<BR> fstream 
                  file;<BR> file.open(“data.dat”,iso::in|ios::binary);<BR> cout&lt;&lt;”输入记录号:”;<BR> cin&gt;&gt;i;<BR> int 
                  pos=(i-1)*sizeof(student);<BR> file.seekg(pos);<BR> file.read((char 
                  *)&amp;stud,sizeof(student));<BR> cout&lt;&lt;stud.no&lt;&lt;”\t”&lt;&lt;stud.name&lt;&lt;”\t”&lt;&lt;stud.degree&lt;&lt;endl;<BR> file.close();<BR>}<BR></P></TD></TR></TBODY></TABLE><!-- InstanceEndEditable --></TD></TR></TBODY></TABLE></TD></TR>
  <TR vAlign=center bgColor=#eeeeee>
    <TD colSpan=3 height=28>
      <DIV align=center><A 
      onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.nuist.edu.cn')" 
      href="http://www.nuist.edu.cn/JSJ/syjx/xt/xt8.htm#"><SPAN 
      class=mb14>设为首页</SPAN></A><STRONG>|</STRONG><A class=mb14 
      href="javascript:addme()">加入收藏</A><STRONG>|</STRONG><A 
      href="http://www.nuist.edu.cn/"><SPAN 
      class=mb14>学校首页</SPAN></A><STRONG>|</STRONG><A 
      href="http://www.nuist.edu.cn/jsj"><SPAN 
    class=mb14>计科系首页</SPAN></A></DIV></TD></TR>
  <TR>
    <TD class=mb14 vAlign=top bgColor=#176bab colSpan=2 height=88>
      <DIV align=center><BR><FONT color=#ffffff>Copyright&copy; 2004-2005 Depart of 
      Computer Science &amp; Technology Nuist</FONT></DIV></TD>
    <TD width=15 bgColor=#176bab>&nbsp;</TD></TR>
  <TR>
    <TD height=1></TD>
    <TD width=581></TD>
    <TD></TD></TR></TBODY></TABLE><MAP name=Map><AREA shape=RECT coords=9,9,75,25 
  href="http://www.nuist.edu.cn/JSJ/syjx/index.htm"><AREA shape=RECT 
  coords=86,9,150,26 href="http://www.nuist.edu.cn/JSJ/syjx/jxdg.htm"><AREA 
  shape=RECT coords=157,9,220,27 
  href="http://www.nuist.edu.cn/JSJ/syjx/skja.htm"><AREA shape=RECT 
  coords=230,9,310,26 href="http://www.nuist.edu.cn/JSJ/syjx/dmt.htm"><AREA 
  onclick="MM_goToURL('parent','../xt.htm');return document.MM_returnValue" 
  shape=RECT coords=320,10,397,26 
  href="http://www.nuist.edu.cn/JSJ/syjx/xt.htm"><AREA 
  onclick="MM_showHideLayers('Layer1','','hide','Layer2','','show')" shape=RECT 
  coords=405,10,469,25 href="http://www.nuist.edu.cn/JSJ/syjx/xt/xt8.htm#"><AREA 
  onclick="MM_showHideLayers('Layer1','','show','Layer2','','hide')" shape=RECT 
  coords=476,10,538,26 href="http://www.nuist.edu.cn/JSJ/syjx/xt/xt8.htm#"><AREA 
  shape=RECT coords=549,10,612,26 
  href="http://www.nuist.edu.cn/JSJ/syjx/ckwx.htm"><AREA shape=RECT 
  coords=620,9,684,26 
href="http://www.nuist.edu.cn/JSJ/syjx/zlxz.htm"></MAP></CENTER><!-- InstanceEnd --></BODY></HTML>

⌨️ 快捷键说明

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