Upload
franklin-paul
View
216
Download
4
Embed Size (px)
Citation preview
CSCI 171
Presentation 1
Computer Software
• System Software– Operating systems– Utility programs– Language compilers
• Application Software
Language Compilers
• Programming Generations– 5 Generations
• 1GL - Machine Language• 2GL - Assembly Language• 3GL - Compiled Languages
– Procedural» COBOL» C
– OOP» Java» C++
• 4GL – SQL• 5GL
History of C
• Bell Telephone Laboratories (1972)
• Dennis Ritchie (also created UNIX)
• A - B - C
Initially Many Versions
• Incompatibility
• ANSI– American National Standards Institute
• ANSI Standard C
Advantages of C
• Powerful, Flexible– Operating Systems– Applications software– Compilers
• Popular
• Portable
• Modular (should be written in functions)
Problem Solving Technique
• Define Problem
• Devise plan to fix problem
• Implement the plan
• Test
Necessary Information
• Is computer program required?
• Inputs/Outputs
• Formulas
• Organization (flow of logic)
Ex: Find area of a circle
• Is computer required?
• Inputs / Outputs– Need the radius of circle as input– Area will be the output
• Formulas– Area = pi * radius ^ 2
Find area of circle - continued
• Flow of logic:– Request radius of circle– Calculate area = pi * radius ^ 2– Output area
Steps in C programming cycle
• Use editor to create source code
• Compile source code into object code
• Link object file into executable file
• Execute file
Use editor to create source code
• Any editor can be used– Editor supplied with language
• Any text based editor
• DOS editor
• Notepad
• Write program following syntax of language
• Save file as: filename.c
Compile Source Code
• Different compilers use different commands
• Most (such as Borland, Code Warrior) have IDE - can compile via GUI interface
• Process creates a new file: filename.obj
• This file is object code - in format readable by machine
Link object file
• Most compilers will do this via GUI interface as well (may combine compiling and linking)
• Links internal C library functions (such as printf, scanf) with source code
• Creates new file: filename.exe
Execute Program
• Program can now be executed– Type filename at DOS prompt– Most compilers allow program to be run via
GUI interface• may combine compiling, linking, and running
• Finished product can be shared– source code does not have to be shared
Using the CodeWarrior compiler• Open up CodeWarrior through the Start Menu
– Metrowerks CodeWarrior…CodeWarrior IDE
• Select New… from the File menu• Select 'Win32 C Stationary‘• Enter (or select) the location• Enter the project name• Click 'Ok‘• Click on the + next to 'Win32 Console App‘• Double click 'C Console App‘• Open up the 'Source' folder by clicking on the + next to it• Double click main.c - this will open up a text based editor where you can type your
program (there will be some code in there automatically, you can delete it or change it)
• Write the source code• Run the program by selecting Run from the Project menu.
Sample C Program – Circle Area#include <stdio.h>
int main( void ) {const double pi = 3.14159;double radius = 0.0, area = 0.0;
printf("Enter the radius of the circle: ");scanf("%lf", &radius);
area = radius*radius*pi;
printf("The area of the circle is: %lf", area);}