【C++代码】
include
include
include
using namespace std;
class AbstractFile{
protected:
string name; //文件或目录名称
public:
void printName(){cout$amp; virtual void addChild(AbstractFile *file)=0; //给一个目录增加子目录或文件}
virtual void removeChild(AbstractFile *file)=0; //删除一个目录的子目录或文件
virtual list *getChildren()=0; //获得一个目录的子目录或文件
};
class File:public AbstractFile{
public:
File(string name) {(1) = name;}
void addChild(AbstractFile *file){return;}
void removeChild(AbstractFile *file){return;}
(2) getChildren(){return (3) ;}
};
class Folder :public AbstractFile{
private:
list childList: //存储子目录或文件
public:
Folder(string name){ (4) name;}
void addChild(AbstractFile*file){childList.push_back(file);}
void removeChild(AbstractFile*file){childList.remove(file);}
list*getChildren(){return (5) ;}
};
void main(){
//构造一个树形的文件/目录结构
AbstractFile *rootFolder=new Folder("c:\\ ");
AbstractFile*compositeFolder=new Folder("composite");
AbstractFile *windowsFolder=new Folder("windows");
AbstractFile*file=new File("TestCompositejava");
rootFolder->addChild(compositeFolder);
rootFolder->addChild(windowsFolder);
compositeFolder->addChild(file);
}
时间:2023-12-12 11:51:15
相似题目
-
下列数据中合法的c++字符常量是()。
A . ’as’
B . ”a”
C . ’123’
D . ’\\&rsquo
-
下列Visual C++的说法正确的是:()。
A . A、Visual C++支持代码的优化的版本是:专业版和个人版
B . B、Visual C++支持代码的优化的版本是:个人版和企业版
C . C、Visual C++支持代码的优化的版本是:个人版和家庭版
D . D、Visual C++支持代码的优化的版本是:专业版和企业版
-
C++源程序文件的默认扩展名为()。
A、cpp
B、exe
C、obj
D、Lik
-
下面关于C++的说法,不正确的是()。
A . C++是由BjarneStroustrup博士开发成功的
B . C++保留了C语言原有的优点,增加了面向对象的机制
C . C++和C语言没有任何关系
D . C++与C语言兼容
-
C++语言
-
C++程序下列说法正确的有()
A . 对调用的虚函数和模板类都进行迟后编译
B . 基类与子类中函数如果要构成虚函数,除了要求在基类中用virtual声明,而且必须名字相同且参数类型相同返回类型相同
C . 重载的类成员函数都必须要:或者返回类型不同,或者参数数目不同,或者参数序列的类型不同
D . 静态成员函数和内联函数不能是虚函数,友员函数和构造函数也不能是虚函数,但是析构函数可以是虚函数
-
C++语言通过()来建立类族。
A . 类的嵌套
B . 类的继承
C . 虚函数
D . 抽象类
-
C++的优化技术包括:()。
A . A、可产生最小可执行代码的优化和可产生最简单逻辑的优化
B . B、可产生最简单逻辑的优化和可提高执行速度的优化
C . C、可产生最小可执行代码的优化和可提高执行速度的优化
D . D、可产生最少代码的优化和可提高执行速度的优化
-
在C++程序中,语句之间必须用()分隔。
-
C++属于应用软件。
A . 正确
B . 错误
-
下列常量中不能作为c++常量的是()。
A . 0382
B . 0xB4
C . .5e-2
D . 123
-
C++语言的预编译指令包括()
-
C++语言执行程序的开始执行点是().
-
编写一个简单的C++程序,输出“Hello!C++ program。”
-
在C++语言的结构化程序设计中,【6】是程序的基本组成单元;在C++语言的面向对象设计框架中
在C++语言的结构化程序设计中, 【6】 是程序的基本组成单元;在C++语言的面向对象设计框架中, 【7】 是程序的基本组成单元。
-
用 Visual C++ 6.0 编写的代码(unmanaged code),如何在 CLR 下和其他 dot net component 结合
用 Visual C++ 6.0 编写的代码(unmanaged code),如何在 CLR 下和其他 dot net
component 结合?
-
若期末评优条件要求VB与C++两门课程只要有一门95分以上即可,若a表示VB成绩,b表示C++成绩,则表达式是()
A.a>=95 and b>95
B.a>=95 or b>95
C.a or b>95
D.a and b>95
-
阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。 [说明] ①定义私有数据成员code、en
阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。
[说明]
①定义私有数据成员code、english分别用于表示考生的编号、英语成绩,它们都是int型的数据。
②完成成员函数void Student::inputinformation()的定义,该函数用于用户输入一个考生对象的信息,输入格式如下:
输入编号:
英语成绩:
计算机成绩:
③利用已实现的类Student的成员函数,完成函数void firstname(Student *A[],int uum)的定义,该函数根据考生信息A[],输出num个考生中总分最高者的编号及其相应的总分,在此不考虑总分相同的情况。
源程序文件test1.cpp清单如下:
include < iostream. h >
class Student
(1)
int computer;
int total;
public
void getinformation();
void computesum();
int getcode();
int gettotalscore();
~Student();
};
void Student: :getinformation()
{
(2)
cout <<"英语成绩:";
cin> >english;
cout <<"计算机成绩:";
cin > > computer;
void Student:: computesum ()
total = english + computer;
cout <<"编号" << code <<"总分:" <<total << endl;
int Student::getcode()
return code;
}
int Student:: gettotalscore ()
{
return total;
}
void firstname(Student * A[] ,int num)
{
(3)
tempsum = (* A[0] ). gettotalscore();
for(int i=1; i <num; i++)
{
if (((* A[i] ). gettotalscore() ) > tempsum)
{
tempcode = (* A[i] ). getcode();
tempsum = (* A[i] ). gettotalscore();
}
}
cout <<"总分最高者--" << tempcode <<":" << tempsum <<endl;
}
void main()
{
Student * A[3];
int i,n =3
for(i=0;i<n;i ++)
A[i] = new Student;
A[i] -> getinformation()
for(i=0;i<n;i ++)
{
A[i] -> computesum()
firstname (A,3 );
}
-
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【C++程序】
include < stdio. h >
include < string. h >
define Max 1000
class Bank
{
int index;
char date [Max] [10]; // 记录交易日
iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱
int rest[ Max]; // 记录每次交易后余额
static iht sum; // 账户累计余额
public:
Bank() {index =0;}
void deposit(char d[ ] , int m) //存入交易
{
strcpy (date [ index ], d);
amount[ index] = m;
(1);
rest[ index] = sum;
index++;
}
void withdraw (char d[ ], int m) //取出交易
{
strcpy(date[ index] ,d);
(2);
(3);
rest[ index] = sum;
index++;
}
void display();
};
int Bank:: sum = 0;
void Bank:: display () //输出流水
{
int i;
printf("日期 存入 取出 余额\n");
for (4)
{
printf(" %8s" ,date[i] );
if (5)
printf(" %6d" , -amount[i] );
else
printf("%6d ",amount[i] );
printf("% 6d\n" ,rest[i] );
} }
void main()
{
Bank object;
object. deposit ("2006.2.5", 1 00 );
object. deposit("2006.3.2" , 200);
object. withdraw("2006.4.1", 50);
object. withdraw("2006.4.5", 80);
object. display ();
}
本程序的执行结果如下:
日期 存入 取出 余额 2006.2.5 100 100
2006.3.2 200 300
2006.4.1 50 250
2006.4.5 80 170
-
请用150字以内的文字简要说明[C++代码1]、[C++代码2]这两种对传输门进行状态模拟的设计思路的区别之处。
-
以下说法中正确的是(48)。A.C++程序总是从第一个定义的函数开始执行B.C++程序总是从main函数开始
以下说法中正确的是(48)。
A.C++程序总是从第一个定义的函数开始执行
B.C++程序总是从main函数开始执行
C.C++函数必须有返回值,否则不能使用函数
D.C++程序中有调用关系的所有函数必须放在同一个程序文件中
-
在进行任何C++流的操作后,都可以用C++流的有关成员函数检测流的状态;其中只能用于检测输入流状态的操作函数名称是
A.fail
B.eof
C.bad
D.good
-
【简答题】用C++语言编写的代码程序_____。
-
有一段年代久远的C++代码,内部逻辑复杂,现在需要利用其实现一个新的需求,假定有以下可行的方案,应当优先选择()
A.修改老代码的接口,满足新的需求
B.将老代码抛弃,自己重新实现类似的逻辑
C.修改老代码的内部逻辑,满足新的需求
D.在这段代码之外写一段代码,调用该代码的一些模块,完成新功能需求