DeltaTime

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

QueryPerformanceFrequency(&g_tSecond);

QueryPerformanceCounter(&g_tTime);

.

.

.

.

.

QueryPerformanceCounter(&tTime);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////


QueryPerformanceFrequency : CPU 프로세서의 초당 클럭수

QueryPerformanceCounter : 부팅시부터 현재까지 CPU 클럭 동작 횟수.


자료형은 _int64이다.


프레임당 움직인 거리 =   1회 연산의 클럭 수  /  초당 클럭수

g_fDeltaTime = (tTime.QuadPart - g_tTime.QuadPart) / (float)g_tSecond.QuadPart;


ex) 360/3600일 경우 한번 연산 당 360클럭이 소요. 10번 연산하면 1초. (기본 속도의 출력은 10FPS)
fSpeed는 게임의 속도.
float fSpeed = 6 * g_fDeltaTime; (속도 적용 후 출력은 6*10  = 60FPS)


1. 크기 8짜리 2차원 배열을 매개변수로 받을 때

define_Item이라는 구조체가 존재할 때

이 구조체의 배열 define_Item *itemList[MAX_ITEM_LIST][MAX_TYPE_LIST];

define_Item* (*i)[8]

'Computer > C와 C++' 카테고리의 다른 글

학생 관리 프로그램 & 도서관 책 관리 프로그램  (0) 2018.07.06
7월 3일  (0) 2018.07.03
7월 2일 C/C++  (0) 2018.07.02

1. 학생관리 프로그램


#include <iostream>
#include <string.h>
using namespace std;
#define NAME_SIZE 32
#define ID_SIZE 8
#define MAX_STUDENT 64

enum{
    MENU_INSERT=1,
    MENU_DELETE,
    MENU_FIND,
    MENU_PRINT
};

struct Student{
    char sName[NAME_SIZE];
    // +1 for '\0'
    char sID[ID_SIZE+1];
    int sKor;
    int sEng;
    int sMath;
    int sTotal;
    float sAvg;
};

void ErrorHandling(string msg);
int studentInsert(Student *student,int& sCount);
int studentDelete(Student *student,int& sCount);
int studentFind(Student *student,int& sCount);
int studentPrint(Student *student,int& sCount);

int main(){
    system("clear");
    int selectMenu;
    int studentCount = 0;
    Student sArray[MAX_STUDENT] = {};
    while(1){
        cout << endl;
        cout << "Manage Student Prg" << endl;
        cout << "1. Insert" << endl;
        cout << "2. Delete" << endl;
        cout << "3. Find" << endl;
        cout << "4. Print" << endl;
        cout << "Select Menu : ";
        cin >> selectMenu;
        system("clear");
        if(cin.fail()){
            cin.clear();
            cin.ignore(1024,'\n');
        }
        
        switch(selectMenu){
            case MENU_INSERT:
                if(studentInsert(sArray, studentCount) == -1){
                    ErrorHandling("Cannot Insert");
                    continue;
                }
                break;
            case MENU_DELETE:
                if(studentDelete(sArray, studentCount) == -1){
                    ErrorHandling("Cannot Delete");
                    continue;
                }
                break;
            case MENU_FIND:
                if(studentFind(sArray, studentCount) == -1){
                    ErrorHandling("Cannot Find");
                    continue;
                }
                break;
            case MENU_PRINT:
                if(studentPrint(sArray, studentCount) == -1){
                    ErrorHandling("Cannot Print");
                    continue;
                }
                break;
            default: {
                ErrorHandling("Input 1~4");
                continue;
            }
        }
    }
    return 0;
}

