Read in your tongue here..

Tuesday, January 19, 2016

ATM Program in TCL Linux.

proc writetofile { record data } {
    set i [expr [lindex $record 0]-1]
    set data [lreplace $data $i $i $record]
    set fp [open "data.txt" w]
    foreach x $data {
        puts $fp $x
    }
    close $fp
    puts "Transaction Successful."
}

proc depo { record data } {
    puts "**********\t Deposit Menu \t**********"
    puts "Enter amount to deposit:"
    gets stdin amount
    if {[lindex $record 3]=="SC"} then {
        puts "1.Savings Account\n2.Current Account\n3.Exit\nEnter Choice:"
        gets stdin choice       
        switch $choice {
            1 {
                puts "Current Balance is: Rs.[lindex $record 4]/="
                set record [lreplace $record 4 4 [expr [lindex $record 4]+$amount]]
                puts "New Modified Balance is: Rs.[lindex $record 4]/="
            }
            2 {
                puts "Current Balance is: Rs.[lindex $record 5]/="               
                set record [lreplace $record 5 5 [expr [lindex $record 5]+$amount]]
                puts "New Modified Balance is: Rs.[lindex $record 5]/="
            }
            3 {
                exit
            }
            default {
                puts "Invalid Input!!! Exiting Now..."
                exit
            }
        }
    } else {
        puts "Current Balance is: Rs.[lindex $record 4]/="       
        set record [lreplace $record 4 4 [expr [lindex $record 4]+$amount]]
        puts "New Modified Balance is: Rs.[lindex $record 4]/="
    }
    writetofile $record $data
}
proc withd { record data } {
    puts "**********\t Withdrawal Menu \t**********"
    puts "Enter amount to withdraw:"
    gets stdin amount
    if {[lindex $record 3]=="SC"} then {
        puts "1.Savings Account\n2.Current Account\n3.Exit\nEnter Choice:"
        gets stdin choice       
        switch $choice {
            1 {
                puts "Current Balance is: Rs.[lindex $record 4]/="
                if {[lindex $record 4]<$amount} then {
                    puts "Insufficient Funds!!!"
                    exit
                } else {               
                    set record [lreplace $record 4 4 [expr [lindex $record 4]-$amount]]
                }
                puts "New Modified Balance is: Rs.[lindex $record 4]/="
            }
            2 {
                puts "Current Balance is: Rs.[lindex $record 5]/="
                if {[lindex $record 5]<$amount} then {
                    puts "Insufficient Funds!!!"
                    exit
                } else {               
                    set record [lreplace $record 5 5 [expr [lindex $record 5]-$amount]]
                }
                puts "New Modified Balance is: Rs.[lindex $record 5]/="
            }
            3 {
                exit
            }
            default {
                puts "Invalid Input!!! Exiting Now..."
                exit
            }
        }
    } else {
        puts "Current Balance is: Rs.[lindex $record 4]/="
        if {[lindex $record 4]<$amount} then {
            puts "Insufficient Funds!!!"
            exit
        } else {               
            set record [lreplace $record 4 4 [expr [lindex $record 4]-$amount]]
        }
        puts "New Modified Balance is: Rs.[lindex $record 4]/="
    }
    writetofile $record $data
}

proc bal { record } {
    puts "**********\t Balance Enquiry \t**********"
    if {[lindex $record 3]=="SC"} then {
        puts "1.Savings Account\n2.Current Account\n3.Both\n4.Exit\nEnter Choice:"
        gets stdin choice       
        switch $choice {
            1 {
                puts "Savings Account Balance is: Rs.[lindex $record 4]/="
            }
            2 {
                puts "Current Account Balance is: Rs.[lindex $record 5]/="
            }
            3 {
                puts "Savings Account Balance is: Rs.[lindex $record 4]/="
                puts "Current Account Balance is: Rs.[lindex $record 5]/="
            }
            4 {
                exit
            }
            default {
                puts "Invalid Input!!! Exiting Now..."
                exit
            }
        }
    } elseif {[lindex $data $index 3]=="S"} then {
        puts "Savings Account Balance is: Rs.[lindex $record 4]/="   
    } else {
        puts "Current Account Balance is: Rs.[lindex $record 4]/="
    }
}

