Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

C++ openGL #02: window size, position, title and color

Bismillahir Rahmanir Rahim
Assalamualaikum everyone!! 

_________________________________

Now i'm showing you how can set a window size, position, title and color in c++ openGL.
we are you using codeblocks for doing compile. if you don't have you can see this tutorials :

http://iubatians.blogspot.com/2015/05/opengl-c-and-glut-using-codeblocks-and.html


Bye the way, our first task is create a project.
In main function:

int main(int iArgc, char** cppArgv) {
glutInit(&iArgc, cppArgv);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutInitWindowSize(650, 350);
 glutInitWindowPosition(200, 200);
 glutCreateWindow("Bangladesh");
 Initialize();
glutDisplayFunc(Draw);
 glutMainLoop();
  return EXIT_SUCCESS;
}

 glutInitWindowSize(width , height );  this function defined your window size width and height 
you can adjust this on your screen as you needed.
note: width and height in pixels

glutInitWindowPosition(X, Y);   this function defined your window position where it will be appear the window when you run the project. 
Window X location in pixels
Window Y location in pixels

glutCreateWindow("here put your window title");  this function defined your window title.

now the last one is change the window color....
go  Initialize() function. Under this function write a function

glClearColor(GLfloat red,,
                       GLfloat green,
                       GLfloat blue,
                       GLfloat alpha);
here alpha must be less than equal  1. you can take color code from here click

Download complete code
















OpenGL, C++ and GLUT using CodeBlocks and MinGW

Bismillahir Rahmanir Rahim

Hey, what's up? Now i gonna show how configure GL,glut in codeblocks.
Download below file:

  1. CodeBlocks
  2. Glut
unzip Glut file .

Step-1:

Copy glut.h file

Go    C:\Program Files (x86)\CodeBlocks\MinGW\include\GL               for 64-bits
         C:\Program Files \CodeBlocks\MinGW\include\GL                        for 32-bits
past here....

Step-2:

Copy glut32.lib file

Go    C:\Program Files (x86)\CodeBlocks\MinGW\lib               for 64-bits
         C:\Program Files\CodeBlocks\MinGW\lib                        for 32-bits
past here....

Step-3:

Copy glut32.dll file

Go    C:\Windows\System32
past here....

Step-4:

Now create a Glut project

Browse your codeblocks MinGW
C:\Program Files (x86)\CodeBlocks\MinGW or
C:\Program Files\CodeBlocks\MinGW

Press Ok! and continue ..........

Now open main.cpp and write at top # include<windows.h>

Then Build and run....

IF showing any kinds of errors like as below

Then copy Glut32.dll

and go to your project location Ex: E:\C++ graphics\Hello\bin\Debug ( it's my project location )
you must go your project location and past glut32.dll file in Debug folder


For more details see the video :

Turing machine recognize a language 0^n1^n | n>0

Bismillahir Rahmanir Rahim

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    char ch[100];
    scanf("%[^\n]s",ch);
    int l=strlen(ch);
    ch[l]='\0';
    int head=0,state=0;
    while(true)
    {
        switch(state)
        {
        case 0:
                if(ch[head]=='0'){
                    state=1;
                    ch[head++]='x';
                    }
                else if(ch[head]=='y'){
                        state=3;
                        ch[head++]='y';
                        }
                else
                    state=5;
                //cout<<ch<<endl;
                continue;
        case 1:
                if(ch[head]=='0'){
                   state=1;
                   ch[head++]='0';
                   }
                else if(ch[head]=='1'){
                        state=2;
                        ch[head--]='y';
                        }
                else if(ch[head]=='y'){
                        state=1;
                        ch[head++]='y';
                        }
                else
                        state=5;
            //cout<<ch<<endl;
            continue;
        case 2:
            {
                if(ch[head]=='0'){
                    state=2;
                    ch[head--]='0';
                    }
                else if(ch[head]=='x'){
                        state=0;
                        ch[head++]='x';
                        }
                else if(ch[head]=='y'){
                        state=2;
                        ch[head--]='y';
                        }

                else
                        state=5;
            //cout<<ch<<endl;
            continue;

            }
        case 3:
                if(ch[head]=='y'){
                    state=3;
                    ch[head++]='y';
                    }
                else if(ch[head]=='\0'){
                        state=4;
                        ch[head]='\0';
                        }
                else
                        state=5;
           // cout<<ch<<endl;
            continue;
        case 4:
            cout<<"Accept"<<"\t";
            cout<<ch<<endl;
            return 0;


        case 5:
            cout<<"Reject"<<"\t";
            cout<<ch<<endl;
            return 0;


        default:
            cout<<"Error"<<endl;
            return 0;
        }
    }

    return 0;
}

