Sunday, 3 December 2017

Class 10 - Arrays

Array is an interesting topic. Imagine a situation where you
want to input the names of students in your class along with
the roll no and 3 subjects marks. There are 50 boys in your
class. Then how many variables you need? There is no point
in writing a program. Array comes in handy in such a
situation .

An array is a collection of values of same data type. Each element in an array is refered by the array name with the subscript or index.It is enclosed in square bracket [ ], whereas methods use ( ).
  • Declaration
  • Memory allocation
  • Initialization
Declaration:
Like the normal declaration of variables, we need to declare the array also.
data type array name[];

int marks[];
Memory allocation:
data type array name[]=new datatype[size];

int a[]=new int[10];


How many values you are going to use should be mentioned where it is given size.The common mistake we make here is writing the variable name after new.

int a[]=new a[10]; is wrong

Initializing values

int a[]={10,20,30,40};

The place value of each element is called a subscript or an


index. The index value starts from zero, so the last

element index is one less than the size.

To find the length of an array use length.


int l=a.length;

No brackets after length.  It finds the length of the array 'a'


which is 4 and it is stored in a variable l;

To accept 10 values from the user.

Example 1: Blue J method
class ar1
{
public static void main(int a[])

Example 2: Scanner Method


import java.util.*;
class ar1
{
public static void main()
   {
int a[]=new int[10];--------------------------1


Scanner s=new Scanner(System.in);


int i,l,s=0;


l=a.length;------------------------------------2


System.out.println("Enter the values");


for(i=0;i<l;i++)------------------------------3


a[i]=s.nextInt();------------------------------4


for(i=0;i<l;i++)


s=s+a[i];-------------------------------------5
 

System.out.println(a[i]);

   }
}
Step 1 : an array a is created ,

Step 2 :finds the  Length

Step 3 : index starts from 0 and less than length l

Step 4 : The values are store in a.First value is stored in
a[0], second in a[1] and so on

Step 5: When i=0, a[0] value is added to s, when i=1 ,a[1] is added and so on..

Loop plays an important role in Arrays , whether it is for accepting values or printing it.

Accepting values :

  • System.out.println("Enter the values");

    for(i=0;i<l;i++)


    a[i]=s.nextInt();


    Printing :

    for(i=0;i<l;i++)


    System.out.println(a[i]);


Write the Java statements for the following:

  • Declare 5 integers in code.
            int code[] = new int[5];
  • Declare to store 10 names.
           String names[ ] = new String[10];
  • Assign the values 10.5, 20.5, 30.5, 40.5 to an array number.
           float number[ ] = { 10.5, 20.5, 30.5, 40.5};


Search 
  • Linear

  • Binary

import java.util.*;
class linear{
public static void main()
   {
int a[]=new int[10];


Scanner s=new Scanner(System.in);


int i,l,n,flag=0;


l=a.length ;


System.out.println("Enter the values");


for(i=0;i<l;i++)


a[i]=s.nextInt();


System.out.println("Enter the number to be searched");

n=s.nextInt();


for(i=0;i<l;i++)
{
   if(a[i]==n)
     {
       flag=1;
        break;
    }
}


if(flag==1)


System.out.print(n+"found");


else


System.out.print(n+"not found");


  }
}

Initially flag is 0, if the number is found the flag value will change to 1.


Binary Search

This might look little complicated,but if you understand how it works,it is a cake walk.

The prerequisite is that the array elements should be arranged in some order either in ascending or descending.

In the boards generally the question will not ask you to sort
 and search in the same program.

The linear search takes more time since it has to check each
 and every element sequentially.It is a good idea but not a great one.

So, here in binary search the idea is divide the array and discard whatever not necessary.

Step 1: we are going to divide the array into  two parts.
           
              For that we should find the middle value.

Step 2: Compare the number  to be searched say 'n' with                   the middle value say 'm'.If both are same,  Bingo.

Step 3: If the n is smaller than m, then you would find n in 

the first half ,if the array  is arranged in ascending order.Then 

you dont want the second part anymore.discard it. So the

length changes after you discard the second part.Lower index 

value remains the same that is 0, but upper limit becomes

middle value - 1.Then step 2 will be repeated.

If the n is bigger than m, then you would find n in the second

half ,if the array  is arranged in ascending order.Then you

dont want the first part anymore.discard it. So the length

changes after you discard the second part.Upper index value

remains the same, but lower limit becomes middle value +

1.Then step 2 will be repeated.

Example :

The array is
 14 ,  23,  28, 36,  69,  88
The number to be searched is 23.

Step 1:
Middle value = (lower index +Upper index)/2
                      = (0+5)/2
                      = 2.5
Either round off or truncate it. Let us take 3.So the middle value is 36.
Step 2 :
Compare 23 and 3 rd element 36.Both are not same.
Step 3 :
23 is smaller than 36, that means 23 will not be there after 36.

so discard second half, that is elements after 36.Lower index is still 0, and upper index becomes the value before the middle value , i.e 28.

Checking will go on till it finds the value.

If the value to be searched is 88 then,

88 is bigger than 36, therefore 88 will not be in the list

before 36.

so discard first half, that is elements before 36.upper

index remains the same and lower index becomes the

value after the middle value.

