INCLASS.CPP
资源名称:C++100.rar [点击查看]
上传用户:wszmarenbt
上传日期:2013-04-26
资源大小:2552k
文件大小:1k
源码类别:
Windows编程
开发平台:
Visual C++
- //THE PROGRAM IS TO INSERT ONE CLASS INTO ANOTHER
- //FILE INCLASS.CPP
- #define CONST1 78
- #define CONST2 12
- #define CONST3 23
- #include <stdio.h>
- #include <conio.h>
- class INCLASS_1
- {
- private :
- int DATA;
- public :
- INCLASS_1(int NUM)
- {
- DATA=NUM;
- };
- void OUTPUT()
- {
- printf("n %d",DATA);
- }
- };
- class INCLASS_2
- {
- private :
- int DATA;
- public :
- INCLASS_2(int NUM)
- {
- DATA=NUM;
- };
- void OUTPUT()
- {
- printf("n %d",DATA);
- }
- };
- class OUTCLASS
- {
- private :
- int DATA;
- INCLASS_1 OB1;
- INCLASS_2 OB2;
- public :
- OUTCLASS(int NUM);
- void OUTPUT()
- {
- printf("n %d",DATA);
- }
- void OUTPUTOB1()
- {
- OB1.INCLASS_1::OUTPUT();
- }
- void OUTPUTOB2()
- {
- OB2.INCLASS_2::OUTPUT();
- }
- };
- OUTCLASS::OUTCLASS(int NUM):OB1(CONST1),OB2(CONST2)
- {
- DATA=NUM;
- }
- int main(void)
- {
- OUTCLASS TEST(CONST3);
- clrscr();
- TEST.OUTPUT();
- TEST.OUTPUTOB1();
- TEST.OUTPUTOB2();
- getch();
- return 0;
- }