Tuesday 30 August 2016

Class 8 : Operators in VB

Ch : 5 Operators and Functions

In this chapter we are going to learn about the basic steps such as variable, data type, operator in Visual Basic
1. Variable :
The value is going to change every time.
x=3 , here x is a variable.
Rules for naming a variable :
1. First character should be a letter.
2. Other characters may be letter,digit.
3. No special characters except underscore( _ ).
4. Maximum limit is 255 characters.
5. Keywords are not allowed.
Examples :
1. a   -  Valid variable
2. s1  - Valid variable
3. Computer_Science - Valid variable
Identify the valid and invalid variables :
1.  _123              - Invalid variable(Should start with an alphabet)
2.  Bond007        - Valid variable
3.  Cotton  Boys  - Invalid variable(Special character space)
4. Middle      - Valid variable
5. ProgRam   - Valid variable
6. A * b         - Invalid variable(Special character *)


Thursday 28 July 2016

Class X - Methods

Its not ROCKET  SCIENCE.....

Its just COMPUTER SCIENCE .....



METHODS
When our program is too complicated, the best approach is to divide it into smaller sections, so that it is easy to write the code and also easy to debug.
If we want to use  a set of statements in more than one place, instead of writing the same code  again and again,we can write it once and call it wherever we need it.
For instance
*******************************************************
WELCOME TO MY BLOG
*******************************************************
Class X Notes.

*******************************************************
class example1
{
    public static void main( )
       {
          System.out.println("******************************");
          System.out.println("WELCOME TO MY BLOG");
          System.out.println("******************************");
          System.out.println("Class X Notes");
              System.out.println("****************************");
      }
}
In the above program the highlighted lines are repeated 3 times. We can reduce the code by writing once and calling it 3 times.
class example1
{
    public static void main( )
       {           
                    star( );
                    System.out.println("WELCOME TO MY BLOG");
                    star( );
                    star( );
                 }
public static void star ( )
     {
                Sytem.out.println("****************************");
      }
}
Method Header
access_specifier  modifier  return data_type method name( )e.g :
 public static void main() 
 

NOTE
  • The other name for method is FUNCTION
  • A method can be easily identified .A method name is always followed by the opening and closing parentheses ( ).
  • A method name must begin with a letter or an underscore, it also can contain letters, numbers and underscore.
  • Access specifier and modifier are optional.
  • main( )  method can be written anywhere in the program.
Function header or prototype
The first line of the method with the name of the method,data type of the return value, number and the type of arguments is called the header or prototype.
Function Signature
It is the number and types of arguments.
1. Example
Write a program to add two numbers .
class addition{
public static void main( )
  {
     int a=10,b=45; --------------------------------------------1
     int s= add(a,b); -------------------------------------2,6     System.out .print("Sum = "+s);-----------------------7
}
 int add(int a,int b)----------------------------------------3
  {      int c;
       c=a+b;-----------------------------------------------4
       return  c; --------------------------------------------5  
  }
}
In the above program , the numbers are the order in which the program will be executed. In the step 2, add( ) is the method name,this is the function call.the control will go to the function in step 3.The method statements will be executed.And the answer will be sent to the step which called the function, that is step 2.The answer is stored in variable s.The data type of the answer is int that is why the return data type is int in function header. Step 2 is also called calling a funtion or invoking a function.
Tha above program can be written like this:

class addition
{
public static void main( )
  {
     int a=10,b=45; --------------------------------------------1
      add(a,b); -------------------------------------2    
}
 void add(int a,int b)----------------------------------------3
  {      int c;
       c=a+b;-----------------------------------------------4
       System.out.print(c); -----------------------------------5  
  }
}
There is a change in step 2, the answer is not stored in any variable .The answer is displayed in the method add itself, thats why there is no return statement and also the datatype is void in function header.  a and b in step 2 are called actual parameters ,a and b in step 3 is called formal parameters.
2. Example 
 Write a program to find the factorial of a number .
class factorial
{
public static void main( )
  {
     int n=5; --------------------------------------------1
     int x= fact(n); -------------------------------------2,8
     System.out .print("Factorial = "+x);------------9
}
 int fact(int n)----------------------------------------3
{
     int i,f=1; ------------------------------------------4
    for(i=1;i<=n;i++)---------------------------------5
     f=f*i; ----------------------------------------------6
  return f; --------------------------------------------7
}
}
After the  step 2 the control will go to the function fact.It will complete all the statements there and send the answer back to main function. The answer will be an integer value ,thats why the return data type is int.
3. Example
Write a program to display the sum of the series

