Lessons from CST exercise - PowerPoint PPT Presentation

About This Presentation
Title:

Lessons from CST exercise

Description:

Title: Lessons from CST exercise Author: Jack Patzer Last modified by: jack patzer Created Date: 1/7/2001 6:34:38 PM Document presentation format – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 13
Provided by: JackP157
Learn more at: https://sites.pitt.edu
Category:

less

Transcript and Presenter's Notes

Title: Lessons from CST exercise


1
Engr 0012 (04-1) LecNotes 18-01
2
Contrasting MATLAB with C
MATLAB
C language
No real equivalent
Workspace - interactive computation
main - program control function/algorithm
script - program control algorithm
functions - perform specific computation or task
functions - perform specific computation or task
Engr 0012 (04-1) LecNotes 18-02
3
Contrasting variables
MATLAB
C language
You must decide type based upon need and use
Two variable types
double precision, complex string (text)
int (/-32,000) log int (/- 2 billion) float
(8 digits 10/-37) double (16 digits
10/-307) char (ASCII character)
Use meaningful names
Use meaningful names
Engr 0012 (04-1) LecNotes 18-03
4
I/O Commands
MATLAB
C language
Engr 0012 (04-1) LecNotes 18-04
5
decision (branching) structures - if/elseif
MATLAB
C language
Engr 0012 (04-1) LecNotes 18-05
6
decision (branching) structures - switch/case
MATLAB
C language
Engr 0012 (04-1) LecNotes 18-06
7
repetition (looping) structures - for loop
MATLAB
C language
Engr 0012 (04-1) LecNotes 18-07
8
repetition (looping) structures - while loop
MATLAB
C language
Engr 0012 (04-1) LecNotes 18-08
9
repetition (looping) structures - do..while loop
MATLAB
C language
Engr 0012 (04-1) LecNotes 18-09
10
sample C-program
/ Your Name(s) Engineering 12, Fall Term
2002 Class Activity 18-1 / // include
libraries include ltstdio.hgt // prototypes
void displayheader( void ) //
main()
preprocessor commands
Engr 0012 (04-1) LecNotes 18-10
11
sample C-program
//
main() // begin main // variable
declarations int first double second
char letter displayheader() //
algorithm printf( "\nPlease enter an integer
gt " ) scanf( "d", first )
printf( "\nPlease enter a real number gt " )
scanf( "lf", second ) printf( "\nPlease
enter a character gt " ) fflush( stdin )
scanf( "c", letter ) fflush( stdin )
printf( "\n\nYou entered the integer d "
" \n the real number lf "
" \n and the character c \n\n",
first, second, letter )
return(0) // end main //
void
displayheader( void )
variable declaration section for main
command to display header
Engr 0012 (04-1) LecNotes 18-11
12
sample C-program
//
void displayheader( void ) /
purpose display header info to screen goal
state header info on screen / // begin
displayheader printf( "Your name(s)" )
printf( "\nEngineering 12, Fall Term 2003" )
printf( "\nClass Activity 18-1 \n" ) printf(
"\n\nThis program performs simple I/O operations"
) printf( "\n" ) // end displayheader
Engr 0012 (04-1) LecNotes 18-12
Write a Comment
User Comments (0)
About PowerShow.com