YTU 2609: A改错题--学生信息的输入和输出
2609: A改错题--学生信息的输入和输出
时间限制: 1 Sec 内存限制: 128 MB提交: 238 解决: 157
题目描述
注:本题只需要提交标记为修改部分之间的代码,请按照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;
}
输入
第一行: 学号 姓名
第二行: 学号 姓名
输出
第一行: 学制 学号 姓名
第二行: 学制 学号 姓名
样例输入
101 zhangsan
102 lisi
样例输出
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 nam[20]):maxSchoolPeriod(Period),no(no)
    {
        strcpy(name,nam);
    }
    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;
}
    ------------------- 这是千千的个人网站哦! https://www.dreamwings.cn -------------------
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号