proc menu { record data } {
    puts "**********\tMain Menu\t**********"
    puts "1.Deposit\n2.Withdrawal\n3.Balance Enquiry\n4.Exit\nEnter Choice:"
    gets stdin choice
    switch $choice {
        1 {
            depo $record $data
        }
        2 {
            withd $record $data
        }
        3 {
            bal $record
        }
        4 {
            exit
        }
        default {
            puts "Invalid Input!!! Exiting Now..."
            exit
        }
    }
}
set fp [open "data.txt" r]
set file_data [read $fp]
close $fp
set data [split $file_data "\n"]
puts "**********/tWelcome To ATM Services./t**********"
set attempts 0
while {$attempts<3 br="">    incr attempts
    puts "Enter your user id:"
    gets stdin userid
    puts "Enter your pin:"
    gets stdin pin
    if {[string length $pin]!=4} then {
        puts "PIN should be of 4 digits only!!! Please try again. [expr 3-$attempts] attempts left!!!"
    continue
    }
    set index 0
    foreach record $data {
        if {$userid==[lindex $record 1] && $pin==[lindex $record 2]} then {
        set index [lindex $record 0]
        }
    }
    if {$index!=0} then {
        puts "Welcome, $userid."
        menu [lindex $data [expr $index-1]] $data
        break
    } else {
        puts "Wrong Credentials!!! Please try again. [expr 3-$attempts] attempts left!!!"
        continue
    }
}

Monday, September 21, 2015

Free Android App Development.

Want to learn Android App Development?
I will teach you all I know.
Don't worry for the money. It's completely FREE of cost.
Contact me:
  • Facebook: https://www.facebook.com/codeLb
  • Gmail: singhrahhul@gmail.com
  • WhatsApp: +919534598218

Tuesday, May 27, 2014

Abstract class in Java

import java.util.Scanner;
abstract class Person{
    String name, city;
    Scanner sc=new Scanner(System.in);
}
class Emp extends Person{
    int empcode;
    float bsal;
    void get()
    {
        System.out.println("Enter employee name:");
        name=sc.nextLine();
        System.out.println("Enter city:");
        city=sc.nextLine();
        System.out.print("Enter employee code:");
        empcode=sc.nextInt();
        System.out.print("Enter basic salary:");
        bsal=sc.nextFloat();
    }
    void disp()
    {
        System.out.println("Employee name:"+name);
        System.out.println("City:"+city);
        System.out.println("Employee Code:"+empcode);
        System.out.println("Basic Salary:"+bsal);
    }
}
class Stu extends Person{
    int roll;
    String course;
    void get()
    {
        System.out.println("Enter student name:");
        name=sc.nextLine();
        System.out.println("Enter city:");
        city=sc.nextLine();
        System.out.print("Enter course:");
        course=sc.nextLine();
        System.out.print("Enter roll:");
        roll=sc.nextInt();
    }
    void disp()
    {
        System.out.println("Student name:"+name);
        System.out.println("City:"+city);
        System.out.println("Roll:"+roll);
        System.out.println("Course:"+course);
    }
}
public class Abs{
    public static void main(String args[])
    {
        Emp obj1=new Emp();
        Stu obj2=new Stu();
        obj1.get();
        obj2.get();
        obj1.disp();
        obj2.disp();
    }
}

Monday, May 26, 2014

Factorial by recursion using static method

package Rahul;
import java.util.Scanner;
public class Fact {
   
static int fact(int num)
    {
        if(num==0)
            return 1;
        else
            return(num*fact(num-1));
    }

    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter number:");
        int n=sc.nextInt();
        System.out.print("Factorial of "+n+"="+Sec.fact(n));
    }
}

Wednesday, May 21, 2014

Inheritance in Java

