Sunday, October 17, 2010

[DSA] Common Mistakes in Programming

There are few categories of mistakes/error/bug in programming. Suchs as logic erros, syntax errors, core dumpz (run time error)/
I came across many many types of mistakes in programming that student commit. These mitakes fall majorly into the syntax error which is the easiest to troubleshoot. As compared to logic errors, there are formal mathematical way to prove that the logic and the premise it holds.

As the old programming guru’s mantra: “It takes more pairs of eyes to spot the bug”

Below is NAF (Need A Fix) buggy code that I have created (50lines only....easy). Your "TASK" is to "SOLVE IT", "FIX IT", PLS DO NOT EAT IT!!!

PLS POST/SHARE your answers here, add in as comments.
//=======================================================




//=========================================================

NO KICK???????????!!!!!!!!!!!

try the below (100lines, 5qns), covers strings, STL containers, iterators. Errors such as syntax error, runtime error and a little bit of logic error.

Note: "HEROES ONLY"

//==========================================================



19 comments:

xz said...

Cannot go pass the void errors. Any tips?

sjteo said...

the code at which line?

xz said...

for the 50-line. 1st void error already cannot pass.

sjteo said...

erm... the error is at which line?

HY said...

He's talking about line 6: "void whyCallMe(input){". "input"'s variable type is not declared.

heng gnee dcpe/2b03 said...

cher, I am stuck for the common mistakes program...


int result = 0;
string strIn = "";
cout << "Spot the common mistake(s)" << endl;

result = func1(int 10,int 20);
cout << "sum 10+20: " << result << endl;


this part there is a syntax error and I cannot find it... can help me?

HY said...

@ heng gnee: When you call a function, you don't declare the values that you pass to the function.

sjteo said...

@heng gnee,
==>result = func1(int 10,int 20);

i already mentioned this example in class. just pass the number directly will do.

sjteo said...

@HY, thanks for helping~~

heng gnee dcpe/2b03 said...

http://snipt.net/hengnee/50-error-code

this is what I have managed so far...

Johnathan Teo DCPE 2A/05 said...

http://snipt.net/sgxbuster/50-line-not-com


not done dunno how do le

HY said...

@Johnathan Teo
Use your codeblock compiler to check the errors. You need to be able to recognize what kind of error it is when they show you. You need to know this during the lab tests, quizzes and exams.

sjteo said...

@Johnathan, take a look at syntax error. usually they have a red wormly line below it. like you have a typo in m$ word.

then look at compiler output in the command window. it will give you some hints on the error.

heng gnee dcpe/ft/2b/03 said...

http://snipt.net/hengnee/success-in-removing-mistakes


the getline part was the only part that I didn't get in the previous version of my post.

had to do damn lot of research to know that getline(cin, whatever) to input string and pass it through function... sorry for the very late work...

sjteo said...

@heng gnee,
is better late then never.
anyway, the hints already released on the week discuss about I/O stuff

sjteo said...

@heng gnee,
is better late then never.
anyway, the hints already released on the week discuss about I/O stuff

Yi Wei said...

http://snipt.net/jellybanana/naf-50-lines

with a little help from henggnee, i have managed to finish this. Sorry bout the delay, I just started my engine haha.

Yi Wei said...

http://snipt.net/jellybanana/naf-100-lines

Help me check if I've done it correctly, thank you.

sjteo said...

@yiwei,
being later is better then never