c++
C++是一门强大的面向对象编程语言,由C语言发展而来,”++“意为更进一步发展,C++充分吸收了C语言的优点,同时汲取了面向对象的编程思想,其后拥有STL库的强大支撑,具有封装、继承、多态三大特性,常以高效能著称。
-
写出下面程序的执行结果:1)#include <iostream> using namespace std; class A { friend double count(A&); public: A(double t, double r):total(t),rate(r){} private: double total; double rate; }; double count(A& a) { a. total+=a.rate*a.total; return a.total; } int main(void) { A x(80,0.5),y(100,0.2); cout<<count(x)<<','<<count(y)<<'\n'; cout<<count(x)<<'\n';return 0; }2)#include<iostream> using namespace std; class Count { private: static int counter; int obj_id; public: Count(); //constructor static void display_total(); //static function void display(); ~Count(); //destructor }; int Count::counter; //definition of static data member Count::Count() //constructor { counter++; obj_id = counter; } Count::~Count() //destructor { counter--; cout<<"Object number "<<obj_id<<" being destroyed\n"; } void Count::display_total() //static function { cout <<"Number of objects created is = "<<counter<<endl; } void Count::display() { cout << "Object ID is "<<obj_id<<endl; } int main(void) { Count a1; Count::display_total(); Count a2, a3,a4; Count::display_total(); a2.display(); a4.display(); return 0; }3)#include <iostream > using namespace std; class BASE { char c; public: BASE(char n):c(n){} virtual ~BASE(){cout<<c;} }; class DERIVED:public BASE { char c; public: DERIVED(char n):BASE(n+1),c(n){} ~DERIVED(){cout<<c;} }; int main(void) { DERIVED('X'); return 0; }
-
改正下面程序段中的错误,写出整个正确的程序段template<T> void print(T *a) { cout<<a<<’\n’;} void main( ) { const int x=0; cout<<y<<’\n’; int y; x=5; int* p p=&y; print(p); return 0; }
-
下面程序为什么会编译错误,并改正错误(提出解决办法)。class window { protected: int basedata; }; class border: public window { }; class menu: public window { }; class border_and_menu: public border,public menu { public:int show() { return basedata; }
-
指出下列程序片段中的错误标号,写出正确语句或解释错在何处。1)①int index=675; ②const int *ptr=&index; ③int *const ntptr=&index; ④*ptr=555; ⑤*ntptr=666; ⑥int another=8; ⑦ptr=&another; ⑧ntptr=&another;2)①int arrp; ②arrp=new int[15]; ③delete arrp;
-
下面不属于C++的预定义的流对象是
-
如需要向一个二进制文件尾部添加数据,则该文件的打开方式为
-
若目前D盘根目录下并不存在test.txt文件,则下列打开文件方式不会自动创建test.txt文件的是
-
下列关于文件流的描述中,正确的是
-
打开文件时可单独或组合使用下列文件打开模式(①ios_base::app ②ios_base::binary ③ios_base::in ④ios_base::out),若要以二进制读方式打开一个文件,需使用的文件打开模式为
-
在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是
-
当使用ifstream流类定义一个流对象并打开一个磁盘文件时,文件的默认打开方式为
-
要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是
-
当使用ofstream流类定义一个流对象并打开一个磁盘文件时,文件的默认打开方式是
-
要利用C++流进行文件操作,必须在程序中包含的头文件是
-
如下函数的功能是从键盘输入的字符中统计数字字符的个数,用换行符结束输入,划线处缺失的部分是
-
语句ofstream f("SALARY.DAT", ios_base::app);的功能是建立流对象f,并试图打开文件SALARY.DAT与f关联,而且
-
下列控制对齐方式的操作符中,错误的是
-
下列语句都是程序运行时的第1条输出语句,其中一条语句的输出效果与其他三条语句不同,该语句是
-
下列控制格式输入输出的操作符中,能够设置浮点数精度的是
-
有如下程序(数组输出格式控制相关),运行时的输出结果是