import java.io.*;
class Student {
    String n,c,s;
    int r,sem;
    Student(){};
    void get(String name, String cou, String ses, int roll, int seme)
    {
        n=name;
        c=cou;
        s=ses;
        r=roll;
        seme=sem;
    }
    void display(){System.out.println("Name: "+n+"\nCourse: "+c+"\nSession: "+s+"\nRoll: "+r+"\nSemester: "+sem);}
}
class Marks extends Student{
    int m[]=new int[3];
    Marks()
    {
        super();
        m[0]=m[1]=m[2]=0;
    }
    void get(int marks[])
    {
        m[0]=marks[0];
        m[1]=marks[1];
        m[2]=marks[2];
    }
    void display()
    {
        Student:display();
        System.out.println("Makrs:\n"+m[0]+"\t"+"\t"+m[1]+"\t"+m[2]);
    }
}
class Main{
        public static void main(String args[])throws IOException
    {
        InputStreamReader ni=new InputStreamReader(System.in);
        BufferedReader in=new BufferedReader(ni);
        Marks obj1=new Marks();
        System.out.print("Enter Student's name:");
        String name=String.valueOf(in.readLine());
        System.out.print("Enter course:");
        String cou=String.valueOf(in.readLine());
        System.out.print("Enter session:");
        String ses=String.valueOf(in.readLine());
        System.out.print("Enter roll number:");
        int roll=Integer.parseInt(in.readLine());
        System.out.print("Enter semester:");
        int seme=Integer.parseInt(in.readLine());
        obj1.get(name,cou,ses,roll,seme);
        System.out.print("Enter marks of three subjects:");
        int marks[]=new int[3];
        marks[0]=Integer.parseInt(in.readLine());
        marks[1]=Integer.parseInt(in.readLine());
        marks[2]=Integer.parseInt(in.readLine());
        obj1.get(marks);
        obj1.display();
    }
}

Saturday, April 19, 2014

Calculating GCD of two numbers using Java

class GCD{
        public static void main(String args[])
        {
                int gcd=1;
                int n1=Integer.parseInt(args[0]);
                int n2=Integer.parseInt(args[1]);
                int num=n1<n2?n1:n2;
                if(num==1)
                        System.out.println("GCD of "+n1+" and "+n2+"="+gcd);
                else       
                {
                        for(int i=2;i<=num/2;i++)
                                if(n1%i==0&&n2%i==0)
                                        gcd=i;
                        System.out.println("GCD of "+n1+" and "+n2+"="+gcd);
                }
        }
}

Calculating roots of quadratic equation using Java

class Quad{
        public static void main(String args[])
        {
                int a,b,c;
                double d,r1,r2;
                a=Integer.parseInt(args[0]);
                b=Integer.parseInt(args[1]);
                c=Integer.parseInt(args[2]);
                d=b*b-4*a*c;
                if(d==0)
                {
                        r1=-b+Math.sqrt(d)/(2*a);
                        System.out.println("Roots are real and equal:\nRoot="+r1);
                }
                else if(d>0)
                {
                        r1=-b+Math.sqrt(d)/(2*a);
                        r2=-b-Math.sqrt(d)/(2*a);
                        System.out.println("Roots are real and unequal:\nRoot 1="+r1+"\nRoot 2="+r2);
                }
                else
                        System.out.println("Roots are imaginary.");
        }
}

Prime Numbers between 1 to 100 using Java

class Prime2{
        public static void main(String args[])
        {
                System.out.println("Prime numbers between 1 to 100 are:");
                int i=1,c=0,j;
                for(;i<=100;i++)
                {
                        for(j=2;j<=i/2;j++)
                                if(i%j==0)
                                        c++;
                        if(c==0)
                                System.out.print(i+" ");
                        c=0;
                }
        }
}

Checking Prime Number using Java

class Prime{
        public static void main(String args[])
        {
                int num=Integer.parseInt(args[0]),c=0;
                for(int i=2;i<=num/2;i++)
                        if(num%i==0)
                                c++;
                if(c==0)
                        System.out.println(num+" is a prime number.");
                else
                        System.out.println(num+" is not a prime number.");
        }
}