How to create XML file for employee management system and display it using CSS?

    Employees are working for many organizations. For maintaining the details,we need to collect the name,employee id,designation and salary details.

Here,  we use CSS(Cascading Style sheets) to display XML files. For doing this,we need to open any text editor like notepad.

Create two files  and name that as “employee.xml” and “employee.css”

Add the following code.

employee.xml

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/css" href="employee.css"?>

<payroll>

  <Heading> Welcome to the Employee management system </Heading>

     <employee>

          <name> adhav </name>

           <id> Emp01  </id>

           <Designation> Executive </Designation>

          <salary > 35000 </salary>

      </employee>

<employee>

          <name> chitra </name>

           <id> Emp02  </id>

           <Designation> Executive </Designation>

          <salary > 36,500 </salary>

      </employee>

<employee>

          <name> chandar </name>

           <id> Emp03 </id>

           <Designation> Senior Executive </Designation>

          <salary > 45000 </salary>

      </employee>

<employee>

          <name> Deepan </name>

           <id> Emp04  </id>

           <Designation> Executive </Designation>

          <salary > 36500 </salary>

      </employee>

<employee>

          <name> varun </name>

           <id> Emp05  </id>

           <Designation> Manager </Designation>

          <salary > 55000 </salary>

  </employee>

</payroll>


”employee.css”

employee{

                 background-color: yellow;

                  Width:100%;

               }

Heading {

                 color : black;

                 font-size : 35pt;

                 background-color : skyblue;

                }

Heading,name,id,Designation,salary {

                display : block;

                 }

name {

          color: brown;

          font-weight: BOLD;

          font-size: 25pt;

     }

 

Once you have saved this two files in same folder in same directory, just open the xml file in web browser.

You will get the output like this……

Welcome to the Employee management system

Adhav

Emp01

Executive

35000

Chitra

Emp02

Executive

36500

Chandar

Emp03

Senior Executive

45000

Deepan

Emp04

Executive

36500

Varun

Emp05

Manager

55000


Thus, the way to display xml file using css is easily  implemented.

  


C programs to practice -Find the factorial of given number by recursion

     Factorial is the continuous multiplication of the number from 1,2,…upto the number. Using recursion concept, this can be achieved easily.

Program :”factrec.c”

#include<stdio.h>

#include<conio.h>

int factorial(int n)

{

if (n<=1)

 return(1);

else

 return(n*factorial(n-1));

}

void main()

{

 int  n,fact=0;

printf(“ Enter the number”);

scanf(“%d”,&n);

fact= factorial(n);

printf(“The factorial of %d is : %d”,n,fact);

getch();

}

 

Output:

Enter the number 5

The factorial of 5 is 120

 

Now,let us try some interesting number series called Fibonacci series….

First,get the number of elements for the series as ‘n’. 

Using a loop, repeat the process until the number reaches to n.

Add the last two number and print the number.

Once the loop is finished, close the program.

Now, the program begins….

“Fibonacci.c”

#include <stdio.h>

int fibonacci(int x)

{

  if (x==0) { return(0); }

  else if(x==1) { return( 1);}

 return fibonacci(x-1)+fibonacci(x-2);

}

void main()

{

  int n,x;

  printf("Enter the number of elements");

  scanf("%d",&n);

  for(x=0;x<n;x++)

  {

   printf("%d \t \n" ,fibonacci(x);

  }

  getch();

}


the output is given below....

Enter the number of elements  7

0

1

1

2

3

5

8



C Programs to practice- Sum of the digits and count the number of digits in a number

 To find the sum of the digits of a given number, follow the steps given below.

Get the input as integer.

Check whether the number is greater than zero, repeat the below steps.

Use modulation operator, separate the digit and store it to a variable

Add the variable value to sum.

Divide the number by 10

Finally, print the sum value.

 The program begins....

Program: sum.c

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,sum=0,n;

 printf("Enter the number");

 scanf("%d",&a);

 while(a>0)

 {

  n=a%10;

  sum=sum+n;

  a=a/10;

 }

 printf("The sum of the digit is:%d",sum);

 getch();

 }

 

 Output :

 Enter the number 456

The sum of the digit is: 15

Try this:

How to count the number of digits in the given number.

Tip: Use the same logic(sum of the digit) with simple change.

Think about it.

 

Program: “Count.c”

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,count=0,n;

 printf("Enter the number");

 scanf("%d",&a);

 while(a>0)

 {

  n=a%10;

  count++;

  a=a/10;

 }

 printf("The number of the digit is:%d",count);

 getch();

 }

The output is shown below....

Enter the number 234

The number of the digit is: 3