13+23+33+….n3
using the function cube()
class sum

{
public static void main(int n)---------1
{
int i,s=0;
for (i=1;i<=n;i++)
s=s+cube(i);
System.out.print("Sum="+s);
}
public static int cube(int a)
  {
    int c=a*a*a;
    return c;
   }
}
In step 1 you should accept the value of ' n ' from the user. In the above question we should find the cube of each number.We write the code for this once, but call it again and again.

Let me introduce the scope of variables here......

The scope of the variable is nothing but where all you can use a particular variable in a program.
  • Local variable - Variable which is declared inside any function.You can use the variable only in that function not throughout the program .
  • Global variable - variable declared ouside all functions. i.e. just after class.This can be used anywhere in the program.
Example 4
Define a class salary describesd as below:
Data members : Name,Address,Subject,Salary,Income tax
Member methods :
  1.   accept the details of the teacher
  2. display the details
  3. compute the income tax as 5% of the annual salary above Rs.1,75,000.
Write a main method to create an object .
import java.util.*;
class salary
{
String name,address,subject;-----------1
double sal,it;--------------------------2
void get(String n,String add,String sub,double s1)------3
{
  name=n;
  address=add;
  subject=sub;
  sal=s1;
}
void compute()
{   
   int a=sal*12 ;
  if(a > 175000)
          it=0.05* a;
  else
          it=0;
}
void display( )
{
  System.out.println("Name="+name);
  System.out.println("Address="+address);
  System.out.println("Subject="+subject);
  System.out.println("Salary="+sal);
  System.out.println("tax="+it);
}
public static void main()
{
   salary ob=new salary();---------------------------4
   Scanner s=new Scanner(System.in);
    System.out.println("Enter the name");
    name=s.next();
    System.out.println("Enter the address");
    address=s.next();
    System.out.println("Enter the subject");
    subject=s.next();
    System.out.println("Enter the  Monthly salary");
   salary=s.nextDouble();
   ob.get(name,address,subject);
   ob.compute();
   ob.display( );
}
}

Steps 1 and 2 are the global variables.You can use them anywhere in the program. In step 3, the values received from the main method . and in   get ()  the values are stored in global variable for the same reason mentioned above.compute() and display() are according to the question.In step 4, we create an object. salary is the calss name,donot use anything else, ob is the object name,you can give any name. new is the keyword, it allocates memory for the object.
Remember to write the global variable on the left hand side and local variable on the right hand side in void get().Donot mix it up
Methods can be divided into
  • Pure method or accessors - methods donot change the state of an object.
  • Impure mentod or mutators - methods the change  the state of the object.
Method Overlaoding or Function OverloadingThere can be more than one method with the same name.But the problem is how the control will go to the method it is supposed to go.Thats why there should be  some difference in the methods.So method overloading will have more than one method with same name but differ in the number or types of arguments or both.   
Write a program using a function called area( ) to do the following :
  1. Area of a circle
  2. Area of a square
  3. Area of a rectangle

import java.util.*;
class menu
{
public void area(int r)
{
System.out.println("Area of circle="+(3.14*r*r));
}
public void area(int l,int b)
{
System.out.println("Area of rectangle="+(l*b));
}
public void area(float side)
{
System.out.println("Area of square="+(side*side));
}
public  void main( )
{
   Scanner s =new Scanner(System.in);
   System.out.println("Enter radius");
   int r=s.nextInt();
   System.out.println("Enter length and breadth");
    int l=s.nextInt();
    int b=s.nextInt();
   System.out.println("Enter side:");
   float side=s.nextFloat();
area(r);-------------------1
area(l,b);-----------------2
area(side);---------------3
}
}

In step 1 and step 3 have same number of arguments but different data type values and all the 3 functions have same name and differ in something or the other so it represents function overloading.
I give a similar program, try it.If you want your program to be checked, mail it to me.
Write a program using a class to calculate the volume,surface area and the diagonal of cuboid with the following specifications:
class name  : Cuboid
Data members : int l,int b,int h
Member funcions :
void input() : Accept length,breadth and height of cuboid
void calculate() : find volume,surface area and diagonal
void dispaly(): Print the result
Volume of cuboid : lxbxh
Surface Area : 2(lb+bh+lh)
Diagonal :  square root of   l2+b2+h2

