Skip navigation.

DTM' Blog

I can do it, you can do it, and we all can do it >:D<<

Posts tagged with "C++er"

How to install Eclipse for C/C++

"The Eclipse Platform is a kind of universal tool platform - an open extensible IDE for anything and nothing in particular".
Eclipse platform chính là một tool platform, là một open IDE, tức là nó có thể hỗ trợ cho mọi ngôn ngữ như C/C++, PHP, Javascript.. chứ không riếng gì Java
Nếu là một người mới học C/C++ chắc hẳn các bạn rất quen thuộc với DevC++, CodeBock, Visual studio.. Trong bài viết này mình xin hướng dẫn cách cài đặt bộ công cụ Eclipse for C++
-----
*Trước tiên các bạn download Eclipse IDE for C/C++ Developers (tức là Eclipse đã được Plugin sẵn CDT (C/C++ development tools) hoặc tài bản Eclipse Classic và CDT )
*Tiếp theo download MinGW tools
*Install MinGW
1. Chạy file MinGW-...exe (e.g MinGW-5.1.4.exe)
2. Chọn thư mục bạn muốn cài đặt(và hãy nhớ vị trí này) (e.g C:\MinGW)
3. Chọn full install
4. Set path enviromnet variable như sau :
- Vào Control Panel/System/Advanced/Environment Variables
- Chọn path trong list System variables
- Press Edit
- Trong Variable value các bạn chèn thêm vào phía cuối một giá trị MinGW director (e.g ;c:\MinGW\bin)
* Install Eclipse for Cdestination loacation/C++ Developers
- Unzip gói Eclipse vừa download vào một thư mục (e.g C:\Programfile\Eclipse)
- Chạy file eclipse.exe và các bạn đã có một IDE lý tưởng để học C/C++
*Ngoài ra các bạn có thể cài đặt gdb giúp cho việc debug
- Download gdb
- Chạy file gdb-..exe
- Chọn thư mục cài đặt chính là MinGW director.
--------
Bây h thì hãy chạy thử một chương trình Hello word đơn giản bằng cách
- Vào file chọn New/C++ Project
- Add Project name,
- Trong phần Project types chọn Executable/Helloword C++ Project
- Chạy file projectname.cpp và xem thử nhé


Ngoài ra Eclipse còn khá nhiều tính năng khác, các bạn có thể tự nghiên cứu và chia sẻ vs DTM nhá >: D<

Các hàm cơ bản

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
using namespace std;