C programs to practice - To check the given number is odd or even by using conditional operator

 First, let us know the logic behind this problem. To check the given number is odd or even,just  use %(modulation) operator. It will give you the reminder.

 If the reminder is zero,it is even number. Otherwise, the given number is odd number.

Now, the coding snippet begins....

Program “oddoreven.c”

#include<stdio.h>

#include<conio.h>

void main()

{

int a;

printf(“Enter the number”);

scanf(“%d”,&a);

(a%2==0)? printf(“Given number is even”): printf(“Given number is odd”);

getch();

}

 

Output:

 Enter the number 5

Given number is odd


Now, try this....

 Write a c program to find which number is greater among the given two numbers using conditional operator.

Program: “great2.c”

#include <stdio.h>

#include<conio.h>

void main()

{

 int c,d;

 printf("enter the two numbers");

 scanf("%d %d",&c,&d);

 (c>d)? printf("c is greater than d"): printf("d is greater than c");

 getch();

 }

C Programs to practice- Find the sum of the digits of a given number

 

To find the sum of the digits of a given number, follow the steps given below.

  • Get the input as integer.
  • Check whether the number is greater than zero, repeat the below steps.
  • Use modulation operator, separate the digit and store it to a variable
  • Add the variable value to sum.
  • Divide the number by 10
  • Finally, print the sum value.

The program is given below....

Program: sum.c

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,sum=0,n;

 printf("Enter the number");

 scanf("%d",&a);

 while(a>0)

 {

  n=a%10;

  sum=sum+n;

  a=a/10;

 }

 printf("The sum of the digit is:%d",sum);

 getch();

 }

 

 Output : 

Enter the number 567

The sum of the digit is: 18


Try this:

How to count the number of digits in the given number.

Tip: Use the same logic(sum of the digit) with simple change.

Think about it.

 

Program: “Count.c”

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,count=0,n;

 printf("Enter the number");

 scanf("%d",&a);

 while(a>0)

 {

  n=a%10;

  count++;

  a=a/10;

 }

 printf("The number of the digit is:%d",count);

 getch();

 }

C Programs to practice - Biggest of three numbers


  This program is used to find the biggest number among three number. The program reads 3 numbers and check each number and find the biggest number.

Program: “Big3.c”

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,b,c;

 printf("Enter the three numbers");

 scanf("%d %d %d",&a,&b,&c);

 if(a>b && a>c)

  printf("%d is the biggest number",a);

  else if(b>c)

   printf(" %d is the biggest number",b);

   else

   printf("%d is the biggest number",c);

   getch();

}

Output:

Enter the three numbers 2 3 5

5 is the biggest number


Try:

Write a c program to exchange two numbers.

How to do it???

Still thinking…

Here is the program

#include<stdio.h>

#include<conio.h>

void main()

{

 int x,y;

 printf("enter the numbers");

 scanf("%d %d",&x,&y);

 x=x+y;

 y=x-y;

 x=x-y;

 printf("The two numbers after exchange");

 printf("%d %d",x,y);

 getch();

 }

C Programs to practice -Fahrenheit to Celsius and Celsius to Fahrenheit conversions

 Fahrenheit to Celsius conversion:

This is a simple temperature conversion program. In this program ,the given temperature is in Fahrenheit. This program converts it to Celsius by using a simple formula.

Program: “Fahrentocelsius.c”

#include<stdio.h>

#include<conio.h>

void main()

{

/* variable declaration statement. Fa- Fahrenheit, ce- Celsius */

 float fa, ce;                     

printf(“ Enter the temperature value in Fahrenheit”);

/* read the Fahrenheit value */

scanf(“%f”,&fa);     

/ * formula for converting Fahrenheit to Celsius value */

ce=(fa-32)*5/9;

/* The converted celsius  value*/

printf(“The temperature value in celsius is: %f”,ce);

getch();

}


Try it :

In the same way, you can try the Celsius to Fahrenheit conversion in  your own.

Steps for converting Celsius to Fahrenheit:

Declare two variable Celsius,Fahrenheit as float.

Get the input for Celsius temperature value.

Use the formula to convert Celsius to Fahrenheit.

Print the Fahrenheit value.

#include<stdio.h>

#include<conio.h>

void main()

{

 float fahren,Celsius;

printf(“ enter the Celsius valus”);

scanf(“%f,&Celsius);

fahren=(Celsius*1.8)+32;

printf(“The converted  value  is:%f”,fahren);

getch();

} 

How to install turbo c++ in your pc/Laptop?

C is a structured programming language. It was developed by Dennis Ritchie in AT&T bell laboratories. It is the base language of all programming language. Bcpl and B languages are the previous languages.

Features:

C has lot of features.

·       C is a middle level language. It supports system level functions and high level programming.

·       It is portable. The user can run in any machine. It is machine independent language.

