2009 mcgraw-hill, inc. all rights reserved. c for engineers and scientists: an interpretive approach...
TRANSCRIPT
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Discussion 1
• Commonly used commands• Executing program hello.c using Ch in ChIDE• A sample problem: find the volume of a cylinder• The _chrc and .chrc start-up file• The _path system variable
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Commonly Used CommandsCh supports all Windows commands and most Unix commands
Command Usage Description
cd cd Change to the home directory
cd dir Change to the directory dir
cp cp file1 file2 Copy file1 to file2
ls ls List contents in the working directory
mkdir mkdir dir Create a new directory dir
pwd pwd Print (display) the name of the working directory
rm rm file remove file
chmod chmod +x file Change the mode of file to make it executable
chide chide file.c Edit and execute program file.c
vi vi file Edit file
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
• Examples of Commands
C:/Documents and Settings/Administrator> cd /C:/> mkdir tmpC:/> cd tmpC:/tmp> mkdir eme5C:/tmp> cd eme5C:/tmp/eme5> pwdC:/tmp/eme5C:/tmp/eme5> cp C:/Ch/demos/bin/hello.c hello.cC:/tmp/eme5> lshello.cC:/tmp/eme5> chide hello.c
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Executing Program hello.c Using Ch in ChIDE
Click “Run” or “Start” to execute the program
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
• Files in Ch
C:/Ch> pwdC:/ChC:/Ch> lsbin/ demos/ docs/ include/ license/ README.TXT sbin/config/ dl/ extern/ lib/ package/ release/ toolkit/C:/Ch> cd docsC:/Ch/docs> C:/Ch/docs> lsREADME.TXT chguide.pdf chinstall.pdf chref.pdf man/
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Using GIMP to grab an image
• Download GIMP from http://www.gimp.org/windows/ http://www.gimp.org/macintosh/
• Install GIMP
• Click menu File• Click menu Create• Click menu Screen Shot• Click Grab. Then move the cursor to a window to be
acquired.
• Save or print out the acquired window.
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Example 1
• Find the volume of a cylinder– Radius: 3.5m– Height: 4.6m
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Example 1 (cont.)
• Find the volume of a cylinder
/* File: cylinder.cCalculate and display the volume of the cylinder withthe radius of 3.5 meters and height of 4.6 meters */
#include<stdio.h>
int main() { printf("volume = %f m^3\n", 3.14159*3.5*3.5*4.6); return 0;
}
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Example 2
• Write a program that calculates the area of a rectangle. The length and width of the rectangle are specified in the program.
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
Example 2 (cont.)/* File: area.c */#include <stdio.h>
int main() { double l, w, a; l = 2.5; /* length 2.5 meters */ w = 3.6; /* width 3.6 meters */ a = l*w;
printf(“The area is %f m^2\n”, a);
return 0;
}
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
The _chrc and .chrc start-up file
• The file _chrc in Windows and .chrc in Unix and Mac is the individual start-up file in your home directory, and will be invoked each time when Ch is launched.
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach Open the startup file _chrc in Windows or
.chrc for Unix for editing through ChIDE
2009 McGraw-Hill, Inc. All rights reserved.
C for Engineers and Scientists: An Interpretive Approach
The _path system variable
• The variable _path in the _chrc or .chrc file is used to set up paths for executable files.