DOC PREVIEW
SJSU ME 30 - lab1_basic_concepts

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications Lab Project 1 Beginning Programming Concepts and Getting Started with Ch and ChIDE Introduction There are a handful of fundamental concepts that you need to understand in order to effectively write programs in C We will focus on a few of them in this laboratory session Data types their memory requirements and how they combine arithmetically Variables and constants Operators Expressions and statements Formatted input and output Today s lab is not meant to be an exhaustive tour of all of these concepts Rather it is to expose you to some of the salient elements and get your feet wet with some of the software tools that we will be using in the lab We will be using a nifty C interpreter called Ch and an integrated development environment called ChIDE that were developed by Prof Harry Cheng from UC Davis to learn how to program in C This laboratory session will introduce Ch and ChIDE and you will get some experience using them Objectives Following completion of today s lab you should be able to List and explain the basic kinds of data Distinguish between variables and constants Declare integer floating point and character variables List the basic data types used in C Identify and explain commonly used operators in C Use C operators correctly according to their placement in the hierarchy chart Write and execute simple C programs in ChIDE Set up and evaluate expressions and equations using variables constants operators and hierarchy of operations Write statements that will produce formatted output Procedure If there are not enough computers to work at individually then find a partner to work with If you do work with a partner make sure that you take turns at the keyboard during the lab session Follow the instructions below and fill out the answer sheets Note everyone must turn in an individual lab report at the end of the session Turn in your answer sheets together with the cover page shown on the next page Fill out the cover page completely and staple it together with your answer sheets Points will be deducted if the cover sheet is not completely and legibly filled out Use the MS Word template available on the ME 30 website so that you can easily fill out your report and cover sheets Under the section of the cover sheet labeled Description summarize the problem s you solved You must also include a summary of the strategy you used as well as the methods you employed and any observations or conclusions about what you learned from the laboratory This is perhaps the most important part of the lab so do a good job on it Note that you are not limited to fitting the summary on the cover sheet BJ Furman ME 30 Computer Applications Lab1project doc 15AUG2009 Page 1 of 8 SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications Save your work on your own USB storage device before you leave the lab The hard drives on the computers in the lab are frequently refreshed so you ought not rely on them for saving your work from session to session References Cheng H H 2010 C for Engineers and Scientists An Interpretive Approach McGraw Hill New York ISBN 978 0073376059 BJ Furman ME 30 Computer Applications Lab1project doc 15AUG2009 Page 2 of 8 SAN JOS STATE UNIVERSITY First Initial Last Name Department of Mechanical and Aerospace Engineering ME 30 Computer Applications Proj Lab Project Report Cover Sheet Date Name print Last Name First Name Partners Project Title Description BJ Furman ME 30 Computer Applications Lab1project doc 15AUG2009 Page 3 of 8 SAN JOS STATE UNIVERSITY Last Name First Initial Department of Mechanical and Aerospace Engineering ME 30 Computer Applications 0 Getting Started with Ch and ChIDE 0 1 Open ChIDE by double clicking on the ChIDE icon 0 2 Open a Ch shell window by clicking on the Ch icon 0 3 Get familiar with the ability of Ch to interactively evaluate C expressions statements and functions Use the Ch shell window to evaluate the following expressions type them and hit ENTER Add comments and observations about what you learn in the process Expression 0 3 1 1 2 0 3 2 1 2 0 3 3 2 3 5 3 0 3 4 2 2 2 0 3 5 pow 2 3 0 3 6 5 7 0 3 7 5 7 0 3 8 define PI 3 14159 sin 30 PI 180 0 3 9 log 10 0 3 10 printf 4b 1 Result Comments and observations Any difference What is the log function See Note 2 first 0 3 11 printf 4b 2 0 3 12 printf 4b 4 0 3 13 printf 4b 8 0 3 14 float 7 0 0 3 15 dir Notes 1 What is wrong Describe results The Ch shell will execute C expressions without a terminating semicolon I highly recommend that you discipline yourself to include a terminating semicolon because when you get to writing C programs you MUST terminate statements with a semicolon or else you will get an error during compilation 2 The Ch shell buffers what you enter at the command line You can save lots of typing by recovering previous typing by hitting the up arrow Each time you hit the up arrow you go back one entry in the buffer Hitting the down arrow moves you ahead in the buffer You can edit the command line by moving the cursor using the left and right arrows and then using the delete or backspace keys You can also copy from the command line by clicking and dragging over a section of text then pressing the right mouse button or using the Edit command menu from the upper left icon in the Ch shell window You can paste in a similar manner Experiment with this 3 Ch understands Unix commands and shell programs We probably won t talk about these so much but you can do lots of things using shell commands BJ Furman ME 30 Computer Applications Lab1project doc 15AUG2009 Page 4 of 8 Last Name SAN JOS STATE UNIVERSITY First Initial Department of Mechanical and Aerospace Engineering ME 30 Computer Applications 1 Data Types see sections 2 2 2 6 and 7 1 7 4 in H K 1 1 For each of the following items identify what kind of data it is for example variable constant etc its data type and the number of bytes needed store it on a PC Item 1 1 1 C 1 1 2 7050 1 1 3 stop value 1 1 4 2 71 1 1 5 1 623E45 Notes 4 Kind of Data Data Type No of bytes needed to store on the PC C provides an operator sizeof which will return the number of bytes needed to store the variable or constant or data type whose name is placed between the parentheses See what happens if you type and enter sizeof int to the Ch prompt 2 Variables and Constants see sections 2 1 2 …


View Full Document
Download lab1_basic_concepts
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lab1_basic_concepts and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lab1_basic_concepts and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?