Friday 31 January 2014

Write a program in c++ that input your marks and calculate your percentage if percentage is less than 33 then it display that “sorry you are fail” otherwise you it show the message “congratulation you are pass” . your total marks is 850

Example 2 if else statement:

statement:

Write a program in c++ that input your marks and calculate your percentage if percentage is less than 33 then it display that “sorry you are fail” otherwise you it show the message “congratulation you are pass” . your total marks is 850?

Logic:

   The main logic in this example we calculate the percentage by arithmetic operation. So the question is how to calculate the percentage ?? for this we divide the input marks by total marks and multiply it 100 then we get the percentage. Then we use if else condition

Program:

#include "stdafx.h"
#include "iostream"
#include"conio.h"
using namespace std;
 void main()
{
float marks,t_marks;
float percentage;
t_marks=850;
            cout<<"enter the marks==";
cin>>marks; 
percentage= (marks/t_marks)*100;   
if(percentage<33)
           cout<<"sorry you are fail";             
     else
               cout<<"congrates you are pass";           

_getch();       

}
                                                   
                                                             DOWNLOAD SOURCE CODE


Write a program in c++ that take a number as input and tell that number is even or odd.

Example if else statement:

Logic:
        If we divide a number with 2 if the reminder is zero then the number is even otherwise the number will be odd. In c++ for find the reminder we use arithmetic operator “%” . so this is the logic of our program that we use in our program.

program:

 #include "stdafx.h"
#include "iostream"
 #include"conio.h"
using namespace std;
 void main()
{
            int num;
            cout<<"enter the number==";
            cin>>num;                                                      //input the number
            if(num%2==0)
           cout<<”number”<<num<<” is even”;             //display output is condition is true
     else
               cout<<”number”<<num<<” is odd”;           //display output is condition is false

            _getch();       //function use for display the all output until we press a char

}

                                                


Wednesday 15 January 2014

If and else statement

If and else statement:

                                    In c++ the compiler run our program instruction by instruction or line by line.Sometime we have some specific statement or instruction that we want to run when certain condition full fill. For this c++ provide the conditional statement.  If statement use for this purpose .

Syntax

If(condition)
Statement ;

If is a keyword that take a condition if the condition is true then the statement will be run otherwise the statement will not be run.

Example:

If(x==100)
Cout<<”congrats your condition is true”;


You can use more than one statement that is effect by if condition for this we use {}. Every statement that will be written within {} will be run when if condition is true

Syntax

If(condition)
{
Statement 1;
Statement 2;
.
.
.
Statement n;
}

Example:

If(x==100)
{
Cont<<”the value of x is 100”;
Cout<<”congratulaion your output is diaplaying”;
Cout<<”this example is written by programminglogic.net”;
}
If condition will be false than nothing will be happened no output will be display.  so if we want that when  conditon will false some instruction should be run then we use if else

Syntax of if ,else statement

If(condition)
Statement;
else
Statement;

Syntax for more than one statement

If(condition)
{
Statement 1;
Statement 2;
.
.
Statement n;
}
else
{
Statement 1;
Statement 2;
.
.
Statement n;
}

Example:

If(x==100)
Cout<<”the value of x is 100”;
else
Cont<<”the value of x is less than or greater than 100”;

Flow chart of if ,else statement:

if else 

Nested if ,else:

                          We use if ,else  statement for conditional statement when we have multiple condition which is related to each other then we use nested if ,else . we can simply say that a nested if ,else statement is an if ,else statement with  another  if else statement inside it . we use it when we have more than one choice  . 

Syntax of nested if,else statement:

If(condition)
//Some code
elseif(condition)
//some code
Elseif(condition)
//some code
.
.
.
.
.else
//Some code
The  nested  if else  statement means that if the top condition is not true, then try checking other condition. If anyone condition is true , then ignore the rest of the available conditions. If no one condition is true then execute the else part of the statement .
flow chart:
nested if else



Wednesday 8 January 2014

How to make an dice in blander part 2

How to make an dice in blander:

                                     part 2


