/*create own personal library in c++, using gcc compiler in linux platform.
atfirst create a source file and a header file. then create a main file to
include header file. here tem.cpp is source file and tem.h is header
file. main.cpp is main file.here tempalte is used instead of function definition. */
//template is a general case for functions for diff. datatypes as "int,float,double".
//note : - use '>' & '<' as ']' & '[' respectively.
//"tem.h"
template[class T]
T sum[T a,T b]
{
return a+b;
}
//"tem.cpp"
#include[iostream]
#include"tem.h"
//compile source file tem.cpp as "gcc -c tem.cpp"
//object file tem.o is created.
//"main.cpp"
#include[iostream]
#include"tem.h"
using namespace std;
int main()
{
cout[["sum is "[[sum(3,5)[[endl;
cout[["sum is "[[sum(3.0,5.0)[[endl;
return 0;
}
//compile it as "g++ -Wall main.cpp tem.o
//run as "./a.out" result will be
//"sum is 8"
//"sum is 8.0"
Hi, this is the blog for programs in different programming languages designd by me. the all programs are original and not copied from any where.
Saturday, May 29, 2010
c++ - create personal library(linux platform)
/*create own personal library in c++, using gcc compiler in linux platform.
atfirst create a source file and a header file. then create a main file to
include header file. here function.cpp is source file and function.h is header
file. main.cpp is main file. */
//note : - use '>' & '<' as ']' & '[' respectively.
//"function.h"
int sum(int a,int b);
//"function.cpp"
#include"function.h"
int sum(int a,int b)
{
return a+b;
}
//then compile source file function.cpp as gcc -c function.cpp
//it creates object file function.o
//"main.cpp"
#include[iostream]
#include"function.h"
using namespace std;
int main()
{
cout[["sum is "[[sum(3,5)[[endl;
return 0;
}
//compile it as "g++ -Wall main.cpp function.o"
//and then run as "./a.out" the result "sum is 8".
//
atfirst create a source file and a header file. then create a main file to
include header file. here function.cpp is source file and function.h is header
file. main.cpp is main file. */
//note : - use '>' & '<' as ']' & '[' respectively.
//"function.h"
int sum(int a,int b);
//"function.cpp"
#include"function.h"
int sum(int a,int b)
{
return a+b;
}
//then compile source file function.cpp as gcc -c function.cpp
//it creates object file function.o
//"main.cpp"
#include[iostream]
#include"function.h"
using namespace std;
int main()
{
cout[["sum is "[[sum(3,5)[[endl;
return 0;
}
//compile it as "g++ -Wall main.cpp function.o"
//and then run as "./a.out" the result "sum is 8".
//
Friday, May 28, 2010
my stuff - my fotos of vaishno devi & beyond.
.......................................................................
.......................................................................
.......................................................................
.......................................................................
check out me in these photos
java - simple calculator for add,sub in applet
/*first program in java, strating with basic applet program "calculator.java" compile it in DOS prompt as"c:\java\jdk1.5\bin\javac calculator.java" */
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class calculator extends Applet implements ActionListener
{
Label l1,l2,l3,l4;
TextField t1,t2;
Button b1,b2,b3,b4;
public void init()
{
b1=new Button("add");
b2=new Button("sub");
b3=new Button("mul");
b4=new Button("div");
l1=new Label("number1");
l2=new Label("number2");
l3=new Label("result");
l4=new Label(" ");
t1=new TextField(22);
t2=new TextField(22);
add(l1);add(t1);add(l2);add(t2);add(l3);add(l4);add(b1);add(b2);
add(b3);add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}//init() closed
public void actionPerformed(ActionEvent ae)
{
String s1=t1.getText();
String s2=t2.getText();
int i=Integer.parseInt(s1);
int j=Integer.parseInt(s2);
String str=ae.getActionCommand();
if(str.equals("add"))
l4.setText(String.valueOf(i+j));
else if(str.equals("sub"))
l4.setText(String.valueOf(i-j));
else if(str.equals("mul"))
l4.setText(String.valueOf(i*j));
else if(str.equals("div"))
l4.setText(String.valueOf(i/j));
repaint();
}//actionPerformed() closed
public void paint(Graphics g)
{g.drawString("creator-amrendra",5,240);}
}
//create a html file in which "calculator.class" is tagged named as "cal.html".
/*(html) (head)
(applet code="calculator.class" height=250 width=300)
(/applet) (/head)(/html) */
//note :- use '>' & '<' instead of ')' & '(' respectively.
//run applet as "appletviewer cal.html"
Subscribe to:
Posts (Atom)