CSE 1320 Basics Dr. Sajib Datta CSE@UTA.

Slides:



Advertisements
Similar presentations
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Advertisements

Computer Programming w/ Eng. Applications
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Conditionals – if - else Dr. Sajib Datta
True or false A variable of type char can hold the value 301. ( F )
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Introduction to C Programming
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 2: Using Data.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 5.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
4. EXPRESSIONS. Display the value of pi, to 5 decimal places, right justified, in 9 columns Read in someone’s height in feet and inches using.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Programming Fundamentals. The setw Manipulator setw changes the field width of output. The setw manipulator causes the number (or string) that follows.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Dr. Sajib Datta CSE Spring 2016 INTERMEDIATE PROGRAMMING.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Dr. Sajib Datta Jan 16,  The website is up.  Course lectures will be uploaded there ◦ Check regularly for assignments and update.
Dr. Sajib Datta Jan 15,  Instructor: Sajib Datta ◦ Office Location: ERB 336 ◦ Address: ◦ Web Site:
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Dr. Sajib Datta Jan 23,  A precedence for each operator ◦ Multiplication and division have a higher precedence than addition and subtraction.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Dr. Sajib Datta Sep 3,  A new operator used in C is modulus operator: %  % only used for integers, not floating-point  Gives the integer.
CSE 220 – C Programming Expressions.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 2 - Introduction to C Programming
Primitive Data, Variables, Loops (Maybe)
Chapter 2 - Introduction to C Programming
CSE1320 INTERMEDIATE PROGRAMMING
CSE1320 INTERMEDIATE PROGRAMMING
CSE1320 INTERMEDIATE PROGRAMMING Operators+Conditionals+Loop
CSE1320 INTERMEDIATE PROGRAMMING
CSE1320 INTERMEDIATE PROGRAMMING
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
CSE1320 INTERMEDIATE PROGRAMMING
CSE1320 INTERMEDIATE PROGRAMMING
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
OPERATORS in C Programming
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
OPERATORS in C Programming
Presentation transcript:

CSE 1320 Basics Dr. Sajib Datta CSE@UTA

Course Details The website is up. Course lectures will be uploaded there Check regularly for assignments and update

Programming Platform You have to execute your code on Omega server Connect Omega Server using SSH If you are using Macbook or Linux (such as Ubuntu), then open Terminal, and commend ssh your_UTA_NET_ID@omega.uta.edu. Then it will ask for password (UTA NetID password). If you are using Windows, please download SSH (Secure Sheel Client) http://www.uta.edu/oit/cs/unix/ssh/Secure-Shell-Client.php Download Code:Blocks: http://www.codeblocks.org/ Open source, cross platform, free IDE

Using Omega Server A Linux server Get an account! http://www.uta.edu/oit/cs/web/omega-web.php Provides C, C++, Lisp, Prolog, Cobol, and Fortran language compilers Connect using SSH http://www.uta.edu/oit/cs/files/sftp/ssh/index.php

Using Omega Windows users: download SSH client from OIT http://www.uta.edu/oit/cs/unix/ssh/Secure-Shell- Client.php

Connecting to Omega

Provide Login Information omega.uta.edu

Provide Password

File Transfer

Omega Terminal

From MAC/Linux Applications -> Utilities -> Terminal Login: $ ssh your_netID@omega.uta.edu Logout: $ logout<Return>

Some UNIX commands ls : displays the files in a specified directory [vxg4212@omega ~]$ ls rm : delete a file [vxg4212@omega ~]$ rm file_name

Some UNIX commands mv : rename files [vxg4212@omega ~]$ mv old_filename new_filename [vxg4212@omega ~]$ mv old_filename directory/new_name

More… pwd -> print the current (working) directory cd -> change directory cd .. ->go up one level mkdir -> make a new directory rmdir -> remove a directory Note: Commands can have options. Use man command_statement to get full details

Working with VI vi editor [vxg4212@omega ~]$ vi file_name.extension Two modes: Command mode and Insert mode

Working with VI Insert mode: entered text is inserted into the file Hit i to get into insert mode Hit Esc to get out of insert mode :x <Return> to exit vi Whole lot of options available in insert mode! For more on vi please visit: http://www.cs.colostate.edu/helpdocs/vi.html

C compiler gcc : compile a C program vxg4212@omega ~]$ gcc -o my_out program_file.c Run the compiled program vxg4212@omega ~]$ my_out<Return>

Introduction to C Variables, Statements, Operators, Expressions

Basics Storing information - Variables Statements - Declaration, Assignment, Function Making decisions – Conditionals int num; num = 51; if (num > 25) printf(“a large class. \n”); else printf(“a small class. \n”); Repeating certain tasks – Loops Print “CSE 1311003” 1000 times Variable declaration Assigning a value to the variable conditional Print function conditional Print function