4th step:

            Now perform the Boolean operation on each sphere
for this select the cube and go to properties panel and chose add modifier and chose the operation difference and select an sphere , spher.001 ,sphere.002 etc
we have 21 sphere as name sphere , sphere.001 etc as  show in fig below
after performing the Boolean operation on each sphere 

5th step:

           now go to scenes window which is in right side and above the properties panel and invisible and unreadable all sphere object as show below fig
after make all sphere invisible your sphere look like this

6th step:

now press tab and go to edit mode then your cube look like this

now go to properties panel and go to add material then press the + button and press new button as show fig below
after pressing new button and click the diffuse and chose the color and press the assign button now press the tab to go the outside from the edit mode as show in fig below
now your dice is ready look like below fig
                                              download blender file


How to make a dice in blender part 1

How to make a dice in blender(2.69): 

                                             part 1

     1)-First step understand the blender interface

Basic understanding:

1.1)We select a object by right click of mouse button.
1.2)we can rotate the our whole interface by  pressing middle mouse button and rotate
1.3)we can rotate single object not interface by select the object by right click and press r key then move the mouse cursor then our object will rotate.
1.4) we can scale our object by select the with right click and press s key and move the mouse cursor.
1.5) we can translate our object in any position by select the object with right click and move the mouse by keeping the right button of mouse pressed.
1.6) for zooming scroll the mouse wheel .
   By default blender has three objects one is cube second is camera and third one is lamb . so our task make an dice so we delete other all objects expect cube by delete button or key x.
Right side window of blender is the properties penal of an objects and left side window is toolbox. Where we can translate , rotate and scale etc of our object directly without pressing any key. Above the properties panel there is a window where we can sees the all seen. As show in below window.
interface

 Now Make a dice:

                   Now we have only cube in our workplace .

1st step:

           Make the cube corners smooth or rounded.
 For this select the cube by right click and  then go to  properties panel and go to add modifier and chose the Bevel and not  press apply now .  Then your cube will be rounded. As show in fig below
first step

now press the tab key for go to edit mode and chose the faces option and now go to tool box and subdivide option 4 times.  now press the tab now press the apply button which is on right side on properties panel as show fig below


2nd step:

   .color the cube
for this go to properties panel and chose material there will be option of diffuse where you can change the color as show in fig below

3rd  step:

 Make the dot on all faces of cube

 Face one:

 click any where of the screen then go to add -->mesh--->UV sphere take a sphere and place it at front face  that half of sphere inside the cube and half will be out side of cube. you can scale the sphere if needed as show in fig

half of sphere will be inside and half will be outside you can see in other view for pushing the sphere inside. as show in fig below

similarly add sphere in other faces

face two:


face three:

face four:


face five:

face six:


now save your work and go to part 2 of this tutorial  part 2


Monday 6 January 2014

Basic input and output instruction in c++

Basic input and output instruction:

               Two major function is use for basic input cin and getline.
                and for output we use cout

Output(cout)

Library /header file:

 #include<iostream>

Explanation:

                   Cout is used for basic output in c++. Cout is used with two less than signs which is written as “cout<<”.  The << operator insert the data cout  function  which is shows as output. The “<<” operator can be use more than one time in a statement.

Example:

 #include<iostream>
Using namespace std;
main()
{
Cout<<” this is programminglogic.net example”<<endl;
Int a=10;
Cout<<a<<endl;
Cout<<””the value of a is=”<<a;
}

Output screen of above example:

                  this is programminglogic.net example
                  10
                  the value of a is= 10


so the above example shows that if we write the string with cout it display it as it is. And if we write the variable with cout it display its value. As show is in output screen.
Note:
         String always written in double quotes . if we write the variable name in double quotes then compiler will take it as string not a variable.

Input(cin)

Library

          #input<iostream>
 

Explanation:

                 Cin is use for basic input in c++. User use the cin for taking input from keyboard. Two greater than signs use with c++. Which is written as “cin>>” . The operator “>>” also called overload operator.

Example:

 Int a;
  Cin>>a;     //  any integer value that user enter by keyboard it will store in variable a.

