#include
#include
using namespace std;
class Student{
public:
void setData(char *no,char *na,int sco);
~Student();
static int getSum();
static int getCount();
static double calAverage();
void show();
static void showStaticData();
private:
char *stuNo;
char *name;
int score;
static int sum;
static int count;
//static int ave;
};
void Student::setData(char *no,char *na,int sco)
{
stuNo=new char[strlen(no)+1];
name=new char[strlen(na)+1];
strcpy(stuNo,no);
strcpy(name,na);
score=sco;
sum+=score;
count++;
}
Student::~Student()
{
delete []name;
delete []stuNo;
count--;
sum-=score;
// ave=sum/count;
}
int Student::getSum()
{
return sum;
}
int Student::getCount()
{
return count;
}
void Student::show()
{
cout<<"创建对象前,学生总人数、总分为:"<
cout
cout
cout
}
void Student::showStaticData()
{
cout
cout
}
int Student::count=0;
int Student::sum=0;
int main()
{
char *no,*na;
int sco;
cin>>no>>na>>sco;
Student stu[30];
while((cin>>no>>na>>sco)&&Student::getCount()<30)
{
stu[Student::getCount()].setData(no,na,sco);
}
return 0;
}
c++如何实现以组合键Ctrl+Z或人数>30结束输入
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- threenewbee 2018-10-06 03:21关注
ctrl+z是eof
可以用
while (1)
{
if (scanf("%d", &input) == EOF) break;
if (input > 30) break;
...
}解决 无用评论 打赏 举报