Sunday, 16 December 2018

Class 9 - continue statement

1.
     for (int i = 1; i <= 5; ++i) 
{      
         if (i > 5)
         {
            continue;
         }      
         System.out.println(i);
}
The output for the above code fragment is
1
2
3
4
5
when the value of i is greater than 5, the control will go to the next iteration, so from 6 to 10 will not be printed.

2. 

for (int i = 1; i <= 10; ++i)
 {     
         if (i > 4 && i < 9)
        {
            continue;
         }     
         System.out.println(i);
      }  
The output will be 
1

2
3
4
9
10

Sunday, 9 December 2018

Class 9 - Loop revision

Points to remember :
1. break statement is used to break the loop.
2. continue sends the control to the update expression.
3. for loop is used for fixed iterations.That is where you know the final limit.
4. In while loop, condition is tested before execution.
5. The do while loop executes the statements atleast once even if the condition is false.
6. Infinite loop : control does not reach the test condition.
7. Empty loop : loop does not contain any statement in the body.


1. What will be the output for the following programs:
i)
            for(a=0;a<30;a++)
           {
                   if(a==5)
                   break;
                   System.out.print(+a);
          }

ii)
      for(x=1;x<=5;x++)
      {
           if(x==2)
          continue;
          if(x==4)
          continue;
System.out.println(x);
      }
iii)
        int x=0;
       while(x<=10)
        {
               x++;
             if(x==4)
              break;
             System.out.println(x);
        }
2. Differentiate : while and do while.
3.Write a program to enter a number and print the sum of odd numbers and even numbers for the first n natural numbers.                                                                     [ICSE]
4.
      i)         12+22+32+42+…………+n2
      ii)     x2/2+x3/3+………xn/n

1. Fibonacci series:
 0,1,1,2,3,5,8.............................
2. Prime number:
    The divisors are one and the number itself.
    e.g : 5 : divisors 1 and 5
3. Perfect number :
     The sum of the divisors(excluding the number) equal to the number itself.
    e.g : 6
       divisors are 1+2+3=6
4. Armstrong number:
    e.g :
         153=13+53+33
               =1+125+27
               =153
5. Palindrome number:
  e.g:
        272: reverse the number 272.

Friday, 14 September 2018

Class 10 - Arrays (2018)

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.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:
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..

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.


Sorting Arrays
  • Selection Sort
  • Bubble Sort
Before we go to sorting , learn how to swap two values.
let us take x=30 and y=20, now interchange these two in java.
we might write
        x=y;
        y=x;
Now the value of x will be 20 and y also will be 20, coz in the first line y is assigned to x.Therefore the value of x is 20.In the second line ,we assign 20 to y not 30.Therefore we need one more temporary variable.
       temp=x;
        x=y;
        y=temp;
temp takes the value 30, x becomes 20, and y becomes 30.
Bubble Sort:
import java.util.*;
class bubble{
public static void main()
   {
int a[]=new int[10];
Scanner s=new Scanner(System.in);
int i,j,l,temp; 
l=a.length ;
System.out.println("Enter the values");
for(i=0;i<l;i++) -----------------------------------1
a[i]=s.nextInt();-----------------------------------2

for(i=0;i< l-1;i++)--------------------------------3
{
    for(j=i+1;j<l;j++)------------------------------4
      {
         if(a[i]>a[j])----------------------------------5
           {
              temp=a[i];
              a[i]=a[j];
               a[j]=temp;
           }
     }
}
System.out.println("The values after sorting");
  for(i=0;i<l;i++)
System.out.println(a[i]);
}
}

step 1 and 2  : input values
step 3 and 4 : There should be 2 loops,so that we compare the top most element with the least value.
step 4: If the top value is bigger(in case you want to sort in ascending order) the you should change it.Therefore swap the values.
Selection Sort :
import java.util.*;
class selection
{
public static void main()
   {
int a[]=new int[10];
Scanner s=new Scanner(System.in);
int i,j,l,temp,loc; 
l=a.length ;
System.out.println("Enter the values");
for(i=0;i<l;i++) 

a[i]=s.nextInt();
for(i=0;i< l-1;i++)
{
      small=a[i];---------------------------------------1
      loc=i;---------------------------------------------2
    for(j=i+1;j<l;j++)
        {
            if(small > a[j])------------------------------3
              {
                 small=a[j];-------------------------------4
                 loc=j;
              }
        }
        temp=a[i];------------------------------------5
        a[i]=a[loc];
        a[loc]=temp;
    }
System.out.println("The values after sorting");
  for(i=0;i<l;i++)
System.out.println(a[i]);
}
}

