码迷,mamicode.com
首页 > 编程语言 > 详细

C++课程设计类作业4

时间:2017-06-14 02:27:01      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:执行   images   img   obj   ima   析构   val   private   its   

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 class xiexin
 4 {
 5 public:
 6     xiexin()
 7     {
 8         weight=0;
 9         grade=0;
10         cout<<"weight="<<weight<<",grade="<<grade<<endl;
11     }
12     xiexin(int w,int g)
13     {
14         weight=w;
15         grade=g;
16         cout<<"weight="<<weight<<",grade="<<grade<<endl;
17     }
18     ~xiexin()
19     {
20         cout<<"Destructor......\n";
21     }
22     void setvalue(int w=100,int g=40)
23     {
24         weight=w;
25         grade=g;
26         cout<<"weight="<<weight<<",grade="<<grade<<endl;
27     }
28     static int calculate(xiexin obj)
29     {
30         return obj.weight*obj.grade;
31     }
32     friend void display(xiexin obj);
33 private:
34     int weight;
35     int grade;
36     static int cnt;
37 };
38 int xiexin::cnt=0;
39 void display(xiexin obj)
40 {
41     cout<<"weight="<<obj.weight<<",grade="<<obj.grade<<",total="<<xiexin::calculate(obj)<<endl;
42 }
43 int main()
44 {
45     xiexin boxl;
46     display(boxl);
47     xiexin box2(5,10);
48     display(box2);
49     box2.setvalue(20,18);
50     display(box2);
51 }

如果函数中有多条语句的话,会先执行完这些语句,直到函数结束再析构

技术分享

C++课程设计类作业4

标签:执行   images   img   obj   ima   析构   val   private   its   

原文地址:http://www.cnblogs.com/ECJTUACM-873284962/p/7004484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!