Programming tips that always work


OH !!! The problem is easy, I got it, I know what is tricky in the problem, I can definitely make this program and then you just start your work on keyboard and after working for a while all of a sudden you stop writing code.

Does this happens to you a lot of time ???
Okay then I guess, this post will help you in figuring out what you are missing…

So, What do you think, why it happens to you – because you don’t actually know what you need, what you need to design, you know how to write a program, how to code, how to indent and other required things, but what is that makes you stop writing …???

Its the Idea you need to get first of all…See how it helps.
To check that, I’d like you to follow these simple steps every time you begin coding

  1.  To save a lot of time, you don’t really need to start directly with coding, In fact this should be the last thing to do.
    So my first tip is – Take a pen & paper
  2. Observe carefully what is given to you, and what is asked – you may think that it is very simple, but this is what people underestimate, so please don’t just skip this part and give it extra time so that your mind can really understand what the problem is ??
    So the second tip is – Plant the seed of problem in your mind.
  3. Now this is the time where power of experience comes, the more experienced you are in logic designing and problem solving, more quickly you will design you solution.
    The third tip is – Design algorithm – See how this solution will works in your scenario
  4. If you think and if your solution fits over all the problem cases, Its time to move on to keyboard, write all your code what you’ve designed in your algorithm.
    Fourth tip is – Write everything you know( Don’t try to trim the code at this moment)
  5. The time you’ll be exhausted and that’s why this task should be easy and see what you gotta do here
    Fifth tip – Debugging – Try to resolve errors/warnings, indent your code, prepare documentation and try to shorten your code.

 

Always remember……
PROGRAMMING IS NOT ABOUT WRITING A CODE…A TYPIST CAN ALSO DO THE SAME…IT IS ALL ABOUT PROBLEM SOLVING

Full House in a game of POKER — Get the Probability


You want to write a program that

1) has a class ‘card’ which identifies each card from a pack of cards with number and suite like
Example: Ace of Hearts would be ’1H’, 7 of Clubs would be ’7C’, King of Diamonds would be ’13D’ etc.

2) the program should pick a random card from 52 cards that are part of standard deck (without jokers). and basd on card picked, output all possible combnations for a Full house in Poker containing that card.
For example:
if I pick 4S (for 4 of Spades), the output should say: you picked 4S all possible combinations of Full House containing
4S: 4S4C1S1C1H 4S4H1S1C1H 4S4D1S1C1H . . … etc. And

3) Print out the probability that you would get a full house if you pick this card, and 4 more cards at random

Get the code which tells you how much is the probability of getting a full House in a game of POKER from CS_IT folder from my box widget.

How to take one by one images from your webcam using opencv


#include "opencv2/highgui/highgui.hpp"
#include<stdio.h>
using namespace std;
using namespace cv;
int main()
{
 for(int i = 0; i<100;i++)
 { 
 CvCapture* capture = cvCaptureFromCAM(0);
 cvGrabFrame(capture);
 cvRetrieveFrame(capture);
 IplImage* img = 0;
 img = cvRetrieveFrame(capture);
 cvNamedWindow("Window",1);
 cvShowImage("Window",img);
 waitKey(1);
 cvReleaseCapture(&capture); 
 }
 return 0;
}

How to load an image in your opencv program


#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main()
{
 IplImage* img = NULL;
 cvNamedWindow("Image",1);
 img = cvLoadImage("satan.jpg",1);
 cvShowImage("Image",img);
 cvWaitKey(0);
 cvDestroyWindow("Image");
 cvReleaseImage(&img);
 return 0;
}

How to implement ‘Closing’ operation on an image


#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main()
{
 IplImage* newImg = NULL;
 IplImage* procImg = NULL;
 
 cvNamedWindow("Original",1);
 cvNamedWindow("Closed",1);
 
 newImg = cvLoadImage("satan.jpg",1);
 cvShowImage("Original",newImg);
 procImg = cvCloneImage(newImg);
 cvDilate(newImg,procImg,NULL,4);
 cvErode(procImg,procImg,NULL,4);
 
 cvShowImage("Closed",procImg);
 
 cvWaitKey(0);
 cvDestroyWindow("Original");
 cvDestroyWindow("Closed");
 cvReleaseImage(&newImg);
 cvReleaseImage(&procImg);
 return 0;
}

How to implement ‘Opening’ operation on an image


#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main()
{
 IplImage* newImg = NULL;
 IplImage* procImg = NULL;

 cvNamedWindow("Original",1);
 cvNamedWindow("Opened",1);

 newImg = cvLoadImage("satan.jpg",1);
 cvShowImage("Original",newImg);
 procImg = cvCloneImage(newImg);
 cvErode(newImg,procImg,NULL,4);
 cvDilate(procImg,procImg,NULL,4);

 cvShowImage("Opened",procImg);

 cvWaitKey(0);
 cvDestroyWindow("Original");
 cvDestroyWindow("Opened");
 cvReleaseImage(&newImg);
 cvReleaseImage(&procImg);
 return 0;
}

How to implement Dilation operation on an image


#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main()
{
 IplImage* newImg = NULL;
 IplImage* dilateImg = NULL;
 
 cvNamedWindow("Original",1);
 cvNamedWindow("Dilated",1);
 
 newImg = cvLoadImage("satan.jpg",1);
 cvShowImage("Original",newImg);
 dilateImg = cvCloneImage(newImg);
cvDilate(newImg,dilateImg,NULL,4);
 cvShowImage("Dilated",dilateImg);
 
 cvWaitKey(0);
cvDestroyWindow("Original");
 cvDestroyWindow("Dilated");
cvReleaseImage(&newImg);
 cvReleaseImage(&dilateImg);
return 0;
}
Follow

Get every new post delivered to your Inbox.

Join 327 other followers

%d bloggers like this: