- Crystal

advertisement
Dr. Sajib Datta
CSE@UTA

The website is up.

Course lectures will be uploaded there
◦ Check regularly for assignments and update


For omega access, each student that needs to
have access to it will need to contact the help
desk and request it. The best way is to call
them at 817-272-2208 and ask to have
omega access added to your NetID account.
Visual Studio download information:
◦ http://www.uta.edu/oit/cs/software/microsoft/visu
al-studio-2010/index.php
A Linux server
 Get an account!
 http://www.uta.edu/oit/cs/web/omegaweb.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



Windows users: download SSH client from OIT
http://www.uta.edu/oit/cs/unix/ssh/SecureShell-Client.php

omega.uta.edu

Applications -> Utilities -> Terminal

Login:
◦ $ ssh your_netID@omega.uta.edu

Logout:
◦ $ logout<Return>

ls : displays the files in a specified directory
◦ [vxg4212@omega ~]$ ls

rm : delete a file
◦ [vxg4212@omega ~]$ rm file_name

cp : copy files (caution, will replace if file
already exists)
[vxg4212@omega ~]$ cp source_file destination_file

mv : rename files
◦ [vxg4212@omega ~]$ mv old_filename
new_filename

[vxg4212@omega ~]$ mv old_filename
directory/new_name
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




vi editor
[vxg4212@omega ~]$ vi file_name.extension
Two modes: Command mode and Insert
mode

Insert mode: entered text is inserted into the
file

Hit i to get into insert mode

Hit Esc to get out of insert mode
Whole lot of options available in insert mode!
http://www.cs.colostate.edu/helpdocs/vi.html


Local computer to a remote computer
scp file_name user_name@server:/home/user_name/

Remote server to your local computer
scp user_name@server:/home/user_name/file_name
/home/local-user_name/file_name



gcc : compile a C program
vxg4212@omega ~]$ gcc -o my_out
program_file.c
Run the compiled program
◦ vxg4212@omega ~]$ my_out<Return>
◦Variables, Statements,
Operators, Expressions



Storing information - Variables
Statements - Declaration, Assignment, Function
Making decisions – Conditionals
Variable declaration
int num;
Assigning a value to the variable
num = 51;
conditional
if (num > 25)
Print function
printf(“a large class. \n”);
conditional
else
Print function
printf(“a small class. \n”);

Repeating certain tasks – Loops
◦ Print “CSE 1311003” 1000 times


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

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’, ‘?’

Lowercase letters, uppercase letters, digits,
and underscore

First character must be a letter or an underscore

Not key words

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));

Declare a variable
◦ 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;

Print a variable
◦ 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”);


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 statements are when we declare
variables for use.

void main()
{
int a;
……
}


Have a left side and a right side.
The right side:
◦ 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?]

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

Example:

◦ integer = integer / integer
◦ int a = 7, b = 5;
◦ int answer;
◦ answer = a / b;
float a = 7.1, b = 5.2;
int answer;
answer = a / b;
Download