Make Your Search Easy ! :) Use me

Thursday, August 10, 2017

Unit Conversion (Length)

Program to convert the distance from kilometer into meter, feets, inches, and centimeters.


#include<iostream.h>
#include<conio.h>

void main()
{
    float dist,dist_m,dist_ft,dist_in,dist_cm;
      cout<<"\t\t\tUNIT CONVERTER"<<endl;
      cout<<"Enter distance (in KM) : ";
      cin>>dist;
      dist_m=dist*1000;
      dist_ft=dist*(100000/30.48);
      dist_in=dist_ft*12;
      dist_cm=dist_m*100;
      cout<<"\n\nDistance in Meters is : "<<dist_m<<" m ";
      cout<<"\nDistance in Feets is : "<<dist_ft<<" feets ";
      cout<<"\nDistance in Inches is : "<<dist_in<<" inches ";
      cout<<"\nDistance in Centimeters is : "<<dist_cm<<" cm ";
      getch();

   }

Program to find out a minimum number of notes and coins of various denominations needed for given amount.


#include<iostream.h>
#include<conio.h>

void main()
{
   int amount, note2000, note500, note100, note50, note20, note10, coin5, coin2, coin1;
         note2000=note500=note100=note50=note20=note10=coin5=coin2=coin1=0;

         cout<<"Enter the amount :";
         cin>>amount;
         if(amount>=2000)
          {
          note2000=amount/2000;
            amount%=2000;
          }
         if(amount>=500)
            {
            note500=amount/500;
                  amount%=500;
               }
         if(amount>=100)
            {
                note100=amount/100;
                  amount%=100;
               }
         if(amount>=50)
            {
                note50=amount/50;
                  amount%=50;
               }
         if(amount>=20)
            {
                note20=amount/20;
                  amount%=20;
               }
         if(amount>=10)
            {
                note10=amount/10;
                  amount%=10;
               }
//Remove the coin section if only notes is needed

         if(amount>=5)
            {
                coin5=amount/5;
                  amount%=5;
               }
         if(amount>=2)
            {
                coin2=amount/2;
                  amount%=2;
               }
         if(amount>=1)
            {
                coin5=amount/1;
                  amount%=1;
               }
         cout<<"\n\nMinimum No. of notes requeired for "<<amount<<" is : "<<endl;
         cout<<"\nNo. of Rs 2000 Note : "<<note2000;
         cout<<"\nNo. of Rs 500 Note : "<<note500;
         cout<<"\nNo. of Rs 100 Note : "<<note100;
         cout<<"\nNo. of Rs 50 Note : "<<note50;
         cout<<"\nNo. of Rs 20 Note : "<<note20;
         cout<<"\nNo. of Rs 10 Note : "<<note10;

//Remove the following 3 statements if only notes is needed

         cout<<"\nNo. of Rs 5 coin : "<<coin5;
         cout<<"\nNo. of Rs 2 Coin : "<<coin2;
         cout<<"\nNo. of Rs 1 Coin : "<<coin1;
         cout<<"\nTotal No. of Notes : "<<(note2000+note500+note100+note50+note20+note10);
         cout<<"\nTotal No. of Coins : "<<(coin5+coin2+coin1);
         getch();

   }

Program to find the greatest number and its frequency from a series of inputs, without storing all the inputs.


#include<iostream.h>
#include<conio.h>

void main()
{
         int max=0,num,i,j=0,flag=0;
         cout<<"Enter the number of inputs to be entered :";
         cin>>i;
         do
          {
          cout<<"Enter number "<<(j+1)<<"  : ";
            cin>>num;
            if(num>max)
            {
            max=num;
                  flag=0;
               }
            if(num==max)
            {
                flag++;
               }
            j++;
          }while(j<i);
         cout<<"\n\nGreatest number is : "<<max<<endl;
         cout<<"Frequency of greatest number is : "<<flag;
         getch();

   }

Wednesday, August 9, 2017

Program to print the following alphabetical pattern:-

Alphabetical Pattern


#include<iostream.h>
#include<conio.h>