step 1 : Take the value in ith place as the small value.Initially the first value is small.So that we can compare it with other values.
step 2: Record the location of that value
step 3 :Compare the small value with the other values
step 4 :If small is bigger than the other value then assign that value to small.
step 5: Swap the values
 Write a program to pass an array to a function:
import java.util.*;
class arr2
{
void get(int a[], int l)
{   int i;
    for(i=0;i<l;i++)  
    System.out.println(a[i]);
}
public static void main()
   {
arr2 ob=new arr2();

int a[]=new int[10];
Scanner s=new Scanner(System.in);
int i,j,l,temp; 
l=a.length ;
System.out.println("Enter the values");
for(i=0;i<l;i++)  

a[i]=s.nextInt();
ob.get(a,l);
}
}

Class 7 - Number System

 Number System
1. Binary Number System
Only 0 and 1 are allowed in binary number system. So the base is 2(only two numbers)
e.g:
 (101)2
2. Decimal Number System
0,1,2......9 are allowed in decimal number system. So the base is 10( 0 to 9,totally 10 numbers)
e.g:
(25)10

The base is written along with the number to identify the number system.
Conversion from binary to decimal :
20=1
21=2
22=4 (2 x 2)
23=8(2 x 2x 2)
24=16(2 x 2x 2 x 2)
 and so on.......




2. (110)2

1   1   0

 = 1 x 2 2 + 1 x 2 1+ 0 x 2 

 = 4 + 2 + 0
= 6
Answer = (6) 10

3. (111)2
 = 1 x 2 2 + 1 x   2 1   + 1 x   2 0
= 4 + 2+ 1
= 7

4. (1011)2
=1 x   2 3  + 0 x 2 2 + 1 x   2 1   + 1 x   2 0

= 8+0 + 2+ 1
= 11

5. (1101)2
=1 x   2 3  + 1 x 2 2 + 0 x   2 1   + 1 x   2 0

= 8+4 + 0+ 1
= 13

Conversion from decimal to binary

This involves repeated division of the quotient by two, the remainder forms the part of the answer.
1. (4)10

4 / 2 = 2  remainder = 0
2/2 = 1    remainder = 0

You cannot divide 1 by 2, so stop now. Therefore the answer is
=(100)2

2. (7)10

7 / 2 = 3 remainder = 1
3 / 2 = 1 remainder = 1

(111)2


3. (13)10

13 / 2 = 6 remainder = 1
6 / 2 = 3   remainder = 0
3 / 2 = 1   remainder = 1
= (1101)2

I Term Exam 2018

Children ,  I will post revision for classes 7,8 and 9. At Least spend 15 to 30  mts every day  for the next 3 days. I am sure  you will be good to go. Remember its not Rocket Science.


If you need any guidance message me, i will get back to you. 

Tuesday, 21 August 2018

20th Aug - to 24th Aug

Class 7 : 

Commands and Statements in QBASIC.
Simple programs in QBASIC


Class 8 :

Simple Programs in Java.

Wednesday, 25 July 2018

Java

There are some very good questions from this chapter.But almost all of them are direct.
Types of Java :
  • Stand alone : A java program developed by the user.
  • Internet applets : Java programs which are executed using web browser.
Basic features of Java :
  • Object oriented programming
  • both complied and intepreted
  • platform independent
  • No memory pointers like in c++
  • No preprocessor
  • Automatic memory management
  • Built in networking
  • Dynamic binding
  • Open product (i.e) freely available
  • Multithreaded : Perform multiple tasks simultaneously.
 The conversion of high level language(source code) to machine level language can be done in two ways.
Interpreter converts  line by line.
Whereas compiler converts all at once.

Byte code:
The java programs are converted to a code called byte code.It is independent of the machine on which the program is to run.Java virtual machine (JVM)is an interpreter which translates byte code into machine code.
Java Source code--->java complier--->byte code--->JVM

Java code can run on many computers coz  java interpreters(JVM) exist for most operating systems.

Comments in Java :
  • Single line comment : //
  • Multi line comment : /*                        */
Errors :
  • Syntax : e.g semicolon missing,bracket missing,variable not declared.
  • Run time :(e. g)dividing by zero
  • Logic : The program does not produce the answer we want.

class 9 Java introduction

Creating a set of instructions to make the computer to do something is no Rocket Science. Just a bit of logic, bit of syntax, bit of patience, bit of interest and bit of concentration in the class are all you need to learn the language.

Programming ,  most of the times involve 4 steps:
  1. Declaration
  2. Assign / Input
  3. Calculation (if necessary)
  4. Print
Example 1 :

Write a program to print your name and school name.

class prog1
{
  public static void main( )
  {
      System.out.print("Bishop");
      System.out.print("Cottons");
   }
}
   
   This is the basic structure of the program. You might have noticed that the program did not use all the above 4 steps. 

  We don't have to use all the steps in all the programs. 
