SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications Lab Project 2 Formatted I O and the Basic Structure of a C Program Introduction In this lab session we ll look at how to print out data from your program to the monitor and read in data from the keyboard and we ll get familiar with the structure of a C program The ability to handle input and output referred to as I O is not built in to the C language Rather there are I O functions in a library pre written and compiled bits of code that you can make available for your program to use that we call to handle I O Two of the often used I O functions are printf for formatted output and scanf for formatted input Again today s lab is not meant to be an exhaustive tour of formatted I O but a brief tour to get you up to speed so you can use it quickly Objectives Following completion of today s lab you should be able to Write programs will produce formatted output and take data using formatted input Write programs using a structured approach Procedure Again to save paper follow use the answer sheets by typing your work in the soft copy version of this document Note everyone must turn in an individual lab report at the end of the session Download a copy of this document and fill out the cover sheet completely before starting on your answer sheets Points will be deducted if the cover sheet is not completely filled out If the problem involves you having to write a program to get credit for the problem follow these steps Capture the screen screenshot of your program typed in ChIDE with the output of the program shown at the bottom to prove that it works Do this by pressing the Prt Sc button on your keyboard Past the screenshot on a page of your report Make sure that it is large enough to be legible See the example below BJ Furman ME 30 Computer Applications Lab2project 31AUG2009 doc 31AUG2009 Page 1 of 4 SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications When you write your programs use the structure shown in lecture and also demonstrated in the miles to kilometers c program available on the ME 30 website http www engr sjsu edu bjfurman courses ME30 source miles to kilometers c 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 You can expand the summary to another sheet if needed 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 To get credit for this lab project you must also save your work on the desktop of the computer you used in the E407 lab using the following procedure Save your report using the following naming convention all lower case lastname firstinitial sec n lab1 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 lab1 report doc Upload your report and any related files to Blackboard under the Lab 1 Assignment 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 Lab2project 31AUG2009 doc 31AUG2009 Page 2 of 4 First Initial Last Name SAN JOS STATE UNIVERSITY 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 Lab2project 31AUG2009 doc 31AUG2009 Page 3 of 4 Last Name First Initial SAN JOS STATE UNIVERSITY Department of Mechanical and Aerospace Engineering ME 30 Computer Applications 1 Formatted Output see Chapter 9 in H K 1 1 Write a program that sums two numbers 34 and 15 9 and prints their sum as an output 1 2 Write a program that prints the value 500 with and without a leading sign 1 3 Write a program that prints your first name with a space between each letter 1 4 Write a program that prints your first name with one letter on each line 2 Formatted Input and Output see Chapter 9 in H K 2 1 Write a program that gets two integers from the user echoes the two values back to the user sums the values and prints out their sum 2 2 Write a program that gets two integers from the user echoes the two values back to the user then prints out their product 2 3 Write a program that gets an integer from the user and prints out its value in hexadecimal format BJ Furman ME 30 Computer Applications Lab2project 31AUG2009 doc 31AUG2009 Page 4 of 4
View Full Document