Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Prepared by: Eng. Maryam Adel Abdel-Hady

Similar presentations


Presentation on theme: " Prepared by: Eng. Maryam Adel Abdel-Hady"— Presentation transcript:

1  Prepared by: Eng. Maryam Adel Abdel-Hady eng_maryamadel@yahoo.com

2  http://linuxcommand.org/lc3_wss0100.php http://linuxcommand.org/lc3_wss0100.php

3  Use to perform arithmetic operations.  Syntax: o expr op1 math-operator op2  Examples: $ expr 1 + 3 $ expr 2 - 1 $ expr 10 / 2 $ expr 20 % 3 $ expr 10 \* 3 $ echo `expr 6 + 3`  Note: o expr 10 \* 3 - Multiplication use \* and not * since its wild card. o If you define a variable x that equal expr 2 +3 >> NO SPACE between equal and expr >> x=`expr 2 + 3`

4 $ echo `expr 6 + 3`  Note: (1) First, before expr keyword we used ` (back quote) sign not the (single quote i.e. ') sign. Back quote is generally found on the key under tilde (~) or on the letter ( ذ ) on PC keyboard OR to the above of TAB key. (2) Second, expr is also end with ` i.e. back quote. (3) Here expr 6 + 3 is evaluated to 9, then echo command prints 9 as sum (4) Here if you use double quote or single quote, it will NOT work ----------------------------- $ echo "expr 6 + 3" # It will print expr 6 + 3 $ echo 'expr 6 + 3' # It will print expr 6 + 3

5  Even or odd ?!!

6  Even or odd ?!! By using ( expr ) You can write it as: If test `expr $number % 2` -eq 0

7 Loops in Shell Scripts

8 for (( expr1; expr2; expr3 )) do..... repeat all statements between do and done until expr2 is TRUE …… done --------------- Ex: for (( i = 0 ; i <= 5; i++ )) do echo "Welcome $i times" done

9 while [ condition ] do command1 command2 command3...... done ---------------- Ex: i=1 while [ $i -le 10 ] do echo “Welcome $i” i=`expr $i + 1` done

10 Examples

11  Write a function that print all the positive numbers < 40 that are divisible by 4, and calculate the summation and the average of them.

12 You can write it as: If [ `expr $i % 4` –eq 0 ] $count `

13  Write a bash script that will print grade A for exam percentage greater or equal to 90, B for scores in the range 80 to 89, C for scores in the range 70 to 79, D for grades in range 60 to 69, and F for all other grades, then you copy this bash file in another file its name in (A, B, C, D or F) According to the entered score.

14

15  Write a bash script that repeatedly collects positive integers from the user, stopping when the user enters a negative number or zero. After that, output the product of all positive entries. A sample run should appear on the screen like the text below : Enter a number: 3 Enter a number: 10 Enter a number: 2 Enter a number: -213 The product of all your positive numbers is 60

16

17  Design FCFS algorithm that take number of processes with its burst time. And let that all processes arrive in the same time Then calculate the average waiting time of them. A sample run should appear on the screen like the text below : Enter the number of process you want to enter: 3 Burst time of p1: Burst time of p2: Burst time of p3: The average waiting time is:

18 Programming Languages in UBUNTU

19 (1) C/C++ Programs

20  http://www.wikihow.com/Compile-a-C/C%2B%2B-Program-in- Ubuntu http://www.wikihow.com/Compile-a-C/C%2B%2B-Program-in- Ubuntu  Steps: 1. Open up a terminal on Ubuntu Linux and install the build-essential package by typing the following command in the terminal Type/Copy/Paste: sudo apt-get install build-essential This will install the necessary C/C++ development libraries for your Ubuntu Linux system to create C/C++ programs. 2. Create a directory and a sub directory to hold your C/C++ programs and your main HelloWorld program. Type/Copy/Paste: mkdir -p CCPP/HelloWorld We are using CCPP for the main directory to hold our created C/C++ programs which stands for C and C++ programs directory and we are using the sub directory HelloWorld to hold our main program.

21 3. Then we will change into our created directory by issuing the following command Type/Copy/Paste: cd CCPP/HelloWorld 4. Next we will use a text editor such as gedit or nano to create our C or C++ source code using the following command.

22 Example for: C Program

23 5. For example for a C source code file we would issue the following command Type/Copy/Paste: gedit main.c or Type/Copy/Paste: nano main.c o This command for creating a script file called main.c 6. Enter the following C source code below: o Type/Copy/Paste: #include int main() { printf("\nHello World,\nWelcome to my first C program in Ubuntu Linux\n\n"); return(0); } 7. Save the file as main.c and exit

24 8. To compile the C program: o Type/Copy/Paste: gcc -Wall -W -Werror main.c -o HelloWorldC o The first line will invoke the GNU C compiler to compile the file main.c and output (-o) it to an executable called HelloWorldC. o The options -Wall -W and -Werror instruct the compiler to check for warnings. 9. If you should happen to get permission errors, you need to make the file executable. You can do this by issuing the following commands below o Type/Copy/Paste: chmod +x HelloWorldC

25 10. In order to execute your program you will have to type in the following commands.To execute the C program version of the program: Type/Copy/Paste:./HelloWorldC

26 Example for: C++ Program

27 5. For example for a C++ source code file we issue the following command o Type/Copy/Paste: gedit main.cpp o or o Type/Copy/Paste: nano main.cpp o This command for creating a script file called main.c 6. Add the following lines below to create your C++ source code: Type/Copy/Paste: #include using namespace std; int main() { cout<<"\nHello World,\nWelcome to my first C ++ program on Ubuntu Linux\n\n"<<endl; return(0); } 7. Save the file as main.cpp and exit

28 8. To compile the C program: o If you are compiling the C++ program version of Hello World type in the terminal Type/Copy/Paste: g++ -Wall -W -Werror main.cpp -o HelloWorldCPP 9. If you should happen to get permission errors, you need to make the file executable. You can do this by issuing the following commands below o Type/Copy/Paste: chmod +x HelloWorldCPP

29 10. In order to execute your program you will have to type in the following commands. To execute the the C++ program version of the program: o Type/Copy/Paste:./HelloWorldCPP

30 (2)Java

31  First you must have Java application such oracle Java,to install it follow this steps: How to Install Oracle Java on Ubuntu Linux  or you can write this command to install a Java application sudo apt-get install openjdk-6-jdk Java –version  to show the version Gedit userinput.java  write your java program o Show this video: http://youtu.be/3w9HckeYY-Q  Then you can follow these steps http://www.wikihow.com/Create-Your-First-Java-Program-on-Ubuntu-Linux

32 (3)C#

33  http://developer.ubuntu.com/resources/programming- languages/c-sharp/ http://developer.ubuntu.com/resources/programming- languages/c-sharp/

34  Mono is a software platform designed to allow developers to easily create cross-platform applications. It is an open source implementation of Microsoft’s.Net Framework based on the ECMA standards for C# and the Common Language Runtime. We feel that by embracing a successful, standardized software platform, we can lower the barriers to producing great applications for Linux.  هذا البرنامج يعمل لاكثر من لغة http://developer.ubuntu.com/resources/programming-languages/c- sharp/ http://linuxpoison.blogspot.com/2010/11/how-to-compile-and-run- c-net.html

35 (4)PHP

36 http://www.allaboutlinux.eu/how-to-run-php-on-ubuntu/


Download ppt " Prepared by: Eng. Maryam Adel Abdel-Hady"

Similar presentations


Ads by Google