BCA Raipur - BCA Notes S-1

Post your notes and other just by mailing us at bcaraipur@live.com

BCA Raipur - BCA Notes S-2

Post your notes and other just by mailing us at bcaraipur@live.com

BCA Raipur - BCA Notes S-3

Post your notes and other just by mailing us at bcaraipur@live.com

BCA Raipur - BCA Notes S-4

Post your notes and other just by mailing us at bcaraipur@live.com

BCA Raipur - BCA Notes S-5

Post your notes and other just by mailing us at bcaraipur@live.com

google search

Popular Posts


Welcome to BCA Notes

>>>>>>>>>>>>>>>>

Visitors

Search This Blog

Blogger templates

Visitor Map


Thursday, 21 August 2014

Selection Sort Algorithm

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

class List
{
public:
// Array of integers to hold values
int arr[20];

// Number of elements in array
int n;

// Function to accept array elements

void read()
{
while (1)
{

cout<<"\nEnter the number of elements in the array: ";
cin>>n;

if (n <= 20)
break;
else
cout << "\nArray can have maximum 20 elements\n";
}

//Display the header

cout<<"\n";
cout<< "-----------------------\n";
cout<< "Enter array elements  \n";
cout<<"-----------------------\n";

// Get array elements
for( int i = 0; i < n; i++ )
{
cout<<"<"<<i+1<<"> ";
cin>>arr[i];

}
}

//Function to swaps the element at index x with the element at index y

void swap(int x, int y)
{
int temp;

temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;

}

void SelectionSortArray()
{
for (int i= 0; i<n-1; i++) //For n-1 passes
{
//Find the minimum value from arr[i] to arr[n-1]

int min = i; //Suppose minimum value is at index i

//Compare all values from index i+1 to index n-1 with
//the value at index min to determine the minimum value.

for (int j=i+1; j<n; j++)
{
if (arr[j] < arr[min])
{
min = j;//Store the index of smaller value in min
}
}

//Swap the value at index i with the value at index j
//to store the minimum value at index i.

swap (i,min);
}
}

void display()
{
cout<<endl;
cout<<"-----------------------\n";
cout<<" Sorted array elements \n";
cout<<"-----------------------\n";

for( int j = 0; j < n; j++ )
{
cout<<arr[j]<<endl;
}
}
};


int main()
{
// Instantiate an instance of the class
// clrscr();
List myList;

// Accept array elements
myList.read();

// Sort the array
myList.SelectionSortArray();

// Display sorted array
myList.display();

cout<<endl<< "Press Return to exit.";
getch();

}

Merge Sort Algorithm

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

class List
{
    public:
        int arr[20];
        int sorted[20];
        int cmp_count; //Number of comparisons
        int mov_count; //Number of data movements

        // Number of elements in array
        int n;

        List()
        {
            cmp_count = 0;
            mov_count = 0;
        }

void read()
{
// Get the number of elements to store in the array
while (1)
{
cout << "\nEnter the number of elements in the array: ";
cin >> n;
if (n <= 20)
break;
else
cout << "\nArray can have maximum 20 elements.\n";
}

cout << "\n-----------------------\n";
cout << " Enter array elements  \n";
cout << "-----------------------\n";

// Get array elements
for (int i = 0; i < n; i++)
{
cout << "<" << i + 1 << "> ";
cin >> arr[i];
}
}

        void m_sort(int low, int high)
        {
            int mid;

            if (low >= high)
                return;

            mid = (low + high) / 2;

            m_sort(low, mid);
            m_sort(mid + 1, high);
            merge(low, mid, high);
        }

        void merge(int low, int mid, int high)
        {
            int i, j, k;

            i = low;
            j = mid + 1;
            k = low;

            while ((i <= mid) && (j <= high))
            {
                if (arr[i] <= arr[j])
                {
                    sorted[k++] = arr[i++];
                }
                else
                {
                    sorted[k++] = arr[j++];
                }
cmp_count++;
            }

            //If there are still some elements in the first sub list
            //append them to the new list.

            while (i <= mid)
            {
                sorted[k++] = arr[i++];
mov_count++;
            }

            //If there are still some elements in the second sub list
            //append them to the new list.

            while (j <= high)
            {
                sorted[k++] = arr[j++];
mov_count++;
            }

            //Copy the sorted elements in the original array
            for (i = low; i <= high; i++)
{
                arr[i] = sorted[i];
mov_count++;
}
        }

void display()
{
cout << "\n-----------------------\n";
cout << " Sorted array elements \n";
cout << "-----------------------\n";

for (int j = 0; j < n; j++)
{
cout << arr[j]<< endl;
}

cout << "\nNumber of comparisons: " << cmp_count;
cout << "\nNumber of data movements: " << mov_count;
}

int getSize()
{
return (n);
}
};

void main()
{
    clrscr();
    // Declaring the object of the class
    List myList;
// Accept the array elements
myList.read();

    // First call to merge sort algorithm
    myList.m_sort(0, myList.getSize() - 1);

    // Display sorted array
myList.display();
getch();
}

Linear Search algorithm

#include <iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int arr[20];    //Array to be searched
    int n;      //Number of elements in the array
    int i;

    // Get the number of elements to store in the array
    while (1)
    {
cout << "Enter the number of elements in the array(1-20): ";
cin >> n;
if ((n>0) && (n <= 20))
   break;
else
   cout << "\nArray should have minimum 1 and maximum 20 elements.\n\n";
    }

    //Accept array elements
    cout << "\n-----------------------\n";
    cout << " Enter array elements\n";
    cout << "-----------------------\n";

    for (i = 0; i < n; i++)
    {
cout << "<" << (i + 1) << "> ";
cin >> arr[i];
    }

    char ch;
    int ctr;

    do
    {
//Accept the number to be searched
int item;
cout << "\nEnter the element you want to search: ";
cin >> item;

//Apply linear search
ctr = 0;
int find=0;
for (i = 0; i < n; i++)
{
   ctr++;

   if (arr[i] == item)
   {
cout << "\n" << item << " found at position " << i + 1 << endl;
find++;
//break;
   }

}


if ((i == n) && (find==0))
   cout << endl << item << " not found in the array\n";

cout<<"\nNumber of comparisons: "<<ctr;

cout << "\n\nContinue search (y/n):";
cin >> ch;

    } while ((ch == 'y') || (ch == 'Y'));
}





Insertion sort algorithm

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[100],i,n,p,ptr,temp;

cout<<"\n------------ INSERTION SORT ------------ \n\n";

cout<<"Enter No. of Elements : ";
cin>>n;

cout<<"\nEnter Elements : \n";
for(i=1;i<=n;i++)
{
cin>>a[i];
}

a[0]=0;

for(p=2;p<=n;p++)
{
temp=a[p];
ptr=p-1;

while(temp<a[ptr])
{
a[ptr+1]=a[ptr];                // Move Element Forward
ptr--;
}

a[ptr+1]=temp;                 // Insert Element in Proper Place
}

cout<<"\nAfter Sorting : \n";
for(i=0;i<n;i++)
a[i] = a[i+1];
for(i=0;i<n;i++)
{
cout<<a[i]<<endl;
}

getch();
}




Quick sort algorithm

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

class List
{
    
    public:
        int arr[20];    //Array of integers to hold values
        int cmp_count; //Number of comparisons
int mov_count; //Number of data movements
    
        int n; // Number of elements in the array

        List()
        {
            cmp_count = 0;
   mov_count = 0;
        }

void read()
{
// Get the number of elements to store in the array
while (1)
{
cout << "\nEnter the number of elements in the array: ";
cin >> n;
if (n <= 20)
break;
else
cout << "\nArray can have maximum 20 elements.\n";
}

cout << "\n-----------------------\n";
cout << " Enter array elements  \n";
cout << "-----------------------\n";
       
// Get array elements
for (int i = 0; i < n; i++)
{
cout << "<" << (i + 1) << "> ";
cin >> arr[i];
}
}

void swap(int x, int y) //Swaps the element at index x with the element at index y
        {
            int temp;
            temp = arr[x];
            arr[x] = arr[y];
            arr[y] = temp;
        }
    
        void q_sort(int low, int high)
        {
            int pivot, i, j;
            if (low > high)
return;
        
            //Partition the list into two parts:
            //One containing elements less than or equal to pivot
            //Other containing elements greater than pivot
        
            i = low+1;
            j = high;
        
            pivot = arr[low];
        
            while (i <= j)
            {
                //Search for an element greater than pivot
                while ((arr[i] <= pivot) && (i <= high))
                {
                    i++;
   cmp_count++;
                }
cmp_count++;
            
                //Search for an element less than or equal to pivot

                while ((arr[j] > pivot) && (j >= low))
                {
                    j--;
   cmp_count++;
}
cmp_count++;
            
                if (i < j)  //If the greater element is on the 
                            //left of the smaller element
                {
                    //Swap the element at index i with the element at index j
                    swap(i, j); 
   mov_count++;
                }
            }
        
   //j now contains the index of the last element in the sorted list.
        
            if (low < j)
{
                swap(low,j);    //Move the pivot to its correct position in the list
mov_count++;
            }
        
            //Sort the list on the left of pivot using quick sort
            q_sort(low, j - 1);
        
            //Sort the list on the right of pivot using quick sort
            q_sort(j + 1, high);
        }

void display()
{
cout << "\n-----------------------\n";
cout << " Sorted array elements \n";
cout << "-----------------------\n";

for (int j = 0; j < n; j++)
{
cout << arr[j] << endl;
}
       
cout << "\nNumber of comparisons: " << cmp_count;
cout << "\nNumber of data movements: " << mov_count;
}

int getSize()
{
return (n);
}
};


void main()
{
// Declaring the object of the class
clrscr();
List myList;
        
// Accept array elements
myList.read();
   
        // Calling the sorting function
        myList.q_sort(0, myList.getSize() - 1);  // First call to Quick Sort Algorithm
        
        // Display sorted array
myList.display();
getch();
}

Program on Bubble sort algo

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class List
{
public:  
// Array of integers to hold values
int arr[20];
// Number of elements in array
int n;

// Function to accept array elements
void read()
{
while (1)
{
cout<<"\nEnter the number of elements in the array: ";
cin>>n;
if (n <= 20)
break;
else
cout << "\nArray can have maximum 20 elements\n";
}

//Display the header

cout<<"\n";
cout<< "-----------------------\n";
cout<< "Enter array elements  \n";
cout<<"-----------------------\n";

// Get array elements
for( int i = 0; i < n; i++ )
{
cout<<"<"<<i+1<<"> ";
cin>>arr[i];
}
}

// Bubble Sort function
void BubbleSortArray()
{
for (int i = 1; i < n ; i++) //For n-1 passes
{
//In pass i, compare the first n-i elements
//with their next elements

for (int j = 0; j < n-i; j++)
{
if (arr[j] > arr[j+1]) //If the elements are not in the correct order
{
//Swap the elements
int temp;
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}

// Function to display the contents of the array
void display()
{
cout<<endl;
cout<<"-----------------------\n";
cout<<" Sorted array elements \n";
cout<<"-----------------------\n";
for( int j = 0; j < n; j++ )
{
cout<<arr[j]<<' ';
}

cout<<endl<< "Press Return to exit.";
getchar();
}
};


void main()
{
// Instantiate an instance of the class
clrscr();
List myList;

    // Function call to accept array elements
    myList.read();

    // Function call to sort array
    myList.BubbleSortArray();

    // Function call to display the sorted array
    myList.display();

}

Program on binary selection>>>

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int arr[20];    //Array to be searched
    int n;      //Number of elements in the array
    int i;

    // Get the number of elements to store in the array
    while (1)
    {
cout << "Enter the number of elements in the array: ";
cin >> n;
if ((n>0) && (n <= 20))
   break;
else
   cout << "\nArray should have minimum 1 and maximum 20 elements.\n\n";
    }

    //Accept array elements
    cout << "\n---------------------------------------\n";
    cout << " Enter array elements in ascending order\n";
    cout << "----------------------------------------\n";

    for (i = 0; i < n; i++)
    {
cout << "<" << (i + 1) << "> ";
cin >> arr[i];
    }

    char ch;

    do
    {
//Accept the number to be searched
int item;
cout << "\nEnter the element you want to search: ";
cin >> item;

//Apply binary search
int lowerbound = 0;
int upperbound = n - 1;

//Obtain the index of the middlemost element
int mid = (lowerbound + upperbound) / 2;
int ctr = 1;
while ((item != arr[mid]) && (lowerbound <= upperbound))
{
   if (item > arr[mid])
lowerbound = mid + 1;
   else
upperbound = mid - 1;
   mid = (lowerbound + upperbound) / 2;
   ctr++;
}

if (item == arr[mid])
   cout << "\n" << item << " found at position " << (mid+1) << endl;
else
   cout << "\n" << item << " not found in the array" << endl;

cout<<"\nNumber of comparisons: " <<ctr;

cout << "\n\nContinue search (y/n):";
cin >> ch;
    } while ((ch == 'y') || (ch == 'Y'));
}






Monday, 11 August 2014

System Analysis & Designing FAQ

System Analysis & Designing
Frequently asked questions

Q.1 What is a system?

Ans:- The term system is grieved from the Greek work systema, which means an organized relationship among functioning units or components.

Q.2 Explain phases of system development life cycle?

Ans:- Following arr the phases of system development life cycle :-
  1. Recognition of need.
  2.  Feasibility study.
  3. Analysis.
  4. Design.
  5. Implementation.
  6. Post-implementation
  7. Maintenance.
Q.3 Name the different types of system?

Ans:- Following are the different types of system:-
  1.  Physical or Abstract System.
  2.  Man Made System.
  3. Open & Closed System.
Q.4 Write down the characteristics of system?

Ans:- Following are the characteristics of System:-
  1. Organization.
  2. Interaction.
  3. Interdependence.
  4. Integration.
  5. Central objective.
Q.5 Roles of System Analyst ?

Ans:- Follow the link