Java provides two ways in which a value can be called.
  • Pass or call by value : Its simple,just pass the value in calling function and receive the value in receiving function like in the above examples.
  • Pass or call by reference : Reference is the memory address. The memory address of the variable is passed , so if there is a change in the receiving function, then it will refelect in the calling function also.e.g passing arrays.

Monday 18 July 2016

Class 7 - HTML worksheet 1

1. Write a program in HTML to display the following :

My first program                        ---------------------------- 1
I am in class 7                               -----------------------------2

Bishop Cotton Boys' School        -----------------------------3

<html>
<head>
<title> Example 1</title>
</head>
<body >

<b> My first program</b> <br>
 I am in  <I> class 7 </I> <p>
<u> Bishop Cotton Boys' School</p>
</body>
</html>


The  line1 is darker than the rest of the program. This is because of the bold tag. to go to the next line use the <br> tag.
In line 2 , only class 7 is slanting , so use italics tag for that.
There is a blank line between  line 2 and line 3, so paragraph tag should be used. Even if you close <p> before <u> tag also will give same effect.
In line 3,a line is drawn below the whole sentence using <u> tag.

2. What would be the output for the following program:
<html>
<head>
<title> Example 2</title>
</head>
<body bgcolor=olive text=yellow>           ------------------1
 Computers<br>Class 7                             ------------------ 2
<p>                                                            ------------------ 3
Cottonnian shield 

</p>
</body>
</html>


Line 1 : the background colour. The spelling is bgcolor. The foreground color is yellow. Remember it is text,  not text color.
Line 2 : <br> tag moves the cursor to the next line.So Class 7 is displayed in the next line.
Line 3 : <p> tag leaves a blank line.




Friday 15 July 2016

Class 7 -HTML

Select the correct answer:
  1. HTML stands for
  • Hyper Text Markup Language
  • Hyper Text Makeup Language

2. Container element has both
  • opening and middle tag
  • opening and closing tag
3. <br> is
  • a line break tag
  • an empty tag
  • line break and an empty tag
4. Firefox is
  • an editor
  • a web browser
  • search engine
5. How would you give the background colour
  • <body backcolor=red>
  • <body bgcolour=red>
  • <body bgcolor=red>
  • <body backcolour=red>
  • <body bg color=red>
6. To change the colour of the letters and numbers you type
  • <text=green>
  • <body textcolour=green>
  • <body text=green>
  • <textcolour=green>
7. <p> tag
  • moves the cursor to the next line
  • leaves a blank line
  • leaves a paragraph
8. _____ are not displayed in the web browser.
  • comments
  • title
  • body
9. To align the text in the middle of the page
  • <align=center>
  • <align=centre>
  • <p align=centre>
  • <center>
10. Heading tags ranges from ___ to _____
  • 1 to 7
  • 1 to 6
  • 1 to 3
11. To make the text look darker
  • <dark>
  • <b>
  • <bold>
12. To draw a line across the text
  • <u>
  • <line>
  • <strike>
  • <strikethrough>
13. The largest heading tag is
  • <head>
  • <h1>
  • <h6>

14. The text between <title> and </title> will be displayed
  • in the title bar
  • in the heading bar
  • in the web page
  • none of the above
15. An attribute is
  • an additional information about the tag
  • main tag
  • an example
