4 Pages

Day22_Ele

Course: COMPE 160, Spring 2012
School: San Diego State
Rating:
 
 
 
 
 

Word Count: 1655

Document Preview

Introduction CompE160 to Programming Marino Day 22 1. The char data type References Deitel Chapter 8 and Appendix B. AsciiCode.doc in folder Misc Google Ascii Code The data type char is used to represent characters, including both printing characters (i.e., letters, numerals, punctuation marks, and a few special characters) and various control characters (e.g., space, horizontal tab, vertical tab, and...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> San Diego State >> COMPE 160

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.
Introduction CompE160 to Programming Marino Day 22 1. The char data type References Deitel Chapter 8 and Appendix B. AsciiCode.doc in folder Misc Google Ascii Code The data type char is used to represent characters, including both printing characters (i.e., letters, numerals, punctuation marks, and a few special characters) and various control characters (e.g., space, horizontal tab, vertical tab, and others). The most widely used code for representing characters for many years has been the American Standard Code for Information Interchange (Ascii, pronounced ask-ee). See the document ASCII Code.doc in directory Misc for a definition of the Ascii code. Appendix B of Deitel also defines the code, but Deitels table is a bit harder to interpret. The length of the char data type for our C compiler is one byte. Most C compilers, including ours, use the first 128 byte values (i.e., the bytes beginning with bit 0) to represent characters using the Ascii code. The remaining 128 byte values (i.e., the bytes beginning with 1) can be used to represent characters not represented by the Ascii code, for example characters in other alphabets, math symbols, etc.. We will confine our discussion to Ascii characters. A few characteristics of the Ascii code that are useful for C-programmers to recognize are the following: The capital letters are sequential starting with decimal 65 (i.e., A is 65, B is 66, etc.). The lowercase letters are sequential, starting with 97 for letter a. The decimal digits are sequential starting with 48 for character 0. The space character is 32. The horizontal tab stop character is 09. The newline character may be represented by either 00001101 (carriage return) or 00001010 (line feed). Which one is used depends upon the compiler (see item 3 below). 2. Hexadecimal and Octal Representation of Binary Words Octal notation is a shorthand notation for representing binary words. The bits of a binary word are separated into groups of 3 bits, starting from the right. Each group of 3 bits is represented by a single decimal digit: 0 represents 000; 1 represents 001; 2 represents 010; 7 represents 111. For example, the binary word 11101110 is represented in octal notation as 356. Hexadecimal notation is the same as octal notation, except that the binary word is separated into groups of 4 bits each. Since there are 16 different 4-bit words and only 10 decimal digits, we need 6 additional symbols to represent words 1010, 1011, 1111. The first 6 letters of the alphabet are used for this purpose: A represents 1010; B 1 CompE160 Introduction to Programming Marino represents 1011; F represents 1111. For example, the word 11000101 is represented in hexadecimal notation as C5. Octal and hexadecimal notation are normally used simply as shorthand representations of binary words. The words themselves may represent any sort of information (e.g., integer values, characters, floating point values, colors, etc.). However, octal notation may also be thought of as the base-8 representation of an integer value. For example, the octal word 273 may be thought of as representing the integer 2*82 + 7*81 + 3*80 = 2*64 + 7*8 + 3*1 = 187. Similarly, hexadecimal notation can be thought of as the base-16 representation of an integer value. For example, the hexadecimal word 3CE may be thought of as representing the integer value 3*162 + 12*161 + 14*160 = 3*256 + 12*16 + 14*1 = 974. The C language allows hexadecimal notation to be used to represent integer values. To indicate that an integer constant is being specified using hexadecimal notation, precede the hex characters with 0x. For example, if x is an integer variable, the statement x = 0x3CE; assigns the decimal value 974 to variable x. 3. Representing Character Values in a Program In a C program, character values (character constants) are represented in single quotes. For example, 'A' represents the byte 01000001. Notice that the letter A by itself (i.e., without the enclosing quotes) cannot be used to represent the Ascii character value for letter A because the letter A by itself would be interpreted by the compiler as the name of a variable. A few non-printing character values are represented by a "escape sequences". Some of these we have already been using in strings. The most important of these are '\n' for newline; '\t' for horizontal tab; '\b' for 00001000 (backspace); and '\a' for 00000111 (bell or beep a for audible). For other special characters that are represented by escape sequences, see Deitel, Section 9.10. Any character value can be represented by an escape sequence that specifies the Ascii byte in octal notation. For example, '\014' represents 00001100 (the formfeed character, ff), and '\101' represents 01000001 (character A). C also allows hexadecimal representation of characters in escape sequences. For example, \x41 represents 01000001 (capital A). Octal notation was widely used when C was first developed, but hexadecimal notation is more commonly used today. 4. char Variables Variables of type char are declared and initialized in the usual way. For example, the declaration c1, statement char c2 ='A'; allocates memory for two char variables named c1 and c2 (one byte each), and initializes variable c2 to 01000001. C allows the arithmetic operators (+, -, *, /, and %) and the relational operators (<, <=, >, >=, ==, and !=) to be used with the char data type. Hence it is possible to use a char variable as a one-byte integer variable. In fact, a char variable may be declared as either signed (Two's Complement code range -128 through +127) or unsigned (straight Base 2 code range 0 through 255). Which one is the default when a variable is simply declared char depends on the compiler. To determine the 2 CompE160 Introduction to Programming Marino default type for your compiler, execute the statements: char c = '\777'; printf("c = %d\n", c); If the output is "c = 255", the data type char is unsigned char; if the output is "c = -1", the data type char is signed char. 5. Using Arithmetic with char Variables Arithmetic operators are useful for processing characters. For example, if a char variable c represents an uppercase letter, it may be converted to lowercase by executing the statement c = c + 32; since the Ascii code for each lowercase letter is 32 greater than the Ascii code for the uppercase version (e.g., to convert A to a, add 32: 65 + 32 = 97). Equivalently (and better), c = c + ('a' 'A'); As another example, suppose that c is a char variable and x is an int variable. If c represents a decimal digit ('0' through '9'), then the following statement will assign to x the numeric value of the digit: x = c '0'; 6. Library Functions for Processing Characters The C runtime library provides a collection of functions for processing character data. These functions are in the sub-library ctype (header file ctype.h). The ctype functions are all simple, and have names that suggest their purpose (e.g., toupper converts lowercase letters to uppercase; isdigit returns true if a character is a decimal digit and false otherwise; isxdigit returns true if a character is a hexadecimal digit, false otherwise). The ctype functions all have a single parameter variable of type int. This seems odd, since the input information is normally a character, not an int. However, C requires that the int data type be at least as long as the char data type, so a char variable can be specified as the argument in a call to a ctype function. It will automatically be converted to an int without loss of information. Exercises 1. Write a program that prints out a few characters using the hexadecimal escape sequence notation to represent the characters. Include control characters as well as printing characters from the Ascii table. To see the effect of some of the special characters, try embedding the control characters in a sequence of normal printing characters. For example, try the statement printf("%c%c%c%c%c\n", '\x41', '\x42', '\x08', '\x43', '\x44' ); Refer to the Ascii table to explain the output. Aside. Octal notation is not often used today. But you may occasionally see it in older programs. The above printf statement would be written using octal escape sequences instead of hexadecimal as follows: printf("%c%c%c%c%c\n", '\101', '\102', '\010', '\103', '\104' ); Execute this statement to verify that this is so. 3 CompE160 Introduction to Programming Marino 2. The CarriageReturn and LineFeed characters ('\x0D' and '\x0A') are often troublesome, because not all systems handle them the same way. Experiment to see how your system handles these characters. For example, try the statements printf("%c%c%c%c%c\n\n", printf("******\n"); printf("%c%c%c%c%c\n\n", printf("******\n"); printf("%c%c%c%c%c\n\n", printf("******\n"); printf("%c%c%c%c%c\n\n", printf("******\n"); printf("%c%c%c%c%c\n\n", '\x41', '\x42', '\x0A', '\x43', '\x44' ); '\x41', '\x42', '\x0D', '\x43', '\x44' ); '\x41', '\x0A', '\x0D', '\x43', '\x44' ); '\x41', '\x0D', '\x0A', '\x43', '\x44' ); '\x41', '\x0D', '\x42', '\x0A', '\x43' ); 3. The newline character \n represents the control operation go to the beginning of the next line. But the operation of going to the next line actually is represented by a sequence of two Ascii characters: LineFeed \0A and CarriageReturn \0D . The way \n is represented in memory may vary from one system to another. It might be represented by \0A or by \0D , or by both \0A and \0D . Write a program that determines how \n is represented on your system. 4. Write a program that prompts the user to enter an integer between 1 and 117 and then prints the characters associated with that integer and the next 9 consecutive integer values, all on the same line. Explain the output that is produced by consulting an Ascii table 5. Try running the program of the previous exercise and entering larger integers, for example, try entering 321 or 577. Can you explain the output that is produced? 6. Write your own versions of the library functions isdigit, isalnum, isxdigit, toupper and tolower. 4
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:

San Diego State - COMPE - 160
Chapter 2Answers to Selected Exercises 2. [was #2] (a) The program contains one directive (#include) and four statements (three calls of printf and one return). (b)Parkinson's Law: Work expands so as to fill the time available for its completion.3. [wa
DeVry Chicago - MANAGEMENT - 340
Case Study Week 6Read the &quot;Pine Valley Furniture&quot; Case at the end of Chapter 10 under Case Problemsand answer question 1, parts a through d (pp. 376).a. Locate a technical writing article on the Web. Briefly summarize this article.Source: www.dailywri
DeVry Chicago - MANAGEMENT - 340
Chapter1:ReviewQuestionsSolutions1. What is information systems analysis and design?Information systems analysis and design is the process of developing andmaintaining an information system.2. What is systems thinking? How is it useful for thinking ab
DeVry Chicago - MANAGEMENT - 340
Chapter2:ReviewQuestionsSolutions1. Describe and compare the six sources of software.The six sources of software identified in the textbook are: (1) informationtechnology services firms, (2) packaged software providers, (3) vendors ofenterprise soluti
DeVry Chicago - MANAGEMENT - 340
Chapter3:ReviewQuestionsSolutions1.Discuss the reasons why organizations undertake information system projects.Information system projects are undertaken for two primary reasons: to take advantageof business opportunities and to solve business problems
DeVry Chicago - MANAGEMENT - 340
Chapter4:ReviewQuestionsSolutions1. Describe the project identification and selection process.Organizations vary as to how they identify projectssome projects are identifiedby top-down initiatives while others are identified by bottom-up initiativesand
DeVry Chicago - MANAGEMENT - 340
Chapter6:ReviewQuestionsSolutions1. What is a data-flow diagram? Why do systems analysts use data-flowdiagrams?A data-flow diagram is a picture of the movement of data between external entitiesand the processes and data stores within a system. Systems
DeVry Chicago - MANAGEMENT - 340
Chapter7:ReviewQuestionsSolutions1.What characteristics of data are represented in an E-R diagram?An E-R diagram shows many characteristics of data, including the definition,structure, and relationships within data. Additionally, this diagram showscar
DeVry Chicago - MANAGEMENT - 340
Chapter8:ReviewQuestionsSolutions1. Describe the prototyping process of designing forms and reports. Whatdeliverables are produced from this process? Are these deliverables thesame for all types of system projects? Why or why not?Designing forms and r
DeVry Chicago - MANAGEMENT - 340
Chapter9:ReviewQuestionsSolutions1. What is the purpose of normalization?The purpose of normalization is to rid relations of anomalies. The goal is to formwell-structured relations that are simple and stable when data values change ordata are added or
DeVry Chicago - MANAGEMENT - 340
WEEK1InformationSystemsAnalysisandDesignAllorganizationshaveinformationsystems,andusethemforoperational,tactical,andstrategicadvantage.For informationsystemstoremaineffective,thesesystemsmustefficientlycapture,store,process,anddistributeinformation ac
DeVry Chicago - MANAGEMENT - 340
Problems and Exercises Week 6Chapter 10: questions 1, 6, and 13 (pp. 375)(I dont know why, but I answered question 3 also so I left it)1) One of the difficult aspects of using the single location approach to installationis choosing an appropriate loca
DeVry Chicago - MANAGEMENT - 340
Week 1TCOs 1, 2, 3What are some of the key roles and skills a Systems Analyst needs to succeed that are mentioned in our book?DoestheroleofanSAdependontheorganization.Forexample,wouldthisbeaspecificjobinalargerorganizationbutmaybeanadditional responsi
DeVry Chicago - MANAGEMENT - 340
Week 1 Discussion 2TCOs 1, 2, 3What are the phases of the traditional SDLC? In your own words, tell us what is significant about that phase.What are the six types of CASE tools?How can CASE tools aid the Systems Analyst when developing a system?What
DeVry Chicago - MANAGEMENT - 340
Week 2 Discussion 1TCOs 1, 2, 6What is an RFP, and how do analysts use one to gather information about hardware and system software?What are the differences between ASPs and MSPs?Whatiscloudcomputing?Howdotheseconceptsrelatetocloudcomputing?What meth
DeVry Chicago - MANAGEMENT - 340
Week 3 Discussion 2TCOs 2, 6There are six factors used in assessing project feasibility. They are economic, operational, technical, schedule, legal and contractual,and political. Which one of these six assessment factors is the most important? Why? Can
DeVry Chicago - MANAGEMENT - 340
Week 4 Discussion 1TCOs 3, 4, 5Data collection takes a lot of time. Therefore, it is not worth the time and trouble. What do you think? What are some faster ways toaccomplish data collection?Let's look at other methods to collect information for syste
DeVry Chicago - MANAGEMENT - 340
Week 4 Discussion 2TCOs 3, 4, 5Data flow diagrams can be hard to develop and understand. In simple system design, data flow diagrams and process models may notbe necessary. What do you think about not using data flow diagrams in some cases?Explain the
DeVry Chicago - MANAGEMENT - 340
How would you assess a system's usability? How would you know when a system was&quot;usable&quot;?Once the system is complete I would have internal evaluation or validation of the functionality as well as the usabilityof the system. The initial assessment or eva
DeVry Chicago - MANAGEMENT - 340
CUSTOMER PROFILEName:LastFirstMIStreetCityStateAddress:Phone:(XXX)XXX-XXXXEmail:Gender:Birth Year:Ethnicity:HouseholdIncome Range:Household FamilySize:Education Level:OccupationalIndustry:Comments:ZipProducts by Demographics Summar
DeVry Chicago - MANAGEMENT - 340
Chapter 8 Review QuestionsProblems and Exercises - Chapter 8: questions 1, 2, 3, and 4 (pp. 283)1.Describe the prototyping process of designing forms and reports. Whatdeliverables are produced from this process? Are these deliverables the same forall
DeVry Chicago - MANAGEMENT - 340
Pine Valley Furniture Case StudyWeek 5a.What data will the Customer Profile Form need to collect? Using the guidelinespresented in the chapter, design the Customer Profile Form.CUSTOMERPROFILEName:LastFirstMIStreetCityStateAddress:Phon
DeVry Chicago - MANAGEMENT - 340
Week 7 Problems and Exercises Appendix B1) When should you use an Agile method, and when should you use anengineering-based method for developing a system? Support your answer.An Agile or adaptive process is recommended if your project involves unpredi
DeVry Chicago - MANAGEMENT - 340
In what way are organizations systems? \In general a system is a collection of subsystems incorporated to achieve an overall goal. Systems have inputs, processes, outputsand outcomes, with ongoing feedback among these various parts. If one part of the s
DeVry Chicago - MANAGEMENT - 340
MGMT340Week 1 HomeworkProblems and Exercises - Chapter 1: question 1 and question 10 (pp. 27)1. Why is it important to use systems analysis and design methodologies when building asystem? Why not just build the system in whatever way seems to be quick
DeVry Chicago - MANAGEMENT - 340
1)What is an RFP, and how do analysts use one to gather information about hardware and system software?According to our text a request for proposal (RFP) is a document provided to vendors to ask them to propose hardware and systemsoftware that will mee
DeVry Chicago - MANAGEMENT - 340
Problems and ExercisesChapter 2: Questions 2 &amp; 32. Review the criteria for selecting off-the-shelf software presented in this chapter. Use yourexperience and imagination and describe other criteria that are or might be used to select offthe-shelf softw
DeVry Chicago - MANAGEMENT - 340
MGMT340Week 1 Pine Valley Case StudyPine Valley Case Study Question 1, parts a through d (pp. 27-28)a. How did Pine Valley Furniture go about developing its information systems? Why do youthink the company chose this option? What other options were av
DeVry Chicago - MANAGEMENT - 340
MGMT 340 Week 4 HomeworkProblemsandExercisesChapter5:questions3and5(pp.160)3.Suppose you were asked to lead a JAD session. List 10 guidelines you would follow inplaying the proper role of a JAD session leader.JAD sessions should be offsite,Proper p
DeVry Chicago - MANAGEMENT - 404
Review QuestionsName: _1.What is the difference between a main summary task and a summary task?Main summary task represent the entire project and summary tasks represent the phases of the projectwhich fall below the main summary task on a Gantt chart
Johns Hopkins - ECON - 607
Problem set 12607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single subm
Johns Hopkins - ECON - 607
Problem set 12607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single subm
Johns Hopkins - ECON - 607
Problem set 11607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single subm
Johns Hopkins - ECON - 607
Problem set 11607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single subm
Johns Hopkins - ECON - 607
Problem set 10607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single subm
Johns Hopkins - ECON - 607
Problem set 10607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single subm
Johns Hopkins - ECON - 607
Problem set 9607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single submi
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Problem set 8607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single submi
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Problem set 7607: Applied MacroeconometricsFall 2009Jon FaustThe following is due at the beginning of next class. You can turn in anypaper in my mailbox or in class; email me and requested computer work.You may work in groups; hand in a single submi
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Empirical rejection frequency- nominal 5 percent t-test- t stats. with 5 std. err. estimates- No heterosked. in epspiT:3050100200-0.0000.0690.0610.0560.0490.0930.0760.0630.0510.0780.0670.0580.0490.0600.0580.0540.0460.0700.0650
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Johns Hopkins - ECON - 607
Spectrum analysis and bootstrapNatsuki AraiJohns Hopkins UniversityMacroeconometrics Class Presentation, JHU, 11/11/09Natsuki Arai (JHU)Macroeconometrics Class Presentation11/11/091 / 14Why is spectrum analysis useful?Why is spectrum analysis use
Johns Hopkins - ECON - 607
Seasonal AdjustmentJiae YooJHU EconomicsNovember 4, 2009Jiae YooSeasonal AdjustmentOutlineTime series and Seasonal adjustmentBasics of the SSAA (X-11, X-12-ARIMA)End sample problem2-sided lter and Rational expectationsSeasonal factor: Departmen
Johns Hopkins - ECON - 607
Cyclical Components of GDPBlair ChapmanJohns Hopkins UniversityOctober 27, 2009Blair Chapman (Johns Hopkins University)Cyclical Components of GDPOctober 27, 20091 / 15IntroductionOverview:GDPRegressionsHodrick-Prescott FilterCorrelations amon
Johns Hopkins - ECON - 607
Brief data analysis of associationbetween GDP growth and somebetween GDP growth and somepolitical and economic factorsYichen QinMacroconometrics 607class presentationOct 21st, 20091Brief outline1. Data description2. Data challengeData challeng
Johns Hopkins - ECON - 607
Integration and co-movementin the G-7 countriesChiara Lo PreteJohns Hopkins UniversityOctober 7th, 2009OutlineOutline1. Trends in mean and standard deviation of GDP,consumption and investment growth in the G-7countries2. Evidence on rising econo
Johns Hopkins - ECON - 607
Uncovered Interest Parity (UIP)Yoichi GotoSeptember 30, 2009Uncovered Interest Parity Relation (1/2)Uncovered Interest Parity (UIP) relation states that domestic andforeign bonds must have the same expected rate of return in termsof a common currenc
Johns Hopkins - ECON - 607
OutlineMacroeconometrics PS3The Problem of Vintage DataXi YangJohns Hopkins UniversitySeptember 23, 2009Xi YangThe Problem of Vintage DataOutlineMacroeconometrics PS31 Macroeconometrics PS3Introduction of the Process of Data VintageHow Much Do
Johns Hopkins - ECON - 607
Measures of inflationMacroeconometrics16-09-2009Michele MazzoleniTopicsTopicsSourcesInflation rate over timeLevel comparison: different cost of lifeSub-components of CPI and policymakingConclusionsSourcesSourcesFor CPI and subcomponents:www