int studentInsert(Student *student, int& sCount){
    if(sCount == MAX_STUDENT-1)
        return -1;

    cout << "input name :";
    cin >> student[sCount].sName;
    cout << "input ID :";
    cin >> student[sCount].sID;
    cout << "input Kor score : ";
    cin >> student[sCount].sKor;
    cout << "input Eng score : ";
    cin >> student[sCount].sEng;
    cout << "input Math score : ";
    cin >> student[sCount].sMath;
    student[sCount].sTotal = student[sCount].sKor + student[sCount].sEng
                            + student[sCount].sMath;
    student[sCount].sAvg = (student[sCount].sTotal)/3.f;
    ++sCount;
    system("clear");
    return 0;
}

int studentDelete(Student *student, int& sCount){
    if(sCount == 0)
        return -1;

    int deleteIndex=0;
    cout << "input delete index :";
    cin >> deleteIndex;
    
    for(int i=deleteIndex; i<sCount-1; i++){
        student[i] = student[i+1];
    }
    --sCount;
    return 0;  
}

int studentFind(Student *student, int& sCount){
    if(sCount == 0)
        return -1;
    char findName[NAME_SIZE];
    bool findout = true;
    cout << "input name to find : " << endl;
    cin >> findName;
    
    for(int i=0; i<sCount; i++){
        if(!strcmp(findName, student[i].sName)){
            cout << "Name\t" << student[i].sName << endl;
            cout << "ID\t" << student[i].sID << endl;
            cout << "KOR\t" << student[i].sKor << endl;
            cout << "ENG\t" << student[i].sEng << endl;
            cout << "MATH\t" << student[i].sMath << endl;
            cout << "Total\t" << student[i].sTotal << endl;
            cout << "Average\t" << student[i].sAvg << endl;
            findout = false;
        }
    }
    if(findout = true)
        cout << "cannot find" <<endl;
    return 0;
}

int studentPrint(Student *student, int& sCount){
    if(sCount == 0)
        return -1;

    cout << "============= student list =============" << endl;
    for(int i=0; i<sCount; i++){
        cout << "Index\t" << i << endl;
        cout << "Name\t" << student[i].sName << endl;
        cout << "ID\t" << student[i].sID << endl;
        cout << "KOR\t" << student[i].sKor << endl;
        cout << "ENG\t" << student[i].sEng << endl;
        cout << "MATH\t" << student[i].sMath << endl;
        cout << "Total\t" << student[i].sTotal << endl;
        cout << "Average\t" << student[i].sAvg << endl;
        cout << "========================================" << endl;
    }
    return 0;    
}

void ErrorHandling(string msg){
    system("clear");
    cout << msg <<endl;
}

2. 도서관 책 관리 프로그램


#include <iostream>
#include <string.h>
using namespace std;
#define BOOK_NAME_SIZE 64
#define BOOK_NUMBER 8
#define MAX_BOOK_COUNT 64

enum {
    MENU_REGISTER=1,
    MENU_LEND,
    MENU_RETURN,
    MENU_LIST
};

struct Library{
    char bName[BOOK_NAME_SIZE];
    char bNumber[BOOK_NUMBER+1];
    int bPrice;
    bool isLend;
};

void ErrorHandling(string msg);
int bRegister(Library *b, int& bookCnt);
int bLend(Library *b, int& bookCnt);
int bReturn(Library *b, int& bookCnt);
int bList(Library *b, int& bookCnt);

int main(){
    int bookCount=0;
    int selectMenu;
    Library myBook[MAX_BOOK_COUNT] = {};
    while(1){

        cout << endl;
        cout << "Library System" << endl;
        cout << "1. Register Book" << endl;
        cout << "2. Lend Book" << endl;
        cout << "3. Return Book" << endl;
        cout << "4. Book List" << endl;
        cout << "select menu : ";
        cin >> selectMenu;
        
        if(cin.fail()){
            cin.clear();
            cin.ignore(1024,'\n');
        }
        
        switch(selectMenu){
            case MENU_REGISTER:
                if(bRegister(myBook, bookCount) == -1){
                    ErrorHandling("Cannot Register");
                    continue;
                }
                break;
            case MENU_LEND:
                if(bLend(myBook, bookCount) == -1){
                    ErrorHandling("Cannot Lend");
                    continue;
                }
                break;
            case MENU_RETURN:
                if(bReturn(myBook, bookCount) == -1){
                    ErrorHandling("Cannot Return");
                    continue;
                }
                break;
            case MENU_LIST:
                if(bList(myBook, bookCount) == -1){
                    ErrorHandling("Cannot Print List");
                    continue;
                }
                break;
            default:
                continue;
        }
    }
    return 0;
}