getline() function: 

            we normally use cin for taking input from user. but when user enter a string for input which including blank spaces. for example we have a string variable.
string info;
cin>>info;
let user enter "my name is umer". 
when user  display it my cout so then output display on screen "my" expect "my name is umer" it mean when cin find the blank space it stop the extraction. so the solution of this problem for string input we use the getline() function . which is more efficient for string input. and it take the string input with spaces.

syntax:

      getline(cin,variable name);

header file/library:

       #include<iostream>

Example(cin vs getline):

   #include "stdafx.h"
    #include "iostream"
   #include<string>           //for string data type
    #include"conio.h"         //for getch()
   using namespace std;
   void main()
{
string info1,info2;
cout<<"enter your first information==";
cin>>info1;
cout<<"enter your second information==";
getline(cin,info2);
cout<<"your first information is=="<<info1<<endl;
cout<<"your second information is=="<<info2<<endl;
_getch();
}
Note:
         every time user enter the input "my name is umer".

output:

enter your first information==my name is umer        
enter your second information==my name is umer  
your first information is==my                                    
your second information is==my name is umer        
you
you clearly seen in output when you use cin for taking input. only display "my" when you use getline then display all "my name is umer". because our input include blank spaces.

Combine example of cin and cout function:

     #include "stdafx.h"
    #include "iostream"
    #include "stdio.h"
   #include"conio.h"
using namespace std;
 void main()
{
            int a,b,c;
            cout<<"enter the value of a"<<endl;
            cin>>a;                                                      //input the value of a
            cout<<"enter the value of b"<<endl;
            cin>>b;                                                      //input the value of b
            cout<<"eter the value of c"<<endl;
            cin>>c;                                                        //input the value of c
            cout<<"the value of a=="<<a<<endl;         //output the value of a
            cout<<"the value of b=="<<b<<endl;        //output the value of b
            cout<<"the value of c=="<<c<<endl;        //output the value of c
            _getch();       //function use for display the all output until we press a char

}

output of above program:

enter the value of a
10
enter the value of b
20
enter the value of c
30
the value of a==10
the value of b==20
the value of c==30



String in c++:

String in c++:

Library :

  “ #include<string>”

Explanation:


                      Collection of character is called string.  Char data type only store the single character .for storing the collection of data c++ provide a data type as string  in which we can store the collection of character. For use this data type c++ provide a library “#include<string>”  this is not fundamental library. But it behave like fundamental type. By using this library we use many string functions like string comparison etc we will discuss it later in our lesson.

Example:

#include<iostream>
#include<string>
Using namespace std;
     main()
{
String new;        //declaration of new variable whose data type is string
    new=”this is programming logic .net site”    // initialization of variable

…………………….
…………………….
…………….
}


Thursday 2 January 2014

Operator in c++

Operator in c++:

                                           The following operator use in c++:

  1.       Assignment  operator
  2.       Arithmetic operator 
  3.       Compound assignment operator
  4.       Increase and decrease  operator
  5.       Relational and equality operators operator
  6.       Logical operators
  7.       Conditional operator 
  8.       Comma
  9.       Bit wise Operators
  10.       Explicit type casting operator

Assignment operator:

                                            assignment operator use in c++ that is " =".  The assignment operator uses to assigns a value to a variable.
 e.g
                      b=5;
This above statement assigns the value 5 to the variable b. The left part of the assignment operator (=) is known as the lvalue (left value) and the right part as the rvalue (right value). The lvalue has to be a variable whereas the rvalue can be either a constant or variable.
e.g.
                       int a=5;
                       int b=a;

Arithmetic operator:

                                     The five arithmetical operations use in the C++ language which are addition(+), subtraction(-) , division(/), multiplication(*),modulo(%). You are all familiar with first four operator in mathematics .these four operator same work here in c++ as mathematics. The new one for you is modulo (%) operator. Modulo is the operation that gives the remainder of a division of two values. For example, if we write:
                                                 A=11%3;
Then variable A will contain the value 2. 