16. An example of WYSIWYG
  • MS Word
  • Frontpage
  • HTML



      Wednesday 13 July 2016

      Class 8 - Introduction to Visual Basic

      Visual Basic

      Visual basic was derived from the language BASIC. 

      BASIC has its own limitations., it is a simple programming language but used only in a text based environment. But visual basic is

      • User friendly

      • Supports Graphical User Interface(GUI)VB

      VB is an Event- driven programming, which means the flow of the program is determined by an Event.

      An Event is an action performed either by mouse click, double click or pressing keys on the keyboard.

       Integrated Development Environment describes the interface and the environment we use to create our own applications.

       1. Form design window
       2. Tool box

       3. Menu bar

       4. Project explorer

       5. Properties window

       6. Form layout


      Project Explorer Window
                   
                    It lists all the forms in the project. The components of the window are:
      • View code
      • View object
      • Toggle folders
      • Project name
      • Forms folder
      • form module


      Properties Window

                    It displays the properties like font name, caption, background colour etc of the selected object on the form.

      A form is saved with an extension  .frm .
      A project is saved with an extension .vbp .

              To execute the visual basic program :
      •         Click Run from Start option
      •         Click start on the Toolbar
      •         Press F5 key
                            

      Class 7 : Introduction to HTML

      HTML
      HTML (Hyper Text MarkUp Language) is used to create web pages. The codes are called tags. The tags are given within < and >.
      There are two types of tags ,
      i.                   Container Tag : It has both opening and closing tags.
                               e.g : <html>  </html>
      ii.                 Empty Tag     : It has only a opening tag.
                              e.g : <br>
      The basic structure of a HTML document is
      <html>
      <head>
      <title>
      </title>
      </head>
      <body>
      ………
      ……..
      </body>
      </html>
       Whatever is typed between <title> and </title>  will be displayed on the title bar not in the web page.

      <html>
      <head><title> My Page BCBS</title>
      </head>

      <body>
      Your text goes here.
      </body>
      </html>

      Example 1 :
      <html>
      <head><title> My Page BCBS</title>
      </head>
      <body>
      Bishop Cotton Boys' School
      </body>
      </html>


      The output will be :




      The data entered between <body> and </body> only  will be displayed in the web page.
      Line break tag <br>:
      It moves the cursor to the next line.
      Paragraph Tag <p> :
      It leaves a blank line.
      Example 1 :
      <html>
      <head><title> My Page BCBS</title>
      </head>
      <body>
      BCBS <p>

      Thomas House <br>
      Pope House <br>
      Elphick House <br>
      Pakenham Walsh  House <br>
      Pettigrew House
      </body>
      </html>


      The output will be :

       

      Monday 14 March 2016

      Class 8 - Repetition Programming(For)

      Loops

      If we want to repeat a set of statements , looping statements are used.
      There are two types :
      • For ... Next
      • Do ....Loop

      For ... Next

      Probably this is the easiest of the looping statements. The general form is given as

      For variable=initial value to final value step value
      --------------
      -------------
      Next variable

      1. Display the numbers from 1 to 10.

      Dim a as integer
      For a=1 to 10
      Print a
      Next a

      Note :
      • Step value is used to increment or decrement . In the above program it should have been Step 1, since the difference between two numbers is 1. But Step 1 is the default value so no need to write it.
      2. Display the even numbers from 5 to 50

      Dim a as integer
      For a=6 to 50 step 2
      Print a
      Next a

      3. Display the following numbers:
           100 
           90
           80
           ....
           ....
           10


      Dim a as integer
      For a=100 to 10 step -10
      Print a
      Next a

      Note :
      Here the numbers are in descending order , therefore step -10. 
       

      Class 7 - Frames(Revision)


      Class 7 - Creating Frames (video)

      Sunday 13 March 2016

      Class 7 - Creating Frames

      One.html
      <html>
      <body bgcolor=olive text=white>
      <b><center> One</center></b>
      </body>
      </html>


      ------------------------------------------------------------------------------------
      Two.html
      <html>
      <body bgcolor=pink text=white>
      <b><center> Two</center></b>
      </body>
      </html>


      -----------------------------------------------------------------------------------

      <html>
      <frameset rows=30%,*>
      <frame src=one.html>
      <frame src=two.html>
      </frameset>
      </frameset>


      Output :


      *******************************************************

      <html>
      <frameset cols=30%,35%,*>
      <frame src=three.html>
      <frame src=four.html>
      <frame src=five.html>
      </frameset>
      </frameset>



      Output :


      ---------------------------------------------------------------------------------
      <html>
      <frameset rows=35%,*>
      <frame src=one.html>
      <frameset cols=30%,35%,*>
      <frame src=three.html>
      <frame src=four.html>
      <frame src=five.html>
      </frameset>
      </frameset>
      </html>


      Output :


       

      Monday 11 January 2016

      Class 7 (table)

      Class 7- HTML Quiz1

      Loading HTML

      Class - 7 (Table)

      Loading Table