cpp00

YP J·2022년 6월 9일
0

CppModule

목록 보기
1/9

ex00

// ?

ex01

// ?

ex02

함수: _displayTimestamp(void)

// [19920104_091532] // YYYYMMDD_HHMMSS 꼴임
#include <ctime> // Timestamp 관련 함수들
#include <iostream>
int main()
{
    char buf[18];
    time_t curtime;
    struct tm *timeinfo;

    time(&curtime);
    timeinfo = localtime(&curtime);
    strftime(buf, 18, "[%Y%m%d_%H%M%S]",timeinfo);
    std::cout << buf << ' ' ;
}

>> [20220609_172703] 

1)time_t time(time_t *seconds)

  • 1970년 1월 1일 UTC기준 00:00:00으로부터 얼마나 많은 초가 흘렀는지 세어서 반환

2) struct tm *locatltime(const time_t *timer)

  • time() 함수 결과로 나온 초 값을 보기 쉽게 계산해서 tm 구조체 형식으로 반환
  • struct tm 구조체
    struct tm 
     {
    			int tm_sec;         // 초,  range 0 to 59
    	int tm_min;         // 분, range 0 to 59
    	int tm_hour;        // 시간, range 0 to 23
    	int tm_mday;        // 일, range 1 to 31
    	int tm_mon;         // 월, range 0 to 11
    	int tm_year;        // 1900년 부터의 년
    	int tm_wday;        // 요일, range 일(0) to 토(6)
    	int tm_yday;        // 1년 중 경과 일, range 0 to 365
    	int tm_isdst;       // 섬머타임 실시 여부 (양수, 0, 음수)
     };

3) size_t strftime(char *ptr, size_t maxsize, const char *format, const struct tm *timeptr)

  • 시간을 사용자가 원하는 형식에 맞추어 출력
  • format에 들어 있는 형식에 맞추어 timeptr이 가리키는 tm 구조체 의 값을 해석하여 현재 시간을 ptr 이 가리키는 배열에 저장.
  • 이때 출력 되는 문자열의 최대 길이는 maxsize

STL

표준 템플릿 라이브러리라고 불리는 STL(Standard Template Libaray)은 자료구조와 알고리즘을 효율적으로 관리할 수 있도록 C++ 에서 제공 하는 표준 라이브러리
-> 추후 알고리즘 풀면서 더 파볼 예정

소멸자 호출 순서

클래스를 0~7순으로 객체를 추가했을때 소멸시 OS에 따라 0~7 로 소멸 될수 있고 7~0 으로 소멸 될수 있다.
MacOS -> 7~0 ,역순으로 소멸
ubuntu -> 0~7 로 소멸

다른 이유는 std::vector 또는 클래스 의 소멸자 구현이 시스템마다 다르기 때문이다.

배낀곳 https://velog.io/@dogfootbirdfoot/CPP-Module-00

#pragma once

#ifndef #endif vs #pragma once

  • 전자는 macro wrapper 방식을 이용해서 중복 include를 제거하는 것이고,
    • 전자의 방법은 #ifndef 매크로 처리기를 통해 특정 매크로가 선언되어 있으면 조건이 참이 아니므로 #endif 까지의 코드가 무효화됩니다.
    • 매크로 래퍼 방식은 전처리기가 파일을 계속 읽어서 위의 #ifndef 문을 비교해봐야 합니다. 즉 #include "xxx.h"를 발견할 때마다 xxx.h 파일을 스캔한다.
  • 후자는 #pragma directive로 처리기에 직접 지시하는 방법의 차이가 있습니다.
    • #pragma once는 컴파일러 (정확히는 preprocessor겠지요)에게 이 파일은 한번만 읽어들이라고 지시하는 것
  • #pragma 자체는 표준에서 정의된 전처리
    지시어가 맞습니다. 하지만 그 뒤에 붙는 것들은 컴파일러마다 알아서 정의하도록되어 있습니다. 따라서 #pragma 지시어는 이식성이 없다고 볼 수 있다.

/// 결론 2개 같이 쓰면 어떻게 되나??

가져온곳:
https://kldp.org/node/46662
https://docs.microsoft.com/ko-kr/cpp/preprocessor/once?view=msvc-170

함수 :생성자 Account( int initial_deposit )