Compound assignment operator:

                                                                                              compound assignment operator use in c++ that is (+=, -=, *=, /=, %=, >>=, <<=, &=,^=, |=)  When we want to modify the value of a variable then we can use compound assignment operators:
          
   expression                            is equivalent to
------------------------------------------------------------------------
 value += increase              value = value + increase;
 a -= 5;                                   a = a - 5;
 a /= b;                                   a = a / b;
 price *= units;                      price = price * units;
 a%=b;                                  a=a%b;
 a^=b;                                    a=a^b;

and same for all operator.

Increase and decrease  operator:

        the increase operator use in c++ that is ++ and the decrease operator use in c++ that is -- . They are equivalent to +=1 and to -=1, respectively. It means it increase or decrease one value to the variable.

 For example:

     Int a=2;
     a++;           //now value of a become 3.
     a--;             // now value of a again 2
these operator can be use as prefix or post-fix. That mean that can be use either before the variable like(++a) or after the variable like (a++).
The difference between them can easily understand by the following example.

Example prefix:

B=2;
A=++B;      // here the value of A=3 and value of B=3.

Example post-fix:

B=2;
A=B++;      // here the value of A=2 and value of B=3

In Example prefix, B is increased before its value is assign to A. While in Example post-fix, the value of B is first assign to A and then B is increased. That is the difference between prefix and post-fix in c++.

Relational and equality operators operator:

In order to comparison between two expressions we  use the relational and equality operators in c++. Six type of operator are use in c++ which are:

==   Equal to
!=    Not equal to
>     Greater than
<      Less than
>=    Greater than or equal to
<=    Less than or equal to

Note:
       Be careful, The operator = (one equal sign) is not the same as the operator == (two equal signs), the first one is an assignment operator and the other one (==) is the equality operator.

Logical operators:

                                                logical operator use in c++ that is ( !, &&, || )The Operator ! is the C++ operator is equivalent the Boolean operation ‘NOT’. It only has one operand and at right side of operand and operator && is equivalent to Boolean operator ‘AND’. It perform operation on two operand and operator || is equivalent to Boolean operator ‘OR. It also takes two operand for operation. Operands mean here variable.

&& OPERATOR

 a        b            a && b
 True    true            true
True    false           false
false    true            false
false    false           false

 || OPERATOR

a            b           a || b
true        true       true
true        false      true
false       true       true
false      false      false

 Conditional operator :

                                  condition operator use in c++ that is "?".  It is conditional operator in c++. It return a value if the expression is true and return other value if the expression is false.

Syntax:
             Condition ? return 1: return2;

Example:

  #include <iostream>
using namespace std;
int main ()
{
int a,b,c,d;
a=7;
b=2;
c = (a>b) ? a : b;       //here condition is true so assign value of a to c i.e c=7
d = (b>a) ? a : b;      //here condition is false so assign value of b to d so d=2
return 0;
}

Comma operator:

                   Comma operator use to seprate the more than one expression in c++.

Example:

             Int a;
             Int b;
      Here we have two instruction or expression int a and int b. if we want to write it in single instruction then we use the comma operator. Like this
           Int a,b;

Bit wise Operators :

 Bit wise operator modify the variable that have bit pattern in it. following bit wise operator use in c++.

-----------------------------------------------------------------------------------
operator                   is equivalent                      description
&                                      AND                                Bit wise AND
|                                        OR                                   Bit wise Inclusive OR
^                                       XOR                                Bit wise Exclusive OR
~                                       NOT                                Unary complement (bit inversion)
<<                                     SHL                                 Shift Left
>>                                     SHR                                Shift Right

Explicit type casting operator:

 Type casting operator allow you convert one type to another type. For this we use parentheses ();

Example:

              Int a;
              Float  b=2.6;
              a=(int) b;       // a=2

in above example we want to convert float in int data type. So we write the int in parentheses. So the instruction   a=(int) b;  here a is int data type and b is float data type. So the value of  b is 2.6 which is floating value . so that instruction tell the compiler assign the ‘a’ only integer value. So here assign a=2

precedence of operator:

precedence of operator