Easier View

Very sorry, The posts are all mixed-up . View blog archieve to start learning =D

About Me

My name is Luke Chin. Here to teach you guys how to code C++

Thursday, April 12, 2007

Summary

Ok, You have learnt many things so far. If , for , while . different types of statements and conditions.

The For Statement

//The for statement is much similar to the while statement loop wise

#include
using std::cout;
using std::cin;
using std::endl; // if you havent seen this before it justs ends the line

int main()
{

for (int A = 1 ; A<= 30 ; A++)
{
cout << A << endl;

}

system("pause");
return 0;
}

-the for statement is made up of 3 parts

for ("initalization" ; "condition" ; "action")

The while Statement

// The while statement is used to repeat a sequence of statements as long as they are true


#include
using std::cout;
using std::cin;
using std::endl; // if you havent seen this before it justs ends the line

int main()
{
int A;
A=1 ; //just making the variable A which is a number to 1

while (A<=30) //while A lesser or equal to 30 (start)
{
cout << A << endl; // print A
A++; // A + 1
} // (end) the loop just prints A and adds 1 to it prints A again until 30

system("pause");
return 0;
}

The if statement ( A step ahead pay attention)

// the if statement is used to choose alternative courses of actions

#include
using std::cout; //this states that your using it so theres nomore (std::cout) just (cout)
using std::cin; // same as above but for cin

int main()
{
int grade;
cout << " Enter a grade ";
cin >> grade;

if (grade>=90)
cout << "The grade is a A";

if(grade>=80)
cout << "The grade is a B";

if(grade>=70)
cout << "The grade is a C";

system("pause");

return 0;
}


// This is a simple example of if (we will be getting more into the IF later)

-here are some things you need to know

sign meaning
> greater than
< lesser than
>= greater than or equal to
< = lesser than or equal to
== equal to
!= not equal

Doing mathematics in C++

#include

int main()
{
int num1,product,num2;


std::cout << "enter integer 1 :"; std::cin >> num1;
std::cout << "enter integer 2 :"; std::cin >> num2;
product = num1 * num2;
std::cout << product;
system("pause");
return 0;
}


-do you understand what this code does? it asks the user for 2 numbers and multiplies them
and prints the product to the screen.

sign meaning
+ addition
- subtraction
++ increment +1
-- decrement -1
/ divide
* multiplication
% mudulus // returns the remainder

Wednesday, April 11, 2007

Using input in programs (Strings)

#include // input output header file
#include // string header file

int main() // you MAIN function

{
std::string name; // string varaible name

std::cout << "enter your name"; // prompting for the users name std::cin >> name; // accepting name
std::cout << "Hi , " << name; // printing hi , name

system("pause"); // this is used to pause the application


return 0; // ending your program
}

Your First C++ Program =D

#include // input output header file

int main() // you MAIN function
{
std::cout << "Helloworld"; // printing helloworld to the screen

system("pause"); // this is used to pause the application

return 0; // ending your program
}

C++ Glossary

Algorithm
---------------
A procedure or a series of steps for solving a particular problem. The
word derives from the name of the mathematician, Mohammed ibn-Musa
Al-Khowarizmi, a famous mathematician who lived between 780-850.
Algorithms can be written in English or higher-level programming
languages like C++.

Array
---------
A multi-slot variable that can store more than one value. Each value can
be manipulated independantly.

Assembler
-----------------
A piece of software that translates a specific assembly language into
machine language for a specific processor.

Assembly Language
--------------------------------
A set of instructions that a programmer can use to create a program for
use on a specific processor. Assembly language is translated into
machine language by a piece of software called an assembler.

Bit
----
The smallest possible unit of memory. A bit can store only two different
values (0 or 1). The term for a group of eight bits is called a byte.

Byte
--------
A small unit of memory. A byte is composed of eight bits. One bit can
store two different combinations (0 or 1), two bits can store four different
combinations (00, 01, 10, 11), three bits can store eight different
combinations (000, 001, 010, 011, 100, 101, 110, 111); following the
pattern, eight bits, or one byte, can store 256 different values.

Call by reference
---------------------------
Declaring a function argument type to be a reference, thus passing a
reference (name for an object or a function) rather than a value to the
called function.

Call by value
---------------------
Passing a "copy" of an argument to the called function.

Casting
------------
The act of viewing (and often converting) the information contained in a
variable of a certain data type as if that information was of another type.

Class
---------
A container of objects used only in object oriented programming (OOP).
Classes can store data and custom functions for a number of objects that
share certain charactersitics orproperties. A class called "Shape" could
store the objects "circle", 'square", "rectangle" and "triangle".

Comment
---------------
Used to help the programmer to describe source code. They are placed
in the program's code to explain each specific function. This is helpful
when programmers are working in teams or when a programmer
continues work on an ageing program after they might have forgotten
why they used the functionsthat they did. When source code is
compiled into
assembly language, all commentsare removed.

Compiler
--------------
A piece of software that takes your code and translates it into a specific
assembly code. Compilers can be quite complicated pieces of software.
They are used to create wrapped-up, finished files (for example,
executables or dll's)

Cout
--------
In the C++ language, this is the name given to the standard output
stream. Characters that are sent to this stream are outputed to the user.

Debug
-----------
To find and remove errors or logical mistakes in a program.

Execute
--------------
The act of running a certain program. This involves loading the program
from disk into main memory, reserving memory space for the program to
work with, and executing the steps of the program as outlined by the
programmer.

Function
--------------
A block of code that performs a specific operation or task. Most
programming languages come
with a set of functions; however, you can also write your own functions.

Garbage
--------------
Variable values that are undefined, or bad input into a program.

Instruction Set
-----------------------
A set of commands that a specific processor understands. These
instructions are wired into the logic of the CPU.

Keyword
--------------
A word that the programming language uses to perform predfined
commands or functions. For example, "break" or "int".

Machine Language
-------------------------------
A processor specific set of binary codes that correspond to actions to be
taken by the processor of a machine.

Main
--------
In C++, this is the first function that is called when a program is executed.
When a program reaches the end of main(), the program terminates.
Every program in C++ must have a main() function.

Object
-----------
Any item that can be individually selected and manipulated using its
predefined data or functions.

Operator
--------------
A symbol that represents a specific action. For example, a plus sign is an
operator that represents addition.

Parameter
-----------------
A piece of data that is passed into a program, subroutine, or function call.

Path
--------
A path is used to specify where certain files can be found in a directory
tree on disk.

Portable
--------------
The easiness to take a piece of code written in a programming language
and rewriting it in another.

Pseudo-Code
----------------------
A high-level abstraction of code, usually used to outline the general steps
in an algorithm without having to write actual code. Pseudo-code is
useful in the design stage where the basic structure of the program is
drawn.

Record Structure
----------------------------
A structure that can store multiple data types, as branches of a main
variable. For example, the variable "Face" could have member data
variables "nose", "eye", mouth", etc...Manipulating the variable "nose"
wouldbe done as follows: "face.nose".

Return Type
--------------------
Specifies the type of data that is returned from a function call.

Data Type
-----------------
Describes what sort of information a variable stores, as well as how much
space that information takes up.

Variable
-------------
A label, given by a programmer, to represent a piece of data within a
certain program. This name is then used to refer to that piece of data.

C++ Compiler

Dev C++ is a powerful compiler and it is also free , I'll be posting it .
- http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe

P.S
Any C++ compiler will work. ( Highly recommend Microsoft Visual C++ 6.0 )

Posted by CodeGuru at 9:38 PM 0 comments