목록으로 2012.12.13. 14:13
C언어

ver1 ,2 ,3

youtube

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

class Person{
private:  
        string name;
        static int cnt;

public:
        Person(string n){name=n; cnt++;}
        static int getCnt(){return cnt;}
        void setName(string n){name=n;}
        string getName(){return name;}
};

int Person::cnt=0;
        
        int main()
        {

                Person p1("Kim");
                Person p2("Kang");
                Person p3("Lee");
        
                cout<<"총인원:"<<Person::getCnt()<<endl;
        }

Ver2

 

 

 

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

class Person
{
private:
        string name;
        static int cnt;
public:
        Person(string n){ name=n; cnt++;}
        static int getCnt(){ return cnt;}
        void setName(string n){ name=n; }
        string getName(){return name; }

};
int Person::cnt=0;

class Student : public Person
{
private:
        int quiz1, quiz2, sum;
        float avg;
public:
        Student(string n, int q1, int q2):Person(n){ quiz1=q1; quiz2=q2; }
        void setQuiz(int q1, int q2){ quiz1=q1; quiz2=q2; }
        void calcSumAvg(){sum=quiz1+quiz2;  avg= sum/2.0;}
        int getSum(){ return sum; }
        float getAvg() { return avg; }
        };

        int main()
        {
                Student s1("kim",20,30);
                Student s2("kang",10,50);
                Student s3("lee",20,20);
        cout << "총인원:" << s1.getCnt() <<endl;
}

Ver3

 

#include <iostream>
#include <ctime>

#include<string>

#include <fstream>

using namespace std;

class Person{
private: 
        string name;
        static int cnt;

public:
 Person(){cnt++;}
        Person(string n){name=n;}
        static int getCnt(){return cnt;}
        void setName(string n){name=n;}
        string getName(){return name;}
};

int Person::cnt=0;

class Student : public Person
{
private:
        int quiz1, quiz2, sum;
        float avg;
public:
  Student(){}
        Student(string n, int q1, int q2):Person(n){ quiz1=q1; quiz2=q2; }
        void setQuiz(int q1, int q2){ quiz1=q1; quiz2=q2; }
        void calcSumAvg(){sum=quiz1+quiz2;  avg= sum/2.0;}
        int getSum(){ return sum; }
        float getAvg() { return avg; }
        };

        int main()
        { 
    Student s[3];
    s[0].setName("kim");
    s[1].setName("kang");
    s[2].setName("lee");
        cout << "총인원:" << s[0].getCnt() <<endl;
}

댓글 0

댓글 작성 권한이 없습니다. 로그인하기

NO
TITLE
섬네일
profile 너에게제공 | 12. 21 | 조회
16
XML
profile 너에게제공 | 12. 14 | 조회
15
XML s
XML
asf | 12. 14 | 조회
14
XML XML
profile 너에게제공 | 12. 07 | 조회
13
XML | 12. 07 | 조회
12
XML
s | 11. 30 | 조회
11
XML asd
XML
124 | 11. 23 | 조회
9
XML 124
XML
dqw | 11. 23 | 조회
8
XML 124
profile 너에게제공 | 11. 23 | 조회
7
profile 너에게제공 | 11. 23 | 조회
6
profile 너에게제공 | 11. 09 | 조회
4
XML
sdaf | 10. 26 | 조회
3
XML asdf