2016/10/31
来源:互联网 发布:isp图像处理编程 编辑:程序博客网 时间:2024/05/01 12:28
1631-5 黄加勉 <2016.10.31> 【连续第30天总结】
A.今日任务
1.纯虚函数(100%)
2.抽象类(100%)
3.接口类(50%)
B.具体内容
1.只有声明没有函数体的虚函数是纯虚函数,格式为virtual 返回值 函数名(参数)= 0;
2.包含纯虚函数的类称为抽象类
3.抽象类不能用来实例化对象,这种属性会被继承,直到纯虚函数被定义
4.只有纯虚函数的类称为接口类,接口类更像是一种协议,一种属性,继承接口类的派生类包含了接口类定义的属性
5.两个程序,第一个尝试了纯虚函数和抽象类,还有一个是从字符串中删去某元素的算法
附代码:
/*虚函数和抽象类实验*/
#include <iostream>
#include <string>
using namespace std;
class caneat
{
public:
virtual void eat() = 0;
};
class canwork
{
public:
virtual void work() = 0;
};
class Person :public caneat, public canwork
{
public:
Person() {}
virtual ~Person() {};
};
class Worker :public Person
{
public:
Worker() {}
virtual ~Worker() {}
virtual void eat()
{
cout << "eat" << endl;
}
virtual void work()
{
cout << "work" << endl;
}
};
int main()
{
Worker *wk = new Worker();
wk->eat();
wk->work();
delete wk;
wk = NULL;
system("pause");
return 0;
}
/*字符串中删去某元素*/
#include <iostream>
#include <string>
using namespace std;
string sub(string str1, string str2);
int main()
{
string str1, str2;
cin >> str1;
cin >> str2;
cout << sub(str1, str2) << endl;
system("pause");
return 0;
}
string sub(string str1, string str2)
{
int i, j;
bool val = 1, flag = 0;
while (val)
{
val = 0;
int x = str1.size();
int y = str2.size();
for (i = 0; i < x - y + 2; i++)
{
if (str1[i] == str2[0])
{
int temp = i + 1;
for (j = 1; j < y; j++)
{
if (str1[temp] != str2[j]) break;
temp++;
}
if (j == y)
{
for (j = i; j < x; j++)
{
if (j < x - y)
{
str1[j] = str1[j + y];
}
else if (j >= x - y)
{
str1[j] = ' ';
}
}
val = 1;
flag++;
}
}
}
}
if (flag)
{
return str1;
}
else
{
return "this element is not included";
}
}
C.明日任务
1.接口类
2.RTTI
3.异常处理
A.今日任务
1.纯虚函数(100%)
2.抽象类(100%)
3.接口类(50%)
B.具体内容
1.只有声明没有函数体的虚函数是纯虚函数,格式为virtual 返回值 函数名(参数)= 0;
2.包含纯虚函数的类称为抽象类
3.抽象类不能用来实例化对象,这种属性会被继承,直到纯虚函数被定义
4.只有纯虚函数的类称为接口类,接口类更像是一种协议,一种属性,继承接口类的派生类包含了接口类定义的属性
5.两个程序,第一个尝试了纯虚函数和抽象类,还有一个是从字符串中删去某元素的算法
附代码:
/*虚函数和抽象类实验*/
#include <iostream>
#include <string>
using namespace std;
class caneat
{
public:
virtual void eat() = 0;
};
class canwork
{
public:
virtual void work() = 0;
};
class Person :public caneat, public canwork
{
public:
Person() {}
virtual ~Person() {};
};
class Worker :public Person
{
public:
Worker() {}
virtual ~Worker() {}
virtual void eat()
{
cout << "eat" << endl;
}
virtual void work()
{
cout << "work" << endl;
}
};
int main()
{
Worker *wk = new Worker();
wk->eat();
wk->work();
delete wk;
wk = NULL;
system("pause");
return 0;
}
/*字符串中删去某元素*/
#include <iostream>
#include <string>
using namespace std;
string sub(string str1, string str2);
int main()
{
string str1, str2;
cin >> str1;
cin >> str2;
cout << sub(str1, str2) << endl;
system("pause");
return 0;
}
string sub(string str1, string str2)
{
int i, j;
bool val = 1, flag = 0;
while (val)
{
val = 0;
int x = str1.size();
int y = str2.size();
for (i = 0; i < x - y + 2; i++)
{
if (str1[i] == str2[0])
{
int temp = i + 1;
for (j = 1; j < y; j++)
{
if (str1[temp] != str2[j]) break;
temp++;
}
if (j == y)
{
for (j = i; j < x; j++)
{
if (j < x - y)
{
str1[j] = str1[j + y];
}
else if (j >= x - y)
{
str1[j] = ' ';
}
}
val = 1;
flag++;
}
}
}
}
if (flag)
{
return str1;
}
else
{
return "this element is not included";
}
}
C.明日任务
1.接口类
2.RTTI
3.异常处理
0 0
- 2016/10/31
- 2016/10/31
- CVPR 2016-10-31
- 2016/10/31学习工作日志
- 2016/10/31 宝贝儿蛋,万圣节快乐。
- 写于2016年10月31日晚
- 2016年10月31日学习总结
- 1622-5 孔富晨 总结《2016年10月31日》 【连续第31日总结】
- 10-31
- 1508-张晨曦总结《2016年-10月-31日》【连续10天总结】
- LeetCode 2016 47,31
- 2016-3-31 笔记
- 2016-03-31
- 2016-03-31
- 2016-07-31
- 2016-07-31
- 2016-07-31
- 2016/8/31
- 修复U盘(未完)
- C++函数传参、函数指针的定义以及调用
- 离散傅里叶变换的推导
- HDG学习笔记
- Android开发中关于Spinner;Checkbox; RadioButton; EditText;怎样向其他Ativity传值
- 2016/10/31
- 图像分割结果的评估
- three.js环境下的一种飞线动画实现方法
- 网络编程(30)—— IP地址分类和子网掩码的作用
- JAVA中==和equals的区别
- 笑死了,打错一个字,竟然...
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhaubo
- 内存映射+矩阵
- prolog学习_修道士野人问题