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);//拷贝构造函数
};
类的定义&参数细节
最新推荐文章于 2024-10-12 00:54:53 发布