1 #include<stdio.h>
2 #include<string.h>
3 #include<math.h>
4 #include<iostream>
5 #include<algorithm>
6 #include<queue>
7 #include<vector>
8 #include<set>
9 #include<stack>
10 #include<string>
11 #include<sstream>
12 #include<map>
13 #include<cctype>
14 #include<limits.h>
15 using namespace std;
16 class box
17 {
18 public:
19 box(int h=10,int w=10,int len=10); // 在声明函数的时候 指定默认参数 .
20 int volume();
21 private:
22 int height,width,length;
23 };
24 box::box(int h,int w,int len)
25 {
26 height=h,width=w,length=len;
27 }
28 int box::volume()
29 {
30 return height*width*length;
31 }
32 int main()
33 {
34 box box1(5); // 随意给定 0-3个实参 实参按照顺序对应 给定
35 printf("%d\n",box1.volume());
36 }
#include<stdio.h>
#include<iostream>
using namespace std;
class Complex // 定义 Complex类
{
public:
Complex(double r=10,double i=10) // 定义构造函数 设置默认参数.
{
real=r,imag=i;
}
void display() //定义 输出函数
{
cout<<real<<"+"<<imag<<"i";
}
Complex operator + (Complex &c2) //定义复数相加函数 .
{
Complex c;
c.real=real+c2.real; // 这个 c2对象是在"+"之后的那个东西 .
c.imag=imag+c2.imag;
return c;
}
private:
double real,imag;
} ;
int main()
{
Complex a(3,4),b,c;
c=a+b;
c.display();
}