September 7, 2011

Example 10

Task:
Create a program that ask for input integers n with the following provisions:
if  n = 5
Output :
***  *
     * *
*****
* *
* ***


Code:
for row <-- 1 to n do
{
  for column <-- 1 to n do
  {
    if (row = 1) and (column <= N div 2 + 1) then
    {
      output("*");
    } else if (row = n) and (column >= n div 2 + 1) then
    {
      output("*");
    } else if (column = 1) and (row >= n div 2 + 1) then
    {
      output("*");
    } else if (column = n) and (row <= n div 2 + 1) then
    {
      output("*");
    } else if (column = n div 2 + 1) or (row = n div 2 + 1) then
    {
      output("*");
    } else
    {
      output(" ");
    }
    output("\n"); /*new line*/
  }
}

September 5, 2011

Example 9

Task:
Create a program that ask for input integers n with the following provisions:
if  n = 5


Output : 
*       *
  *   *
    *
  *   *
*       *
 Code:
for row <-- 1 to N do
{
  for column <-- 1 to N do
  {
    if (row = column) or (row + column = N + 1) then
    {
      output("*");
    } else {
      output(" ");
    }
    output("\n"); /* new line */
  }
}



September 3, 2011

Example 8

Task:
Create a program that ask for input integers n with the following provisions:
if  n = 5


Output :
   *
   *
*****
   *
   *

Code:
for row <-- 1 to N do
{
  for column <-- 1 to N do
  {
    if (row = N div 2 + 1) or (column = N div 2 + 1) then
    {
      output("*");
    } else {
      output(" ");
    }
    output("\n"); /* new line */
  }
}

September 2, 2011

Example 7

Task:
Create a program to calculate the number of words.
Example:
Sentence: learn algorithm
Word count: 2


Code:
input sentence

isAnyWord<-F 
num<-0
for a<-1 to Length(sentence), a++
{
  if sentence[a]!= ' ' then isAnyWord <- T //if not space
  if sentence[a] = ' ' then //if space
  {
    if isAnyWord = T then //if previously there was a word, num++
    { 
      num++
      isAnyWord = F
    } 
  }
}

September 1, 2011

Example 6

Task:
Prompted to enter a user id and password if id and password is correct then the user will view the first entry is required, otherwise the process is repeated from the beginning to user id and password are correct.
Code:
id,password : string

begin
repeat
input id 
input password
   until 
   id = 'username' and  password = '123'
   print('You have entered the main page')
end.

August 31, 2011

Example 5

Task:
Create programs that require the input of a string. Example: If input = hello
Output:  

hello  
e     l
l      l
l     e
olleh

Code:

 //print "hello" first line
 for a<-1 to Length(sentence),a++
 {
   print sentence[a]
   print newline
 }
 //print the second line of until before the last line
 for a<-2 to Length(sentence)
 {
 print sentence[a]
 for b<-1 to Length(sentence)-2{print space}
 print sentence[Length(sentence)+1-a]
 print newline
 }
 //print "olleh" last line
 for a<-Length(sentence) downto 1,a-
 {
   print sentence [a]
 }

August 29, 2011

Example 4

Task:
Make a program  that require input an integer n:
Example:
If n = 3
Output:
1
2
3
2
1

If n = 4
Output:

1
2
3
4
3
2
1


Code:
input n
For a <- 1 to n do a++
{
  print a + newline
}

For a <- n-1 downto 1 do a--
{
  print a + newline
}

August 28, 2011

Example 3

Task:
Create a program that require input an integer n.
example output:
if n = 5
*****
*****
*****
*****
*****

if n = 3
***
***
***

Code :
input n
For a <- 1 to n
{
  For b <- 1 to n
  {
    print "*"
  }
}

August 26, 2011

Example 2

Task:
Make coding that print an even number of 1 to 100.

Code: 
for n <-- 1 to 100
{
  if (n mod 2) = 0 then print n
}

August 25, 2011

Example 1

Task:
Create an algorithm to display numbers 1-100 provided that:

  • Multiples of 3 is replaced with fizz

  • Multiples of 5 is replaced with  buzz

  • Multiples of 3 & 5 be replaced with fizzbuzz
Code :
for num 1 to 100
if mod 3*5 print fizzbuzz
else if mod 3 print fizz
else if mode 5 print buzz
else cetak num

August 23, 2011

Why Learning by Sample?

During I learned a desktop-based visual programming and web-based, there is an important lesson taken from a learning process. That learning programming is very hard to do if starts with a theory and concepts that are too high.

It will lead novices give up before starting the learning process by immediately imagine how hard it is to learn a programming language. Of course it is very harmful for learners, both in the academic world and professional world.

And after trying various methods, came to a conclusion that was a learning process that is considered the author of today's most effective and efficient is to learn programming in a way just try to make applications from the simplest level to the level of the complex in stages. Method that also often called as Learning by Sample referred to as the already proven to learn a programming language faster and better.

The actual method has been applied also by Microsoft to publish the series HOL (Hands On Lab) featuring examples of programming with a certain level and immediately put into practice by the user. HOL unfortunately is rarely noticed by novice programmers, and still not popular usage for both academia and professional.

C++ Language Tutorial

These tutorials explain the C++ language from its basics up to the newest features of ANSI-C++, including basic concepts such as arrays or classes and advanced concepts such as polymorphism or templates. The tutorial is oriented in a practical way, with working example programs in all sections to start practicing each lesson right away.

Introduction:
Instructions for use
Basics of C++:
Structure of a program
Variables. Data Types.
Constants
Operators
Basic Input/Output
Control Structures:
Control Structures
Functions (I)
Functions (II)
Compound Data Types:
Arrays
Character Sequences
Pointers
Dynamic Memory
Data Structures
Other Data Types
Object Oriented Programming:
Classes (I)
Classes (II)
Friendship and inheritance
Polymorphism
Advanced Concepts:
Templates
Namespaces
Exceptions
Type Casting
Preprocessor directives
C++ Standard Library:
Input/Output with files