int bRegister(Library *b, int& bookCnt){
    if(bookCnt == MAX_BOOK_COUNT)
        return -1;
    system("clear");
    cin.ignore(1024,'\n');
    cout << "Book name : ";
    cin.getline(b[bookCnt].bName, BOOK_NAME_SIZE);
    cout << "Lending Price : ";
    cin >> b[bookCnt].bPrice;
    cout << "Book Number : ";
    cin >> b[bookCnt].bNumber;
    b[bookCnt].isLend = false;
    
    ++bookCnt;
    system("clear");
    return 0;
}

int bLend(Library *b, int& bookCnt){
    if(bookCnt == 0)
        return -1;
        
    system("clear");
    cin.ignore(1024,'\n');
    char bookNameToLend[BOOK_NAME_SIZE];
    cout << "input Book name to lend : ";
    cin.getline(bookNameToLend, BOOK_NAME_SIZE);
    for(int i=0; i<bookCnt; i++){
        if(!strcmp(bookNameToLend, b[i].bName)){
            b[i].isLend = true;
            cout << b[i].bName << " lended" << endl;
        }
    }
    return 0;
}

int bReturn(Library *b, int& bookCnt){
    if(bookCnt == 0)
        return -1;
    system("clear");
    cin.ignore(1024,'\n');
    char bookNameToReturn[BOOK_NAME_SIZE];
    cout << "input Book name to return : ";
    cin.getline(bookNameToReturn, BOOK_NAME_SIZE);
    for(int i=0; i<bookCnt; i++){
        if(!strcmp(bookNameToReturn, b[i].bName)) {
            b[i].isLend = false;
            cout << b[i].bName << " returned" << endl;
        }
    }
    return 0;
}

int bList(Library *b, int& bookCnt){
    if(bookCnt == 0)
        return -1;
    system("clear");
    cout << "============ book list =============" << endl;
    for(int i=0; i<bookCnt; i++){
        cout << "Book Name\t" << b[i].bName << endl;
        cout << "Lending Price\t" << b[i].bPrice << endl;
        cout << "Book Number\t" << b[i].bNumber << endl;
        if(b[i].isLend)
            cout << "on Lending" << endl;
        else
            cout << "on Library" << endl;
        cout << "===================================" << endl;
    }
    return 0;
}

void ErrorHandling(string msg){
    system("clear");
    cout << msg <<endl;
}


'Computer > C와 C++' 카테고리의 다른 글

7월 10일  (0) 2018.07.11
7월 3일  (0) 2018.07.03
7월 2일 C/C++  (0) 2018.07.02

1. 별 찍기 다이아몬드

#include <iostream>

#include <math.h>

using namespace std;

#define n abs(i)


int main(){

    for(int i=-4; i<=4; ++i){

        for(int j=0; j<n; j++)

            cout << " ";

        for(int j=0; j< 2*(4-n)+1; j++)

            cout << "*";

        cout << endl;

    }

    return 0;

}



2. *(a+i)

int *a로 선언된 포인터 정수형 a에서 *a+i가 아닌 *(a+i)로 i번째 요소를 가져올 수 있다.



3. malloc의 반환 값은 항상 (void*)

malloc의 사용

int *a1 = (int*)malloc(4*sizeof(int));

int a2[4];

int *tmp;


a1=tmp가 가능하지만 a2=tmp 불가능.


