1 Star 0 Fork 0

Sjianzhao / C++学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
流.cpp 2.63 KB
一键复制 编辑 原始数据 按行查看 历史
Sjianzhao 提交于 2021-04-06 18:34 . update
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
#define examp_1 0
#define examp_2 1
#define examp_3 1
#define examp_4 1
#define examp_5 1
#define examp_6 1
#define examp_7 1
#define examp_8 1
#if examp_1
//多态性:同一个消息,在不同的对象中可以实现不同的行为
typedef class jz_std1
{
private:
float x, y;
protected:
public:
jz_std1(float a, float b) :x(a), y(b) { ; }
~jz_std1() { }
void get_value(float a, float b)
{
x = a;
y = b;
}
float outX() const { return x; }
float outY() const { return y; }
}jz_std;
typedef class jz_std2 :public jz_std1
{
private:
float red;
protected:
public:
jz_std2(float a, float b, float c) :jz_std1(a, b), red(c) { ; }
~jz_std2() { }
float out_red_value() const;
float out_mianji();
}jz_st2;
float jz_std2::out_red_value() const
{
return red;
}
float jz_std2::out_mianji()
{
return 3.14*red*red;
}
#elif examp_2
typedef class jz_std11
{
private:
int num;
string name;
float score;
protected:
public:
jz_std11(int a, string b, float c) :num(a), name(b), score(c) { ; }
~jz_std11() { }
virtual void display();
}jz_st11;
void jz_st11::display()
{
cout << "num : " << num << endl << "name : " << name << endl << "score : " << score << endl;
}
typedef class jz_std12 :public jz_std11
{
private:
float wage;
protected:
public:
jz_std12(int a, string b, float c, float d) :jz_std11(a, b, c), wage(d) { ; }
~jz_std12(){ }
virtual void display();
}jz_st12;
void jz_st12::display()
{
cout << "wage : " << wage << endl;
}
#elif examp_3
#elif examp_4
#elif examp_5
#elif examp_6
#elif examp_7
#elif examp_8
#endif
int main(void)
{
#if examp_1
jz_std num1(3.14, 1.414);
cout << "x = " << num1.outX() << "y = " << num1.outY() << endl;
num1.get_value(5.96, 8.71);
cout << "x = " << num1.outX() << "y = " << num1.outY() << endl;
cout << endl << endl << endl;
jz_st2 num2(5, 5, 3);
cout << "x = " << num2.outX() << "\ny = " << num2.outY() << endl << "red = " << num2.out_red_value() << endl;
cout << "mianji = " << num2.out_mianji() << endl;
#elif examp_2
jz_st11 num1(1001, "wang", 89.3f);
jz_st12 num2(1002, "li", 92.6f, 24.0f);
num1.display();
num2.display();
#elif examp_3
#elif examp_4
#elif examp_5
#elif examp_6
#elif examp_7
#elif examp_8
#endif
system("pause");
return 0;
}
C++
1
https://gitee.com/Sjianzhao/Cplusplus.git
git@gitee.com:Sjianzhao/Cplusplus.git
Sjianzhao
Cplusplus
C++学习
master

搜索帮助