Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, November 25, 2011

Learn VB.NET Programming - Lesson 4 - String Handling

What is string handling?

String handling is the use of various methods to manipulate a string into a form that a program needs it in. You will already know from a previous lesson that a string is a variable that stores text. All programs use text in some way since text is used to show messages to the user and for getting input from the user which makes string handling an important part of programming.

String concatenation

String concatenation means joining 2 strings together. To join 2 strings together you can use either an ampersand (&) or a plus (+). Here is an example that uses the ampersand to join 2 strings together with a space between them.

Learn VB.NET Programming - Lesson 3 - Variables


What is a variable?

A variable is something that is used in a program to store data in memory. Variables are used for storing the data that a program is busy working with. Variables can store all sorts of different types of data including things like numbers and text. Variables are important because it is almost impossible to write a useful program that doesn't use them.

Declaring a variable

Here is an example of how to declare a variable followed by an explanation.
Imports Microsoft.VisualBasic
Imports System

Class Variables

   Shared Sub Main()
      Dim MyInt As Integer
   End Sub

End Class

Learn C++ Programming Tutorial Lesson 10 - Classes


Creating a class

The class keyword is used when creating a class followed by the class name. All other parts of the class are put inside curly brackets. The last curly bracket must be followed by a semi-colon. Here is an example of how to create a class called Student.
class Student
{
};

A class can have private members which other parts of the program can't access and public members which can be accessed from outside the class. The private and public keywords are used for this.
class Student

Learn C++ Programming Tutorial Lesson 9 - Reading and writing text and data files


Writing text files

A text file is a file that stores words and sentences in plain text. You must include the fstream.h header file before you can use files. You must then create a ofstream object which will let you open a file and output data to it. When creating the object you must put the name of the file you want to open in brackets. If the file does not exist it will be created and if it already exists it will be cleared.
ofstream f("test.txt");
You write to a file in a similar way as you write to the screen. All you have to do is replace cout with the name of the ofstream object.
f << "Hello";
Use the close method of the ofstream object to close the file when you are finished working with it. If you don't close a file then some data may not be written to it.
f.close();

Learn C++ Programming Tutorial Lesson 8 - Structures


What is a structure?

A structure is used to group variables together under one name. If you have a student structure for example then you will group the student number and student name together.

How to create and use a structure

The first thing to do when creating a structure is to use the struct keyword followed by the structure name. You need to put curly brackets after that which will contain the things that make up the structure. Always remember to put a semi-colon after the curly brackets. Here is an example of a structure called student.

Learn C++ Programming Tutorial Lesson 7 - Functions


What is a function?

A function is a sub-program that your program can call to perform a task. When you have a piece of code that is repeated often you should put it into a function and call that function instead of repeating the code.

Creating your own function

You declare a function in a similar way as you create the main function. You first put void then the function name and some brackets. The function code goes between curly brackets after that. Here is a function that prints Hello.

Learn C++ Programming Tutorial Lesson 6 - Arrays


What is an array?

An array is a group of variables that uses one name instead of many. To access each of the individual variables you use a number.

How to use an array

To declare an array put square brackets after the name of the array. These square brackets must have the number of variables or elements inside them. Here is an example of how to declare an array of integers which has 3 elements

Learn C++ Programming Tutorial Lesson 5 - Pointers


What is a pointer?

A pointer is a variable that holds a memory address. It is called a pointer because it points to the value at the address that it stores.

Using pointers

If you want to declare a pointer variable you must first choose what data type it will point to such as an int or a char. You then declare it as if you were declaring a variable in the normal way and then put a * in front of its name to show that it is a pointer. Here is an example of how to declare a pointer to an integer.

Learn C++ Programming Tutorial Lesson 4 - Loops


A loop lets you repeat lines of code as many times as you need instead of having to type out the code a whole lot of times.

For Loop

The for loop is used to repeat code a certain number of times between 2 numbers. You have to use a loop variable to go through each loop. The first part of a for loop initializes the loop variable to the number from which the loop starts. The second part is the condition that the loop must meet to exit the loop. The third part is used to increment the value of the loop variable. Here is an example of how to print the word Hello 10 times.

Learn C++ Programming Tutorial Lesson 3 - Decisions


if statement

The if statement is used to test the values of variables and do something depending on the result. For example you can check if a value that the user has entered is equal to a certain value.
int age;
cout << "Enter your age: ";
cin >> age;
if (age == 18)
   cout << "\nYou are 18 years old";

In the above example you will see that we used a == instead of a = because == is used for testing equality and = is used to assign a value to a variable. If the age entered by the user equals 18 then it prints "You are 18 years old" on the screen. Here are the operators that can be used in an if statement.

Learn C++ Programming Tutorial Lesson 2 - Variables and Constants


What are variables?

A variable is a space in memory where a program stores data. Variables can store numbers and letters among other things.

Declaring variables

Before you can use a variable you must declare it. When you declare a variable you choose its data type and give it a name. Here is an example of how to declare a variable of the data type integer with the name i.
int i;
Here is a table of the basic data types that C++ supports.

Learn C++ Programming Tutorial Lesson 1 - First Program

