Wednesday, March 14, 2018

Materialise CSS : A practical approach

Hi friends,

Here is an article published by my friend Madhav , about the famous CSS framework Materialise .
He has explained it in a very simple and nice way.

I hope it helps you all

Thanks
Happy Coding!
 Write to me at:
1. TopCoder
2. HackerEarth
3. Hacker Rank
4 Youtube
5. Blogger
6. GitHub
7. Stackoverflow
8. Facebook
9. linkedin
10. Medium 
11. Quora

Friday, March 9, 2018

Interactive C program : To create and update records

Here is an interactive C program written by me to create and update records in a txt file

/* program to create a text file   and update records  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <dirent.h>
int main(void)
{

    FILE *fp;   /* file pointer*/
    char fName[30];
    char name[30];
    int age=0, SrNo=0,SrNo2=0,count_lines=0;
    char  qualification[20];
    char action,en,ch,c;

    A: printf("Type 'N' to create a new file and enter records\n");
    printf("Type 'U' to read/update/modify records in an existing file\n");
    scanf("%s",&action);
    if(action=='N')
    { //start of option if
        printf("Enter file name with .txt extension to create :");
        scanf("%s",fName);

        /*creating (open) a file, in “w”: write mode*/
        fp=fopen(fName,"w");
        /*check file created or not*/
        if(fp==NULL)
        {
        printf("File does not created!!!");
        exit(0); /*exit from program*/
        }

        //printf("\nFile created successfully.\n");
        printf("Start entering students records\n");
    // printf("Finally type e to exit or any other character to continue adding more records\n");
        while(en !='e')
        {

            printf("\nEnter (space separated) student's name, age and qualification \n");

            scanf("%s", name);
            SrNo++;
            fprintf(fp, "Roll No.%d  Name  :%s\t",SrNo, name);

            //printf("Enter student's age\n");

            scanf("%d", &age);

            fprintf(fp, "Age  :%d\t", age);

            // printf("Enter students qualification\n");

            scanf("%s", &qualification);

            fprintf(fp, "Qualification  :%s\n", qualification);

            printf("Type e to exit or any other char to add more records  ");
            //en = getchar();
            scanf("%s",&en);
            if(en== 'e')
            {   printf("\nFile created and records saved successfully.\n");
            break;
            }
        }
        fclose(fp);
    }  //end of option if
     else if(action=='U')
  {   //start of option if
          DIR *p;
            struct dirent *pp;
            p = opendir(".");

            if (p != NULL)
            {
                while ((pp = readdir (p))!=NULL)
                {
                    int length = strlen(pp->d_name);
                    if (strncmp(pp->d_name + length - 4, ".txt", 4) == 0)
                     {
                        puts (pp->d_name);
                     }
                }

                (void) closedir (p);
            }

            printf("\n1] Enter filename to read, from the above list of files\n");
            printf("2] Enter filename to add new records, from the above list of files\n");
            printf("3] Enter filename to delete a record, from the above list of files\n");
            printf("4] Enter filename to replace a record, from the above list of files\n");
            printf("5] Exit\n");

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////

            while(1)
    {  //start of main while
                printf("\nEnter your choice : ");

                scanf("%d", &ch);

                switch (ch)
            {   //start of switch
                case 1:
                     printf("Enter the filename to be opened \n");

                     scanf("%s", fName);

                    /*  open the file for reading */

                    fp = fopen(fName, "r");

                    if (fp == NULL)

                    {

                        printf("Sorry this file does not exist !!, cannot open file \n");

                        exit(0);

                    } //end of if

                    c = fgetc(fp);

                    while (c != EOF)

                    { // start of 2nd while

                    printf ("%c", c);

                    c = fgetc(fp);

                    } //end of 2nd while

                    fclose(fp);
                    break;    // eo case 1

                case 2:
                    printf("Enter the filename to be opened and new record to be added\n");

                     scanf("%s", fName);

                    /*  open the file for reading */

                    fp = fopen(fName, "r");

                    if (fp == NULL)

                    {

                        printf("Cannot open file \n");

                        exit(0);

                    } //end of if
                    c=getc(fp);
                        while (c != EOF)

                    { //start of while

                            //Count whenever new line is encountered

                            if (c == '\n')

                            {

                                count_lines = count_lines + 1;

                            }

                            //take next character from file.

                            c = getc(fp);

                    } // end of while

                        fclose(fp); //close file.
                    SrNo2= count_lines;

                  fp=fopen(fName,"a");
                    /*check file created or not*/
                    if(fp==NULL)
                    {
                        printf("File not created!!!");
                        exit(0); /*exit from program*/
                    }

                    //printf("\nFile created successfully.\n");
                    printf("Start entering students records\n");
                    // printf("Finally type e to exit or any other character to continue adding more records\n");

                    while(en !='e')
                {

                    printf("\nEnter (space separated) student's name, age and qualification \n");

                    scanf("%s", name);
                    SrNo2++;
                    fprintf(fp, "Roll No.%d  Name  :%s\t",SrNo2, name);

                    //printf("Enter student's age\n");

                    scanf("%d", &age);

                    fprintf(fp, "Age  :%d\t", age);

                    // printf("Enter students qualification\n");

                    scanf("%s", &qualification);

                    fprintf(fp, "Qualification  :%s\n", qualification);

                    printf("Type e to exit or any other char to add more records  ");
                    //en = getchar();
                    scanf("%s",&en);
                    if(en== 'e')
                    {   printf("\nFile created and records updated successfully.\n");
                        //break;
                    }
            }
        fclose(fp);


                case 3:




                case 4:



                case 5:
                    exit(0);
                default:
                    printf("Wrong choice entered !! please try again\n");


            } // end of switch

    } //eo while
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
     } //eo option if
     else
     {
         printf("Incorrect option entered, please try again\n");
         goto A;

     }
       
   return 0;

}