4. 포인터를 배열처럼 쓸 수 있으나 포인터!=배열



5. 깊은 복사와 얕은 복사

 클래스의 복사생성자 사용 두 인스턴스의 각 변수가 가리키는 주소가 같은 것을 얕은 복사라고 한다. 하나를 지워버리면 해당 주소의 값이 사라지기 때문에 나머지 하나에서는 오류. 그래서 깊은 복사를 한다. 깊은 복사 시 복사생성자에 의해 생성된 나머지 하나의 인스턴스도 같은 값을 가지는 변수를 새로 할당받는다.

얕은 복사



깊은 복사




6. 연산자 오버로딩

1) 멤버 함수 연산자 오버로딩

 p1 + p2는 p1.operator+(p2);


2) 전역 함수 연산자 오버로딩

 p1 + p2는 operator+(p1, p2);


7. template swap


#include <iostream>
using namespace std;
template <typename T>

void swap(T *a, T *b){
    T *temp;
    temp = a;
    a = b;
    b = temp;
}

int main(){
    int a = 5;
    int b = 10;
    string c = "hello";
    string d = "hi";
    swap(a,b);
    swap(c,d);
    cout << a << " " << b << endl;
    cout << c << " " << d << endl;
    return 0;
}


'Computer > C와 C++' 카테고리의 다른 글

7월 10일  (0) 2018.07.11
학생 관리 프로그램 & 도서관 책 관리 프로그램  (0) 2018.07.06
7월 2일 C/C++  (0) 2018.07.02

1. namespace

namespace K
{
  int a = 0; 
}
불러올 때  K::a


2. char*과 String의 차이

A. char *a = "abc";

B. String a = "abc";

A는 char형의 "abc"를 가리키는 포인터 타입. (a가 가리키는 것을 바꾸면 세그먼트 폴트 오류)

B는 String클래스의 오브젝트를 생성. a는 String 클래스의 인스턴스. (length(), size() 등 사용가능)


3. _T("")

유니코드를 멀티바이트로 변경


4. 표기법의 종류 (camel, pothole, pascal)

a. camel

int myFristVariable

b. pothole

int MyFirstVariable

c. pascal

int my_first_variable


5. 3.14f와 3.14의 차이

기본적으로 f를 붙여주지 않으면 double형으로 선언된다.


6. cin과 scanf

cin은 처리속도가 scanf에 비해 2~3배 느리다. stdio 버퍼와 동기화하는 과정에서 느려지기 때문.

하지만 코드에 std::ios_base::sync_with_stdio(false);를 추가해주어 동기화를 풀어준다면 scanf와 속도가 비슷해진다.


7. gets와 fgets와 cin.getline

gets는 \n을 만날때 까지 버퍼를 비울 수 없다. 버퍼의 크기를 넘어설 경우 위험.

fgets는 버퍼의 크기를 지정해줄 수 있다.

위 두개는 c언어의 이야기. c++에서는 getline을 사용하면 됨.

getline(cin, string); 한 라인 단위로 받아옴.


8. XOR(Exclusive OR)

같을 때 False

다를 때 True


9. rand()함수의 사용

srand((unsigned int)time(0)) 선언. (매번 무작위 숫자 생성)

rand()%100. 

실무에선 난수 발생알고리즘을 따로 만들어 사용.


10. 열거체 enum

enum {

RCK=1,

PPR,

SRS

}

일 때 RCK는 1, PPR은 2, SRS는 3.



https://ide.c9.io/cccc1763/cpp_basic_1807

180702 Folder

1_shift                shift 연산

2_enhancement    아이템 강화 프로그램

3_RPS                가위바위보

4_decToHex        10진수를 16진수로

'Computer > C와 C++' 카테고리의 다른 글

7월 10일  (0) 2018.07.11
학생 관리 프로그램 & 도서관 책 관리 프로그램  (0) 2018.07.06
7월 3일  (0) 2018.07.03

+ Recent posts