欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    高级语言程序设计cha.ppt

    • 资源ID:6358482       资源大小:1.63MB        全文页数:76页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    高级语言程序设计cha.ppt

    A First Book of ANSI CFourth Edition,Chapter 2Getting Started in C Programming,A First Book of ANSI C,Fourth Edition,2,Objectives,Introduction to C ProgrammingProgramming StyleData TypesArithmetic Operations,A First Book of ANSI C,Fourth Edition,3,Objectives(continued),Variables and DeclarationsCase Study:Temperature ConversionCommon Programming and Compiler Errors,A First Book of ANSI C,Fourth Edition,4,Introduction to C Programming,A First Book of ANSI C,Fourth Edition,5,Introduction to C Programming(continued),C provides a comprehensive set of functionsStored in a set of files known as the standard libraryThe standard library consists of 15 header files,A First Book of ANSI C,Fourth Edition,6,Introduction to C Programming(continued),A First Book of ANSI C,Fourth Edition,7,Introduction to C Programming(continued),A First Book of ANSI C,Fourth Edition,8,Identifiers,Identifiers in C consist of three types:Reserved wordsStandard identifiersProgrammer-created identifiers,A First Book of ANSI C,Fourth Edition,9,Identifiers(continued),Reserved word:word that is predefined by the programming language for a special purpose and can only be used in a specified manner for its intended purposeAlso referred to as keywords in C,A First Book of ANSI C,Fourth Edition,10,Identifiers(continued),A First Book of ANSI C,Fourth Edition,11,Identifiers(continued),Standard identifiers:words predefined in CMost of the standard identifiers are the names of functions that are provided in the C standard libraryIt is good programming practice to use standard identifiers only for their intended purpose,A First Book of ANSI C,Fourth Edition,12,Identifiers(continued),A First Book of ANSI C,Fourth Edition,13,Identifiers(continued),Programmer-created identifiers:selected by the programmerAlso called programmer-created names Used for naming data and functionsMust conform to Cs identifier rulesCan be any combination of letters,digits,or underscores(_)subject to the following rules:First character must be a letter or underscore(_)Only letters,digits,or underscores may follow the initial characterBlank spaces are not allowedCannot be a reserved word,A First Book of ANSI C,Fourth Edition,14,Identifiers(continued),Examples of invalid C programmer-created names:4ab7calculate totalwhileAll uppercase letters used to indicate a constantA function name must be followed by parentheses An identifier should be descriptive:degToRadians()Bad identifier choices:easy,duh,justDoIt C is a case-sensitive languageTOTAL,and total represent different identifiers,A First Book of ANSI C,Fourth Edition,15,The main()Function,A First Book of ANSI C,Fourth Edition,16,The main()Function(continued),Function header line,Executable statements,A First Book of ANSI C,Fourth Edition,17,The printf()Function,printf()formats data and sends it to the standard system display device(i.e.,the monitor)Inputting data or messages to a function is called passing data to the functionprintf(Hello there world!);Syntax:set of rules for formulating statements that are“grammatically correct”for the languageMessages are known as strings in CA string of characters is surrounded by double quotesprintf(Hello there world!);,A First Book of ANSI C,Fourth Edition,18,The printf()Function(continued),Function arguments,A First Book of ANSI C,Fourth Edition,19,The printf()Function(continued),Comment,Preprocessor command,Header file,Invoking or calling the printf()function,A First Book of ANSI C,Fourth Edition,20,The printf()Function(continued),Output is:Computers,computers everywhereas far as I can C,Newline escape sequence,A First Book of ANSI C,Fourth Edition,21,Programming Style:Indentation,Except for strings,function names,and reserved words,C ignores all white spaceWhite space:any combination of one or more blank spaces,tabs,or new linesIn standard form:A function name is placed,with the parentheses,on a line by itself starting at the left-hand cornerThe opening brace follows on the next line,under the first letter of the function nameThe closing function brace is placed by itself at the start of the last line of the function,A First Book of ANSI C,Fourth Edition,22,Programming Style:Indentation(continued),Within the function itself,all program statements are indented two spacesIndentation is another sign of good programming practice,especially if the same indentation is used for similar groups of statementsDont do this:intmain()printf(Hello there world!);return 0;,A First Book of ANSI C,Fourth Edition,23,Programming Style:Comments,Comments help clarify what a program does,what a group of statements is meant to accomplish,etc.The symbols/*,with no white space between them,designate the start of a comment;the symbols*/designate the end of a comment/*this is a comment*/Comments can be placed anywhere within a program and have no effect on program executionUnder no circumstances may comments be nested/*this comment is/*always*/invalid*/,A First Book of ANSI C,Fourth Edition,24,Programming Style:Comments(continued),A First Book of ANSI C,Fourth Edition,25,Data Types,Data type:set of values and a set of operations that can be applied to these valuesBuilt-in data type:is provided as an integral part of the language;also known as primitive type,A First Book of ANSI C,Fourth Edition,26,Data Types(continued),A First Book of ANSI C,Fourth Edition,27,Data Types(continued),A literal is an acceptable value for a data typeAlso called a literal value or constant2,3.6,8.2,and Hello World!are literal values because they literally display their values,A First Book of ANSI C,Fourth Edition,28,Data Types(continued),A First Book of ANSI C,Fourth Edition,29,Integer Data Types,A First Book of ANSI C,Fourth Edition,30,Integer Data Types(continued),int:whole numbers(integers)For example:0,-10,253,-26351Not allowed:commas,decimal points,special symbolschar:stores individual characters(ASCII)For example:A,$,b,!,A First Book of ANSI C,Fourth Edition,31,Integer Data Types(continued),A First Book of ANSI C,Fourth Edition,32,Integer Data Types(continued),A First Book of ANSI C,Fourth Edition,33,Integer Data Types(continued),A First Book of ANSI C,Fourth Edition,34,Floating-Point Data Types,A floating-point value(real number)can be the number zero or any positive or negative number that contains a decimal pointFor example:+10.625,5.,-6.2,3251.92,+2Not allowed:commas,decimal points,special symbolsfloat:single-precision numberdouble:double-precision numberStorage allocation for each data type depends on the compiler(use sizeof(),A First Book of ANSI C,Fourth Edition,35,Floating-Point Data Types(continued),float literal is indicated by appending an f or Flong double is created by appending an l or L9.234 indicates a double literal9.234f indicates a float literal9.234L indicates a long double literal,A First Book of ANSI C,Fourth Edition,36,Floating-Point Data Types(continued),A First Book of ANSI C,Fourth Edition,37,Exponential Notation,In numerical theory,the term precision typically refers to numerical accuracy,A First Book of ANSI C,Fourth Edition,38,Exponential Notation(continued),A First Book of ANSI C,Fourth Edition,39,Arithmetic Operations,Arithmetic operators:operators used for arithmetic operations:Addition+Subtraction-Multiplication*Division/Modulus Division%Binary operators require two operandsAn operand can be either a literal value or an identifier that has a value associated with it,A First Book of ANSI C,Fourth Edition,40,Arithmetic Operations(continued),A simple binary arithmetic expression consists of a binary arithmetic operator connecting two literal values in the form:literalValue operator literalValue3+712.62-9.8.08*12.212.6/2.Spaces around arithmetic operators are inserted for clarity and can be omitted without affecting the value of the expression,A First Book of ANSI C,Fourth Edition,41,Displaying Numerical Values,Arguments are separated with commasprintf(The total of 6 and 15 is%d,6+15);First argument of printf()must be a stringA string that includes a conversion control sequence,such as%d,is termed a control stringConversion control sequences are also called conversion specifications and format specifiersprintf()replaces a format specifier in its control string with the value of the next argumentIn this case,21,A First Book of ANSI C,Fourth Edition,42,Displaying Numerical Values(continued),printf(The total of 6 and 15 is%d,6+15);The total of 6 and 15 is 21printf(The sum of%f and%f is%f,12.2,15.754,12.2+15.754);The sum of 12.200000 and 15.754000 is 27.954000,A First Book of ANSI C,Fourth Edition,43,Displaying Numerical Values(continued),A First Book of ANSI C,Fourth Edition,44,Displaying Numerical Values(continued),A First Book of ANSI C,Fourth Edition,45,Displaying Numerical Values(continued),A First Book of ANSI C,Fourth Edition,46,Expression Types,Expression:any combination of operators and operands that can be evaluated to yield a valueInteger expression:contains only integer operands;the result is an integerFloating-point expression:contains only floating-point operands;the result is a double-precisionIn a mixed-mode expression the data type of each operation is determined by the following rules:If both operands are integers,result is an integerIf one operand is real,result is double-precision,A First Book of ANSI C,Fourth Edition,47,Integer Division,15/2=7Integers cannot contain a fractional partRemainder is truncated%is the modulus or remainder operator9%4 is 117%3 is 214%2 is 0,A First Book of ANSI C,Fourth Edition,48,Negation,A unary operator is one that operates on a single operand,e.g.,negation(-)The minus sign in front of a single numerical value negates(reverses the sign of)the number,A First Book of ANSI C,Fourth Edition,49,Negation(continued),A First Book of ANSI C,Fourth Edition,50,Operator Precedence and Associativity,Two binary arithmetic operator symbols must never be placed side by sideParentheses may be used to form groupingsExpressions in parentheses are evaluated firstParentheses may be enclosed by other parenthesesParentheses cannot be used to indicate multiplication,A First Book of ANSI C,Fourth Edition,51,Operator Precedence and Associativity(continued),Three levels of precedence:All negations are done firstMultiplication,division,and modulus operations are computed next;expressions containing more than one of these operators are evaluated from left to right as each operator is encounteredAddition and subtraction are computed last;expressions containing more than one addition or subtraction are evaluated from left to right as each operator is encountered,A First Book of ANSI C,Fourth Edition,52,Operator Precedence and Associativity(continued),Example:8+5*7%2*4=8+35%2*4=8+1*4=8+4=12,A First Book of ANSI C,Fourth Edition,53,Operator Precedence and Associativity(continued),A First Book of ANSI C,Fourth Edition,54,Variables and Declarations,Variables are names given by programmers to computer storageVariable name usually limited to 255 charactersVariable names are case sensitive,A First Book of ANSI C,Fourth Edition,55,Variables and Declarations(continued),A First Book of ANSI C,Fourth Edition,56,Variables and Declarations(continued),num1=45;num2=12;total=num1+num2;,Assignment statements,A First Book of ANSI C,Fourth Edition,57,Variables and Declarations(continued),A First Book of ANSI C,Fourth Edition,58,Declaration Statements,Naming and specifying the data type that can be stored in each variable is accomplished using declaration statementsDeclaration statements within a function appear immediately after the opening brace of a functionfunction name()declaration statements;other statements;Definition statements define or tell the compiler how much memory is needed for data storage,A First Book of ANSI C,Fourth Edition,59,Declaration Statements(continued),A First Book of ANSI C,Fourth Edition,60,Declaration Statements(continued),A First Book of ANSI C,Fourth Edition,61,Declaration Statements(continued),A First Book of ANSI C,Fourth Edition,62,Declaration Statements(continued),A First Book of ANSI C,Fourth Edition,63,Declaration Statements(continued),You can omit the f and let the compiler convert the double precision value into a float value when the assignment is made,A First Book of ANSI C,Fourth Edition,64,Selecting Variable Names,Make variable names descriptiveLimit variable names to approximately 20 charactersStart the variable name with a letter,rather than an underscore(_)In a variable name consisting of several words,capitalize the first letter of each word after the first,A First Book of ANSI C,Fourth Edition,65,Selecting Variable Names(continued),Use variable names that indicate what the variable corresponds to,rather than how it is computedAdd qualifiers,such as Avg,Min,Max,and Sum to complete a variables name where appropriateUse single-letter variable names,such as i,j,and k,for loop indexes,A First Book of ANSI C,Fourth Edition,66,Initialization,Declaration statements can be used to store an initial value into declared variablesint numOne=15;When a declaration statement provides an initial value,the variable is said to be initializedLiterals,expressions using only literals such as 87.0+12 2,and expressions using literals and previously initialized variables can all be used as initializers within a declaration statement,A First Book of ANSI C,Fourth Edition,67,Case Study:Temperature Conversion,A friend of yours is going to Spain,where temperatures are reported using the Celsius temperature scale.She has asked you to provide her with a list of temperatures in degrees Fahrenheit,and the equivalent temperature in degrees Celsius.The formula relating the two temperatures is Celsius=5/9(Fahrenheit 32).Initially,you are to write and test a program that correctly converts the Fahrenheit temperature of 75 degrees into its Celsius equivalent.,A First Book of ANSI C,Fourth Edition,68,Case Study:Temperature Conversion(continued),A First Book of ANSI C,Fourth Edition,69,Common Programming Errors,Omitting the parentheses,(),after mainOmitting or incorrectly typing the opening brace,that signifies the start of a function bodyOmitting or incorrectly typing the closing brace,that signifies the end of a functionMisspelling the name of a function;for example,typing print()instead of printf()Forgetting to close a string passed to printf()with a double quote symbol,A First Book of ANSI C,Fourth Edition,70,Common Programming Errors(continued),Omitting the semicolon at the end of each executable statementForgetting to include n to indicate a new lineForgetting to declare all the variables used in a programStoring an incorrect data type in a declared variableUsing a variable in an expression before a value has been assigned to the variable,A First Book of ANSI C,Fourth Edition,71,Common Programming Errors(continued),Dividing integer values incorrectlyMixing data types in the same expression without clearly understanding the effect producedNot including the correct conversion control sequence in print

    注意事项

    本文(高级语言程序设计cha.ppt)为本站会员(牧羊曲112)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开