For your more clarification You can read this presentation click here

Input & output system in online judge

Bismillahir Rahmanir Rahim
সি প্রোগ্রামিং শেখার পরে যখন কেউ প্রবলেম সল্ভিং শুরু করতে যায়, তখন অনেকেই প্রথম যে সমস্যার সম্মুখীন হয় সেটা হল ইনপুট নেয়া, বিভিন্ন প্রবলেমে বিভিন্ন ভাবে ইনপুট নিতে বলা হয়, কখনও বলা হয় EOF(End Of File) পর্যন্ত ইনপুট নিতে হবে, কখনও বলা হয় N সংখ্যক ইনপুট দেওয়া হবে, এই রকম আরও অনেকরকম ভাবে ইনপুট দেওয়া হয়ে থাকে।
ছোট ভাই বোন যারা এই সমস্যা গুলোর মুখোমুখি হয়েছো তাদের জন্য এই পোষ্টটা ।
কথা না বাড়িয়ে আমরা কাজ শুরু করি। :)

প্রথমে আমরা এই প্রবলেমটা সমাধানের চেষ্টা করব।
Problem link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47352
প্রবলেমের প্রথমে Description অংশে বলা হয়েছে আমাদের A+B বের করতে হবে।
এরপর Input অংশে বলা হয়েছে প্রতি লাইনে আমাদের দুইটা করে Integer ইনপুট দেওয়া হবে এইটাও আমরা সহজেই বুঝতে পারলাম, কারন আমরা অনেক স্মার্ট ।
এর ঠিক পরেই বলা হয়েছে Process to end of file। এইটা আবার কী ?? :-?
End Of File মানে হল ফাইলের শেষ পর্যন্ত আমাকে ইনপুট নিতে হবে। মনে করি টেক্সট ফাইলে এই রকমের একটা ইনপুট আছে,
এখন এই ফাইলের শেষ কোথায় সেটা আমরা সহজেই বলতে পারি। শেষের লাইনে যে 3 আছে সেটার পরেই আমদের ফাইলের শেষ, কিন্তু এই ফাইলটা যদি আমরা দেখতে না পারতাম ??
তাহলে বলতে পারতাম না আসলে ফাইলটা কোথায় শেষ হচ্ছে।
এইখানেও বিষয়টা সেই রকমের আমাকে আসলে বলা হয়েছে একটা ফাইল আছে যাতে কিছু ইনপুট আছে কিন্তু আমি জানি না সেটা কোথায় শেষ, কিন্তু আমাকে সেই ফাইলের শেষ পর্যন্তই ইনপুট নিতে হবে।

সি তে EOF নামে একটা জিনিস আছে, এখন আমরা যদি এভাবে লিখি
while (scanf("%d %d",&A, &B) != EOF) {
        
    }
তাহলে End of File (until  not press Ctrl+z , input will be going on) পর্যন্ত আমার প্রোগ্রাম ইনপুটকে প্রসেস করবে। আমাদের ইনপুট যখন শেষ হয়ে যাবে তখন এই লুপ ব্রেক করবে।

Output অংশে বলা হচ্ছে প্রতিবার A আর B ইনপুটের জন্য আমাদের A+B অউটপুট দিতে হবে।
তাহলে উপরের প্রবলেম এর কোডটা আমারা করতে পারি সহজেই।
#include <stdio.h>

int main()
{
    int A, B;

    while (scanf("%d %d",&A, &B) != EOF) {
        printf("%d\n",A+B);
    }

    return 0;
}