[19920104_091532] index:0;amount:42;created
[19920104_091532] index:1;amount:54;created
[19920104_091532] index:2;amount:957;created
[19920104_091532] index:3;amount:432;created
[19920104_091532] index:4;amount:1234;created
[19920104_091532] index:5;amount:0;created
[19920104_091532] index:6;amount:754;created
[19920104_091532] index:7;amount:16576;created
  • _displayTimestamp 사용해서 타임스탬프 찍어주고 index, amount  출력

함수 : displayAccountsInfos(void)

[19920104_091532] accounts:8;total:20049;deposits:0;withdrawals:0
  • private static 변수 출력하기 위해 getter를 사용해(getNbAccounts, getTotalAmount, getNbDeposits, getNbWithdrawals) 각 값 출력

함수 : displayStatus( void ) const

[19920104_091532] index:0;amount:42;deposits:0;withdrawals:0
[19920104_091532] index:1;amount:54;deposits:0;withdrawals:0
[19920104_091532] index:2;amount:957;deposits:0;withdrawals:0
[19920104_091532] index:3;amount:432;deposits:0;withdrawals:0
[19920104_091532] index:4;amount:1234;deposits:0;withdrawals:0
[19920104_091532] index:5;amount:0;deposits:0;withdrawals:0
[19920104_091532] 
```c
index:6;amount:754;deposits:0;withdrawals:0
[19920104_091532] index:7;amount:16576;deposits:0;withdrawals:0
  • 양식에 맞게 _accountIndex, _amount, _nbDeposits, _totalNbWithdrawals 출력 해주면 됨

함수:makeDeposit( int deposit )

[19920104_091532] index:7;amount:16576;deposits:0;withdrawals:0
[19920104_091532] index:0;p_amount:42;deposit:5;amount:47;nb_deposits:1
[19920104_091532] index:1;p_amount:54;deposit:765;amount:819;nb_deposits:1
[19920104_091532] index:2;p_amount:957;deposit:564;amount:1521;nb_deposits:1
[19920104_091532] index:3;p_amount:432;deposit:2;amount:434;nb_deposits:1
[19920104_091532] index:4;p_amount:1234;deposit:87;amount:1321;nb_deposits:1
[19920104_091532] index:5;p_amount:0;deposit:23;amount:23;nb_deposits:1
[19920104_091532] index:6;p_amount:754;deposit:9;amount:763;nb_deposits:1
[19920104_091532] index:7;p_amount:16576;deposit:20;amount:16596;nb_deposits:1
  • 양식에 맞게 입금하기 전 p_amount(_amount), 입금액 deposit, 입금 후 금액 amount(_amount + deposit), 입금 횟수 nb_deposits(_nbDeposits) 출력하면 됨

함수:makeWithdrawal( int withdrawal )

[19920104_091532] index:0;p_amount:47;withdrawal:refused
[19920104_091532] index:1;p_amount:819;withdrawal:34;amount:785;nb_withdrawals:1
[19920104_091532] index:2;p_amount:1521;withdrawal:657;amount:864;nb_withdrawals:1
[19920104_091532] index:3;p_amount:434;withdrawal:4;amount:430;nb_withdrawals:1
[19920104_091532] index:4;p_amount:1321;withdrawal:76;amount:1245;nb_withdrawals:1
[19920104_091532] index:5;p_amount:23;withdrawal:refused
[19920104_091532] index:6;p_amount:763;withdrawal:657;amount:106;nb_withdrawals:1
[19920104_091532] index:7;p_amount:16596;withdrawal:7654;amount:8942;nb_withdrawals:1
  • 이건 출금 관련 함수. 입금과 달리 출금할 금액이 amount보다 크면 refused 돼야 한다.

함수: checkAmount(void) const

  • 이건 그냥 출력 할때 어거지로 썻따.

함수 : 소멸자 ~Account( void )

[19920104_091532] index:0;amount:47;closed
[19920104_091532] index:1;amount:785;closed
[19920104_091532] index:2;amount:864;closed
[19920104_091532] index:3;amount:430;closed
[19920104_091532] index:4;amount:1245;closed
[19920104_091532] index:5;amount:23;closed
[19920104_091532] index:6;amount:106;closed
[19920104_091532] index:7;amount:8942;closed
  • 똑같이 양식에 맞게 변수값들 출력해주고 closed 출력해주면 됨.

배낀곳 https://velog.io/@zhy2on/씨쁠쁠00

profile
be pro

0개의 댓글