返回首页

大家好,我在这里有一个简单的代码,这是一个C类的功课,我需要一个咨询如何写代码前。当电脑问我的名字,如果我推进入计算机必须通过在我的下一个问题,但信息时,要打印这个问题,我推进入它必须表明它没有名称或任何问题,我通过了,plz帮助我,我需要这个代码这么多{S0的} {S0的}


#include <iostream>

#include <string>

using namespace std;

class person

{

private:

    string name;

    string surname;

    int age;

 

public:

    void fill(string,string,int);

    void printinfo();

 

};

void person::fill(string n,string s,int a)

{

	name=n;

    surname=s;

    age=a;

}

void person::printinfo()

{

    cout<<"\n\nName of student : "<<name

        <<"\nSurname : "<<surname

        <<"\nAge : "<<age;

}

class student:public person

{

public:

    int ID;

    int year;

    void setkv(int,int);

    void printkv();

};

void student::setkv(int i,int y)

{

    ID=i;

    year=y;

}

void student::printkv()

{

    cout<<"\nStudent ID is: "<<ID;

    cout<<"\nStudent year is: "<<year;

}

int main()

{

    person p;

    student s;

    string name,surname;

    int i,y,age;

	cout<<"\n\tPlease type needed information !";

    cout<<"\n\nName of student: ";

	cin>>name;

	

    cout<<"Surname: ";

    cin>>surname;

    cout<<"Age: ";

    cin>>age;

 

    p.fill(name,surname,age);

 

    cout<<"The ID of student: ";

    cin>>i;

    cout<<"And Year of study: ";

    cin>>y;

     

    s.setkv(i,y);

	cout<<"\n\n\tThe typed information are : ";

    p.printinfo();

    s.printkv();

cin.get();cin.get();

return 0;

 

}

回答

评论会员: 时间:2