in c++:

#include<iostream>
using namespace std;
int main()
{
    int b,c;
    while(cin>>b>>c)
     cout<<b+c<<endl;
return 0;
}


এখন এই প্রবলেমটা পড়ে দেখি কিছু বোঝা যায় কী না !
এইখানে আমাদের কাজটা ঠিক আগের মতই আমাদের A+B বের করতে হবে।
Input অংশে বলা হয়েছে প্রতি লাইনে আমাদের দুইটা করে Integer ইনপুট দেওয়া হবে এবং এইভাবে অনেক গুলো ইনপুট দেওয়া হবে আমরা জানি নাহ কতক্ষণ ইনপু্ট দেওয়া হবে।
প্রতিবার ইনপুটের জন্য আমাকে অউটপুট দিতে হবে।

একটু চিন্তা করে কোডটা নিজে করার চেষ্টা করুন, আগের প্রবলেমটা যদি বুঝে থাকেন তাহলে এইটা করতে পারবেন খুব সহজেই।

এরপর
এখানে ইনপুট অংশে বলা হয়েছে প্রোগ্রামের শুরুতে একটা ইনপুট দেওয়া হবে N, এর পরবর্তীতে আমাদের কে N সংখ্যক A ও B ইনপুট দেওয়া হবে। একটা লুপ ব্যাবহার করে আমরা খুব সহজেই এইটা করে ফেলতে পারি এভাবে,

    scanf("%d",&N);

    for (i=1 ; i<=N ; i++) {
        scanf("%d %d",&A, &B) ;
        printf("%d\n",A+B) ;
    }

আমি অবশ্য for লুপ ব্যবহার না করে while লুপ ব্যাবহার করি :p

scanf("%d",&N);

    while (N--){
        scanf("%d %d",&a, &b) ;
        printf("%d\n",a+b);
    }


এখন এইটা দেখি
প্রতিলাইনে দুইটা ইনপুট দেওয়া হবে A আর B, যখন A আর B দুইটার মান 0 তখন লুপ ব্রেক করতে হবে।
একটু চিন্তা করলে এইটা করতে পারবেন। চেষ্টা করতে থাকুন।

শেষ প্রবলেম দেখবো আমরা

এইটা অনেক সহজ, বলা হয়েছে অনেক গুলো টেস্ট কেস থাকবে, প্রতি কেসের শুরুতে N ইনপুট দেওয়া হবে, এর পরে একই লাইনে সংখ্যক ইনপুট দেওয়া হবে, সংখ্যা গুলোর যোগফল দেখাতে হবে আমাদের।
যখন N এর মান 0 ইনপুট দেওয়া হবে তখন আমাদের প্রোগ্রাম শেষ করতে হবে।
কোডটা এইভাবে করা যেতে পারে
#include <stdio.h>

int main(){

    int N, i, tmp, sum;

    while(scanf("%d",&N) == 1 && N){

        sum = 0;
        for(i=1 ; i<=N ; i++){
            scanf("%d",&tmp);
            sum = sum + tmp;
        }
        printf("%d\n",sum);
    }

return 0;
}
07. লাইনটা খেয়াল করলে দেখতে পাবেন এখনও পর্যন্ত আমরা এইটার সাথে পরিচিত নাহ। এখানে আসলে কী হচ্ছে ??
আসলে scanf() ফাংশানটা return করে কতগুলো variable সে scan করেছে সেটা।
এভাবে যদি লেখা হয়
scanf("%d %d %d",&a, &b, &c) //এখানে আমি a,b,c তিনটা variable scan করছি তাই এখানে scanf() function retun করবে 3, এভাবে 10 টা scan return করবে 10


আমি যে ৫টা প্রবলেম নিয়ে আলোচনা করলাম সেগুলো ছাড়া আরও ৩টা প্রবলেম আছে, আগের গুলো যদি আপনি বুঝতে পেরে থাকেন তাহলে এই টেকনিক গুলো ব্যাবহার করে আপনি বাকি গুলো করতে পারবেন বলে আমি আশা করছি।

