#include<iostream.h>
class Student
{
private:
int rollno;
int marks;
public:
void getinfo()
{
cout<<"Enter the Roll number:";
cin>>rollno;
cout<<"Enter the marks:";
cin>>marks;
}
void display()
{
cout<<rollno<<'/t'<<marks<<endl;
}
int getmarks()
{
return marks;
}
}; //Student类结束
void main()
{
Student stulist[100];
float total,average;
int no,i;
total=0.0;
cout<<"Enter the number of students:";
cin>>no;
for(i=0;i<no;i++)
{
stulist[i].getinfo();
total=total+stulist[i].getmarks();//添加标记
}
cout<<"Rollno Marks"<<endl;
for(i=0;i<no;i++)
{
stulist[i].display();
}
average=total/no; //查找平均值
cout<<"Average marks="<<average;
} //主程序结束
--《面向对象编程:C++》
980

被折叠的 条评论
为什么被折叠?