 Checking will go on till it finds the value. Otherwise  it will print the nmber not in the list.

class binary
{
public static void main(int a[],int n)---------------------------1
{
int l,i,mid,place,flag=0;


l=a.length;--------------------------------------------------------2


int low=0,up= l -1;----------------------------------------------3


while(low <= upp)----------------------------------------------4


{
      mid = (low+up)/2;------------------------------------------5


      if(a[mid]==n)
         {
              flag=1;------------------------------------------------6


              place=mid;--------------------------------------------7


              break;-------------------------------------------------8


         }
      else if(a[mid] < n)-----------------------------------------9


            low=mid+1;
      else
            upp=mid - 1;
}


if(flag==1)


System.out.print(n+"is found at+(place+1));-----------------10
else


System.out.print(n+"is not found ");


}
}
step 1: input the array, number to be searched

step 2: find the length of the array


step 3:initialize the values for lower and upper index. l-1 coz, index starts from 0.


step 4:the loop should continue as long as lower limit is less than upper limit.


step 5:find the middle value.common mistake here is 
(a[low]+a[upp])/2


step 6:there is some variable with some intial value so that when we find the number, change that value.If the value is not changed then it means the number is not found,coz you would not have gone to step 6.


step 7: if you want to find exactly where the number occurs in the array,then assign the mid index, not mid value.It is not a[mid].


step 8:Once we found the number,come out. no more searching.


step 9:check the number with middle value , change the low or upper index accordingly.


Isn't that easy.


Friday, 1 December 2017

Class 8 - Revision C++ Programming


 1. Identify the valid and invalid variables:

            i.       Bond007 – Valid
           ii.       where?    - invalid ( Special character ? not allowed)
          iii.       Prove them wrong – Invalid(Special character space)
          iv.        int – Invalid(keywords not allowed)
           v.        Plug&Play – Invalid(Special character & not allowed)
          vi.        a123 – Valid
         vii.       10DowningStreet – Invalid(Starts with a number)

  2. Correct the  following statements:
    i.       cin>>”a”;
   ii.       cout<<The answer=>>total;
  iii.       Character a=’x’;
  iv.        k=100

                i.   cin>>a;
       The variable should  not be within quotation.      
ii. cout<<”The answer=”<<total;
     The answer =  is just a message ,not a variable          Therefore it should be within quotations. and << is used          with cout.
                iii.      char a=’x’;
      The data type is char.
                iv.       k=100;
      Most of the statements are terminated by ;


   3.  Write the c++ expression for the following :
                             i.   r2
                  = r * r
                            ii.   a3/6
                 = (a*a*a)/6
Here the multiplication ,division symbols should be written correctly.

