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.
Write an article for LinuxForums Today! Win Great Prizes!
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).
Make a new directory under /home/user-name (eg. hany)/Documents and call it executables.
Add to this directory each executable (compiled) file.
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.
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.
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++:
Open a new document in any text editor (kwrite, kedit or kate).
Type the following lines: #include <stdio.h> int main () { printf ("Hello world from gcc/g++n"); }
Save the file as hellocpp.cpp
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hello1
Open the konsole window and run hello1 (i.e. type hello1 at the prompt).
Fortran 77:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as hello.for
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hellog77
Open the konsole window and run hellog77 (i.e. type hellog77 at the prompt).
gFortran:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as hello.for
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hellogfor
Open the konsole window and run hellogfor (i.e. type hellogfor at the prompt).
Pascal:
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.
Type the following lines: program hello; begin writeln('hello from pascal'); end.
Save the file as hello.pas
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hello
Open the konsole window and run hello (i.e. type hello at the prompt).
SmallEiffel:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as hello.e
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hellose
Open the konsole window and run hellose (i.e. type hellose at the prompt).
Haskell:
Open a new document in any text editor (kwrite, kedit or kate).
Type the following lines: main = do putStrLn "hello, world, from haskell ghc!"
Save the file as hello.hs
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hellohaskell
Open the konsole window and run hellohaskell (i.e. type hellohaskell at the prompt).
ADA:
Open a new document in any text editor (kwrite, kedit or kate).
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;
Save the file as helloada.adb
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hello2
Open the konsole window and run hello2 (i.e. type hello2 at the prompt).
OCaml:
Open a new document in any text editor (kwrite, kedit or kate).
Type the following line: let hello () = print_endline "Hello from OCaml" Save this file as amodule.ml
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
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. hellooc
Open the konsole window and run hellooc (i.e. type hellooc at the prompt).
Java:
Open a new document in any text editor (kwrite, kedit or kate).
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. } }
Save the file as hellojava.java
Compile it per the above table
Run the file, while you are in the directory where hellojava.java and HelloWorldApp.class are residing, by typing java HelloWorldApp
gtkmm:
Open a new document in any text editor (kwrite, kedit or kate).
Type the following line:
#include <gtkmm/button.h> #include <gtkmm/window.h> #include <gtkmm/main.h> #include <iostream> class HelloWorld : public Gtk::Window {
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(); }
Copy the executable (compiled) file to the executables folder (directory), eg. hellogtk
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++:
Open a new document in any text editor (kwrite, kedit or kate).
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; }
Save the file as test00cpp.cpp
Compile it: g++ test00cpp.cpp -o simplemthc
Copy the executable (compiled) file to the executables folder (directory), eg. simplemathc
Open the konsole window and run simplemathc (i.e. type simplemathc at the prompt).
Fortran 77:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as simathg77.for
Compile it: g77 -o simath77 simathg77.for
Copy the executable (compiled) file to the executables folder (directory), eg. simath77
Open the konsole window and run simath77 (i.e. type simath77 at the prompt).
gFortran:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as simathg77.for
Compile it: gfortran -o simathgf simathg77.for
Copy the executable (compiled) file to the executables folder (directory), eg. simathgf
Open the konsole window and run simathgf (i.e. type simathgf at the prompt).
Pascal:
Open a new document in any text editor (kwrite, kedit or kate).
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.
Save the file as simathp.pas
Compile it: fpc simathp.pas
Copy the executable (compiled) file to the executables folder (directory), eg. simathp
Open the konsole window and run simathp (i.e. type simathp at the prompt).
SmallEiffel:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as simathp.e
Compile it: compile simathse.e -o simathse
Copy the executable (compiled) file to the executables folder (directory), eg. simathse
Open the konsole window and run simathse (i.e. type simathse at the prompt).
Haskell:
Open a new document in any text editor (kwrite, kedit or kate).
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)
Save the file as simathaskell.hs
Compile it: ghc -- make -o simathhs simathaskell.hs
Copy the executable (compiled) file to the executables folder (directory), eg. simathhs
Open the konsole window and run simathhs (i.e. type simathhs at the prompt).
ADA:
Open a new document in any text editor (kwrite, kedit or kate).
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;
Copy the executable (compiled) file to the executables folder (directory), eg. simpmthada
Open the konsole window and run simpmthada (i.e. type simpmthada at the prompt).
Java:
Open a new document in any text editor (kwrite, kedit or kate).
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); } }
Save the file as simathjava.java
Compile it per the above table
Run the file, while you are in the directory where simathjava.java and SiMathJava.class are residing, by typing java SiMathJava
gtkmm:
Open a new document in any text editor (kwrite, kedit or kate).
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);
}
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. gtkmmath
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++:
Open a new document in any text editor (kwrite, kedit or kate).
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; } } }
Save the file as areascpp.cpp
Compile it per the above table
Copy the executable (compiled) file to the executables folder (directory), eg. areascpp
Open the konsole window and run areascpp (i.e. type areascpp at the prompt).
Fortran 77:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as areas.for
Compile it: g77 -o areasg77 areas.for
Copy the executable (compiled) file to the executables folder (directory), eg. areasg77
Open the konsole window and run areasg77 (i.e. type areasg77 at the prompt).
gFortran:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as areas.for
Compile it: gfortran -o areasgfor areas.for
Copy the executable (compiled) file to the executables folder (directory), eg. areasgfor
Open the konsole window and run areasgfor (i.e. type areasgfor at the prompt).
Pascal:
Open a new document in any text editor (kwrite, kedit or kate).
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.
Save the file as areasp.pas
Compile it: fpc areasp.pas
Copy the executable (compiled) file to the executables folder (directory), eg. areasp
Open the konsole window and run areasp (i.e. type areasp at the prompt).
SmallEiffel:
Open a new document in any text editor (kwrite, kedit or kate).
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
Save the file as simathp.e
Compile it: compile areasse.e -o areasse
Copy the executable (compiled) file to the executables folder (directory), eg. areasse
Open the konsole window and run areasse (i.e. type areasse at the prompt).
Haskell:
Open a new document in any text editor (kwrite, kedit or kate).
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)
Copy the executable (compiled) file to the executables folder (directory), eg. areashaskell
Open the konsole window and run areashaskell (i.e. type areashaskell at the prompt).
ADA:
Open a new document in any text editor (kwrite, kedit or kate).
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;
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:
Comment title: * please do not put your response text here