Week_2

Course: ENEE 140, Fall 2008
School: Maryland
Rating:
 
 
 
 
 

Word Count: 939

Document Preview

2: Laboratory Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information a. name your program with extension .c b. use o option to specify the name of the executable. For example, gcc hello.c o hello c. "main ()" used in the book is the same as "int main(void)" we used in class in the hello_comment.c 3. Comment: a. Single line...

Register Now

Unformatted Document Excerpt

Coursehero >> Maryland >> Maryland >> ENEE 140

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
2: Laboratory Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information a. name your program with extension .c b. use o option to specify the name of the executable. For example, gcc hello.c o hello c. "main ()" used in the book is the same as "int main(void)" we used in class in the hello_comment.c 3. Comment: a. Single line comment b. Multiple line comment c. Where comments should be added i. At the very beginning of the program ii. Variable declaration iii. Function declaration and implementation iv. Non-trivial (small) block of statements v. Code segment added for testing/debugging purpose 4. functions and variables: two components that make a program 5. Variables a. Variable declaration: <type variable_name;> b. Basic data types in C: char, int, float, double c. Variable name: i. Any letter, digits, and _ (underscore) can be in a variable name. ii. The first character must be letter or _. iii. Variable name should have less than 31 characters. iv. Variable names are case sensitive. v. The following keywords are reserved: auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while d. Tips on naming variables: i. Give meaningful names, but not too long (you need to type them) radius, color, exam_1, proj_2, StudentID. ii. Use upper case letters and _ (occasionally, e.g., between words) to increase readability abadexofvarname, AGoodVarNameEx, a_good_var_name_ex. iii. Add a short comment: float radius; // radius of the circle, read from input iv. Assign safe initial values if possible. float sum = 0; // the sum of my three exam scores int max = 0; // the maximum among some integers. Note that this // this initial value is not safe. e. Assign values to variables: i. Direct assignment: radius = 1.5; ii. Declare variable and assign initial value: float sum = 0; iii. Result of some computation: area = 3.14 * radius * radius; iv. Read in from input (see below): scanf() 6. Define constants: a. Why we need to declare constant as a variable (instead of simply using its value)? b. Two ways to define a constant variable in C: const float PI = 3.14159; const int SIZE = 85; #define PI 3.14159 #define SIZE 85 c. Pay attention to the differences between these two constant variable declarations. 7. Basics on printf() and scanf(): a. Print out a text message: b. Read in a value c. Print out the value of a variable printf("Hello, world!"): scanf("%f", &radius); printf("%f", radius); d. %: format indicator. It tells functions such as scanf() and printf() what is the data type of the variable to be expected. %f for variable of type float and double %d or %i for variable of type int (d stands for decimal integer) %c for variable of type char 8. circle.c Lab Description 1. Objectives: a. Write very simple programs practice to variable declaration, reading input from standard keyboard and performing simple arithmetic operations.. b. Get familiar with UNIX and its text editors (vi and/or emacs). 2. Pre-lab preparations: Reading assignments are for our textbook (Applied C, Fischer et al.) a. Reading: Chapters 1 and 2 and Sections 3.1 through 3.5 of Chapter 3 b. Read the codes posted for week 2. 3. In-lab description: Name: ________________ Lab Report Section: 010_ Date: _________ 1. Debug the following code, first by observation and then verify it on the computer (by modifying the code, compiling it, and executing it). Enumerate the bugs that you find and correct them. You can correct on the original code. (These code are posted in the blackboard, bugs.c in the documentation section, for your convenience. Remember to comment out unnecessary parts and check file name.) a. include <stdio.h> int main(void) {printf(Tuesday\nFeb. 3, 2009\n"); return 0; } Bugs that you find in the program: Which one(s) you did not find? b. #include <stdio.h> int main(void) {print(Tuesday\nFeb. 3, 2009\n"); return 0, } Bugs you find in the program: Which one(s) you did not find? c. #include printf( "Tuesday /n " ); printf( "Feb. 3, 2009/n"); return 0; Bugs you find in the program: Which one(s) you did not find? d. #Include <stdio.h> Int Main() { Printf("Tuesday \n"); Printf("February 3, 2009\n"); Return 0; } Bugs you find in the program: Which one(s) you did not find? e. # include <stdio.h> Int main (void) { printf( "Tuesday /n") printf("Feb. 3, 2009 /n"); return 0; } Bugs you find in the program: Which one(s) you did not find? Total number of bug(s) that you have missed from codes a-e:____________________ 2. Where do you expect the following three statements on variable declarations and what are the differences among them? 1) float PI_1 = 3.1416; 2) const float PI_2 = 3.1416; 3) #define PI_3 3.1416 Read the file comment.txt in the documents section on blackboard. Think about how you would like to comment one line, multiple lines, etc. and use your style consistently in the programs for questions 3-5 (and hopefully for all your programs in the future. Of course, your style might change from time to time as you learn more and more in programming.) 3. Write a complete C-code (including the documentation) which asks the user to input the length and width of a rectangle, and outputs its area and perimeter, assume both length and width are integers. 4. Write a complete C-code (including the documentation) to compute a student's average grade over 3 projects. The individual project scores range from 0.0 to 100.0. 5. Modify the hello_comment.c code so it asks the user which section he/she is in and then prints out the following : (e.g. on input 0101) (note, it will be a little tricky to print out the first 0 in 0101. But there are a couple of ways to do that. ) Hello, welcome to ENEE 140 section 0101.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Maryland - ENEE - 757
The Domain Name SystemAuthor: Paul Mockapetris 1987The old approach: ARPANET : Host name to IP address mapping using a centralized database (i.e., HOSTS.TXT file) maintained by the Network Information Center (NIC) HOSTS.TXT file is ftp-ed daily
Maryland - CMSC - 102
Announcements Project #2 posted. Please start early1Unix Login into linux.grace.umd.edu/solaris.grace.umd.edu Login out (two alternatives) logout exit Commands are case sensitive Listing files ls listing of files in a directory ls -al
Maryland - CMSC - 412
CSMC 412Operating Systems Prof. Ashok K Agrawala 2006 Ashok Agrawala Set 1010.1ObjectivesTo explain the function of file systems To describe the interfaces to file systems To discuss file-system design tradeoffs, including access methods, fil
Maryland - CMSC - 631
Type-Based Flow Analysis: From Polymorphic Subtyping to CFL-ReachabilityJakob Rehof and Manuel FhndrichType-Based Program AnalysisCommon vocabulary Data access paths Function summary Context-sensitivity Directional flow Type-based Type struc
Maryland - CMSC - 433
USENIX COOTS '98April 27, 1998Optimistic Policies: TryingIsolate state into versions E.g. by grouping into a helper class Isolate state changes to atomic commit method that swaps in new state On method entry Save/record current state Apply actio
Maryland - CMSC - 433
Iteration CMSC 433 Programming Language Technologies and Paradigms Fall 2003Iterators and Design Patterns September 25, 2003 Goal: Loop through all objects in an aggregateclass Node { Element elt; Node next; } Node n = .; while (n != null) { .; n
Maryland - CMSC - 433
Administrivia CMSC 433 Programming Language Technologies and Paradigms Spring 2005Iterators and Design Patterns February 15, 2005 Other resources: Thinking in Patterns with Java Link from the class web page Gamma, Helm, Johnson, Vlissides, Des
Maryland - CMSC - 714
Sisal FAQThe Sisal Model of Functional Programming and its Implementation Jean-Luc Gauditot, et al. Presented by Nick RutarWhat does Sisal stand for?Stream and Iteration in a Single Assignment LanguageWhat kind of language is it?Sisal is a func
Maryland - CMSC - 250
Predicate Calculus Subject / Predicate John / went to the store. The sky / is blue. Propositional Logic - uses statements Predicate Calculus - uses predicates predicates must be applied to a subject in order to be true or falseQuantification x
Maryland - CMSC - 631
C ONTEXT- SENSITIVE C ORRELATION A NALYSIS FOR R ACE D ETECTIONPolyvios Pratikakis Jeff Foster Michael Hicks University of Maryland, College ParkContext-sensitive Correlation Analysis for Detecting Races p.1/28Data RacesRace: two threads acces
Maryland - CMSC - 433
(Incomplete) History of GUIsCMSC 433 Programming Language Technologies and Paradigms Spring 2004 1973: Xerox Alto 3-button mouse, bit-mapped display, windows 1981: Xerox Star Double-clicking, overlapping windows, dialogsGraphical User Interf
Maryland - PHYS - 122
Physics 122Final Exam 2 p. 2Name_ Section_Just the answer counts for these. (8 points each) 1) Two little beads have charges on them, q and 2q, a distance d apart. What is the strength and direction of the electric field at a point I marked X
Maryland - HONR - 278
LSU - PHYS - 2102
LSU - APPL - 003
Car reers2Geaux SignUpforO S OnCampusIn nterviewsCareers2Geau C ux SignUpforOnCampus sInterviews TWWW.LSU.EDU/CAREER VISIT Clic ckCareers2Ge eaux. Log ginorcreatea anaccount. TOPNAVIGATIO ONBAR) HOVEROVERMYACCOUNT(T Clic ckMyProfile. Ma ak
LSU - EXST - 7005
EXPERIMENTAL STATISTICS 7005 April 15, 1999NAME _ EXAM 3 All sections : GeaghanRead Carefully. Give an answer in the form of a number or numeric expression where possible. Show all calculations for possible partial credit. Use a value of 0.05 for
LSU - EXST - 7025
1000 900 800Mortality over timeFish Stock Stock700Nt 600500 400 Fishing mortality 300 200 Total mortality 100 0 0 5 10 15 20 25 30 Natural mortalityTime1600 1400 1200Catch per boat dayN0Leslie modelCatch per unit of effortLesli
LSU - EXST - 7005
Outline1) Continuous random variable 2) Uniform distribution 3) Normal distribution 4) Normal approximation of binomial distributionEXST7005 - Statistical Techniques I1Continuous Random Variable A continuous RV, X takes values x anywhere RV i
LSU - EXST - 7013
Reference/Additional Material: Simple Linear Regression1 Introduction Regression analysis is a statistical method for analyzing a relationship between two or more variables in such a manner that one variable can be predicted or explained by using th
LSU - EXST - 7013
Categorical Data AnalysisIntroduction In subject areas such as the social and behavioral sciences, we often encounter data in which the possible outcomes are categories. One example of these type of data are eye color (hazel, blue, brown, green), wh
Virginia Tech - ETD - 07212000
On a turbo decoder design for low power dissipationBy Jia Fei Dissertation submitted to the Faculty of the Virginia Polytechnic Institute and State University in partial fulfillment of the requirements for the degree of Master of Science In Electric
Virginia Tech - ETD - 04222003
Interference Measurements and Throughput Analysis for 2.4 GHz Wireless Devices in Hospital EnvironmentsbySeshagiri KrishnamoorthyThesis submitted to the faculty of the Virginia Polytechnic Institute and State University in partial fulfillment of
Virginia Tech - SRS - 4702
A High Performance Micro Channel Interface for Real-Time Industrial Image Processing ApplicationsThomas H. Drayer, Joseph G. Tront, and Richard W. ConnersBradley Department of Electrical Engineering, Virginia Polytechnic Institute and State Univers
Virginia Tech - ETD - 12192000
Factors Influencing Biotite WeatheringbyRyan Ronald Reed Thesis submitted to the Faculty of the Virginia Polytechnic Institute and State University in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE in Crop and Soil Env
LSU - APPL - 003
LSU - PHYS - 2102
LSU - PHYS - 2102
Todays lectureAmperes law, a powerful tool to compute magnetic fields.To compute magnetic fields, one uses the Biot-Savart law:r r r 0 i d s r dB = 4 r 3And it is evident that the Biot-Savart law is harder to use than Coulombs law. Now, even
LSU - PHYS - 7231
January 22, 2009PHYS 7231Homework 2 Due date: January 29, 20091. Calculate a. the components of grad ( r) in spherical polar coordinates, b. div er , grad div er , curl er , div e , curl e in spherical polar coordinates, c. the components of cur
LSU - PHYS - 2101
Formula Sheet for LSU Physics 2101, Summer '07, Exam 3.Units: 1 m = 39.4 in = 3.28 ft 1 rev = 360 = 2 rad 1 mi = 5280 ft 1 atm = 1.013105 Pa 1 min = 60 s 1 N = 0.225 lb 1 day = 24 h 1 atmL = 101.22 J 1 h = 60 minConstants: g = 9.8 m/s2 G = 6.6710-
LSU - PHYS - 2101
Formula Sheet for LSU Physics 2101, Summer 07, Final Exam.Units: 1 m = 39.4 in = 3.28 ft 1 rev = 360 = 2 rad 1K TC + 273.15 K T = 1 C 1 mi = 5280 ft 1 atm = 1.013105 Pa 9 F TF = TC + 32 F 5 C 1 min = 60 s 1 N = 0.225 lb 1 cal = 4.186 J MEarth = 5.98
LSU - PHYS - 2101
Formula Sheet for LSU Physics 2101, Spring 07.Units: 1 m = 39.4 in = 3.28 ft 1 rev = 360 = 2 rad 1K TC + 273.15 K T = 1 C 1 mi = 5280 ft 1 atm = 1.013105 Pa 9 F TF = TC + 32 F 5 C 1 min = 60 s 1 h = 60 min 1 cal = 4.186 J MEarth = 5.981024 kg MM oon