[태그:] C++

  • C++ report 클래스와 객체, 은행계좌 프로그램

    목차

    [개별실습1] [실습자료7]의 시간 클래스를 이용하여 아래 내용이 실행되도록 클래스를 완성하시오.
    [개별실습2] 은행 계좌 클래스 (교재 6장: 166-168 참고)

    본문내용

    [개별실습1] [실습자료7]의 시간 클래스를 이용하여 아래 내용이 실행되도록 클래스를 완성하시오.

    int main()
    {
    Time clock1, clock3;
    Time clock2(8, 10 , 10);
    clock1.setTime(15,12,30);

    cout << "\n clock1 = " ; // 15:12:30 clock1.displayTime24(); cout << "\n clock2 = " ; // 8:10:10 clock2.displayTime24(); clock3= clock1 + clock2; // clock3= clock1.add(clock2); cout << "\n clock1 + clock2 = " ; // 23:22:40 cout << clock3 << endl; // clock3.display24(); return 0; } ①헤더파일 #include
    #include

    using std::endl; using std::cout; using std::ostream;

    class Time {
    private:
    int hour, minute, second;
    public:
    void setTime(int x, int y, int z);
    void displayTime24();
    Time(int x,int y, int z);
    Time(const Time &clock4); //복사생성자
    Time() {} //생성자 함수 clock1을 도와준다.
    Time operator+(const Time &clock);

    출처 : 해피캠퍼스

  • C++ report 정규직 사원과 시간급 사원의 급여기록을 관리하기 위한 클래스를 사용하여 프로그램

    목차

    없음

    본문내용

    (문제제시)
    1. [구현1]은 주어진 소스를 완성하여 결과를 얻는다.
    2. [구현2]는 제시된 내용대로 클래스를 추가한다.
    3. [구현3]은 개별적으로 내용을 구성하여 클래스를 추가한다.
    ………………………………………………………………………………………………………..
    [구현1] 정규직 사원과 시간급 사원의 급여기록을 관리하기 위한 클래스를 사용하여 프로그램을 구현한다.

    1) 사원 클래스
    class Employee {
    public:
    Employee(){} // 생성자함수
    Employee(string _name, string _ssn) : name(_name), ssn(_ssn),pay(0) {}
    // 이름, 사번,급여
    string get_name() const {return name;}
    string get_ssn() const {return ssn; }
    double get_pay() const {return pay ;}
    void set_name(string new_name) {name=new_name;}
    void set_ssn(string new_ssn) {ssn=new_ssn;}
    void set_pay(double new_pay) {pay=new_pay;}
    virtual void print_check()=0; // 사원정보 출력
    protected:
    string name; //이름
    string ssn;//사번
    double pay; //지급액
    };

    2) 시간급 사원 클래스 : HourlyEmployee

    멤버
    변수
    double wage_rate; //시간당급료
    double hours; //근무시간
    멤버
    함수
    HourlyEmployee(); //생성자함수
    HourlyEmployee(string _name, string _ssn, double _wage_rate, double _hours); // 이름, 사번, 급여, 시간당급료 , 근무시간
    double get_wage_rate()const; //시간당급료 반환
    double get_hours() const;//근무시간 반환
    void set_wage_rate(double new_wage_rate) ;//시간당급료 변경
    void set_hours(double new_wage_rate) ;//근무시간 변경
    void print_check(); // 급여( = 시간당급료* 근무시간) 출력

    출처 : 해피캠퍼스

  • C++ report 스택 클래스, 행렬 클래스

    목차

    없음

    본문내용

    3. 스택 클래스 선언 및 정의

    // **** file: stack.h

    #include
    using namespace std;

    class Stack {
    public:
    enum { MaxStack = 5 };
    void init() { top = -1; }
    void push( int n ) {
    if ( isFull() ) {
    errMsg( “Full stack. Can’t push.” );
    return;
    }
    arr[ ++top ] = n;
    }
    int pop() {
    if ( isEmpty() ) {
    errMsg( “Empty stack. Popping dummy value.” );
    return dummy_val;
    }
    return arr[ top– ];
    }
    bool isEmpty() { return top < 0; } bool isFull() { return top >= MaxStack – 1; }
    void dump() {
    cout << "Stack contents, top to bottom:\n"; for ( int i = top; i >= 0; i– )
    cout << '\t' << arr[ i ] << '\n'; } private: void errMsg( const char* msg ) const { cerr << "\n*** Stack operation failure: " << msg << '\n'; } int top; int arr[ MaxStack ]; int dummy_val; }; 4. 수행 프로그램 //**** file: stack.cpp #include "stack.h" // header for Stack class
    출처 : 해피캠퍼스

  • C++ report 문자, 숫자 관련 프로그램

    목차

    없음

    본문내용

    [개별실습1]
    ☞ 임의의 단일 문자(대문자 ,소문자)를 입력받아 각 해당 문자 (a 또는 A) 부터 (e 또는 E)를 분류하여 가장 많이 입력된 문자와 해당 개수를 구한다.(단, 해당문자가 10개 입력되면 입력종료)
    (결과 예)
    a 또는 A : 1
    b 또는 B : 2
    c 또는 C : 4
    d 또는 D : 2
    e 또는 E : 1

    참조: 실습자료(3/19) 실습2,실습3
    변환함수 : // 지원
    (소문자 -> 대문자 변환 : char(toupper(소문자) )
    해당문자 : c , 해당 개수=4

    #include
    #include //변환함수
    using namespace std;

    int main()
    {
    char munja;
    int count=0;
    int c[5]={0,};
    char n[5]={‘a’,’b’,’c’,’d’,’e’};
    int max=0;
    char m;

    cout << "a~e 또는 A~E 까지 문자 10개를 입력하세요" << endl; while(count<10) { cin >> munja;
    if((‘a’<=munja && munja<='e')||('A'<=munja && munja<='E')) count++;
    출처 : 해피캠퍼스

  • C++ report 다중상속 시간클래스 + 날짜클래스, 클래스 Point, Circle를 통해 상속 개념을 파악

    목차

    (개별실습1) 다중상속 : 시간클래스 + 날짜클래스
    ① 실행 소스

    (개별실습2)
    1. 좌표(Point) 클래스
    2. 원(Circle) 클래스

    본문내용

    (개별실습1) 다중상속 : 시간클래스 + 날짜클래스
    ① 실행 소스
    #include
    #include
    #include
    using namespace std;

    class Time { // 시간 클래스
    protected:
    int hrs, mins, secs;
    public:
    Time(int h, int m, int s) { hrs = h; mins = m; secs = s; }
    virtual void print( ) { cout << hrs << ':' << mins << ':' << secs<출처 : 해피캠퍼스