#include "iostream.h"
struct student
{
private:
int num;
char *name;
int math,english,Cworlds,all;
public:
void set_info(int Num,char *Name);
void set_chengji(int Math,int English,int C);
int allscore();
void display();
};
void student::set_info(int Num,char *Name)
{
num=Num;
name=Name;
}
void student::set_chengji(int Math,int English,int C)
{
this->math=Math;
this->english=English;
this->Cworlds=C;
}
void student::display()
{
cout<<"学号:"<<num<<'\t';
cout<<"姓名:"<<name<<'\t';
cout<<"总成绩:"<<all;
cout<<endl;
}
int student::allscore()
{
all=english+math+Cworlds;
return all;
}
void main()
{
student stu[4];
int NUM=10000;
for(int i=0;i<4;i++)
{
stu[i].set_info(NUM++,"张三");
stu[i].set_chengji(80,90,100);
stu[i].allscore();
stu[i].display();
}
}
-----------------------------------------
#include "iostream.h"
#include "math.h"
struct zuobiao
{
int x,y;
void set_x_y();
zuobiao & set_mid(zuobiao &a);
double set_long();
friend ostream & operator <<(ostream &out,zuobiao &a);
};
void zuobiao::set_x_y()
{
cout<<"请输入横坐标x的值:";
cin>>x;
cout<<"请输入纵坐标y的值:";
cin>>y;
}
zuobiao & zuobiao::set_mid(zuobiao &a)
{
x=(x+a.x)/2;
y=(y+a.y)/2;
return *this;
}
double zuobiao::set_long()
{
double how_long=sqrt(x*x+y*y);
return how_long;
}
ostream & operator <<(ostream &out,zuobiao &a)
{
out<<a.x<<','<<a.y<<endl;
return out;
}
void main()
{
zuobiao zb1,zb2;
zb1.set_x_y();
zb2.set_x_y();
cout<<zb1.set_mid(zb2);
cout<<zb1.set_long();
}
-----------------------------
#include "iostream.h"
struct node
{
int work_num;
int gongz;
node *next;
};
void list(node *l)
{
while(l->next!=NULL)
{
cout<<"工号:";
cout<<l->next->work_num<<endl;
cout<<"工资:";
cout<<l->next->gongz;
cout<<endl;
l=l->next;
}
}
void creat(int n)
{
node *L;
L=new node;
L->next=NULL;
for(int i=0;i<n;i++)
{
node *s;
s=new node;
cout<<"工号:";
cin>>s->work_num;
cout<<"工资:";
cin>>s->gongz;
cout<<endl;
s->next=L->next;
L->next=s;
}
list(L);
}
void main()
{
int n;
cout<<"输入您要创建的职工个数:";
cin>>n;
creat(n);
}
温馨提示:答案为网友推荐,仅供参考