void main()
    {
      char j,k;
      int h,i;
      for(j='A';j<'H';j++)
      {  cout<<j;      }
      for(k=j-2;k>='A';k--)
        {  cout<<k;      }
      for(i=1;i<8;i++)
      {
          cout<<endl;
      for(j='A';j<'H'-i;j++)
      {
          cout<<j;
         }
            for(h=1;h<2*(i);h++)
            {
                cout<<" ";
               }
            for(k=j-1;k>='A';k--)
            {
                cout<<k;
               }
         }
      getch();

   }

Program to calculate age.


#include<iostream.h>
#include<conio.h>

struct date
{ int dd,mm,yyyy;
      void get()
      {
          cout<<"Enter Date: (do not enter zero befor significant digit) ";
            cin>>dd;
            cout<<"Enter Month: (do not enter zero befor significant digit) ";
            cin>>mm;
            cout<<"Enter Year: (do not enter zero befor significant digit)";
            cin>>yyyy;
         }
      void show()
      {
          cout<<endl<<yyyy<<" Years "<<mm<<" months "<<dd<<" days";
         }
    };

void calc(date a, date b)
{
    date age;
      if(b.dd>a.dd)
          {
            a.dd+=30;
               a.mm--;
            }
         if(b.mm>a.yyyy)
          {
            a.mm+=12;
               a.yyyy--;
            }
      age.dd=a.dd-b.dd;
      age.mm=a.mm-b.mm;
      age.yyyy=a.yyyy-b.yyyy;
    cout<<"\nYour age is :\n";
      age.show();
   }

void main()
 {
         date dob,today;
         cout<<"Enter today's date :\n";
         today.get();
         cout<<"\n\nEnter you date of birth:\n";
         dob.get();
         calc(today,dob);
         getch();

 }

Triangle related problem

Program to accept 3 angles and check if is it of a triangle. If yes, also find type of the triangle.


#include<iostream.h>
#include<conio.h>


void main()
 {
        int flag1,flag2,flag3;
              flag1=flag2=flag3=0;
              float angle1,angle2, angle3;
              cout<<"Enter 1st Angle : ";
              cin>>angle1;
              cout<<"Enter 2nd Angle : ";
              cin>>angle2;
              cout<<"Enter 2nd Angle : ";
              cin>>angle3;
              if(angle1+angle2+angle3==180)
              {
                if(angle1==angle2&&angle2==angle3)
                  { cout<<"\n\nGiven angles are of equilateral triangle."; }
                  if(angle1==angle2||angle2==angle3||angle1==angle3)
                     { flag1=1; }
                  if(angle1!=angle2 && angle1!=angle3)
                     { flag2=1; }
                  if(angle1==90||angle2==90||angle3==90)
                  {  flag3=1;}
              if(flag1==flag3)
            { cout<<"\n\nGiven angles are of a right angle isosceles triangle."; }
            if(flag2==flag3)
                  { cout<<"\n\nGiven angles are of a right angle scalene triangle."; }
               }
              else
              { cout<<"\n\nGiven angles are not of a triangle."; }
              getch();

 }

Fibonacci Series

Program to find the Fibonacci value of any given number from 1 to 100.


#include<iostream.h>
#include<conio.h>

void main()
{
    int num,f[100];
      cout<<"Enter a number to find Fibonacci value : ";
      cin>>num;
      f[0]=0;
      f[1]=1;
      for(int i=2;i<=num;i++)
      { f[i]=f[i-1]+f[i-2];}
      cout<<f[num];
      getch();

   }

Number Conversions

Program to convert decimal numbers into hexadecimal, octal and binary.

#include<iostream.h>
#include<conio.h>

//function to obtain hexadecimal value
void show_hex(int a)
{
    int decnum=a,i=0,temp;
      char hex[100];
      while(decnum>0)
      {
          temp=decnum%16;
            //to convert the obtained result into characters
            if(temp<10)
            { hex[++i]=temp+48; }
            else
            {  hex[++i]=temp+55; }
            decnum/=16;
         }
      cout<<"\n\nEquivalent Hexadecimal value for "<<a<<" is : ";
      for(i;i>0;i--)
      {
          cout<<hex[i];
         }
   }

//function to obtain octadecimal value
void show_octal(int a)
{
    int decnum=a,i=0,temp;
      char octal[100];
      while(decnum>0)
      {
          temp=decnum%8;
            //to convert the obtained result into characters
            octal[++i]=temp+48;
            decnum/=8;
         }
      cout<<"\nEquivalent Octadecimal value for "<<a<<" is : ";
      for(i;i>0;i--)
      {
          cout<<octal[i];
         }
   }