The output is going to be :
BishopCottons

System.out.print( ) displays anything written inside the brackets.

In case if I don't want the answer in single line , I have to use

System.out.println( ).

In case if I want the answer in a single line but separated by a space or a comma then,

System.out.print("Bishop" + "  " + "Cottons" ).

The answer will be Bishop  Cottons

In the print statement, the + symbol is not an addition symbol rather it combines two items, that is Bishop and space and also space and Cottons. So there are 3 items Bishop, space , Cottons.

So if I make a small change in my program the answers will be in two different lines.
    
class prog1
{
  public static void main( )
  {
      System.out.println("Kavitha");
      System.out.print("Cottons");
   }
}


 Example 2 :

Write a program to assign two values and print its sum.

class prog2
{
  public static void main( )
  {
      int a, b,c;  -------------------------------------- Step 1
      a=5;         ---------------------------------------Step 2
      b=30;      ----------------------------------------Step 2
      c=a+b;    --------------------------------------- Step 3
      System.out.print(c);  ------------------------- Step 4
     
   }
}

The output will be 35

Step 1 : Declaration.

           Mention the data types of the variables involved.
Step 2: Assign

           Put some values in your variables.
Step 3 : Calculate

           Add the values and store it in the new variable. Remember variable = constant not the other way round.

Step  4 : Print

               Display the answer. you can also write
         System.out.print("Sum= " + c);

The answer will be Sum = 35. This is the good way of displaying the answer with a message.

Steps 1 and 2 can be combined to form a single statement.

  int a = 5, b=30, c;

Input Methods

   We are going to learn 2 input methods .

  • Blue J
  • Scanner


 Blue J Method

class prog3
{
  public static void main( int a, int b ) ----- Accepting values                                                                              from the user
  {
      int c;
      c=a+b;
      System.out.print("Sum = " + c);
   }
}

Even though both a and b are of same data type ,  it should be mentioned twice and should be separated by comma(,).

public static void main( int a, b ) ------ Wrong


 See you in the next post.

Tuesday, 24 July 2018

Class 7 - Revision

QBASIC
Revision :

There are 3 types of character sets : 
Alphabets
Numbers
Special Characters.

Operators:
Arithmetical Operators
Relational Operators
Logical Operators

In arithmetical operators learn the various symbols you use in QBASIC. Because some symbols in computers are different from symbols in Maths like multiplication, division.
You should be able to write the corresponding QBASIC expression for the given Mathematical expression.

e.g:

         4ABC = 4 *A* B*C

In relational operators , learn all the symbols. You should be knowing it gives the answer either in True or False.

e.g:

      X = 5 , Y =8 
(X > 5) will give False 

(Y < >10) will give True

In Logical Operators you should be familiar with the truth tables.

A = 3 , B= 6 and C=10

(A > B) AND (C < 100)
A>B is false so the answer is false.

You should also know how to convert a given instruction into a QBASIC instruction.

e.g:

The sum of a and b  is less than the product of a and b.
          (a + b) < ( a *b)

In the second unit Constants and Variables , 

You should be familiar with the rules for writing the variables and constants.

Numeric variable will store Numeric Constant.
Alphanumeric variable will store alphanumeric Constant.

You cannot mix up the constants and variables.
                                 Numeric variable = Numeric constant
                                             E = 20
                         Alphanumeric variable = Alphanumeric constant
                                           G$ = "Class"

Remember variable on the left hand side and constant on the right hand side.
                               A = 100
In alphanumeric variable , there should be a $ in the end.
Alphanumeric constant should be within double quotation.

                               B$ = " Computer Science"
                               D1$ = " Bond 007"
You should know how to write valid valid(correct) variables for the given constans.

e.g:

                      ------------ = " Rain"
              Here write any valid alphanumeric variable. Because on the right hand side "Rain" is the alphanumeric constant. (Remember double quotation means alphanumeric )
                      W$ = "Rain"

                     --------------- = 7.8
            
              Here write any valid numeric variable. Because on the right hand side 7.8 is the  numeric constant. 
                     
                        B = 7.8

Wednesday, 18 July 2018

Class 7 - QBASIC Expressions


Java Revision 2

Class 8 and 9 

Loading Java

Tuesday, 17 July 2018

Java Revision 1

Class 8 and 9

Monday, 16 July 2018

Class 7 - QBASIC


Loading QBASIC

Class 7 - Variables and Constants

Class 7 Variables



Saturday, 7 July 2018

Class 7 - Fundamentals of QBASIC QUIZ

Friday, 8 June 2018

Welcome


       Hallo and welcome to my class. 

Lesson Plan for the week : (11.06.18 - 15.06.18)

Class 7 :
Ch 1 : Computer Hardware components.
Class 8 :
Ch 6: Networks