   4. Evaluate :
                   i.            (10 >100) && (4>0)
                  ii.            !(25 < 20)
                 iii.            (1+2 <6)

Here the answer will be either true or false.The statements use logical and relational operators.
         in question i.  
           10 is not greater than 100 so it is false . But 4 is greater than 0 , so it is true . Remember in AND operation both the statements should be true to get the answer True.
           Therefor the answer is False.
        in question ii.
            25 is greater than 20  so it is False, but because of the NOT(!) operator  the    answer is True.      
                                
A program in C++ involves 4 basic steps.

1.Declaration
2. Assignment / Input
3. Calculation
4. Output

In step 1 , we declare a variable ( data type and a variable name).
In step 2 , we either give values to variables or accept values from                     the user.
In step 3 , Calculation, if any.
In step 4 , Print the answer.

Simple.
Step 1:
Declaration 
The data types of the variables should be mentioned before we use them.
We need to specify whether the number we are going to use is a whole number(int) or a decimal number(float),
or  we are going to use a single letter(char) or group of characters(String).


Step 3
If we have any calculation to do, we do it in step 3.
Step 4
Finally we print the output(answer).

Program 1:

Assign your class and sec and display them .
#include<iostream.h> ------------------------ 1
#include<conio.h>      ------------------------ 2
void main()                 ------------------------- 3
{
clrscr();                       ------------------------- 4
int c;                           ------------------------- 5
char s;                         ------------------------- 6
c=8;                            ------------------------- 7
s=’G’;                         ------------------------- 8
cout<<c<<s; ------------------------- 9
getch();                      
}




In line nos 1 and 2, we have  header files.It contains pre defined functions. iostream conatains functions for cin and cout.
conio has some functions like clrscr which is clear screen .
In line nos 5,6 we mention the data types(declaration).
In line nos  7,8 we assign the values to the variables. and in line 10 , we print the answer.

Program 2:

Accept 3 numbers and find its average.
#include<iostream.h> 
#include<conio.h>      
void main()                
{
clrscr();                      
int a,b,c,tot;                ------------------------- 1
float avg;                    ------------------------- 2
cout<<"Enter first number:";     
cin>>a;                           -------------------------3
cout<<"\n Enter second number:";        
cin>>b;                                    -------------------------4
cout<<"\n Enter third number:";        
cin>>c;                                    -------------------------5       

tot=a+b+c;                 

avg=tot/3;
cout<<"\n Total="<<tot;
cout<<"\n Average="<<avg;
getch();
}

Here we are accepting 3 numbers from the user, they could be anything. Line numbers 3,4,5 could be written in a single line like this cin>>a>>b>>c;
\n is used to take the cursor to the next line while printing, otherwise everything will be in the same line.

Program 3
Accept the side of the square from the user and calculate its area.
Area of square = side x side


#include<iostream.h> 

#include<conio.h>      
void main()                

{
clrscr();                      
int side,area;                

cout<<"Enter the side:";        
cin>>side;                                     

area=side * side;
cout<<"\n Area ="<<area;
getch();
}


Tuesday, 12 September 2017

Heading Tag - Class 7

Heading tag:
There are 6 heading tags. <h1> is the biggest tag and <h6> is the smallest.
Since the text attribute is used to change the colour, the entire document will have the same colour. Whereas if you use <font color> then you can have different colours.
 <html>
<head>
<title> Worksheet 4 </title>
</head>
<body bgcolor=purple text=white>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>


Line - Class 7

The above output has 5 lines. The first one is a thin line, because there is no size tag.

<html>
<head>
<title> Example 3</title>
</head>
<body>
<hr > <p>
<hr size=3 color=red> <p>
<hr size=8 color=green></p>
<hr size=3 align=right color=blue><p>
<hr size=3 noshade ></p>
</body>
</html>
2.
<html>
<head>
<title> Example 4</title>
</head>
<body>
<font size=1 color=crimson>
We the Cottonians <br></font>
<font size=2 color=blue>
We are all here<br></font>
<font size=3 color=gold>
We want to do YES <br></font>
<font size=5 color=green>
Always our best<br></font>
<font size=4 color=purple>
Our motto is <br></font>
<font size=5 color=olive>
NEC DEXTRORSUM NEC SINSITRORSUM<p>
<font size=6 color=crimson>
Hip Hip Hurrah.......
</body>
</html>



 

List Video

                                                LIST 




List - Class 7


List

  Lists are used when we want to display the information in points. 

There are three types of lists.
  • Ordered List

  • Unordered List

  • Description List / Defenition List

Ordered List :

  • <ol >       - Default list. It gives the numbers.
  • <ol type=A>
  • <ol type=a>
  • <ol type=I>
  • <ol type=i> 


Output :

Unordered List

  • Disc - Default list
  • Circle
  • Square
 Output :

Description List



Output :

 Nested List




Output :


Formatting Tags - Class 7

Formatting tags
The formatting tags are used to give a stylish appearance to the text in the web page.
Bold
The text appears darker.
<b> ..... </b>
Italics
The text appears different(slanting).
<I>....</I>
Underline
There is a line below the text.
<U>.....</U>
Strikethrough
A line is drawn across the text.
<Strike>....</Strike>
Superscript
Text appears above the text.
<Sup>....</Sup>
Subscript
Text appears below the text
<Sub>.....</Sub>
Center
Text appears in the middle of the screen.
<Center>....</Center>

<html>
<head>
<title>
Friends
</title>
</head>
<body bgcolor=olive text =white>
<center><h1>FRIENDS</h1></center>

Written with a pen, sealed with a kiss,<br>
 If you are my <b>friend </b>, please answer me this:<br>
 Are we friends, or are we not?<br>
 You told me once, but I <I> forgot</I>.<br>
 So tell me now, and tell me <u>true</u>,<br>
 So I can say I'm here for you.<p>
 Of all the friends I've ever met,<br>
 You're the one I won't forget.<br>
 And if I die before you do,<br>
 I'll go to <b><I> Heaven </I></b>and wait for you,<br>
 I'll give the <font color=red><h2>angels</h2></font> back their wings<br>
 And risk the loss of everything.<br>
 There isn't a thing I wouldn't do,<br>
 To have a friend just like you!

<p align =right>The true author is unknown

</body>
</html>
 

OUTPUT