OJ嘻唰唰 学生信息的输入与输出

Problem P: A改错题--学生信息的输入和输出

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 164   Solved: 91
[ Submit][ Status][ Web Board]

Description

注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交。

阅读并修改以下程序,实现学生信息的输入和输出。

#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
class Student
{
private:
    const int maxSchoolPeriod;  //学制
    int no;  //学号
    char name[20];  //姓名
public:
/*****修改的起始行******/
    Student(int Period,int no,char name[]):name(name)
    {
        this->maxSchoolPeriod = Period;
        no = no;
    }
/*****修改的终止行*****/
    void output()
    {
        cout<<maxSchoolPeriod<<" "<<no<<" "<<name<<endl;
    }
};
int  main()
{
    int no;
    char name[20];
    cin>>no>>name;
    Student stu1(4,no,name); //本科生4年
    cin>>no>>name;
    Student stu2(3,no,name); //专科生3年
    stu1.output();
    stu2.output();
    return 0;
}

Input

第一行: 学号 姓名
第二行: 学号 姓名

Output

第一行: 学制 学号 姓名
第二行: 学制 学号 姓名

Sample Input

101 zhangsan
102 lisi

Sample Output

4 101 zhangsan
3 102 lisi
代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
class Student
{
private:
    const int maxSchoolPeriod;  //学制
    int no;  //学号
    char name[20];  //姓名
public:
/*****修改的起始行******/
 Student(int Period ,int no,char *name):maxSchoolPeriod(Period)
    {
        strcpy(this->name,name);
        this->no = no;
    }
/*****修改的终止行*****/
    void output()
    {
        cout<<maxSchoolPeriod<<" "<<no<<" "<<name<<endl;
    }
};
int  main()
{
    int no;
    char name[20];
    cin>>no>>name;
    Student stu1(4,no,name); //本科生4年
    cin>>no>>name;
    Student stu2(3,no,name); //专科生3年
    stu1.output();
    stu2.output();
    return 0;
}
运行结果:
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值