Variables A variable is a symbolic name used to represent some information – data A variable is associated with a type, data storage location, its content which can be changed in running the program

Variables C requires the programmer to specify the type of variable. Some examples are: int – used for integers, A number with no fractional part Never with a decimal point 3, 14, -13, 7 double – used for floating point numbers A real number including numbers between the integers 0.5, 1.234 char – used for characters, e.g., ‘A’, ‘7’, ‘?’

Naming a variable Lowercase letters, uppercase letters, digits, and underscore First character must be a letter or an underscore Not key words

Variables Declare a variable: int weight; int height; int weight, height; Different variable types use different amounts of memory /* reports the amount of memory occupied by an int on this hardware */ printf("an int takes %d bytes of memory\n",sizeof(int));

Variables Declare a variable Assign a variable a value int height; [note that no value is still assigned] Assign a variable a value height = 5; Define - Declare & Initialize int height = 5; char name = ‘a’; double marks= 90.3;

Variables Print a variable Type matching printf(“%d”, num); - format specifier, variable Number matching - the number of specifiers is equal to the number of variables Type matching %d for int %lf for double %c for char printf can be used just to print text printf(“this is just a text”);

Statements A C program consists of statements Some types of statements: declaration statements Assignment statements Function calls Control statements Each statement is terminated by a semicolon. Control statement can change the program flow.

Declaration Declaration statements are when we declare variables for use. void main() { int a; …… }

Assignment Have a left side and a right side. The right side: Example: a single value, a complicated expression, or a function call ultimately reduce to a single value, which is then assigned to the variable named on the left side. Example: int num; [declaration] num = 1; num = num + 10; num = num + 2; [what is the final value of num?]

Operators The basic operators that you have in math are also available in C: +, -, *, /, = WARNING: Difference between operators in C and their math use is integer division. The fraction resulting is truncated in integer division integer = integer / integer Example: int a = 7, b = 5; int answer; answer = a / b;

Think! float a = 7.1, b = 5.2; int answer; answer = a / b;

Modulus A new operator used in C is modulus operator: % % only used for integers, not floating-point Gives the integer remainder from integer division. Example: int a = 7, b = 3; int answer; answer = a % b;

More… The following assignment operators are available in C:  += addition  -= subtraction  *= multiplication  /= division  num = num + 2 same as num+=2;  num = num - 1 same as num-=1;

What is the output of ‘x’? int x; x = 10; x += x; printf(“%d”, x);

Recap… We discussed: Omega Variable Statements Operators Data type Declaration, assigning a value, initialization Statements Conditional statements can change the flow of the code Operators +,-,*,% Data type What happens when you assign a float/double to a variable of type int

Operator Precedence What is the value of x? A precedence for each operator Multiplication and division have a higher precedence than addition and subtraction For operators with the same precedence, if they share an operand, they are executed according to the order they occur in the statement. (In most cases, from the left to the right, except assignment operation) Examples: int num, x; num = 2; x = 1 + 3*num/4; What is the value of x?

Operator Precedence Want an addition operation to take place before division? int num, x; num = 2; x = (1 + 3)*num/4; What is x now? int a = 1, b = 4; b += a+2; is equivalent to b = b + (a + 2)

Relational Operators < : is less than <= : is less than or equal to == : is equal to >= : is greater than or equal to > : is greater than != : is not equal to Example: Relational expression: a > 10 If the relation is true, the value of the expression is 1, otherwise 0.

Expressions A combination of operators and operands, where operands can be constants, variables, or combinations of the two 4 4+21 a = (b+c)/2 q>4

Statement vs. Expression A statement is a complete instruction to the computer In C, it is indicated by semicolon An statement is consists of expressions

Increment and Decrement Operator The operand must be a variable Two varieties – prefix and postfix ++ a, --b a ++, b -- This operation increases(decreases) the value of its operand by just one! In the prefix form, the increment or decrement takes place before the value is used in expression evaluation so the value of the expression is different from the value of the operand. In the postfix form, the increment or decrement takes place after the value is used in expression evaluation so the value of the expression is the same as the value of the operand

Increment and Decrement Operator Case1: a = 3; b = 2* ++a;// the value of the expression ++a is the new value of a, therefore b = ? Case2: b = 2* a++;// the value of the expression a++ is the old value of a, therefore, b = ?

Conditionals

if condition if statement gives you choice of either executing a statement or skipping it The basic format of the if statement is if (condition_is_true) do_something; // condition_is_true should be an expression //need the parenthesis for the expression // If expression evaluates to true (nonzero), do something. Otherwise, it is skipped. Normally, expression is relational expression. But in general, any expression will work since it has a value, which can be mapped to true or false.  Examples int x; int y = 6; scanf (“%d”, &x); if (x >= 2) y = 10; printf(“y is %d.\n”, y);

if… Examples int x; int y = 6; scanf (“%d”, &x); if (x >= 2) printf(“y is %d.\n”, y);