单选题 C++
题号 #2604812

在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是(  )。

进入在线模考

参考答案

A

答案解析

streamoff定义于iostream.h中,定义有偏移量0ffset所能取得的最大值,seek—dir表示移动的基准位置,是一个有以下值的枚举:ios::be9:(文件开头)、ios::cur:(文件当前位置)、ios::end:(文件结尾)。

你可能感兴趣的试题

A.cout>>’A’表达式可输出字符A
B.eof()函数可以检测是否到达文件尾
C.对磁盘文件进行流操作时,必须包含头文件fstream
D.以ios_base::0ut模式打开的文件不存在时,将自动建立一个新文件
2 请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中包含一个源程序文件main.cpp,其中有类Book(“书”)和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
书名:C++语句程序设计总页数:299
已把“c++语言程序设计”翻到第50页
已把“c++语言程序设计”翻到第51页
已把“c++语言程序设计”翻到第52页
已把“c++语言程序设计”翻到第51页
已把书合上。
当前页:0
注意:只修改每个“//ERROR ***found***”下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
class Book{
char*title;
int num—pages;//页数
int cur_page;//当前打开页面的页码,0表示书未打开
public:
//ERROR***********found***********
Book(const char*theTitle,int pages)num_pages(pages)
{
title=new char[strlen(theTitle)+1];
strepy(title,theTitle);
cout<<endl<<”书名:”<<title
<<”总页数:”<<num_pages;
}
~Book(){delete[]title;}
bool isClosed()const{return cur_page==0;} //书合上时返回true,否则返回false
bool isOpen()const{return!isClosed();}//书打开时返回true,否则返回false
int numOfPages()const{return num_pages;}//返回书的页数
int currentPage()const{return cur_page;}//返回打开页面的页码
//ERROR***********found***********
void openAtPage(int page_no)const{ //把书翻到指定页
cout<<endl:
i“page_no<l Jj page_no>hum_pages){
tOUt<<”无法翻到第”<<cur page<<”页。”;
ClOSe();
}
else{
cur_page=page_n0;
tout<<”已把“"<<tide<<"”翻到第"<<cur page<<“页”;
}
}
void openAtPrevPage(){openAtPage(cur page—1);{//把书翻到上一页
void openAtNextPage(){openAtPage(cur_page+1);}//把书翻到下一页
void close(){//把书合上
tout<<endl:
if(isClosed())
tout<<"书是合上的。";
else{
//ERROR**********found**********
num_pages=0;
cout<<”已把书合上。”;
}
cOut<<endl:
}
};
int main(){
Book book(”C++语言程序设计”,299);
book.openAtPage(50);
book.openAtNextPage();
book.openAtNextPage();
book.openA.tPrevPage();
book.close();
tout<<”当前页:”<<book.currentPage()<<endl;
return 0:
}
3 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类0ffice的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
办公室房间号:308
办公室长度:5.6
办公室宽度:4.8
办公室面积:26.88
办公室所属部门:会计科
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“///料料found••料”。
#include<isotream>
using namespaee std;
class Room{ //“房间”类
int room_n0;//房间号
double length;//房间长度(m)
double width;//房间宽度(n1)
public:
Room(int the—room—n0,double the~length,double the—width):loom—no(the—room—no),length(the—
length),width(the—width){}
int theRoomNo()eonst{return iDonl—n0;}
//返回房间号
double theLength()const{return length;}//返回房间长度
double theWidth()const{return width;}//返回房间宽度
//**********found**********
double theArea()const{_______________}//返回房间面积(矩形面积)
};
class Office:public Room{//“办公室”类
char*depart;//所属部门
public:
Office(int the_room_n0,double the_length,double the_width,eonst char木the_depart)
//**********found**********
:_______________{
depart=new char[strlen(the depart)+1];
//**********found**********
strcpy(_______________);
}
~Office(){delete[]depart;}
const char*theDepartment()const{return depart;}//返回所属部门
};
int main(){
//**********found**********
Office_______________;
cout<<”办公室房间号:”<<au_office.theRoomNo()<<endl
<<”办公室长度:”<<an office.theLength()<<endl
<<”办公室宽度:”<<an 0ffice.theWidth()<<endl
<<”办公室面积:”<<an office.theArea()<<endl
<<”办公室所属部门:”<<all—office.theDepartment()<<endl;
return 0;
}
找试题 · 找答案 · 找资料 在线模考