Monday, 16 March 2015

4th day programming

Task:your task is to  take to int,float,string and char type variables and output each of the datatype in the next line , you got 5 minutes to do this ?


4th day programming:
Today , we are going to see how to take input,

To take input we use a built in object (a command in form of an object ) i.e  cin (in other word it stands for compile input i.e. standard input streaming )
To use this feature you use the command of the object
“cin” in upcoming after it it has the “>>” operator which is extraction or get from operator

Suppose if you want to ask user to input two int type numbers then

#include<iostream>
Int main()
{
Int num1,num2;   /* you can declare  more than one variable at the same time in the same line separated by a (,)  */
cout<<”Enter the num1 and num2”<<endl;
cin>>num1
cin>>num2;
cout<<”\n Entered number is”<<num1<<” \t ”<<num2;

Return 0;
}

As you can see  /* and */ these are the comment lines used by the programmer to comment on the large scale programming programs such that they can be easily be understood.
On the next line you display the output  “Enter the num1 and num2 ”.
Then you input num1 and num2 , (Point to be noted you can also take input as cin>>num1>>num2; but it will become a little complex)
The 2nd last line you can see  “/n” and “/t” in the quotation , These are escape sequence, they have a specific function, like
\n : for next line
\t : for five space jump
\a : bell
\b : backspace
\f : form-feed                        
You can use them in the message but they won’t appear instead their specific function will be performed.
If you want to print the sum you can also print the sum using the arthematic operation (+,-,*,/)
as it work same on the calculator as well as on the computer  since for the sum if you want to print the sum it will be in 2 step.
1)declare the two int or float or double  type variable
2) intialize the two variables
3) using both variable use the arthematic symbol in between them (variable1+variable2);

4)cout the sum of them.


e.g

double no1,no2;

cout<<"Enter the number 1 "<<endl;cin>>no1; 
cout<<"Enter the number 2"<<endl;cin>>no2;
cout<<"\n sum is :"<<(no1+no2);


or you can also
cout<<"Enter the number 1 "<<endl;cin>>no1; 
cout<<"Enter the number 2"<<endl;cin>>no2;
double sum=no1+no2;
cout<<"\n sum is :"<<sum;


 I hope you have understand this easily now its your task to make a calculator of 4 function?

hint:
use same as above ,just change the operations :)

________________________________________________________________________________
Now the thing arises if you want user to ente the number as well as the arthematic symbole (+,-,*,/)
then condition is required

for that there is a keyword object names as if

Writing style :

if(condition)
statment;
else
statment;

or
if (condition)
{statments;
}
else
{
statments;
}


the if keyword check the condition provided in the parenthesis like

int no=5;
int no2=6;

if(no2>no)
{
cout<<"No 2 is greater"<<endl;
}
else
{
cout<<"no1 is greater"<<endl;0
}

if you concentrate in this if else statment the thing which is happening is that

if  is the keyword it check the condition.
is no2 greater than no ???? yes then the statment below if is printed and the else is skipped . :)


SO let suppose if no2 was 5 n no was 6 then condition of if statment will be false hence , else body will be executed so (no 1 is greater will print )
this is the basic decision case for if else statments.



Sunday, 15 March 2015

3rd day programming

3rd day programming :
Task:

Your task is to print your name , phone number , address on the console screen(the executional black) all the data will be in separate lines  . you got 4 minutes for it.??
e.g
 M Shafay  Amjad
0XXXXXXXXXX
Lahore,Pakistan

Hint: Use cout<< statement;
       And endl;  for next line .


If you have done this task you have learn the previous day lecture very  well.
Now today what we are going to do is that we will learn about what are variables, datatypes;

Datatypes: as we all know that the data is in different forms .
1) Data can be of Int (Integer type) which is in form of integer,its high form is double having supporting more numeric value >2e32. J
2) Data could be in the form of decimal notation such as a Float(decimal pointed value) like 3.145 ,0.25 etc.
 3) Data could be a char (in form of characters )type e.g   a,b,c,d  etc
 4) Data could be string type(in form of a string )(in easy word combinations of character,numbers) e.g
   e.g  Shafay ,Charlie Harper , 12shafay90 , HarpersFamily1999. Etc

Our today’s topic Is to know about data type and how to declare(means create them in our program )
First Objective:
Declaring a Datatype.
To declare an Integer type , In the main() function (where everything of your programing code is written )
Writing:Symbol:
Datatypename  Variablename;
Here Datatype is of(Int or float or char or string), while Variable name is (The name you assign to that data type )
e.g:
int no1;
float number;
char ch;
string name;

Here (int,float,string,char) are datatypes  and no1,number,ch,name are variable name given by us to the code ,which is to be compiled by programming language.


Intializing datatypes:
To Intialize you data type you need to use an assignment operator i.e( = ) ,
In programming you use
For int,float,double
Datatype Variablename= value;
e.g:
for Int,Float:
int no=10;
float num=15;

here as you can see the assignment operator assigns the right numeric value to the left side of the variable name .
so Your second Program is going to be declaring and initializing a Int ,and a float Variable.

After executing


You can see in your program the two type of data being declared and initialized , with there respective variable names (num,no).
Output:
     TO print the output , you use the cout statement after that << operational and after that it is followed by the variable name .

Concept: the basic concept of programming declaration is that ,when you declare a variable it assgn that variable their respective byte  as in case of int it allocate (4 byte) data double(8 byte datq)
char 1 byte data , Boolean (1 byte data and others ).
the thing should be kept in mind that the value entered /assigned to the variable should be of its data types, Unless this you will project to an error or miscalculation .
Basic Error or Flaws by Beginners while declaring:

