C++之特定人数的个人信息输入和输出

这里写的是一个C++小程序,其功能是对一定人数进行个人信息的输入。

代码如下:

#include<iostream>
using namespace std;

class Date{
public:
int getYear();
int getMonth();
int getDay();
void set();
int shows();
~Date(){}  // 对Date进行析构,释放空间
private:
int year;
int month;
int day;

};   //这是date的一个基本类

 int Date::getYear()
 {
  return year;
 }
 int Date::getMonth()
 {
  return month;
 }
int Date::getDay()
{
return day;
 } 
 void Date::set(){
  cout<<"请输入出生年月日(中间用空格隔开): ";  
    cin>>year>>month>>day;  
 }
int Date::shows(){
cout<<"学生出生日期:"<<this->getYear()<<"年"<<this->getMonth()<<"月"<<this->getDay()<<"日"<<endl;   //这里用到的是this指针
}

   //通过接口对类中的函数进行定义


class people:public Date{
public:
int anumber;
int aid;
char asex;
public:
void number();
void id();
void sex();
void show();
~people(){};
};

       //一个people的类,并将Date中的函数继承


void people::sex(){
char asex;
cout<<"请输入性别(男生为m,女生为f):";
cin>>asex; 
}
  void people::id(){
cout<<"请输入学生身份证号:";
cin>>aid;
}
  void people::number(){
cout<<"请输入学生编号:";
cin>>anumber; 

void people::show(){
cout<<"学生编号:"<<anumber<<endl;
cout<<"学生身份证号:"<<aid<<endl;
  cout<<"学生性别:"<<asex<<endl;
}


int main()   //主函数
{   int w,i;
    cout<<"请输入学生人数:"<<endl; 
cin>>w;
for(i=0;i<w;i++)      //一个简单的人数循环,数据范围为int型,超过则考虑其他类型
{
people A;
A.set();
A.number();
A.id();
A.sex();
A.show();
A.shows();

// 对类进行调用输出
cout<<"\n"<<endl;
}
return 0;

// 结束
}



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值