• 목록
  • 아래로
  • 위로
  • 쓰기
  • 검색

C언어 ex1

너에게제공 너에게제공
59 0 1

#include <iostream>
#include <string>
using namespace std;

class Person
{
private:
        string name;
        int age;
        char gender;
public:
        Person(string n="",int a=0,char g='M'){name=n;age=a;gender=g;}

        void setName(string n){name=n;}
        string getName(){return name;}
        void setAge(int a){age=a;}
        int getAge(){return age;}
        void setGender(char g){gender=g;}
        char getGender(){return gender;}
        void display(){ cout<<"이름 : "<<name<<endl;
                                        cout<<"나이 : "<<age<<endl;
                                        cout<<"성별 : "<<gender<<endl;}

};

class Student:public Person
{
private:
        string stdno,dept;
        int year;
public:
        Student(string n="",int a=0,char g='M',string s="",string d="",int y=3):Person(n,a,g)
        {stdno=s; dept=d; year=y;}
        void setStdno(string s){stdno=s;}
        string getStdno(){return stdno;}
        void setDept(string d){dept=d;}
        string getDept(){return dept;}
        void setYear(int y){year=y;}
        int getYear(){return year;}
        void display(){ cout<<"이름 : "<<getName()<<endl;
                                        cout<<"나이 : "<<getAge()<<endl;
                                        cout<<"성별 : "<<getGender()<<endl;
                                        cout<<"학번 : "<<stdno<<endl;
                                        cout<<"학과 : "<<dept<<endl;
                                        cout<<"학년 : "<<year<<endl;}

};

void main()
{
        Person p,s("봄양",22,'f');
        s.display ();
        p.display();
        Student a("여름양",21,'f',"200940033","인터넷정보과",2);
        a.display();
}
 
 

 

신고공유스크랩

댓글 1

댓글 쓰기
profile image
class Person
{
private:
string name;
int age;
char gender;
public:
Person(string n="",int a=0,char g='M'){name=n;age=a;gender=g;}

void setName(string n){name=n;}
string getName(){return name;}
void setAge(int a){age=a;}
int getAge(){return age;}
void setGender(char g){gender=g;}
char getGender(){return gender;}
void display(){ cout<<"이름 : "<<name<<endl;
cout<<"나이 : "<<age<<endl;
cout<<"성별 : "<<gender<<endl;}

};
void main()
{
Person p,s("봄양",22,'f');
s.display ();
p.display();
}
00:17
13.03.28.
권한이 없습니다. 로그인
에디터 모드

신고

"님의 댓글"

이 댓글을 신고하시겠습니까?

댓글 삭제

"님의 댓글"

이 댓글을 삭제하시겠습니까?

공유

퍼머링크