Requirements

Before we start programming in C++ we need a compiler. We will be using a command line compiler for this tutorial. I will be using Borland C++ Compiler 5.5 but you can use any other ANSI/ISO compliant compiler such as gcc.

Hello World Program

Our first C++ program will print the message "Hello World" on the screen. Open a text editor and start by typing the following line:
#include<iostream>

Thursday, November 24, 2011

Learn VB.NET Programming - Lesson 2 - Your First Program


Writing your first program in VB.NET

The first thing you need to do is create a source file. A source file is a text file that contains the source code or in other words the commands that the program must run. VB.NET source files usually have the file extension .vb. We are going to be using Notepad to write our VB.NET code.
Create a text file called hello.vb somewhere where you can easily find it. I am going to create a folder called vbnet in the root of my C drive and then create the source file in there which might be a good idea for you too. Make sure you have the file open in Notepad and then add the lines of code that follow to your source file. Each line of code is explained as I go along.
Imports Microsoft.VisualBasic
Imports System

The Imports keyword is used to import namespaces. This means that you can use the commands in that namespace. The Microsoft.VisualBasic namespace contains commands that you will be using very often that are specific to Visual Basic.NET. The System namespace contains a lot of useful commands and classes, one of which is the command to write things on the screen which you will see later. There are lots of other namespaces to import but the two in the above example are the most important.

Learn VB.NET Programming - Lesson 1 - Getting Started


What is VB.NET?

VB.NET or Visual Basic.NET is a programming language based on Visual Basic and further back than that on the BASIC programming language. It is considered one of the easier programming languages to use. It's ease of use however doesn't make it any less powerful than other programming languages.

Why to learn VB.NET from the command line

VB.NET is usually learnt using a graphical IDE (Integrated Development Environment) such as Visual Studio which is why it is called Visual Basic.NET. There is nothing particularly wrong with learning it

Learn C# Programming Tutorial Lesson 9 - Inheritance, Abstract Classes and Interfaces


Inheritance

Inheritance is the ability of classes to inherit things like methods and variables from another class. This means that you can create one parent class that has a method in it and all the classes that inherit from the parent class can use that method as if it belongs to them as well.
The best way to explain inheritance is with an example. First we will create a class called ParentClass which has a method in it called SayHello() which prints "Hello" on the screen.
using System;

class ParentClass
{
   public void SayHello()
   {
      Console.WriteLine("Hello");
   }
}

Learn C# Programming Tutorial Lesson 8 - Classes and Objects


What is a class?

A class is basically a single module of a program. All C# programs other than the most basic ones use many classes. Classes help to divide up a program into modules so that it is easier to work with the code.
Something you must understand about classes is that they are actually like an architect's plan for a house. You don't usually use the code in a class directly but rather you create objects from a class and use the objects. An object is like the house that is built from the architect's plan.

Learn C# Programming Tutorial Lesson 7 - Working with Strings


Strings are used when displaying messages to the user which happens in almost every program which means that it is very important to understand them well. This lesson will show you some ways to work with strings and how to make it easier to use them.

Methods built into the string data type

The string data type has many methods built into it. The ToUpper() and ToLower() methods for example will change a string to upper case and lower case letters respectively.
string s = "Hello";
string upper = s.ToUpper();
Console.WriteLine(upper);
string lower = s.ToLower();

Learn C# Programming Tutorial Lesson 6 - Methods


When you want to repeat the same lines of code in many different parts of a program you should put that code inside a method and just call the method as many times as you need to.
A method must be created outside other methods including the Main method. Here is an example of how to create a method called PrintHello which will print hello on the screen. The whole program is included to show you where the method must be created.
using System;

class methods
{
   private static void PrintHello()
   {
      Console.WriteLine("Hello");
   }

   public static void Main()
   {
      PrintHello();
   }
}

Learn C# Programming Tutorial Lesson 5 - Arrays


Imagine that you want to enter 10 numbers and calculate their average. You would need to declare 10 variables to do this. That is a lot of variables to have to declare and you still have to read the values in one at a time for each one. An easier way of doing this is to use an array. An array is many variables grouped together under one name.
To declare an array you must first have the data type followed immediately by empty square brackets. After that you put the array's name. Here is how to declare an array of integers called arr.
int[] arr;
This is not an array yet but just a reference to an array. You must set the number of dimensions using the new keyword followed by the data type again with square brackets after it that contain the number of elements you want in the array. The following example creates an array with 3 elements.
int[] arr = new int[3];

Learn C# Programming Tutorial Lesson 4 - Loops


A loop is something that is used to repeat a section of code as many times as you want. If you wanted to print Hello 100 times then you could use 100 lines of code or you can do the same in only a few lines using a loop.

For Loop

The for loop counts from one number to another number. You start a for loop with the for keyword which is followed by brackets. The first section inside the brackets is where you set the starting value of the loop counter variable. The second section is the loop end condition. The third is where the loop counter is incremented. The code to run for the loop goes after the brackets.
Setec Institute || Group : SH6 | | Name : Kim Chanthy. Powered by Blogger.
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Hot Sonakshi Sinha, Car Price in India