Showing posts with label C Plus Plus. Show all posts
Showing posts with label C Plus Plus. Show all posts

Monday, December 8, 2014

C++ Variables and Data Types

  No comments    
categories: 

C++ Variables and Data Types

A Variable is what the program used to store  value in computer's memory temporarily.
The value stored in a memory location is cleaned wen the program that uses it terminates.

Data Types

Data types of variable tell the computer to store different types f value such as number, text, true/false. etc.
They also inform the computer to reserve the different memory's spaces for those variables.
Here is a table of the data type of variables that can be used:


Declaring variables

In C++ before you can use a variable to store any value. it must be declared.
To declare a variable in C++ you must write down its name immediately after its data type.

Example:

int a;//declare a variable named a to store an integer value
You can declare more than one variables of the same type on a single line by separating them with commas.

Example:
 int a,b;

Assigning values to variables
Example:
int a=10;
char c='a';
bool b=true;

Alternatively, You can write as shown below.

int a;
a=10;
char c;
c='a';
bool b;
b=true;

In C++, A variable can also be a signed variable or an unsigned variable.
Signed means that it can have negative numbers and Unsigned means it can't but unsigned gives a variable a greater positive range.

Example:

unsigned int a;

To give the variable a smaller or bigger range respectively. you need to put short or long keyworks.

Example:

short int a;

String data type

A string is a type of variable that can store multiple words.
You can declare a string in three ways.
The first is to declare it as a string pointer by using *symbol the * means that it points to the first character of the string.

Example:
 char *b;
s="Hello";

The second way is to declare it as an array of characters which you must set size when you declare it.
You have to use the strcpy command to assign values to it.
You must also include the string header file to be able to use the strcpy command

Example:

#include<string>
char s[20];
strcpy(s,"Theara");

The last way is to use the string data type

Example:

string s="C++ Programming";

Thursday, November 27, 2014

C++ Basic Syntax and comnets

  No comments    
categories: 
C++ Basic Syntax

In the previous post, you learned to create simple Hello World program in C++ by using Dev-C++ editor. This tutorial teaches you the basic syntax of C++ programming language that you should know since you are new to this computer programming language.
#include <iostream> It is statement written down to include iostream header file. that will allow us to use the command to receive input from users and diplay text on the screen.

using namespace std; The statement will import std namespace and allow us to use commands without having to type out their full name. A namespece defines name of varialbe or functions so that they do not conflict with other variable or functions that have the same names.

** C++ program will start from the main method;

int main(int argc, char *argv[])
{

}

** Return 0; This statement will tell the C++ compiler that your program ends here without any error.A value other than zero will be treated as abnormal termination by the operation system.

Cout followed by <<
it is used to print text on the screen

Comments

Like other language, in C++ programming language, comments are used to explain the code written or to exclude the part of code from being excuted. There are two types of comments.

1.. // is used to make comments for a single line. you can write only a single line of text or code after the single-line comments. For a normal text, it will be used to explain or describe the code. If you place the C++ code after the comment, this code won't be compiled.
2../* */ is used to make comments for multiple lines. you can write multiple lines of text or code in the multiple-line comment block. if you place the code between /*and*/, the won't be compiled.

Example

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
/*Your first program will print the words Hello World on the screen*/
{
cout<<"Hello World\n";//Print Hellow world ont the screen
system("pause");
return 0;
}




The Result



Tuesday, November 25, 2014

What is C++? (The First Program)

  No comments    
categories: 
What is C++???

C++ is an Object-Oriented Programming language that is one of the most pupular languages in the world. C++ programmng language extends C programing language by adding mainly the Object-Oriented (OOP) concept to the core.
In this The C++ programming langurge totorial, you will start with the basi knowledge required to get up and running with C++. Then you will learn some basic and advanced concepts of C++ programming language (along with workabe example code and sample program)
Including C++ variable an data type, operators and expression, conditional statements or decision making, loops or repetitions, array, structure,string manipulation methods, Object-Oriented programming concept, database connectivity and manipulation, file stream, grahic programming, and other example programs source code.
To develop software, normally you need to have a software development tool. 



On the new File menu, select New. The select Project Application and enter the name of the project in the Name text box.
Then Click OK to create the project.







Example:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
cout<<"Hello World\n"<<endl;
system("pause");
return 0;
}




It will prompt you to the save the project. Please save the project. Then you will get the code block as shown below.
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
system("pause");
return 0;
}

You won't need to remove this existring code block. Simply you will write the line of code:
count<<"Hello World\n" above the system ("PAUSE");statement.

This is Result of C++ code above