·       It is a Structured programming language. It supports functions.

·       The compilation and execution speed is fast because it has many inbuilt functions.

·       It is extensible language.

 How to Install turbo C++?

     C programming starts from installing turbo c++ compiler in your system. It has the following steps:

  •  First, Download the turbo c++ software from website. It downloads a zip file “tc3.zip”
  •  Create a folder “turboc” in c: \ and Extract the “tc3.zip” to this folder.
  •  Check the folder c:\turboc and click install.exe file
  •  Install it and start using the turbo c++.

 Thats all. Your Laptop/Pc is loaded with turbo c++.


How to create files, compile and run  in turbo c++ environment?

  •     In the file menu,select new file option.
  •     A New file will be opened. Save it with proper name with .c extension.
  •     Now, start writing your c code to this file.
  •     Once you finished the coding, press alt+f9 key to compile the program.
  •     It shows the error report. If there are any errors, check the code and correct it. Compile it again until there are no errors.
  •     To run the program, press ctrl+f9 key. It shows the output window. There, enter the input values. If your program is correct, it shows the correct output.

This is the first step for C Programming.Let's start the journey of C programming.


How to create DTD for book details in a bookstore?

DTD(Document Type Declaration) is mainly used to describe xml.  The purpose of DTD is  to check vocabulary of the xml. It also checks the validity of the structure of XML documents.

It has the syntax given below.

Syntax:

<!DOCTYPE element DTD identifier

[

  Declaration 1

  Declaration 2

  ………………

  Declaration n

 ]>

 

It has two types listed as follows.

·       -> Internal DTD

·       ->External DTD

First, how the internal DTD is created and used in XML is shown below…

Internal DTD:

This type of DTD is defined inside the XML file. We can use the above syntax here. In the XML declaration, set the standalone attribute to “yes”.

The sample XML code for book store is given below.

 

<?xml version=”1.0” encoding=”UTF-8” standalone=”yes”?>

<! DOCTYPE book [

<!ELEMENT book(name,author,publisher)>

<!ELEMENT  name(#PCDATA)>

<!ELEMENT author(#PCDATA)>

<!ELEMNET publisher(#PCDATA)>

]>

 

 <book>

<name> learn programming </name>

<author> rajeeva </author>

<publisher>xyz publications </publisher>

</book>

This is a simple way to write internal DTD for a book in a book store.

Note:

 All the tags are case sensitive. opening and closing the tags should be in proper manner.


External DTD:

External DTD’s are referred from an external file. The  sample code is given below.

Here, we have to follow two things. One is set the standalone attribute in xml declaration to “no”. second is include the external DTD file.

<?xml version=”1.0” encoding=”UTF-8” standalone=”no”?>

<!DOCTYPE book SYSTEM “book.dtd”>

<book>

    <name> Learn programming </name>

    <author> Rajeeva </author>

    <publisher> abc publicaions </publisher>

</book>

 

The external DTD file “book.dtd” is as follows.

<!ELEMENT book(name,author,publisher>

<!ELEMENT name(#PCDATA)>

<!ELEMENT author(#PCDATA)>

<!ELEMENT  publisher(#PCDATA)>

 

Note:

Instead of using SYSTEM identifier ,we can use PUBLIC identifier  with the external URL .in the <!DOCTYPE …>

Eg: <!DOCTYPE book PUBLIC “URL”>

These are the different ways to create DTD’s in XML. In this xml, the DTD's are used to create a book details in a book store.

How to write your first XML program?

XML is Extensible Markup Language. It is used to create user defined tags. This is derived from SGML(Standard Generalized Markup Language).

Do you like to create your own tags?? If the answer is yes, you try XML.

A simple XML code is given below.

It is a simple birthday message for your beloved one.

<Birthday>

  <Wishes>  Happy birthday  </Wishes>

</Birthday>

  Here, the root tag is <Birthday>. <Wishes>  is the user defined tag. This basic xml program shows you to create a root tag with elements.

To create a basic program, follow the below syntax.

Syntax:

<?xml version=”1.0”?>

<root tag>

  <element1>   </element1>

                    .

                    .

  <elementn>   <elementn>

</root tag>

 Let us write your first XML program for a school student details.

Here, student is the root tag, name of the student,class, school,place are the details. Let us consider these four as our elements. 

<?xml version=”1.0”?>

<student>

<name> Ajay </name>

<class> VIII standard </name>

<School> SS public school </School>

<place>  Chennai </place>

</student>

Note:

·       Tags are case sensitive. so, use the tags in proper case. For example, opening a  <student> tag ,you shouldn’t use ending as like </Student>,</STUDENT>.

·       In the opening statement, <?xml version=”1.0”?>. xml keyword should be in lowercase.