void xuathien(int A[], int N);
void output(int [], int n);
void input(int [], int n);
void xap_xep(int [], int n);
int MaxNumber(int [], int n);
int isprime(int x);
void inputPrime(int[], int n);
void xoasotrungnhau(int[], int n);
int solanxuathien(int [], int n, int x);
void doantangcosophantunhieunhat(int[], int n);
void MaxSum(int[], int n);
main()
{
      int iaData[100], iN;
      int iCnt;
      cout<<"Nhap so phan tu cua day n = ";
      cin>>iN;
      
      input(iaData, iN);            // nhap vao mot day so
     
      output(iaData, iN);           // in ra day
      
      cout<<"\nDoan tang co so phan tu nhieu nhat cua day : \t";  //tim doan tang co so pt nhieu nhat
      doantangcosophantunhieunhat(iaData, iN); 
      
      cout<<"\nDay so sau khi xap xep theo thu tu giam dan : \n";  // xap xep giam dan
      xap_xep(iaData, iN);          
      
      cout<<"\nSo lon nhat trong day : "<<MaxNumber(iaData, iN); // tim so lon nhat trong day
      
      int iA;
      cout<<"\nTim so lan xuat hien trong day cua A = "; cin>>iA;         // so lan XH cua mot pt trong day
      cout<<"\nSo lan xuat hien cua "<<iA<<" = "<<solanxuathien(iaData, iN, iA);
      
      cout<<"\nSo nguyen to trong day \n";        // in ra cac so nguyen to cua day
      inputPrime(iaData, iN);
      

      getch();
      
}
///////////////////////////////////////////////////////////////////////
void input(int A[], int n)
{
     for(int iCnt=1; iCnt <= n; iCnt++)
     {
             cout<<"Nhap phan tu thu "<<iCnt<<" : ";
             cin>>A[iCnt];
     }
     
}
void output(int A[], int n)
{
     for(int iCnt=1; iCnt <= n; iCnt++)
     {
             cout<<A[iCnt]<<"\t";
     }
}
void xap_xep(int A[], int n)
{
     for(int iCnt1=1; iCnt1 <= n; iCnt1++)
     for(int iCnt2=(iCnt1+1); iCnt2 <= n; iCnt2++)
     {
             if(A[iCnt2] > A[iCnt1])
             {
                         int Temp = A[iCnt1];
                         A[iCnt1] = A[iCnt2];
                         A[iCnt2] = Temp;
             }
     }
     for(int iCnt=1; iCnt <= n; iCnt++)
     {
             cout<<A[iCnt]<<"\t";
     }
}
int MaxNumber(int A[], int n)
{
     int Max = A[1];
     for(int iCnt=2; iCnt <= n; iCnt++)
     {
            if(Max < A[iCnt])
            {
                   Max = A[iCnt];
            } 
     }
     return Max;
}
int isprime(int x)
{
    int KT = 1;
     if(x<1)
     {
            KT = 0;
     }
     else
     {
         for(int iCnt=2; iCnt <= (int)sqrt(x); iCnt++)
         {
                 if(x%iCnt == 0)
                 {
                           KT = 0;
                 }
         }
     }
     return KT;
}
void inputPrime(int A[], int n)
{
     int iaPrime[100], iCntPrime=0;
     for(int iCnt=1; iCnt<=n; iCnt++)
     {
             if(isprime( A[iCnt]) == 1 )
             {
                         iCntPrime++;
                         iaPrime[iCntPrime] = A[iCnt];
             }
     }
     xoasotrungnhau(iaPrime, iCntPrime);
    
}
void xoasotrungnhau(int A[], int n)
{
     int KT[50];
     for(int iCnt=1; iCnt <= n; iCnt++)
     {
             KT[iCnt]=1;
             for(int iCnt1=(iCnt+1); iCnt1 <= n; iCnt1++)
             {
                     if( A[iCnt1]==A[iCnt] )
                     {
                         KT[iCnt] = 0;
                     }
             }
             
     }
     for(int iCnt=1; iCnt <= n; iCnt++)
     {
             if(KT[iCnt]) 
             {
                          cout<<A[iCnt]<<"\t";
             }
     }
}
int solanxuathien(int A[], int n, int x)
{
     int iCntX = 0;
     for(int iCnt=1; iCnt <= n; iCnt++)
     {
            if(A[iCnt] == x)
            {
                       iCntX++;
            } 
     }
     return iCntX;
}
void doantangcosophantunhieunhat(int A[], int n)
{
     int maxStart=1, maxEnd=1, tmpStart=1, tmpEnd=1;
     int maxlen=0, tmplen=0;
     for(int iCnt=2; iCnt<=n; iCnt++)
     {
             if(A[iCnt] < A[tmpEnd] )
             {
                        if(maxlen < tmplen)
                        {
                                  maxStart = tmpStart;
                                  maxEnd = tmpEnd;
                                  maxlen = tmplen;
                        }
                        tmpStart = tmpEnd = iCnt;
                        tmplen =1;
             }
             else
             {
                 tmpEnd++;
                 tmplen++;
             }
     }
     if(maxlen < tmplen)
     {
               maxStart = tmpStart;
               maxEnd = tmpEnd;
     }
     for(int iCnt=maxStart; iCnt <= maxEnd; iCnt++)
     {
             cout<<A[iCnt]<<"\t";
     }
}
void MaxSum(int A[30][30], int n)
{
     
}
void xuathien(int A[], int N)
{
     int iKT[30];
     for(int iCnt=1; iCnt <= N; iCnt++)
     {
             iKT[iCnt] = 1;
     }
     for(int iCnt=1; iCnt <= N; iCnt++)
     {
             if( iKT[iCnt] )
             {
                 int SL = 1;
                 for(int iCntT = (iCnt + 1); iCntT <= N; iCntT++)
                 {
                         if( A[iCnt] == A[iCntT] )
                         {
                             SL++;
                             iKT[iCntT] = 0;
                         }
                 }
                 cout<<"\nSo lan xuat hien cua "<<A[iCnt]<<" : "<<SL;
             }
     }
}

Cac dang matrix

