DOC PREVIEW
SJSU ME 30 - Week2 Lab Project

This preview shows page 1-2 out of 5 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 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 Week 2 Lab Project Data Types Variables and Formatted Output Introduction The concept of data types is extremely important in learning how to program in C In this lab you will learn about data types how to declare variables and get practice writing your first programs in C Objectives Following completion of today s lab you should be able to List and describe the types of data commonly used C programs for engineering problem solving Distinguish between a variable and a constant Declare variables with valid names and appropriate data type Evaluate arithmetic and conditional expressions correctly according to operator precedence Write C statements to print 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 Download a copy of the Lab Report Template lab rpt tpt doc from Desire2learn or the ME 30 website Use the template to record your answers to the lab exercises Make sure that you fill out the cover page completely before turning in your report Points will be deducted if the cover sheet is not completely filled out Enter your last name first initial and project number in the labeled boxes in the header by double clicking on it Under the section of the cover sheet labeled Summary 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 You can expand the summary to another sheet if needed Save your work on your own USB storage device or email a softcopy to yourself before you leave the lab The hard drives on the computers in the lab are frequently refreshed so do not rely on them for saving your work from session to session Instructions for turning in your Lab Project report Save your report using the following naming convention all lower case lastname firstinitial sec n lab2 report doc where n is your lab section number Tues 2 Wed 3 Thurs 4 so if your name is John Smith and you are in section 3 you must name your file smith j sec 3 lab2 report doc Upload your report and any related files to Desire2Learn under the Week 2 Lab Project Dropbox before the deadline Turn in a hard copy of your report at the beginning of next week s lab session BJ Furman ME 30 Computer Applications Week2LabProject doc 30JAN2010 Page 1 of 5 SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications Laboratory Exercises Follow the instructions below and enter your work in the Lab Report Template You may want to refer to your textbook or the handouts Notes on Variable Names and Notes on Data Types to help you do the exercises Read the Notes below each table before you start on the exercises listed in that table 1 Data Types see Notes on Data Types from the handouts page on the ME 30 website 1 1 For each of the following items identify what kind of data it is for example numeric character string 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 1 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 Notes on Variable Names from the handouts page on the ME 30 website 2 1 Determine whether the following variable names are valid or not Indicate Yes or No and if not valid explain why not Variable name 2 1 1 ABC 2 1 2 var 123 abc 2 1 3 9sub 2 1 4 foo 2 1 5 max rate Notes 2 Valid If not valid explain why not Check your answers by trying to declare the proposed variable name in the Ch shell BJ Furman ME 30 Computer Applications Week2LabProject doc 30JAN2010 Page 2 of 5 SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications 2 2 Declare the following variables and indicate the number of bytes needed store each one Variable s to declare Declaration statement 2 2 1 num1 num2 of integer type initialized to zero 2 2 2 char1 char2 of character type 2 2 3 float 1 of single precision floating point type 2 2 4 float 2 of double precision floating point type 2 2 5 var 1 of unsigned long integer type Notes 3 Bytes Variables can be initialized to a value at the same time they are declared For example int i 3 declares i to contain a value of integer data type and the value it contains is initialize to 3 3 Operators and Precedence see Appendix A in D D 3 1 For the expressions listed try to determine first by hand what you expect the value of the expression to be using the rules of precedence and the rules of arithmetic with mixed data types in other words DO NOT use the computer to fill out the second column You can use a calculator if needed Then fill out the third column by typing the expression and using Ch to evaluate it Don t change the value you determined by hand if the one determined by Ch is different Fill out the fourth and fifth column with the type and the size of the result in bytes Expression 3 1 1 2 12 3 1 3 1 2 2 12 3 1 3 1 3 2 12 3 1 3 1 4 2 0 12 3 1 3 1 5 10 100 3 1 6 100 10 3 1 7 22 7 3 1 8 double 22 7 3 1 9 double 22 7 3 1 10 22 0 7 3 1 11 char 22 0 7 3 1 12 char 22 0 7 3 1 13 13 2 3 1 14 14 2 3 1 15 1 3 Notes 4 Eval by hand Eval using Ch Type Size bytes Don t forget to use the up arrow to recover previously typed commands in Ch BJ Furman ME 30 Computer Applications Week2LabProject doc 30JAN2010 Page 3 of 5 SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications 5 For readability it is recommended that you put one blank space between the operator and …


View Full Document
Download Week2 Lab Project
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 Week2 Lab Project 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 Week2 Lab Project 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?