Wednesday, December 10, 2008

Problem Solving With C++(Basic Level)

Problem Solving With C++


Hi,in this blog I want to share my knowledge about programming too.I hope i can help other people to learn about programming too.Im not a good student in this course but i have little knowledge to share with others.However you can read and help me to complete the lesson here.I does this because I like to helps other students.Okey for first step i want write about C++.Problem Solving with C++ is a first course learn at University Of Technology MARA(UITM) and my lecturer's name is Puan Norlela Shamsudin.


To write all articel about C++,I refer to my note books,text books and websites to write my articels here because i dont want to share wrong knowlegde with you.Im still learning and if i write or telling you something wrong,please tell me back okay.I like this course because it is very interesting and one day I want to be a expect programmer.I want to create my own program using my own idea and creativite.So i learn hard for it.In my record,I get the highest mark 4/6 times for quiz and 2/2 times for tests.Totally i get 6/8 times highest mark in my class.hahaha.It is not easy to be like that but it is not impossible.I study hard for it.Thank to my lecturer because teach me very well.

Okay,let start learn about C++..........


Introduction To Computer Program.

Why is programming important??

a computer without a program is useless.A computer must have a program to input,process and output data.Before a program is written,a programmer analyzes the requirements and designs correct algorithm so that the program will produce the desired output.Therefore,it is very important that programmers have a good understanding of computers,problem solving approaches and composition of the chosen programming languages.


What I Should Know About Programming??

1.Indentation-help in making the structure of the programm clearer and easier to read.

Example:

Before Identation

if(score>80)
{highest=highest+1;
cout<<"Highest scores";}
else
{low=low+1;
cout<<"lower";}

After identation

if(score>80)
{
highest=highest+1;//one statement
cout<<"Highest scores";//one statement.....so they have two statement.dont forget to use { }
}

else
{
low=low+1;
cout<<"lower";
}

Faisal say:using indentation we can define and read code easyly.as a programmer,you should can make indentation in your writing code.Ensure to use brace { } when you write more then one statement.

2.Comments

comments can be placed anywhere within a program and they will not be executed by the compiler(Other word,not be read by compiler)

a)line comment-start will two slashes(//)and continues with your statement or comment
Example: //main function

main()
{
float perimeter,length;//declaretion statement<-------this is a comment


}//end of main function<-------this is a comment

b)Block comments-start with /* and end with */

example: /* this is my first program*/<----- this is a comment

Faisal say:I recommend to use line comments because it is easy to use and remembers.

3.Program Error

a)Syntax errors-error in the structure or spelling of a statements.

Five(5) comman syntax errors:
1.missing semicolon(;)
2.misspelled reserver word or identifier(cout,cin,void,,,,)
3.Missing a quate("" or ' ')
4.Wrong between slash / with backslash \
5.Invalid use of insertion symbol (>>) or out symbol (<<)

b)Logic error-Flaw in the program or statement

Faisal say:dont worry about syntax error because Turbo C++ will show message the wrong statement but for for logic error,it will be hard to define it because compiler can not define this error.however your program still can run well.