n// Tong hop cac dang matran xoan
#include <iostream.h>
#include <conio.h>
void matranxoanoc1( int N);
void matranngang(int N);
void matranxoanoc2(int N);
void matranvien(int N);
main()
{
      int iN, iaData[100];
      cout<<"NHAP VAO DO LON CUA MA TRAN A[n][n] : n = ";
      cin>>iN;
      cout<<"\n-------------------------------------------\n";
      
      cout<<"Matran xoan oc tu ngoai : \n" ;          // matran xoan oc tu ngoai
      matranxoanoc1(iN); 
      
      cout<<"Matran xoan oc tu trong : \n";
      matranxoanoc2(iN);
      
      cout<<"Matran ngang : \n ";                    // matran xoan theo hang
      matranngang(iN);
      
      cout<<"\nMatran vien : \n";
      matranvien(iN);
      
      getch();
}
///////////////////////////////////////////////////////////////////////
void matranngang(int N)
{
     int iaData[50][50];
     int iTurn=1, iStep=1, iCol=1, iRow=1;
     int chancottang=N, chancotgiam=1;
     
     for(iStep=1; iStep <= N*N; iStep++)
     {
           iaData[iRow][iCol] = iStep;
           switch(iTurn)
           {
                        case 1:
                             {
                                      if(iCol < chancottang)
                                      {
                                              iCol++;
                                      }
                                      else
                                      {
                                          iTurn++;
                                          iRow++;
                                      }
                                      break;
                             }
                        case 2:
                             {
                                      if(iCol > chancotgiam)
                                      {
                                              iCol--;
                                      }
                                      else
                                      {
                                          iTurn = 1;
                                          iRow++;
                                      }
                                      break;
                             }
           }       
     }
     for(int iCntRow=1; iCntRow <= N; iCntRow++)
     {
             for(int iCntCol=1; iCntCol <= N; iCntCol++)
             {
                     cout<<iaData[iCntRow][iCntCol]<<"\t";
             }
             cout<<"\n";
     }
}
void matranxoanoc1( int N)
{
     int iaData[50][50];
     int iTurn=1, iStep=1, iCol=1, iRow=1;
     int chanhangtang = N, chancottang = N;
     int chanhanggiam = 1, chancotgiam = 1;
     for(iStep=1; iStep <= N*N; iStep++)
     {
                  iaData[iRow][iCol] = iStep;
                  switch(iTurn)
                  {
                               case 1:
                                    {
                                        if(iCol < chancottang)
                                        {
                                               iCol++;
                                        }
                                        else
                                        {
                                            iTurn++;
                                            chanhanggiam++;
                                            iRow++;
                                        }
                                        break;
                                    }
                               case 2:
                                    {
                                        if(iRow < chanhangtang)
                                        {
                                                iRow++;
                                        }
                                        else
                                        {
                                            iTurn++;
                                            chancottang--;
                                            iCol--;
                                        }
                                        break;
                                    }
                               case 3:
                                    {
                                        if(iCol > chancotgiam)
                                        {
                                                iCol--;
                                        }
                                        else
                                        {
                                            iTurn++;
                                            chanhangtang--;
                                            iRow--;
                                        }
                                        break;
                                    }
                               case 4:
                                    {
                                        if(iRow > chanhanggiam)
                                        {
                                                iRow--;
                                        }
                                        else
                                        {
                                            iTurn=1;
                                            chancotgiam++;
                                            iCol++;
                                        }
                                        break;
                                    }
                  }
     }
     for(int iCntRow=1; iCntRow <= N; iCntRow++)
     {
             for(int iCntCol=1; iCntCol <= N; iCntCol++)
             {
                     cout<<iaData[iCntRow][iCntCol]<<" \t ";
             }
             cout<<"\n";
     }
}
void matranxoanoc2(int N)
{
     int iaData[50][50];
     int iTurn=1, iStep, iCol=1, iRow=1;
     int chanhangtang = N, chancottang = N;
     int chanhanggiam = 1, chancotgiam = 1;
     for(iStep=(N*N); iStep >= 1; iStep--)
     {
                  iaData[iRow][iCol] = iStep;
                  switch(iTurn)
                  {
                               case 1:
                                    {
                                        if(iCol < chancottang)
                                        {
                                               iCol++;
                                        }
                                        else
                                        {
                                            iTurn++;
                                            chanhanggiam++;
                                            iRow++;
                                        }
                                        break;
                                    }
                               case 2:
                                    {
                                        if(iRow < chanhangtang)
                                        {
                                                iRow++;
                                        }
                                        else
                                        {
                                            iTurn++;
                                            chancottang--;
                                            iCol--;
                                        }
                                        break;
                                    }
                               case 3:
                                    {
                                        if(iCol > chancotgiam)
                                        {
                                                iCol--;
                                        }
                                        else
                                        {
                                            iTurn++;
                                            chanhangtang--;
                                            iRow--;
                                        }
                                        break;
                                    }
                               case 4:
                                    {
                                        if(iRow > chanhanggiam)
                                        {
                                                iRow--;
                                        }
                                        else
                                        {
                                            iTurn=1;
                                            chancotgiam++;
                                            iCol++;
                                        }
                                        break;
                                    }
                  }
     }
     for(int iCntRow=1; iCntRow <= N; iCntRow++)
     {
             for(int iCntCol=1; iCntCol <= N; iCntCol++)
             {
                     cout<<iaData[iCntRow][iCntCol]<<" \t ";
             }
             cout<<"\n";
     }
}
void matranvien(int N)
{
     int iaData[N][N];
     int iRow=1, iCol=1;
     for(int iCnt=1; iCnt <= (int)(N+1)/2; iCnt++)
     {
             for( iCol = iCnt; iCol <= (N-iCnt+1); iCol++)
             {
                     iaData[iRow][iCol] = iCnt;
             }
             iRow++;
             iCol--;
             for( ; iRow <= (N-iCnt+1); iRow++)
             {
                     iaData[iRow][iCol] = iCnt;
             }
             iRow--;
             iCol--;
             for( ; iCol >=iCnt; iCol--)
             {
                     iaData[iRow][iCol] = iCnt;
             }
             iCol++;
             iRow--;
             for( ; iRow >= iCnt; iRow--)
             {
                     iaData[iRow][iCol] = iCnt;
             }
             iRow++;
     }
     for(int iRow=1; iRow <= N; iRow++)
     {
             for(int iCol=1; iCol <= N; iCol++)
             {
                     cout<<iaData[iRow][iCol]<<"\t";
             }
             cout<<"\n\n";
     }
}

Download Opera, the fastest and most secure browser
December 2009
M T W T F S S
November 2009January 2010
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31