C program : File Handling

Sunday, March 4, 2018

Great links for Software Developers

An Android App to check if a number is Prime : Advance Java programming



The Advance java program (source code) of the above Android App made by me is written below
----------------------------------------------------------------------------------------------------------------------

package com.example.primecheck.primecheck;
//Assigment week 2
//author: Ashutosh Kumar Singh, Mobile computing course NPTEL, July 2016. On 07-08-2016
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
import android.view.Menu;


public class FindPrime extends AppCompatActivity {

    private Button btrue, bfalse;
    private Button bnext;
    private TextView tvN;
    int k;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find_prime);

       bnext = (Button) findViewById(R.id.btnN);
        btrue = (Button) findViewById(R.id.btnT);
        bfalse = (Button) findViewById(R.id.btnF);
        tvN = (TextView) findViewById(R.id.tvN);
        tvN.setText("19");



        addListenerOnButton();
    }
    public void addListenerOnButton()
    {


        bnext.setOnClickListener
                (
                        new View.OnClickListener()
                        {
                            @Override
                            public void onClick(View v) {

                               k = myPrime();
                                String s = Integer.toString(k);
                                tvN.setText(s);


                            }

                        }
                );

        btrue.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        int i,  flag = 0;


                        for (i = 2; i <= k/ 2; i++)
                        {
                            if (k % i == 0)
                            {
                                Toast.makeText(getApplicationContext(), "Incorrect", Toast.LENGTH_SHORT).show();
                                flag = 1;
                                break;
                            }
                        }
                        if (flag == 0) {
                            Toast.makeText(getApplicationContext(), "Correct", Toast.LENGTH_SHORT).show();
                        }


                    }

                });

        bfalse.setOnClickListener
                (
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                int i, flag = 0;

                                for (i = 2; i <= k / 2; i++) {
                                    if (k % i == 0) {
                                        Toast.makeText(getApplicationContext(), "Correct", Toast.LENGTH_SHORT).show();
                                        flag = 1;
                                        break;
                                    }
                                }
                                if (flag == 0)
                                {
                                    Toast.makeText(getApplicationContext(), "Incorrect", Toast.LENGTH_SHORT).show();
                                }


                            }
                        }


                );
    }

    int myPrime()
     {
        Random r = new Random();

         int j = r.nextInt(100);
         String s=Integer.toString(j);
        return j;
    }
}


Thanks
Happy apping !

An Android Application : MainActivity (Advance Java programming)



The Advance java program (source code) of the above Android App made by me is written below
 ----------------------------------------------------------------------------------------------------------------------
package com.intellisoftwaresolutions.nifty;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Toast;



public class MainActivity extends AppCompatActivity {

    private Button pbtn1,pbtn2,pbtn3,reset2;
    private TextView tvp,tvap,tvop;
    private EditText etbp,etsp,etobp,etosp,eta;
    float s1, b1,p1,s2,b2,p2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pbtn1=(Button)findViewById(R.id.pbtn1);
        pbtn2=(Button)findViewById(R.id.pbtn2);
        tvp=(TextView)findViewById(R.id.tvp);
        tvop=(TextView)findViewById(R.id.tvop);
        etbp=(EditText)findViewById(R.id.etbp);
        etsp=(EditText)findViewById(R.id.etsp);
        etobp=(EditText)findViewById(R.id.etobp);
        etosp=(EditText)findViewById(R.id.etosp);
        pbtn3=(Button)findViewById(R.id.pbtn3);
        eta=(EditText)findViewById(R.id.eta);
        tvap=(TextView)findViewById(R.id.tvap);
        reset2=(Button)findViewById(R.id.reset2);

