계산 게임 나는 만든다 2014. 3. 29. 18:14

Arithmetic.exe


  숫자 계산을 빨리 하고 싶다고 생각하고 있었던 중, 우연히 '수학의 제왕'이라는 어플을 접했다. 아쉬운 면도 있었지만 쓸 만한 어플인 것 같았다. 나도 계산 능력 향상을 위한 프로그램을 만들어 볼 수 있을 것 같아서 작성해 보았다. 




#include <iostream>

#include <stdlib.h>

#include <time.h>

using namespace std;

int main()

{

    int select=0;

    cout<<"덧셈: 1 입력"<<endl<<"뺄셈: 2 입력"<<endl;

    cin>>select; 

    if(select==1)

    {    

        int w=1;

        int cnt=0; 

        int time1=time(0);

        while(w==1)

        {

            int sum1, sum2, sum3, answer;

            srand(time(0));

            sum1=rand()%100;

            sum2=rand()%100;

            printf("%9d\n +%7d\n-----------\n       ",sum1,sum2);

            cin>>answer;

            cout<<endl;

            sum3=sum1+sum2;

            if(answer==sum3)

            {

                w=1;

                cnt++;

            } 

            else

            {

                break;

            }

            if(cnt==20)

            {

                cout<<"You've solved all the questions"<<endl;

                cout<<"Total caculation time: "<<time(0)-time1<<" seconds"<<endl;

                break;

            }

        }

    }

    

    if(select==2)

    {

        int w=1;

        int cnt=0; 

        int time1=time(0);

        while(w==1)

        {

            int sub1, sub2, sub3, answer;

            srand(time(0));

            sub1=rand()%100;

            sub2=rand()%100;

            if(sub2>sub1)

            {

                printf("%9d\n -%7d\n-----------\n       ",sub2,sub1);

                cin>>answer;

                cout<<endl;

                sub3=sub2-sub1;

            }

            else

            {

                printf("%9d\n -%7d\n-----------\n       ",sub1,sub2);

                cin>>answer;

                cout<<endl;

                sub3=sub1-sub2;

            }

            if(answer==sub3)

            {

                w=1;

                cnt++;

            } 

            else

            {

                break;

            }

            if(cnt==20)

            {

                cout<<"You've solved all the questions."<<endl;

                cout<<"Total caculation time: "<<time(0)-time1<<" seconds"<<endl;

                break;

            }

        }

    }

    system("PAUSE");

}



'나는 만든다' 카테고리의 다른 글

스택 Stack  (0) 2013.11.27
ReChorder  (0) 2013.10.17
스택 Stack 나는 만든다 2013. 11. 27. 16:40


Stack.exe

 

  숫자를 기억하고 읽을 수 있는 스택 Stack 프로그램을 Dev-C++로 만들었다.

 

 

#include <iostream>
using namespace std;
class Stack
{
    int i;
    int stk[20];
public:
    Stack()
    {
        i=0;
    }
    void push(int num)
    {
        stk[i]=num;
        i++;
    }
    void pop()
    {
        i--;
        cout<<"stk["<<i<<"]="<<stk[i]<<endl; 
    }
 };


int main()
{
    Stack stk;
    char enter[5];
    char pop[4]="pop";
    char push[5]="push";
    int w=1;
    int v=1;


    while(w==1||v==1)
    {
        int t=0;
        int k=0;
        int num;       
        cout<<"Enter push/pop...";
        cin>>enter;
        for(t=0; t<3; t++)
        {
            if(enter[t]==pop[t]){
                k++;
            }
        }
        if(k==3)
        {  
            stk.pop();
            w=1;
        }
        else  
            w=0;
           
        t=0;
        k=0;
       

        for(t=0; t<4; t++)
        {
            if(enter[t]==push[t]){
            k++;
            }
        }   
        if(k==4)
        {
            cout<<"Enter number you want to push"<<endl;
            cin>>num;
            stk.push(num);
            v=1;
        }
        else
            v=0;
    }       
  system("PAUSE");
}

 

  

 

'나는 만든다' 카테고리의 다른 글

계산 게임  (0) 2014.03.29
ReChorder  (0) 2013.10.17
ReChorder 나는 만든다 2013. 10. 17. 00:04

 

ReChorder.exe


C++ 기본서를 배우고 만들어 본 프로그램이다. 

음악 코드를 외우기 위한 프로그램이다.

일단은 근음이 C인 코드만 적었다.

코드의 구성음은 영어 대문자로 입력해야 한다.

Dev-C++로 만들었다.



 

#include <iostream>

using namespace std;

class Chord

{

public:

    char name[9];

    char notes[13];

    Chord(char *name, char *notes);

    Chord(){}

    void setName(char *name);

    void setNotes(char *notes);

};

void Chord::setName(char *name)

{

    strcpy(this->name, name);

}

void Chord::setNotes(char *notes)

{

    strcpy(this->notes, notes);

}

Chord::Chord(char *name, char *notes)

{

    setName(name);

    setNotes(notes);

}


int main()

{

    int i=0, t=1, k=0;

    char answer[20];

    Chord C[16];


    C[0].setName("C");

    C[0].setNotes("CEG");

    C[1].setName("Cm");

    C[1].setNotes("CEbG");

    C[2].setName("C7");

    C[2].setNotes("CEGBb");

    C[3].setName("CM7");

    C[3].setNotes("CEGB");

    C[4].setName("Cm7");

    C[4].setNotes("CEbGBb");

    C[5].setName("CmM7");

    C[5].setNotes("CEbGB");

    C[6].setName("Cm7-5");

    C[6].setNotes("CEbGbBb");

    C[7].setName("Cdim");

    C[7].setNotes("CEbGbA");

    C[8].setName("Csus4");

    C[8].setNotes("CFG");

    C[9].setName("Caug");

    C[9].setNotes("CEG#");

    C[10].setName("Cadd2");

    C[10].setNotes("CDEG");

    C[11].setName("Cadd9");

    C[11].setNotes("CEGD");

    C[12].setName("C6");

    C[12].setNotes("CEGA"); 

    C[13].setName("C9");

    C[13].setNotes("CEGBbD");

    C[14].setName("C11");

    C[14].setNotes("CEGBbDF");

    C[15].setName("C13");

    C[15].setNotes("CEGBbDFA");

   

    while(t==1)

    {

        int count=0;

        cout<<"Enter "<<C[k].name<<" notes : ";

        cin>>answer;

        if(strlen(C[k].notes)!=strlen(answer))

        {

            cout<<"<X>"<<endl;

            break;

        }

        for(i=0; i<strlen(C[k].notes); i++)

        {

            if(C[k].notes[i]==answer[i])

            {

                count++;

            }

        }

        if(strlen(C[k].notes)==count)

        {

            t=1;

            k++;

            cout<<"<O>"<<endl;

            if(k==16)

            {

                cout<<"Congratulations! You have solved all the questions correctly."<<endl;

            break;

            }

        }

        else

        {

            cout<<"<X>"<<endl;

            t=0;

        }

    }

  system("PAUSE");

}



'나는 만든다' 카테고리의 다른 글

계산 게임  (0) 2014.03.29
스택 Stack  (0) 2013.11.27