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

C언어 ver1 ,2 ,3

nn
505 0 0

#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

댓글 쓰기
권한이 없습니다. 로그인
에디터 모드

신고

"님의 댓글"

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

댓글 삭제

"님의 댓글"

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

공유

퍼머링크

삭제

"ver1 ,2 ,3"

이 게시물을 삭제하시겠습니까?