        addListenerOnButton();

    }

    public void addListenerOnButton()
    {
        pbtn1.setOnClickListener
                (
                        new View.OnClickListener()
                        {













                            @Override
                            public void onClick(View v) {int i;
                                String value1=etbp.getText().toString();
                                String value2=etsp.getText().toString();
                                b1=Float.parseFloat(value1);
                                s1=Float.parseFloat(value2);
                                if((s1<=0.00)||(b1<=0.00)) {
                                    Toast.makeText(getApplicationContext(), "Non-Zero only", Toast.LENGTH_SHORT).show();
                                }

                                if((s1!=0.00)&&(b1!=0.00)) {
                                    p1 = (((s1 - b1) / b1) * 100) - 0.67f;
                                    i=Math.round(p1);
                                    String np = Integer.toString(i);
                                    tvp.setText(np);
                                }


                            }
                        }

                );
        pbtn3.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        float a,ap;
                        int i,ip,ia;
                        String value=eta.getText().toString();
                        a=Float.parseFloat(value);
                        if(a<=0.00) {
                            Toast.makeText(getApplicationContext(), "Non-Zero values only", Toast.LENGTH_SHORT).show();
                        }

                        if(a!=0.00)
                        {
                            ap = (((s1 - b1) / b1) * 100) - 0.67f;
                            i=Math.round(ap);
                            ia=Math.round(a);
                            ip=(i*ia)/100;
                            String np = Integer.toString(ip);
                            tvap.setText(np);
                        }


                    }
                }
        );
        pbtn2.setOnClickListener
                (
                        new View.OnClickListener()
                        {
                            @Override
                            public void onClick(View v) {
                                String value1=etobp.getText().toString();
                                String value2=etosp.getText().toString();
                                b2=Float.parseFloat(value1);
                                s2=Float.parseFloat(value2);
                                if((s2<=0.00)||(b2<=0.00))
                                {
                                    Toast.makeText(getApplicationContext(),"Non-Zero values only",Toast.LENGTH_SHORT).show();
                                }
                                if((s2!=0.00)&&(b2!=0.00)) {
                                    p2 = (s2 - b2) * 75;
                                    String np = Float.toString(p2);
                                    tvop.setText(np);
                                }

                            }
                        }

                );
        reset2.setOnClickListener(
                new View.OnClickListener()
                {@Override
                 public void onClick(View v)
                    {   etbp.setText("         ");
                        etsp.setText("         ");
                        eta.setText("    ");
                        etobp.setText("     ");
                        etosp.setText("     ");
                        String value1=etobp.getText().toString();
                        String value2=etosp.getText().toString();
                        tvop.setText("    ");
                        tvap.setText("    ");
                        tvp.setText("    ");
                    }
                }
        );
    }
}

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

Thanks
Happy Apping !

Advance Java Programming : A Servlet program

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

//extend HttpServlet class
public class Servlet_1 extends HttpServlet
{
    private String message;
   
    public  void init() throws ServletException
    {
        // do initialization
        message="Ashutosh Singh";
    }
   
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
    {
        //set  response content type
        response.setContentType("text/html");
        // actual logic goes here
        PrintWriter out =response.getWriter();
        out.print("<html><body>");
        out.print("<h1>"+message+"</h1>");
        out.print("</body></html>");
    }
   
    public void destroy()
    {
        //do nothing
    }
}

Thanks
Happy programming !

Advance Java programming : A simple Java Bean Class

//This is simple bean class, containing only one property name with its getters and setters method.
//This class contains one extra method named displayInfo() that prints the student name by the hello message.

package com.ashutoshjava; 
 
public class Student { 
private String name; 
 
public String getName() { 
    return name; 

 
public void setName(String name) { 
    this.name = name; 

 
public void displayInfo(){ 
    System.out.println("Hello: "+name); 




Thanks,
Happy programming !

Advanced Java programming: A JDBC application


package jdbcapp1;

//import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Ashutosh K Singh
 */
public class JdbcApp1 {

        public static void main(String[] args)   //throws ClassNotFoundException
    {
        // TODO code application logic here
        try
        {   
        System.out.println("Ashutosh");
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection=DriverManager.getConnection("jdbc:mysql://localhost/mybooks","AKSingh", "ashutosh");
        Statement statement=connection.createStatement();
        String q1="create table books(id int auto_increment, subject varchar(30), pages int, price varchar(30),primary key(id))";
        int a= statement.executeUpdate(q1);
        System.out.println("table is created sucessfuly ="+a);
        String q2="insert into books values(1,'C by Ashutosh',200,'Rs 230/-')";
        String q3="insert into books values(2,'C++ by Ashutosh',400,'Rs 530/-')";
        String q4="insert into books values(3,'Java by Ashutosh',350,'Rs 430/-')";
        String q5="insert into books values(4,'Android by Ashutosh',700,'Rs 2230/-')";
        statement.executeUpdate(q2);
        statement.executeUpdate(q3);
        statement.executeUpdate(q4);
        statement.executeUpdate(q5);
        System.out.println("values included sucessfuly");
        String q6="select * from books";
        ResultSet set=statement.executeQuery(q6);
        while(set.next())
        {
            System.out.println(set.getInt(1)+" "+set.getString(2)+" "+set.getInt(3)+" "+set.getString(4));
        }
        connection.close();
        }
   
        catch(ClassNotFoundException | SQLException e)
        {
            System.out.println(e);  
        }
    }
   
}


Thanks,
Happy programming !

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...