类的定义&参数细节

void input (string n, string id, string g, string c, string t)
	{
		name = n;
		id = id;
		gender = g;
		college = c;
		tel = t;
	}
infor *p = new infor [t];
p[i].input ( name, id, gender, college, tel );


Complex(){};//必须带{}才可以在有友元函数中用Complex定义一个新的类
Complex addCom(const Complex& c1, const Complex &c2)
{
	Complex a;
	a.real = c1.real + c2.real;
	a.imag = c1.imag + c2.imag;
	return a;
}


void input (long ac, char *na, float bal)
{
	account = ac;
	strcpy (name, na); //需要#include<cstring>函数strcpy(a,b)==将b中的东西复制到a中
	balance = bal;
}
CAccount ca; 
ca.input (account, name, balance0);




Point(double x1, double y1)//带参构造函数
{
	x = x1;
	y = y1;
}
Point a(x1, y1);
a.setX();

//拷贝构造函数 
CFraction(int fz_val, int fm_val)
{
	fz = fz_val;
	fm = fm_val;
}
CFraction add(const CFraction &r)//有的又不加const(实验六B) 
{
	return CFraction (fz * r.fm + r.fz * fm, fm * r.fm);
}
CFraction a (fz1, fm1);
CFraction b (fz2, fm2);
CFraction c = a.add(b);


rob (char *n, char t, int l)
		{
			name = new char [21];
			strcpy(name,n);
			type = t;
			level = l;
			
		}
rob *p;
rob r (name, type, level); 


//静态成员函数
static int getTv()
{
	return tv;
}
static int getDvd()
{
	return dvd;
}
Tv *p = new Tv [n];
for(int i = 0; i < n; i++)
	{
		p[i].setNum(i);
		p[i].setChannel(i);
		p[i].setVol(50);
		p[i].initial(1);
	}
DVD = p->getDvd();
TV = p->getTv(); 

———————————————————— 

class CTelNumber
{
private:
    char *p;//1个字符指针数据成员
public:
	CTelNumber::CTelNumber(char *point)
	{
   		p = new char[8];//因为需要一个动态数组 
    	strcpy(p,point);//别忘了是strcpy
	} 
    ~CTelNumber();//析构
    void print();//打印
    CTelNumber(const CTelNumber &telNum);//拷贝构造函数
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值