Mo__ 2018-10-06 02:18 采纳率: 100%
浏览 1525

c++如何实现以组合键Ctrl+Z或人数>30结束输入

#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;
}

  • 写回答

3条回答 默认 最新

  • threenewbee 2018-10-06 03:21
    关注

    ctrl+z是eof
    可以用
    while (1)
    {
    if (scanf("%d", &input) == EOF) break;
    if (input > 30) break;
    ...
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型