Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications


The programming languages that have compilers operating under Linux OS (we shall be concerned here with openSuse and/or simplyMEPIS VERSION 6.5 or 7.0) and will be coverd here in this section are: C , fortran77, gfortran, pascal (free pascal), SmallEiffel, ADA, Haskell, Ocaml and Java.



Language; Command line compiling command or statement; Example; Compiler type & version
C++ (GNU, gcc); g++; g++ hellocpp.cpp -o hello1;  gcc v. 4.0.3
fortran77 (GNU, gcc);  g77; g77 -o hellog77 hello.for; gcc v. 3.4.6
gfortran (GNU, GCC); gfortran; gfortran -o hellogfor hello.for  gcc v. 4.0.3
pascal (free pascal); fpc; fpc hello.pas;  v. 2.2.0
SmallEiffel (GNU); compile; compile hello.e -o hellose; gnu eiffel compiler release 0.74
HASKELL (GHC); ghc ; ghc -- make -o hellohaskell hello.hs; v. 6.4.1
ADA (GNU, gcc); gcc then gnatbl; gcc -c helloada.adb then gnatbl -o hello2 helloada.ali  gcc v. 4.0.3
OCaml   ocamlopt; ocamlopt -c amodule.ml, ocamlopt -c bmodule.ml, ocamlopt -o hellooc amodule.cmx bmodule.cmx    version 3.10.2
Java; javac; javac helloj.java, to run type java + the class name (eg. HelloClassApp; JDK, version "1.5.0_13"

Let's get graphical:For example, GTK+ is a highly usable, toolkit for creating graphical user interfaces (GUI) which boasts cross platform compatibility and an easy to use API. GTK+ it is written in C, but has bindings to many other popular programming languages such as C++, Perl, Python and C# among others. GTKMM is the wrapper for C++ language (a library used to create graphical user interfaces).gtkmm speaks arabic.GTKMM programs can be compiled and run under Windows operating system. To do so, you may follow the steps given hereafter:
 
Download and install MingW.
Download and install Dev-Cpp.
Download and unzip GTK library under c:MingW.
Download and install gtkmm library under c:Dev-Cpp.
Download and install msys.
Copy the source code into /home/user_name/ directory of C:msys.
Compile source code, example for command line compiling statements in msys window:
export PKG_CONFIG_PATH=c:/Dev-Cpp/gtkmm/pkgconfig
g++ 'pkg-config --cflags gtkmm-2.4' example.cc -o example 'pkg-config --libs gtkmm-2.4'
Run executable (.exe) Windows file

Library; Command line compiling command or statement; Example; Compiler type & version
gtkmm; g++; g++ gtkmareas.cc -o gtkmareas `pkg-config gtkmm-2.4 --cflags --libs`; g++ (GCC) 4.2.1

There are certain libraries that are written for example in C (or C++) that can be added to the microcomputer hard drve. With these libraries and the appropriate compiler, eg. C compiler, linking to such libraries and compiling your source, you can produce an output file (2D or 3D graphics one). Examples for such libraries are Cairo and OpenSceneGraphics (OSG).

Library; Command line compiling command or statement; Example; Compiler type & version
cairo; cc; cc -o hellocairo $(pkg-config --cflags --libs cairo) hellocairo.c; cc (GCC) 4.2.1
OpenSceneGraph (OSG); g++; g++ -c HelloMain.cpp, g++ -c HelloSG.cpp; g++ (GCC) 4.2.1
                                           g++ -o hello HelloSG.o HelloMain.o -I/usr/include -losg -losgDB -losgUtil -losgViewer -losgText
Free GL utility toolkit (GLUT); gcc;  gcc -o helloglut helloglut.c -lm -lGL -lGLU -lglut ;  gcc (GCC) 4.2.1

General:


  1. Make a new directory under /home/user-name (eg. hany)/Documents and call it executables.


  2. Add to this directory each executable (compiled) file.


  3. Go to the desktop, click Documents (Konquerer will open with a list of files & folders plus the menu and probably a tree-like files & folders on your PC), click View on the main menu and then choose Show hidden files. The hidden files that start with a dot (.) will appear.


  4. Go to /home/user-name (eg.han)y/ directory and click on .bashrc file. It will open in a text editor, probably kwrite. Add the following line to the end of the file export PATH=/home/user-name (eg.hany)/Documents/executables:$PATH.
    Then save the file and cose (exit) the editor.


  5. Go to konquerer, click View in the menu list, then choose and click one more time Show hidden files, the hidden ones will
    disappear.



Saying hello in different languages: C++:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: #include <stdio.h> int main () { printf ("Hello world from gcc/g++n"); }


  3. Save the file as hellocpp.cpp


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hello1


  6. Open the konsole window and run hello1 (i.e. type hello1 at the prompt).



Fortran 77:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program hello c This program prints hello, leave at least 7 spaces before typing program hello above write (*, *) 'hello from g77, fortran77' stop end


  3. Save the file as hello.for


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hellog77


  6. Open the konsole window and run hellog77 (i.e. type hellog77 at the prompt).



gFortran:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program hello c This program prints hello, leave at least 7 spaces before typing program hello above write (*, *) 'hello from g77, fortran77' stop end


  3. Save the file as hello.for


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hellogfor


  6. Open the konsole window and run hellogfor (i.e. type hellogfor at the prompt).



Pascal:


  1. Open a new document in any text editor (kwrite, kedit or kate) or open a trminal (konsole) window and type fp to open the FreePascal IDE for Linux.


  2. Type the following lines: program hello; begin writeln('hello from pascal'); end.


  3. Save the file as hello.pas


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hello


  6. Open the konsole window and run hello (i.e. type hello at the prompt).



SmallEiffel:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: class SIMPLE creation make feature make is do io.put_string("Hello
    from SmallEiffel.%N"); io.put_new_line end; end


  3. Save the file as hello.e


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hellose


  6. Open the konsole window and run hellose (i.e. type hellose at the prompt).



Haskell:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: main = do putStrLn "hello, world, from haskell ghc!"


  3. Save the file as hello.hs


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hellohaskell


  6. Open the konsole window and run hellohaskell (i.e. type hellohaskell at the prompt).



ADA:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: -- Print a simple message. with Ada.Text_IO; procedure Helloada is begin
    Ada.Text_IO.Put_Line("Hello, world from ada!"); end Helloada;


  3. Save the file as helloada.adb


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hello2


  6. Open the konsole window and run hello2 (i.e. type hello2 at the prompt).



OCaml:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following line: let hello () = print_endline "Hello from OCaml" Save this file as amodule.ml


  3. Open a new document in any text editor (kwrite, kedit or kate) and type the following line:
    Amodule.hello () Save this file as bmodule.ml


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. hellooc


  6. Open the konsole window and run hellooc (i.e. type hellooc at the prompt).



Java:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: /** *
    The HelloWorldApp class implements an application that * simply prints "Hello World!" to standard output. */ class
    HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World from Java!"); // Display the string. } }


  3. Save the file as hellojava.java


  4. Compile it per the above table


  5. Run the file, while you are in the directory where hellojava.java and HelloWorldApp.class are residing, by typing java
    HelloWorldApp



gtkmm:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following line:


    #include <gtkmm/button.h>
    #include <gtkmm/window.h>
    #include <gtkmm/main.h>
    #include <iostream>
    class HelloWorld : public Gtk::Window
    {

    public:
    HelloWorld();
    virtual ~HelloWorld();

    protected:
    //Signal handlers:
    virtual void on_button_clicked();

    //Member widgets:
    Gtk::Button m_button;
    };


    int main (int argc, char *argv[])
    {
    Gtk::Main kit(argc, argv);

    HelloWorld helloworld;
    //Shows the window and returns when it is closed.
    Gtk::Main::run(helloworld);

    return 0;
    }


    HelloWorld::HelloWorld()
    : m_button("Hello World") // creates a new button with label "Hello World".
    {
    // Sets the border width of the window.
    set_border_width(10);

    // When the button receives the "clicked" signal, it will call the
    // on_button_clicked() method defined below.
    m_button.signal_clicked().connect(sigc::mem_fun(*this,
    &HelloWorld::on_button_clicked));

    // This packs the button into the Window (a container).
    add(m_button);

    // The final step is to display this newly created widget...
    m_button.show();
    }

    HelloWorld::~HelloWorld()
    {
    }

    void HelloWorld::on_button_clicked()
    {
    std::cout << "Hello World" << std::endl;
    }
  3. Compile it per the above table


  4. Copy the executable (compiled) file to the executables folder (directory), eg. hellogtk


  5. Open the konsole window and run hellogtk (i.e. type hellogtk at the prompt).

A simple mathematical program (accepting user input, makingsimple calculatins and outputing results to screen): C++:


  1. Open a new document in any text
    editor (kwrite, kedit or kate).


  2. Type the following lines:
    #include
    <istream> #include <ostream> #include <iostream>
    #include <math.h> using namespace std; int main() { float
    a,b,c; cout << ("enter a numbern") ; cin >>
    a; cout <<("enter another numbern") ; cin >>
    b; c = a*b; cout << "multiplication result = " <<
    c << endl; cout << "division result = " <<
    a/b << endl; cout << "a - b result = " <<
    a-b <<endl; cout << "a + b result = " <<
    a+b <<endl; cout << "square root a and b result = "
    << sqrt(a) <<"; " << sqrt(b) <<endl;
    }


  3. Save the file as test00cpp.cpp


  4. Compile it: g++ test00cpp.cpp -o simplemthc


  5. Copy the executable (compiled)
    file to the executables folder (directory), eg. simplemathc


  6. Open the konsole window and run simplemathc (i.e. type
    simplemathc at the prompt).



Fortran 77:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program simathg77 real a, b, add, sub, mul, divis c This program accepts 2
    numbers and calculates few values write (*,*) 'enter a number a:' read (*,*) a write (*,*) 'enter a number b:' read (*,*) b add = a+b sub = a-b mul = a*b divis = a/b write (*,*) 'a+b = ', add, ' a-b = ', sub, ' a times b = ', mul write (*,*) 'a by b = ', divis, '
    square root of a = ', sqrt(a) write (*,*) 'square root of b = ', sqrt(b) stop end


  3. Save the file as simathg77.for


  4. Compile it: g77 -o simath77 simathg77.for


  5. Copy the executable (compiled) file to the executables folder (directory), eg. simath77


  6. Open the konsole window and run simath77 (i.e. type simath77 at the prompt).



gFortran:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program simathg77 real a, b, add, sub, mul, divis c This program accepts 2 numbers and calculates few values write (*,*) 'enter a number a:' read (*,*) a write (*,*) 'enter a number b:' read (*,*) b add = a+b sub = a-b mul = a*b divis = a/b write (*,*) 'a+b = ', add, ' a-b = ', sub, ' a times b = ', mul write (*,*) 'a by b = ', divis, ' square root of a = ', sqrt(a) write (*,*) 'square root of b = ',
    sqrt(b) stop end


  3. Save the file as simathg77.for


  4. Compile it: gfortran -o simathgf simathg77.for


  5. Copy the executable (compiled) file to the executables folder (directory), eg. simathgf


  6. Open the konsole window and run simathgf (i.e. type simathgf at the prompt).



Pascal:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program test1 (input,output); var a,b,add,sub,mul,divis,sr1,sr2:real; begin writeln('a = '); readln(a); writeln('b = '); readln(b); add := a+b; sub := a-b; mul := a*b; divis := a/b; sr1 := sqrt(a); sr2 := sqrt (b); writeln('a + b =', add:4:2); writeln('a - b =', sub:4:2); writeln('a times b =', mul:4:4); writeln('a by b =', divis:4:4); writeln('suare root of a =', sr1:4:4); writeln('suare root of b =', sr2:4:4); end.


  3. Save the file as simathp.pas


  4. Compile it: fpc simathp.pas


  5. Copy the executable (compiled) file to the executables folder (directory), eg. simathp


  6. Open the konsole window and run simathp (i.e. type simathp at
    the prompt).



SmallEiffel:


  1. Open a new document in any text
    editor (kwrite, kedit or kate).


  2. Type the following lines: class
    SIMATHSE creation make feature a,b:real; make is do
    io.put_string("enter value of first variable: ");
    io.read_real; a:=io.last_real; io.put_string("enter second
    variable: "); io.read_real; b:=io.last_real; io.put_string("a
    + b = "); io.put_real(a+b); io.put_string("%N")
    io.put_string("a - b = "); io.put_real(a-b);
    io.put_string("%N") io.put_string("a times b = ");
    io.put_real(a*b); io.put_string("%N") io.put_string("a
    by b = "); io.put_real(a/b); io.put_string("%N") end;
    end


  3. Save the file as simathp.e


  4. Compile it: compile simathse.e -o simathse


  5. Copy the executable (compiled) file to the executables folder (directory), eg. simathse


  6. Open the konsole window and run simathse (i.e. type simathse at the prompt).



Haskell:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: main = do putStrLn "Please a number: " name <- getLine let x = read name :: Double putStrLn "Please enter another number: " name1 <- getLine let y = read name1 :: Double let z = x + y let a = x * y let b = x / y let c = x - y let d = sqrt x let e = sqrt y putStrLn ("first number = " ++ show x) putStrLn ("second number = " ++ show y) putStrLn ("addition of 2 numbers = " ++ show z) putStrLn ("multiplication of 2 numbers = " ++ show a) putStrLn ("first number by second number = " ++
    show b) putStrLn ("subtracting second number from first = " ++ show c) putStrLn ("square root of first number = " ++ show d) putStrLn ("suare root of second number = " ++ show e)


  3. Save the file as simathaskell.hs


  4. Compile it: ghc -- make -o simathhs simathaskell.hs


  5. Copy the executable (compiled) file to the executables folder (directory), eg. simathhs


  6. Open the konsole window and run simathhs (i.e. type simathhs at the prompt).



ADA:


  1. Open a new document in any text
    editor (kwrite, kedit or kate).


  2. Type the following lines: with
    Gnat.Io; use Gnat.Io; with Ada.Float_Text_IO; use Ada.Float_Text_IO;
    procedure simathada is a, b, c, d ,e, f: float := 0.0; begin
    Put("Enter a numbere, a: "); Get(a); Put("Enter
    another numbere, b: "); Get(b); c := a + b; Put("a + b =
    "); Put(c); New_Line; d := a - b; Put("a - b = ");
    Put(d); New_Line; e := a * b; Put("a times b = "); Put(e);
    New_Line; f := a / b; Put("a divided by b = "); Put(f);
    New_Line; end simathada;


  3. Save the file as simpmthada.adb


  4. Compile it: gcc -c simathada.adb; then: gnatbl -o simpmthada simathada.ali


  5. Copy the executable (compiled) file to the executables folder (directory), eg. simpmthada


  6. Open the konsole window and run simpmthada (i.e. type simpmthada at the prompt).



Java:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: import java.io.*; class SiMathJava { public static void main(String[] args) throws Exception{ String n, n1; Double m1, m, m2, m3, m4, m5, m6, m7; System.out.print("Enter a number: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = br.readLine(); m = Double.valueOf(n); System.out.print("Enter another number: "); BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); n1 = br.readLine(); m1 = Double.valueOf(n1); m2 = m + m1; System.out.print("first number + second one = "); String s = String.valueOf(m2); System.out.println(s); m3 = m - m1; System.out.print("first number - second one = "); String s1 = String.valueOf(m3); System.out.println(s1); m4 = m * m1; System.out.print("first number times second one = "); String s2 = String.valueOf(m4); System.out.println(s2); m5 = m / m1; System.out.print("first number by second one = "); String s3 = String.valueOf(m5); System.out.println(s3); m6 = Math.sqrt(m); System.out.print("square root of first number = "); String s4 = String.valueOf(m6); System.out.println(s4); m7 = Math.sqrt(m1); System.out.print("square root of second number = "); String s5 = String.valueOf(m7); System.out.println(s5); } }


  3. Save the file as simathjava.java


  4. Compile it per the above table


  5. Run the file, while you are in the directory where simathjava.java and SiMathJava.class are residing, by typing java SiMathJava



gtkmm:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following line:


    #include <gtkmm.h>
    #include <gtkmm/main.h>
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    char filename[20];
    gchar buf[32];
    double x, y;
    class ExampleWindow : public Gtk::Window
    {
    public:
    ExampleWindow();
    virtual ~ExampleWindow();

    protected:
    //Signal handlers:
    virtual void on_button_add();
    virtual void on_button_close();
    virtual void on_button_subtract();
    virtual void on_button_multiply();
    virtual void on_button_divide();
    //Child widgets:
    Gtk::Frame m_Frame_Accelerated;
    Gtk::HBox m_HBox_Accelerated, m_HBox_Buttons;
    Gtk::VBox m_VBox_Main, m_VBox, m_VBox_Accelerated, m_VBox_Value;
    Gtk::Label m_Label_Value1, m_Label_Value, m_Label_ShowValue;
    Gtk::Adjustment m_adjustment_value, m_adjustment_value1;
    Gtk::SpinButton m_SpinButton_Value, m_SpinButton_Value1;
    Gtk::Button m_Button_Add, m_Button_Close, m_Button_Subtract, m_Button_Multiply, m_Button_Divide;
    };

    int main(int argc, char *argv[])
    {
    Gtk::Main kit(argc, argv);

    ExampleWindow window;
    //Shows the window and returns when it is closed.
    Gtk::Main::run(window);

    return 0;
    }

    ExampleWindow::ExampleWindow()
    :
    m_Frame_Accelerated("Accelerated"),
    m_VBox_Main(false, 5),
    m_Label_Value("Value of x: "),
    m_Label_Value1("Value of y: "),
    m_adjustment_value(0.0, -10000.0, 10000.0, 0.1, 100.0, 0.0),
    m_adjustment_value1(0.0, -10000.0, 10000.0, 0.1, 100.0, 0.0),
    m_SpinButton_Value(m_adjustment_value, 1.0, 2),
    m_SpinButton_Value1(m_adjustment_value1, 1.0, 2),
    m_Button_Add("addition: x + y"),
    m_Button_Subtract("Subtraction: x - y"),
    m_Button_Multiply("Multiplication: x times y"),
    m_Button_Divide("Division: x / y"),
    m_Button_Close("Close")
    {
    set_title("Math");

    m_VBox_Main.set_border_width(10);
    add(m_VBox_Main);

    m_VBox.set_border_width(5);

    //Accelerated:
    m_VBox_Main.pack_start(m_Frame_Accelerated);

    m_VBox_Accelerated.set_border_width(5);
    m_Frame_Accelerated.add(m_VBox_Accelerated);

    m_VBox_Accelerated.pack_start(m_HBox_Accelerated, Gtk::PACK_EXPAND_WIDGET, 5);

    m_HBox_Accelerated.pack_start(m_VBox_Value, Gtk::PACK_EXPAND_WIDGET, 5);

    m_Label_Value.set_alignment(Gtk::ALIGN_LEFT);
    m_VBox_Value.pack_start(m_Label_Value);

    m_Label_Value1.set_alignment(Gtk::ALIGN_LEFT);
    m_VBox_Value.pack_start(m_Label_Value1);

    m_SpinButton_Value.set_wrap();
    m_SpinButton_Value.set_size_request(100, -1);
    m_VBox_Value.pack_start(m_SpinButton_Value);

    m_SpinButton_Value1.set_wrap();
    m_SpinButton_Value1.set_size_request(100, -1);
    m_VBox_Value.pack_start(m_SpinButton_Value1);


    //Buttons:
    m_VBox_Accelerated.pack_start (m_HBox_Buttons, Gtk::PACK_SHRINK, 5);

    m_VBox_Accelerated.pack_start(m_Label_ShowValue);
    m_Label_ShowValue.set_text("0");

    m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
    &ExampleWindow::on_button_close) );
    m_VBox_Main.pack_start(m_Button_Close, Gtk::PACK_SHRINK);

    m_Button_Add.signal_clicked().connect( sigc::mem_fun(*this,
    &ExampleWindow::on_button_add) );
    m_VBox_Main.pack_start(m_Button_Add, Gtk::PACK_SHRINK);

    m_Button_Subtract.signal_clicked().connect( sigc::mem_fun(*this,
    &ExampleWindow::on_button_subtract) );
    m_VBox_Main.pack_start(m_Button_Subtract, Gtk::PACK_SHRINK);

    m_Button_Multiply.signal_clicked().connect( sigc::mem_fun(*this,
    &ExampleWindow::on_button_multiply) );
    m_VBox_Main.pack_start(m_Button_Multiply, Gtk::PACK_SHRINK);

    m_Button_Divide.signal_clicked().connect( sigc::mem_fun(*this,
    &ExampleWindow::on_button_divide) );
    m_VBox_Main.pack_start(m_Button_Divide, Gtk::PACK_SHRINK);

    show_all_children();
    }

    ExampleWindow::~ExampleWindow()
    {std::cout << "bye." << std::endl;
    }


    void ExampleWindow::on_button_close()
    {
    hide();
    std::cout<<"file name: ";
    std::cin>>filename;
    std::ofstream fout(filename);
    fout<<"x, y, x + y: "<<x<<","<<y<<","<<x+y<<std::endl;
    fout<<"x, y, x - y: "<<x<<","<<y<<","<<x-y<<std::endl;
    fout<<"x, y, x times y: "<<x<<","<<y<<","<<x*y<<std::endl;
    fout<<"x, y, x / y: "<<x<<","<<y<<","<<x/y<<std::endl;
    fout.close();
    std::cout<<"x + y, result: "<<x<<","<<y<<","<<x+y<<std::endl;
    std::cout<<"x - y, result: "<<x<<","<<y<<","<<x-y<<std::endl;
    std::cout<<"x times y, result: "<<x<<","<<y<<","<<x*y<<std::endl;
    std::cout<<"x / y, result: "<<x<<","<<y<<","<<x/y<<std::endl;
    }


    void ExampleWindow::on_button_add()
    {
    sprintf (buf, "%0.*f", m_SpinButton_Value.get_digits(),
    m_SpinButton_Value.get_value()+m_SpinButton_Value1.get_value());
    x = m_SpinButton_Value.get_value();
    y = m_SpinButton_Value1.get_value();

    m_Label_ShowValue.set_text(buf);

    }
    void ExampleWindow::on_button_subtract()
    {
    sprintf (buf, "%0.*f", m_SpinButton_Value.get_digits(),
    m_SpinButton_Value.get_value()-m_SpinButton_Value1.get_value());
    x = m_SpinButton_Value.get_value();
    y = m_SpinButton_Value1.get_value();

    m_Label_ShowValue.set_text(buf);

    }

    void ExampleWindow::on_button_multiply()
    {
    sprintf (buf, "%0.*f", m_SpinButton_Value.get_digits(),
    m_SpinButton_Value.get_value()*m_SpinButton_Value1.get_value());
    x = m_SpinButton_Value.get_value();
    y = m_SpinButton_Value1.get_value();

    m_Label_ShowValue.set_text(buf);

    }

    void ExampleWindow::on_button_divide()
    {
    sprintf (buf, "%0.*f", m_SpinButton_Value.get_digits(),
    m_SpinButton_Value.get_value()/m_SpinButton_Value1.get_value());
    x = m_SpinButton_Value.get_value();
    y = m_SpinButton_Value1.get_value();

    m_Label_ShowValue.set_text(buf);

    }
  3. Compile it per the above table


  4. Copy the executable (compiled)
    file to the executables folder (directory), eg. gtkmmath


  5. Open the konsole window and run gtkmmath (i.e. type gtkmmath
    at the prompt).



A simple program to calculate the areas of a square, arectangle and a triangle: C++:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines:
    #include<iostream> #include<fstream> using namespace std; int main() { char mainsel; float x, y, b1, b3; int quit = 0;
    while (quit==0) { cout<<"enter:a for area of a square, b for area of a rectangle"<<endl; cout<<"c for the area of a triangle and q to quit:"<<endl; cin>>mainsel; if (mainsel == 'a') { cout<< "length (base) of the square: " ; cin >> x ; b3= x*x ; cout <<
    "the area of the square = "<< b3 << endl; continue; } if (mainsel == 'b') { cout<< "length (base) of the rectangle: " ; cin >> x ; cout<< "height of the rectangle: " ; cin >> y; b3= x * y; cout << "area of rectangle = "<< b3 << endl; continue; } if (mainsel == 'c') { cout<< "base of the triangle: " ; cin >> x ; cout<< "height of the triangle: " ; cin >> y; b1 = (x*y/2); cout << "area of triangle = "<< b1 << endl; continue; } if (mainsel == 'q') { quit = 1; break; } } }


  3. Save the file as areascpp.cpp


  4. Compile it per the above table


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areascpp


  6. Open the konsole window and run areascpp (i.e. type areascpp at the prompt).



Fortran 77:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program areas real a, b, area integer x 100 write (*,*) 'enter 1 for the area of a square, 2 a rectangle,' write (*,*) '3 a triangle and 4 to quit:' read (*,*) x IF(x .eq. 1)THEN write (*,*) 'Give legnht of square:' read (*,*) a area = a*a write (*,*) 'Area = ', area goto 100 endif IF(x .eq. 2)THEN write (*,*) 'Give base of rectangle:' read (*,*) a write (*,*) 'Give height of rectangle:' read (*,*) b area = a*b write (*,*) 'Area = ', area goto 100 endif IF(x .eq. 3)THEN write (*,*) 'Give legnht of square:' read (*,*) a write (*,*) 'Give height of rectangle:' read (*,*) b area = a*b/2 write (*,*) 'Area = ', area goto 100 endif end


  3. Save the file as areas.for


  4. Compile it: g77 -o areasg77 areas.for


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areasg77


  6. Open the konsole window and run areasg77 (i.e. type areasg77 at the prompt).



gFortran:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: program areas real a, b, area integer x 100 write (*,*) 'enter 1 for the
    area of a square, 2 a rectangle,' write (*,*) '3 a triangle and 4 to quit:' read (*,*) x IF(x .eq. 1)THEN write (*,*) 'Give legnht of
    square:' read (*,*) a area = a*a write (*,*) 'Area = ', area goto 100 endif IF(x .eq. 2)THEN write (*,*) 'Give base of rectangle:'
    read (*,*) a write (*,*) 'Give height of rectangle:' read (*,*) b area = a*b write (*,*) 'Area = ', area goto 100 endif IF(x .eq.
    3)THEN write (*,*) 'Give legnht of square:' read (*,*) a write (*,*) 'Give height of rectangle:' read (*,*) b area = a*b/2 write (*,*)
    'Area = ', area goto 100 endif end


  3. Save the file as areas.for


  4. Compile it: gfortran -o areasgfor areas.for


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areasgfor


  6. Open the konsole window and run areasgfor (i.e. type areasgfor at the prompt).



Pascal:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines:


    program areas (input,output);
    var choice,q:char;
    var el1,el3,result:real;
    begin
    while (choice<>'q') do
    begin
    writeln ('enter a for area of a square, b for rectangle');
    writeln ('enter c for triangle & enter q to exit');
    readln(choice);
    if choice = 'a' then
    begin
    writeln('base length of square');
    readln(el1);
    writeln('area = ');
    result:=(el1*el1);
    writeln(result:4:2);
    end;
    if choice = 'b' then
    begin
    writeln('base length of rectangle = ');
    readln(el1);
    writeln('height of rectangle = ');
    readln(el3);
    writeln('area of rectangle = ');
    result:=(el1*el3);
    writeln(result:4:2);
    end;
    if choice = 'c' then
    begin
    writeln('base length of triangle = ');
    readln(el1);
    writeln('height of triangle = ');
    readln(el3);
    writeln('area of triangle = ');
    result:=(el1*el3/2);
    writeln(result:4:2);
    end
    end
    end.
  3. Save the file as areasp.pas


  4. Compile it: fpc areasp.pas


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areasp


  6. Open the konsole window and run areasp (i.e. type areasp at the prompt).



SmallEiffel:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: class AREASSE creation make feature noe:integer; el1,el3:real; first:character; make is do from until first ='q' loop menu end --loop end --make menu is do io.put_string("%Nenter a for the area of a square, b for a rectangle,%Nc for a triangle and q to quit: %N"); io.read_character; first:=io.last_character; if first = 'a' then do_selectiona end --first='a' if first = 'b' then do_selectionb end --first='b' if first = 'c' then do_selectionc end --first='c' end --menu do_selectiona is do io.put_string("enter
    the base length of the square: "); io.read_real; el1:=io.last_real; io.put_string("the result: "); io.put_real((el1*el1)); io.put_string("%N") end --do_selectiona do_selectionb is do io.put_string("enter the base length of the rectangle: "); io.read_real;
    el1:=io.last_real; io.put_string("enter the height: "); io.read_real; el3:=io.last_real; io.put_string("the result: "); io.put_real(el1*el3); io.put_string("%N") end --do_selectionb do_selectionc is do io.put_string("enter the base length of the triangle: "); io.read_real; el1:=io.last_real; io.put_string("enter the height of the triangle: "); io.read_real; el3:=io.last_real;
    io.put_string("the area (result): "); io.put_real((el1*el3)/2); io.put_string("%N") end --do_selectionc end --AREASSE


  3. Save the file as simathp.e


  4. Compile it: compile areasse.e -o areasse


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areasse


  6. Open the konsole window and run areasse (i.e. type areasse at the prompt).



Haskell:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: main = do putStrLn "Please a number: " choice <- getLine let ch = read choice::Int if (ch == 1) then do respond else if (ch == 2) then do respond1 else if (ch == 3) then do respond2 else putStrLn"end" respond = do putStrLn "square"
    putStrLn "base length of square: " name <- getLine let x = read name :: Double let a = x * x putStrLn ("area of square
    = " ++ show a) respond1 = do putStrLn "rectangle" putStrLn "base length of rectangle: " name <- getLine putStrLn "height of rectangle: " name1 <- getLine let y = read name1 :: Double let x = read name :: Double let a = x * y putStrLn ("area of rectangle = " ++ show a) respond2 = do putStrLn "triangle" putStrLn "base length of triangle: " name <- getLine putStrLn "height of
    triangle: " name1 <- getLine let y = read name1 :: Double let x = read name :: Double let a = x * y/2 putStrLn ("area of
    triangle = " ++ show a)


  3. Save the file as areashaskell.hs


  4. Compile it: ghc --make -o areashaskell areashaskell.hs


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areashaskell


  6. Open the konsole window and run areashaskell (i.e. type areashaskell at the prompt).



ADA:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: with Gnat.Io; use Gnat.Io; with Ada.Float_Text_IO; use Ada.Float_Text_IO; procedure areasada is a: integer; b, c, d, e, f: float; begin Put("Enter a numbere: 1 for area of a square, 2 area of rectangle, 3 area of triangle, 4 to quit "); Get(a); if A = 1 then Put("Enter length of square: "); Get(b); e := b * b; Put("area of square = "); Put(e); New_Line; elsif a = 2 then Put("Enter length of rectangle base: "); Get(c); Put("Enter height of rectangle base: "); Get(d); e := c * d; Put("area of rectangle = "); Put(e); New_Line; elsif a = 3 then Put("Enter length of triangle base: "); Get(d); Put("Enter height of triangle base: "); Get(f); e := f * d/ 2.0; Put("area of triangle = "); Put(e); New_Line; end if; end areasada;


  3. Save the file as simpmthada.adb


  4. Compile it: gcc -c areasada.adb; then: gnatbl -o areasada areasada.ali


  5. Copy the executable (compiled) file to the executables folder (directory), eg. areasada


  6. Open the konsole window and run areasada (i.e. type areasada at the prompt).



Java:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following lines: import java.io.*; import java.io.*; class AreasJava { public static void main(String[] args) throws Exception { Integer n1, q; String n, m1c, m2c; Double m1,m2, m3; q = 0; while (q == 0) { System.out.print("Enter 1 for area of square, 2 for rectangle or 3 for triangle and 4 to quit: "); BufferedReader br = new BufferedReader(new nputStreamReader(System.in)); n = br.readLine(); n1 = Integer.valueOf(n); if (n1 == 1) { System.out.print("square:
    "); } else if (n1 == 2) { System.out.print("rectangle: "); System.out.print("Enter base length: "); BufferedReader
    br2 = new BufferedReader(new InputStreamReader(System.in)); m1c = br2.readLine(); m1 = Double.valueOf(m1c); System.out.print("Enter height: "); BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); m2c = br1.readLine(); m2 = Double.valueOf(m2c); m3 = m2 * m1; System.out.print("area of rectangle = "); String s = String.valueOf(m3); System.out.println(s); } else if (n1 == 3) { System.out.print("triangle: "); } else if (n1 == 4) { q
    =1; } } } }


  3. Save the file as areasjava.java


  4. Compile it per the above table:
    javac areasjava.java


  5. Run the file, while you are in the directory where areasjava.java and SiMathJava.class are residing, by typing java AreasJava



gtkmm:


  1. Open a new document in any text editor (kwrite, kedit or kate).


  2. Type the following line:


    #include <gtkmm.h>
    #include <gtkmm/main.h>
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    char filename[20];
    gchar buf[32];
    double x, y;
    class ExampleWindow : public Gtk::Window
    {
    public:
    ExampleWindow();
    virtual ~ExampleWindow();

    protected:
    //Signal handlers:
    virtual void on_button_close();
    virtual void on_button_triangle();
    virtual void on_button_square();
    virtual void on_button_rectangle();
    //Child widgets:
    Gtk::Frame m_Frame_Accelerated;
    Gtk::HBox m_HBox_Accelerated, m_HBox_Buttons;
    Gtk::VBox m_VBox_Main, m_VBox, m_VBox_Accelerated, m_VBox_Value;
    Gtk::Label m_Label_Value1, m_Label_Value, m_Label_ShowValue;
    Gtk::Adjustment m_adjustment_value, m_adjustment_value1;
    Gtk::SpinButton m_SpinButton_Value, m_SpinButton_Value1;
    Gtk::Button m_Button_Triangle, m_Button_Close, m_Button_Square, m_Button_Rectangle;
    };

    int main(int argc, char *argv[])
    {
    Gtk::Main kit(argc, argv);

    ExampleWindow window;
    //Shows the window and returns when it is closed.
    Gtk::Main::run(window);

    return 0;
    }

    ExampleWindow::ExampleWindow()
    :
    m_Frame_Accelerated("Accelerated"),
    m_VBox_Main(false, 5),
    m_Label_Value("Value of x (length or height): "),
    m_Label_Value1("Value of y (width or base): "),
    m_adjustment_value(0.0, -10000.0, 10000.0, 0.1, 100.0, 0.0),
    m_adjustment_value1(0.0, -10000.0, 10000.0, 0.1, 100.0, 0.0),
    m_SpinButton_Value(m_adjustment_value, 1.0, 4),
    m_SpinButton_Value1(m_adjustment_value1, 1.0, 4),
    m_Button_Triangle("area = x*y/2"),
    m_Button_Square("area = x * y"),
    m_Button_Rectangle("area = x * y"),
    m_Button_Close("Close")
    {
    set_title("Math");

    m_VBox_Main.set_border_width(10);
    add(m_VBox_Main);

    m_VBox.set_border_width(5);

    //Accelerated:
    m_VBox_Main.pack_start(m_Frame_Accelerated);

    m_VBox_Accelerated.set_border_width(5);
    m_Frame_Accelerated.add(m_VBox_Accelerated);

    m_VBox_Accelerated.pack_start(m_HBox_Accelerated, Gtk::PACK_EXPAND_WIDGET, 5);

    m_HBox_Accelerated.pack_start(m_VBox_Value, Gtk::PACK_EXPAND_WIDGET, 5);

    m_Label_Value.set_alignment(Gtk::ALIGN_LEFT);
    m_VBox_Value.pack_start(m_Label_Value);

    %

 
Rate This Article: poor excellent
 
Comments about this article
Formatting of article
writen by: ImChipBrown on 2009-10-15 11:49:30
It may be my browser, but the instructions which say "Type the following lines" are all on one wrapped line on my display (except the gtkmm instructions).
RE: Formatting of article written by ImChipBrown:
RE: Formatting of article
writen by: kheirha on 2009-11-04 13:21:46
Apparently the formating of this article when published on this forum site was not correct. To view the correct formated article, you may refer to www.vepi.freevar.com or even scribd.com. Thanks for your comment.
Hany
Reply to kheirha:
Formatting of article
writen by: Strider22 on 2009-10-15 18:27:11
The wrapped lines present an unfair comparison. The wrapped lines for the Java
RE: Formatting of article written by Strider22:
RE: Formatting of article
writen by: kheirha on 2009-11-04 13:22:24
Apparently the formating of this article when published on this forum site was not correct. To view the correct formated article, you may refer to www.vepi.freevar.com or even scribd.com. Thanks for your comment.
Hany
Reply to kheirha:
formatting of comments
writen by: Strider22 on 2009-10-15 18:28:32
Only the first line of a comment block shows. Where did the comment go?
RE: formatting of comments written by Strider22:
RE: formatting of comments
writen by: kheirha on 2009-11-04 13:22:40
Apparently the formating of this article when published on this forum site was not correct. To view the correct formated article, you may refer to www.vepi.freevar.com or even scribd.com. Thanks for your comment.
Hany
Reply to kheirha:
Hello World C
writen by: Kelby on 2009-11-28 20:30:08
Your C Hello World program is more of C program. The C variant would look like this

#include
int main()
{
using namespace std;
cout
RE: Hello World C written by Kelby:
RE: Hello World C
writen by: Kelby on 2009-11-28 20:32:07
Ok the format of that post got all messed up once I posted it sorry. I'm new to LinuxForums.
Reply to Kelby:
Where is the python example?
writen by: b2bwild on 2009-12-09 07:04:45
Anyways, It wont run. Because whitespaces are significant in Python.
RE: Where is the python example? written by b2bwild:
RE: Where is the python example?
writen by: kheirha on 2010-02-18 15:21:11
you shall find Python eaxamples in the Scripting languages article, not this one. and you have problems with the formatting of any of both articles you may refer to the following sites www.vepi.freevar.com or scribd.com.
Reply to kheirha:

Comment title: * please do not put your response text here