//function to obtain binary value
void show_binary(int a)
   {
    int decnum=a,i=0,temp;
      char binary[100];
      while(decnum>0)
      {
          temp=decnum%2;
            //to convert the obtained result into characters
            binary[++i]=temp+48;
            decnum/=2;
         }
      cout<<"\nEquivalent binary value for "<<a<<" is : ";
      for(i;i>0;i--)
      {
          cout<<binary[i];
         }
   }

//main program
void main()
{
    int a;
    cout<<"Enter any decimal number :";
      cin>>a;
      show_hex(a);
      show_octal(a);
      show_binary(a);
      getch();
   }

Wednesday, May 17, 2017

Topology In Network Design




Topology : A topology is a usually schematic description of the arrangement of a network, including its nodes and connecting lines.
Think of a topology as a network's virtual shape or structure. This shape does not necessarily correspond to the actual physical layout of the devices on the network. For example, the computers on a home network may be arranged in a circle in a family room, but it would be highly unlikely to find a ring topology there.
Network topologies are categorised into the following basic types:
  1. Bus
  2. Ring
  3. Star
  4. Tree
  5. Mesh
More complex networks can be built as hybrids of two or more of the above basic topologies.

Bus Topology :

Illustration 1: Bus Topology
Illustration 1: Bus Topology
Bus networks (not to be confused with the system bus of a computer) use a common backbone to connect all devices. A single cable, the backbone functions as a shared communication medium that devices attach or tap into with an interface connector. A device wanting to communicate with another device on the network sends a broadcast message onto the wire that all other devices see, but only the intended recipient actually accepts and processes the message.

Ethernet bus topologies are relatively easy to install and don't require much cabling compared to the alternatives. 10Base-2 ("ThinNet") and 10Base-5 ("ThickNet") both were popular Ethernet cabling options many years ago for bus topologies. However, bus networks work best with a limited number of devices.
If more than a few dozen computers are added to a network bus, performance problems will likely result. In addition, if the backbone cable fails, the entire network effectively becomes unusable.

Ring Topology :

Illustration 2: Ring Topology
Illustration 2: Ring Topology
In a ring network, every device has exactly two neighbours for communication purposes. All messages travel through a ring in the same direction (either "clockwise" or "counterclockwise"). A failure in any cable or device breaks the loop and can take down the entire network.
To implement a ring network, one typically uses FDDI, SONET, or Token Ring technology. Ring topologies are found in some office buildings or school campuses.


Star Topology :

Illusration 3: Star Topology
Illustration 3: Star Topology
Many home networks use the star topology. A star network features a central connection point called a "hub node" that may be a network hub, switch or router. Devices typically connect to the hub with Unshielded Twisted Pair (UTP) Ethernet.
Compared to the bus topology, a star network generally requires more cable, but a failure in any star network cable will only take down one computer's network access and not the entire LAN. (If the hub fails, however, the entire network also fails.)


Tree Topology :

Illustration 4: Tree Topology
Illustration 4: Tree Topology
A tree topology joins multiple star topologies together onto a bus. In its simplest form, only hub devices connect directly to the tree bus, and each hub functions as the root of a tree of devices. This bus/star hybrid approach supports future expansion of the network much better than a bus (limited in the number of devices due to the broadcast traffic it generates) or a star (limited by the number of hub connection points) alone.



Mesh Topology :

Illustration 5: Mesh Topology
Illustration 5: Mesh Topology
Mesh topology introduces the concept of routes. Unlike each of the previous topologies, messages sent on a mesh network can take any of several possible paths from source to destination. (Recall that even in a ring, although two cable paths exist, messages can only travel in one direction.) Some WANs, most notably the Internet, employ mesh routing.
A mesh network in which every device connects to every other is called a full mesh. As shown in the illustration below, partial mesh networks also exist in which some devices connect only indirectly to others.


Summary :


Topology remains an important part of network design theory. You can probably build a home or small business computer network without understanding the difference between a bus design and a star design, but becoming familiar with the standard topologies gives you a better understanding of important networking concepts like hubs, broadcasts, and routes.