2个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(string s,int a,int b):name(s),id(a),score(b){}
void display();
private:
string name;
int id;
int score;
};
void Student::display()
{
cout << "姓名:" << ends << name << endl;
cout << "学号:" << ends << id << endl;
cout << "成绩:" << ends << score << endl;
}
int main()
{
Student stu("小明", 19, 97);
stu.display();
system("pause");
return 0;
}
展开全部
#include <iostream.h>
#include <stdlib.h>
class student
{
public:
int no;
char *name;
int deg;
student();
~student();
void display();
};
static int sum,num=3;
static int avg(int sum);
void main()
{
int aver;
student stu[3];
stu[0].no=1;
stu[0].name="li";
stu[0].deg=89;
stu[1].no=2;
stu[1].name="chen";
stu[1].deg=78;
stu[2].no=3;
stu[2].name="zheng";
stu[2].deg=94;
for(int i=0;i<3;i++)
{
stu[i].display();
sum+=stu[i].deg;
}
cout<<"the sum is:"<<sum<<endl;
aver=avg(sum);
cout<<"the average is:"<<aver<<endl;
}
student::student()
{
no=0;
name=(char*)malloc(sizeof(char)*8);
deg=0;
}
student::~student()
{
free(name);
}
void student::display()
{
cout<<no<<"\t"<<name<<"\t"<<deg<<endl;
}
static int avg(int sum)
{
int aver;
aver=sum/num;
return aver;
}
#include <stdlib.h>
class student
{
public:
int no;
char *name;
int deg;
student();
~student();
void display();
};
static int sum,num=3;
static int avg(int sum);
void main()
{
int aver;
student stu[3];
stu[0].no=1;
stu[0].name="li";
stu[0].deg=89;
stu[1].no=2;
stu[1].name="chen";
stu[1].deg=78;
stu[2].no=3;
stu[2].name="zheng";
stu[2].deg=94;
for(int i=0;i<3;i++)
{
stu[i].display();
sum+=stu[i].deg;
}
cout<<"the sum is:"<<sum<<endl;
aver=avg(sum);
cout<<"the average is:"<<aver<<endl;
}
student::student()
{
no=0;
name=(char*)malloc(sizeof(char)*8);
deg=0;
}
student::~student()
{
free(name);
}
void student::display()
{
cout<<no<<"\t"<<name<<"\t"<<deg<<endl;
}
static int avg(int sum)
{
int aver;
aver=sum/num;
return aver;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询