New Android apps UniqueKey

Friday, 15 May 2015

Prime numbers between 2 numbers


#include<stdio.h>
#include<math.h>

main()
{
 int n1,n2,i,j,flag;
 
 printf("Enter 2 numbers\n");
 scanf("%d %d",&n1,&n2);
 
 for(i=n1+1 ; i<n2 ; i++)
 {
  flag = 0;
  
  for(j=2 ; j<=sqrt(i) ; j++)
  {
   if(i%j==0){
    flag=1;
    break;
   }
  }
  if(flag==0)
  printf("%d\t",i);
 }
}

Tuesday, 12 May 2015

Class Program in C++

This is a C++ program to illustrate the class and its use in C++ programming language. Class is a main feature in object oriented programming language like C++.

#include<iostream>
#include<string.h>
using namespace std;

class employee
{
  char name[50];
  int number;
  float basic_pay,allowance,it,gross,net;
  public:
    void read(char e_name[],int e_number,float e_basic_pay);
    void calculate(void);
    void display(void);
};

void employee::read(char e_name[],int e_number,float e_basic_pay)
{
  strcpy(name,e_name);
  number=e_number;
  basic_pay=e_basic_pay;
  
}

void employee::calculate(void)
{
  allowance=(123*basic_pay)/100;
  gross=basic_pay+allowance;
  it=(30*gross)/100;
  net=basic_pay+allowance-it;
}

void employee::display(void)
{
  cout<<"Name: "<<name<<endl;
  cout<<"Number: "<<number<<endl;
  cout<<"Basic pay: "<<basic_pay<<endl;
  cout<<"Allowance: "<<allowance<<endl;
  cout<<"Income tax: "<<it<<endl;
  cout<<"Net Salary: "<<net<<endl;
}

main()
{
  employee e1;
  char e_name[50];
  int e_number;
  float e_basic_pay;
  cout<<"Name: ";
  cin>>e_name;
  cout<<"Employee number: ";
  cin>>e_number;
  cout<<"Basic Pay: ";
  cin>>e_basic_pay;
  e1.read(e_name,e_number,e_basic_pay);
  e1.calculate();
  e1.display();
}

Double Linked List Program

This is a program to show how double linked list works.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
 
struct node
{
     struct node *previous;
     int data;
     struct node *next;
}*head, *last; 

void insert_begning(int value);
int delete_from_end();
void display();

int main()
{
    int value, i, loc;
    head=NULL;
    printf("Select the choice of operation on link list");
    printf("\n1.) insert at begning\n2.)delete from end \n3.) display\n4.exit\n");

    while(1)
    {
          printf("\n\nenter the choice\n");
          scanf("%d",&i);
          switch(i)
          {
            case 1:
                {
                 printf("enter the value you want to insert in node ");
                 scanf("%d",&value);
                 insert_begning(value);
                 display();
                 break;
                }
            case 2:
                   delete_from_end();
                   display();
                   break;
            case 3 :
                   display();
                   break;
            case 4 :
                 {
                      exit(0);
                      break;
                 }
          }
    }
    printf("\n\n%d",last->data);
    display();
    getch();
}

void insert_begning(int value)
{
    struct node *var,*temp;
     var=(struct node *)malloc(sizeof(struct node));
     var->data=value;
     if(head==NULL)
     {
         head=var;
         head->previous=NULL;
         head->next=NULL;
         last=head;
     }
     else
     {
         temp=var;
         temp->previous=NULL;
         temp->next=head;
         head->previous=temp;
         head=temp;
     }
} 

int delete_from_end()
{
      struct node *temp;
      temp=last;
      if(temp->previous==NULL)
      {
           free(temp);
           head=NULL;
           last=NULL;
           return 0;
      }
      printf("\nData deleted from list is %d \n",last->data);
      last=temp->previous;
      last->next=NULL;
      free(temp);
      return 0;
} 

void display()
{
     struct node *temp;
     temp=head;
     if(temp==NULL)
      {
         printf("List is Empty");
      }
     while(temp!=NULL)
     {
          printf("-> %d ",temp->data);
          temp=temp->next;
     }
} 

Android Tutorial : Simple Program

Introducing a simple basic android app. by this program you will understand a basic structure of android app development. 
xml file(activity_main.xml) for layout design is given, and then you have to connect this xml layout file with java file for functionality of this xml layout. 
manifest file is very important in android development, all the activities should be defined in manifest file otherwise app with not run. 

activity_main.xml  File:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="176dp"
        android:text="Click button" />

</RelativeLayout>




MainActivity.java  File:

package com.example.sample;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

 Button b;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  b = (Button)findViewById(R.id.button1);
  b.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
   Toast.makeText(getApplicationContext(), "Button is pressed", Toast.LENGTH_LONG).show();
   }
  });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}

Manifest  File:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

VB Script : Input Box

Write this program in notepad and save it as _filename.vbs 
name=inputbox("Whats your name?")

msgbox("Have a good day, ") + name