e.g:   int no=10.5;

cout<<no;

as you can see we have assign the basic int variable a value , but what we didnt see coming is that instead of outputing 10.5, it outputs 10. 
its because of the data type you given it ignores the pointed value after and takes the value perior to the decimal value().
pointed value .


in case of char type :
 char variablename= ‘a’;
here all the value rather you assign form (a-z) in char type is assigned right after (=) sign in the single quotes (‘’) which represent it is a character type . The most important thing is that a char type is not a character type formed infact it is an Int type as a computer understand a Machine code , and that Machine code is given to computer in the form of ASCII(American Standard computer Instruction…. Whatever ) .





what we didn't knew that the char datatype can also hold datas like  '\a' for a beep, '\r' for the enter button e.t.c. It a basic question of programming about char as it can hold data in backslash also,
the question arises how ?
Actually there is the thing that a data is to be given in form of ASCII and in ASCII there is a specific Int combination for the combined word like (\r for enter , \a for beep ),
so you can also use these specific buttons using char type .

in case of a String :


Declaration & Initialization of String:

String name="shafay";
Remember the value is assign to the string in the double quotes :)


2nd day programming

hope you have downloaded the codeblocks + robert lafore's book.

This is you first basic programming day
in this day we will Understand Compiler :

What is a Compiler ????
compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for converting a source code is to create an executable program. 
Executable files are the file having the extension .exe at the end .
If you are a gamer while installing a game you run an .exe setup,
it is same as that to execute a program , usually a game is also programmed :) 


1)Now open your codeblock.
2)You can see a link of New Project .. click it .
3) now after next , it will ask  program for C or c++ ? choose c++ as we are using c++, then choose Console Application.
4)now there exist where to save that file , and on the top Text Bar (the white bar)
 it is empty write a name of the program and store it on a specific location where you want to create your work space.
5) now you will see at the left corner   Workspace Below that it will be the name you gave to your program , click on that name and there will be another sub folder file as  main.cpp.
Click it
6) here .cpp is the extension of c++ , every program of c++ has extension of cpp :)
7) now it will pop up the first program.
 it looks like

now here you see.

#include<iostream>
this is know as a header file ,a header file is responsible of implementing other files which perform specific task '#' this represent that you are going to open a directory of <anyname> in diamond notation you write the name of the specific file. So what you're doing here is that ,
You are implementing a Iostream(Input /output streaming ) Folder using Include command ,

2nd line ) you see using namespace std;  Leave  it here for a while as it is intermediate level .
Int main() 
now you see written int main here 
Int stands for Integer, while Main is you can say the Brain of a Program, which performs everything  in it . So the every code you write is to be written inside it. it is know as a main function. since a function (which perform a specific task)hind is to have parenthesis right next to its name like main(). it can also be thought as  main is the opening of a program .
{ } curly braces :
these curly braces are know as the body of main function , in this whole the body of you function like your body all the body comes right down to your head , means your main part of your body.
these represent the opening and the closing end of a body.

cout:
cout stands for compile output(a standard output streaming ( stream is  flow of data representation) ) , it is used to display the output of the specific program.
the next to cout you see  "<<" insertion or put to operator  ... This usually directs the content of variable from right to the object at its Left .
as anything "  Hello world " written in "" format followed by cout<< prints out exact the same as it written. while to display multiple cout you use "<<" again and again after every statement e.g
cout<<"Hello"<<" World!"<<endl; 

here the 
endl:
it is to jump or finish the line you are in and go to the next line 

;

a terminator :
 "; " stands for a terminator , it is used to terminate every line of code, it is at the end of all the codded lines, it usually used to terminate that specific operation, function.
It is the most important and basic mistake in programming.
return 0;
you can see return 0;
as in the function you wrote "int main()"  it has a datatype before the function main() which is int : it represent afte completing the function it will give you a value in integer formate Usually to get that value return Integer; is used . it is used also to freeze the ConsoleApplication such that you can read the code .

Now Compile and Run your Program :


now after running 

Now  you can see on the black windows you statement which you write in the "" quotations and 
a space of a line due to endl;
This is your 2nd day task :)

What is Programming ? Which Language to use? 1 day work

First Objective of being a programmer is to understand what is programming ?
Basically Programming is the way of writing you code of a specific program which performs a specific task. In the way of programming you first need to pick a programming language : In my point of view i refer c++ as the Basic Programming language , to be learnt first.
So that a person can have all the skills, Since Skills have 3 stages:::
1)Beginner Programming
2)Intermediate Programming
3)Advance Programming


There are allot of Programming Languages like Java, c# , c++ , Ruby, pyhton. Since if you are a beginner you need to do programming in c++.

Since c++ provides the best concepts of basics as well as best concept of OOP(Object Oriented Programming ).

Your First Objective is to Understand Your Programming Language.

the best book i prefer is of Robert Lafore's Object Oriented Programming in c++ ,

As this book includes the basic Programming stage the beginner programming stage to Intermidiate Programming stage .
Your Tasks:
1) download the book >>  Robert Lafore's Object Oriented Programming in c++
2) Install a Compiler(in which you will run your program )
 compiler are many (you can have codeblocks , or Microsoft visual c++ or Bloodshed dev c++ )
I prefer codeblock from it website http://www.codeblocks.org/ .
download this code block by going to this link :http://prdownload.berlios.de/codeblocks/codeblocks-13.12mingw-setup.exe or http://www.codeblocks.org/downloads/26
3) now relax . it was your first day task :)