HUST-এ এই প্রবলেম গুলো দিয়ে একটা কন্টেস্ট দেয়া আছে, HUST এ অ্যাকাউন্ট না থাকলে একটা অ্যাকাউন্ট খুলে প্রবলেম গুলো চেষ্টা করতে থাকুন। এর পরে না পারলে আমাকে জানান আমি হেল্প করবো। আর কোথায় কোন ভুল পেলে অবশ্যয় জানাবেন।

কন্টেস্ট এর লিংক

:::::::::::::Collected::::::::::::::::::
সবাইকে ধন্যবাদ। ;)

Algorithm and programming technique list step by step

Bismillahir Rahmanir Rahim
Mathematics:
  • Prime finding(sieve)
  • Prime factorization
  • GCD, LCM
  • Factorial
  • Fibonacci
  • Counting, Permutation, combination
  • Exponentiation
  • Modular Arithmetic
  • Euclid, Extended euclid
Data Structure:
  • Stack
  • Queue
  • Priority Queue
  • Linked list
  • Heap
  • Hash table
  • Disjoint Set, Union Find
  • Binary Search Tree
  • Trie, Suffix Array
  • Segmented Tree,Range minimum Query
  • Binary Indexed Tree(BIT)
  • Heavy light Decomposition
Sorting:
  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Quick Sort
  • Merge Sort
  • Counting Sort
  • Radix Sort
  • Bucket Sort
  • Heap Sort
Searching:
  • Linear Search
  • Binary Search
  • Ternary Search
  • Map, HashMap
Dynamic Programming:
  • Rod Cutting
  • Maximum Sum (1D, 2D)
  • Coin Change
  • Longest Common Subsequence
  • Longest Increasing subsequence, Longest Decreasing Subsequence
  • Matrix Chain multiplication
  • Edit Distance
  • Knapsack problem, 0-1 Knapsack
  • Bitmask DP
  • Traveling Salesman problem
  • Digit DP
Greedy Algorithm:
  • Activity selection/Task scheduling problem
  • Huffman coding
Graph Theory:
  • Graph Representation(matrix, list/vector)
  • Breadth First Search(BFS)
  • Depth First Search(DFS)
  • Topological Sort
  • Strongly Connected Component(SCC)
  • Minimum Spanning Tree(kruskal, prim)
  • All pair's shortest path(Floyd Warshall)
  • Djkastra algorithm
  • Bellman Ford Algorithm
  • Directed Acyclic Graph
  • Bipartite Matching
  • Max-Flow, Min-cost max-flow
  • Cayley's Theorem
  • Articulation Point, Bridge
  • Euler tour/path
  • Hamiltonian Cycle
  • Stable Marriage problem
  • Chinese Postman problem
Number Theory:
  • Josephus Problem
  • Farey Sequence
  • Euler's phi
  • Catalan numbers
  • Burnside's lemma/circular permutation
  • Modular inverse
  • Probability
  • Chinese Remainder Theorem
  • Gaussian Elmination method
  • Dilworth's Theorem
  • Matrix Exponentiation
  • Determinant of a matrix
  • RSA public key crypto System
  • GCD 
  • LCM
  • Euler Totient
Computational Geometry:
  • Pick's Theorem
  • Convex hull
  • Line Intersection
  • Point in a polygon
  • Area of a polygon
  • Line Sweeping
  • Polygon intersection
  • Closest Pair
Game Theory:
  • Take Away game
  • Nim
  • Sprague-grundy Number
String:
  • Naive String matching 
  • Rabin karp Algo
  • Finite Automata
  • Knuth-Marris-Pratt Algo
  • Manacher's Algo
  • Aho korasick's Algo
  • Boyer-Moore algo
Others:
  • Recursion
  • C++ Standard Template Library(STL)
  • Backtracking
  • Hungarian Algorithm

Algorithm and programming Technique list (with relative links)

Bismillahir Rahmanir Rahim
Mathematics:


Data Structure:

Sorting:

Searching:

Dynamic Programming:


Greedy algorithm:


Graph Theory:

Number Theory:


Computation Geometry:

Game Theory:

String:

Others: