Search This Blog

COMPUTER SCIENCE CLASS XII

COMPUTER SCIENCE

  1. INTRODUCTION  TO C++
  2. ARRAYS
  3. SORTING   : Sorting tec
    Sorting is arranging the data elements in a particular order. The values in an array or list can either be arranged in ascending or descending order.
    Consider following list of integers as the marks obtained by 7 students in a test:
       3, 12, 6, 8, 5, 9, 15
    After sorting the list elements appear as :
       3, 5, 6, 8, 9, 12, 15
    we may easily find the highest marks and the range of marks in the above list. There are a number of ways to sort a given list of elements. Various algorithms have been devised to sort list of elements . Each sorting technique has its own effective approach depending on situation.
    1. SELECTION SORT 
    2. INSERTION SORT
  4. STACKS
  5. QUEUES

Introduction to C++

Introduction to C++

C++ is an object oriented programming language developed by Bjarne Stroustrup at Bell laboratories.

An object oriented programming language focuses mainly on classes and objects.

Class : It is a group of objects with similar properties and behaviour. 
The term ' class' is used to define the class in C++. Basically, class is a template which defines the structure of the class. For example : car is a class that has a  state( Model, colour, engine, gear etc.)and behaviour (changing gear, speed, applying brakes etc.) 

Let us have a look at the first program in C++

#include<iostream.h>
void main()
{
    cout<<"\n HELLO";
}


Classes in programming : 
Keyword 'class ' is used to define a  class. 
It is used like a template of Abstract Data Type. 
It binds the data with the functions associated with it. 
It is like a blueprint of the data type. 
Networking notes

A computer network allows  one computer to share/ exchange data with another computer.
or when a computer is able to share and exchange data with another computer they are said to be in a network.
Internet: Network of networks is called internet.
Intranet : It a network of networks among computers of same organization.
Extranet : Network of networks of some organisations.

Types of Network

PAN : Personal Area Network
This type of network if confnied within a metre or two.

LAN : Local Area Network
Area of network confined within 1-2 kilometers is  called an LAN

MAN :  Meropolitan Area Network
WAN :  Wide Area Network

Topology : The pattern of arrangement of computers/ nodes in a network is called the topology.


Program to convert binary number into decimal and Decimal to binary

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,g,h,s=0,i=0,d,b,ch;
cout<<endl<<"Enter the choice - "<<endl<<"1:Binary to Decimal"<<endl<<"2:Decimal to Binary"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the Binary Digit"<<endl;
cin>>b;
while(b>0)
{
a=b%10;
s=s+a*(pow(2,i));
i=i+1;
b=b/10;
}
cout<<"Answer ="<<s<<endl;
break;
case 2:
cout<<"Enter the Decimal"<<endl;
cin>>d;
while(d>0)
{
a=d%2;
a=a*pow(10,i);
s=s+a;
i=i+1;
d=d/2;
} cout<<"Answer ="<<s<<endl;
break;
default:
cout<<"Wrong choice"<<endl;
break;
}
getch(); } 

Selection Sort

Selection Sort

Selection sort is a sorting algorithm used to arrange the list of elements in ascending or descending order.
The algorithm divides the list logically into two parts : Sorted and unsorted

Sorting the list in ascending order the algorithm involves by searching for the smallest element in the list and then swapping it with the element at the first position. This swap ensures placing of first element at itssorted position.
Again the sublist from second position is searched for the second smallest element and this second smallest element is swapped with the element at the seond position. this continues till we reache the second last element of the list.



As per this type of sorting algorithm the smallest element is searched and then placed at the first position. After this next smallest element is searched in the list and then exchanged with the element at the second position and so on.
Let us consider an array with following values:
     23,    12,     34,  5,    6,     20
Smallest element is selected
23
12
34
5
6
20
and is exchanged with the element at first position.
5
12
34
23
6
20
 Again second smallest element is selected
5
12
34
23
6
20

and is exchanged with element at second position
5
6
34
23
12
20

Next element at third smallest element is selected
5
6
34
23
12
20

And  isreplaced with third smallest element
5
6
12
23
34
20

Next fourth smallest element is selected
5
6
12
23
34
20
 This fourth smallest element is replaces the element at fourth position
5
6
12
20
34
23
At last the fifth element is selected
5
6
12
20
34
23
And is replaced with element at fifth position
5
6
12
20
23
34
 After five passes this array of six elements is sorted
An array of N elements is sorted with N-1 passes and the last unsorted element is automatically in sorted order.
Algorithm of Selection Sort
1.      Declare a variable MIN to store minimum value.
2.      Declare variable POS to store the p
3.      Declare a temporary variable TEMP.
4.      Declare counter variables S and P .
5.      Set S=0
6.      MIN=AR[S]                                                                     
7.      Set P=S+1
8.      If AR[P]<MIN
  SET MIN=AR[P]
9.      P=P+1
10.  IF (P<N-1) GOTO STEP 8
11.  IF MIN=AR[S] GOTO STEP
12.   TEMP=AR[S]
13.  AR[S]=MIN
14.  AR[POS]=TEMP
15.  S=S+1
16.  IF S<N GOTO STEP 6

17.  STOP