Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.

Similar presentations


Presentation on theme: "Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino."— Presentation transcript:

1 Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino

2 MSMIS Kean University Topics Course Requirements and Introductions Brief history of the C language C program structure C Expressions and Variables C data types C I/O routines

3 Scott Marino MSMIS Kean University Course Requirements Catalog description –Objective –Pre-requisites –Course Outline –Homework –Description –Texts –Attendance Contact Information –smarino@webundies.com Student contact card –Name –E-mail –Phone number –Major –Goal for course

4 Scott Marino MSMIS Kean University The history of C Written by Dennis Ritchie in 1970 Superceded his “B” programming language Originally designed to write operating system code C is popular today because: –Extremely flexible and powerful –Very portable

5 Scott Marino MSMIS Kean University C Program structure A program consists of data and instructions Data storage can be simple variables or more complex structures Instructions are generally assignment statements or control statements Organization is the key to writing good programs

6 Scott Marino MSMIS Kean University C From conception to execution The first step is to create a source file containing source code The compiler translates the source code to object code The linker merges the object file with standard (required) routines and creates an executable program

7 Scott Marino MSMIS Kean University C Program Structure - Style Use comments /* comment */ to document your code –This is important for homework Use indentation to structure program for readability Use self documenting variable names Avoid overly complex statements Keep functions simple and limit levels of if’s

8 Scott Marino MSMIS Kean University C simple expressions * Multiply / Divide % Modulus (remainder) + Addition - Subtraction Multiplication and division take precedence over addition and subtraction within parenthesis () (1 + 2) * 4

9 Scott Marino MSMIS Kean University C variable naming Variable names must start with a letter or an underscore Cannot contain spaces or special characters Case sensitive –total and Total are different variables Can’t use reserved words (int, printf, float, etc.)

10 Scott Marino MSMIS Kean University Variable declarations Syntax –type name; /* comment */ Global variables typically are defined before the main() Local variables are only “visible” within a called function

11 Scott Marino MSMIS Kean University C data types int –Integer data –16 bit machines 32767 to -32768 –32 bit machines 2147483647 to -2147483648 int myvar; prinf(“thevar = %d\n”, myvar);

12 Scott Marino MSMIS Kean University C data types float –Floating point (decimal) data float myvar; /* create myvar */ printf (“thevar = %f\n”, myvar;) The division between float and int data types can differ in the actual resulting value

13 Scott Marino MSMIS Kean University C data types char –Stores characters, numbers, or special characters in a 1 byte field char myvar; /* create myvar */ printf (“thevar = %c\n”, myvar); Multiple chars can be combined into a string

14 Scott Marino MSMIS Kean University C data types Arrays of characters (strings) Requires the string.h header file char myvar[50]; /* creates a 50 character string */ Can reference individual elements –Letter 1 = myvar[0]; –Must keep the \0 null terminator in the array

15 Scott Marino MSMIS Kean University C data types Use string functions to manipulate string arrays –strcyp(myvar,”MSAS5104”); Assigns the constant string to the variable –strcat(str1, str2); Concatenates str2 onto str1 –mylength = length(myvar); –strcmp(str1, str2) Zero if equal, non-zero if not equal printf (“thevar = %s\n”,myvar);

16 Scott Marino MSMIS Kean University C I/O routines Use the printf command to format the data to be printed Requires the stdio.h header file %d for decimal output %f for floating output %c for character output %s for string output \n is the newline character

17 Scott Marino MSMIS Kean University C I/O routines Reading strings as input fgets(name, sizeof(name), stdin); –Name is the variable name –Will include the end-of-line character –sizeof(name) limits the number of characters that can be read –stdin is either a file or the keyboard


Download ppt "Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino."

Similar presentations


Ads by Google