第四周 课后实践--程序阅读
来源:互联网 发布:如何搭建网络采购平台 编辑:程序博客网 时间:2024/05/16 07:16
代码1:
#include <iostream>using namespace std;class A{ int a , b ;public : A( ) { a=b=0; cout <<"a="<<a<<","<<"b="<<b<<endl; } A(int aa, int bb): a(aa),b(bb) { cout <<"a="<<a<<","<<"b="<<b<<endl; } ~A( ) { cout<<"Destructor "<<a<<" "<<b<<endl; }};int main(){ A x, y(2, 3); return 0;}
运行结果:
代码2:
#include <iostream>using namespace std;class A{public: A() { cout<<"A"; } ~A() { cout<<"~A"; }};class B{ A *p;public: B() { cout<<"B"; p=new A(); } ~B() { cout<<"~B"; delete p; }};int main(){ B obj; return 0;}
运行结果:
代码3:
#include <iostream>using namespace std;class toy{public: toy(int q, int p) { quan = q; price = p; } int get_quan() { return quan; } int get_price() { return price; }private: int quan, price;};int main(){ toy op[3][2]= { toy(10,20),toy(30,48), toy(50,68),toy(70,80), toy(90,16),toy(11,120) }; int i; for (i=0; i<3; i++) { cout<<op[i][0].get_quan()<<","; cout<<op[i][0].get_price()<<"\n"; cout<<op[i][1].get_quan()<<","; cout<<op[i][1].get_price()<<"\n"; } cout<<"\n"; return 0;}
运行结果:
代码4:
#include <iostream>using namespace std;class DA{ int k;public: DA(int x=1): k(x) { } ~DA() { cout<<k; }};int main(){ DA d[]= {DA(3),DA(3),DA(3) }; DA *p=new DA[2]; delete []p; return 0;}
运行结果:
第二个和第四个程序不明白。
0 0
- 第四周 课后实践:阅读程序
- 第四周 课后实践--程序阅读
- 第四周课后实践:阅读程序
- 第十四周 课后实践:阅读程序
- 第一周 课后实践:阅读程序
- 第一周课后实践:阅读程序1
- 第2周项目1课后实践,阅读程序
- 第一周 课后实践:阅读程序(2)
- 第一周 课后实践:阅读程序(3)
- 第一周课后实践:阅读程序2,3
- 第5周课后实践·阅读程序
- 第6周课后实践·阅读程序
- 第四周 阅读程序
- 第四周阅读程序
- 第四周 阅读程序
- 15第四周实践——阅读程序
- 第四周程序阅读(1)
- 第四周程序阅读(2)
- Android消息驱动机制Handler+Looper+Thread+MessageQueue
- linux grep命令
- Find The Multiple
- php使用session来保存用户登录信息
- Layouts
- 第四周 课后实践--程序阅读
- mysql数据库 ibatis环境下column "username" not found问题
- 控制字符串
- [LeetCode] Median of Two Sorted Arrays
- tomcat缓存
- linux系统性能调优第一步——性能分析(vmstat)
- Oil Deposits
- make参数详解
- 斐波那契数列的几种实现与递归(Fibonacci Function and Recurrence)