程序设计原理Chapter 10
- 格式:ppt
- 大小:3.23 MB
- 文档页数:64
c语言程序设计教程第二版课后答案【篇一:c语言程序设计(第2版)-- 课后题答案】p> 参考答案第1章进入c语言程序世界二、1.i love china!printf(we are students.\n)2.6项目实训题参考答案1.编写一个c程序,输出以下信息:* * * * * * * * * * * * * * * * * * * *i am a student!* * * * * * * * * * * * * * * * * * * *main(){ printf(********************\n);printf( i am a student!\n);printf(********************\n);}2.已知立方体的长、宽、高分别是10cm、20cm、15cm,编写程序,求立方体体积。
解:main(){int a,b,c,v;a=10;b=20;c=15;v=a*b*c;printf(v=%d,v);}本程序运行结果为:v=3000第2章编制c程序的基础知识一选择题c b a b a c c二操作题,2,-8,23.000000,2.500000,-8.0000002. abc defghwhy is21+35equal 523.34214. aaa项目实训题1.定义一个符号常量m为5和一个变量n值为2,把它们的乘积输出。
#define m 5main(){ int n,c;n=2; c=m*n;printf(%d\n,c);}2.编程求下面算术表达式的值。
(1)x+a%3*(int)(x+y)%2/4,设x=2.5,a=7,y=4.7;(2)(float)(a+b)/2+(int)x%(int)y,设a=2,b=3,x=3.5,y=2.5。
(1)main(){ int a=7;float x=2.5,y=4.7;printf(%f\n,x+a%3*(int)(x+y)%2/4);}(2)main(){ int a=2,b=3;float x=3.5,y=2.5;printf(%f\n,(float)(a+b)/2+(int)x%(int)y);}第三章顺序结构程序设计一选择题a c d c c二操作题1. x=3,a=2,b=32. z=12.7000002 13 3 2 bb cc abc n3. 1 2 1a2 1 2三.编程题编程题解:#include stdio.hmain(){float sj,gz,yfgz;printf(time,salary:);scanf(%f,%f,sj,gz);yfgz=sj*gz*0.9;printf(total salary:%f\n,yfgz);}本程序运行结果为:time,salary:4,3crtotal salary:10.8000002.编写一个程序求出任意一个输入字符的ascii码解:#include stdio.hmain(){char c;printf(input a string:);scanf(%c,c);printf(%c ascii is %d\n,c,c);}本程序运行结果为:input a string:acra ascii is 973、编写一个程序用于水果店售货员算帐:已知苹果每斤2.50元,鸭梨每斤1.80元,香蕉每斤2元,橘子每斤1.6元,要求输入各类水果的重量,打印出应付3解:main(){float p,y,x,j,ys,g,fk;printf(apple,pear,banana,orange(weight)=);scanf(%f,%f,%f,%f,p,y,x,j);ys=2.5*p+1.8*y+2*x+1.6*j;printf(fu kuan=);scanf(%f,g);fk=g-ys;printf(result:\n);printf(fukuan=%6.2fyuan\nshoukuan=%6.2fyuan\nzhaohui=%6. 2fyuan\n,g,ys,fk);}本程序运行结果为:apple,pear,banana,orange(weight)=1,2,3,4fu kuan=100result:fukuan=100.00yuanshoukuan= 18.50yuanzhaohui= 81.50yuan项目实训1.假设银行定期存款的年利率rate为2.25%,并已知存款期为n 年,存款本金为capital元,试编程计算n年后可得到本利之和deposit。
第Ⅰ部分:实验指导实验1:Java开发环境J2SE一、实验目的(1)学习从网络上下载并安装J2SE开发工具。
(2)学习编写简单的Java Application程序.(3)了解Java源代码、字节码文件,掌握Java程序的编辑、编译和运行过程。
二、实验任务从网络上下载或从CD-ROM直接安装J2SE开发工具,编写简单的Java Application程序,编译并运行这个程序。
三、实验内容1.安装J2SE开发工具Sun公司为所有的java程序员提供了一套免费的java开发和运行环境,取名为Java 2 SDK,可以从上进行下载。
安装的时候可以选择安装到任意的硬盘驱动器上,例如安装到C:\j2sdk1.4.1_03目录下。
教师通过大屏幕演示J2SE的安装过程,以及在Windows98/2000/2003下环境变量的设置方法。
2.安装J2SE源代码编辑工具Edit Plus教师通过大屏幕演示Edit Plus的安装过程,以及在Windows98/2000/2003操作系统环境下编辑Java 原程序的常用命令的用法。
3.编写并编译、运行一个Java Application程序。
创建一个名为HelloWorldApp的java Application程序,在屏幕上简单的显示一句话"老师,你好!"。
public class HelloWorldApp{public static void main(String[] args){System.out.println("老师,你好!");}}4.编译并运行下面的Java Application程序,写出运行结果。
1:public class MyClass {2:private int day;3:private int month;4:private int year;5:public MyClass() {6:day = 1;7:month = 1;8:year = 1900;9:}10:public MyClass(int d,int m,int y) {11:day = d;12:month = m;13:year = y;14:}15:public void display(){16:System.out.println(day + "-" + month + "-" + year);17:}18:public static void main(String args[ ]) {19:MyClass m1 = new MyClass();20:MyClass m2 = new MyClass(25,12,2001);21:m1.display();22:m2.display();23:}24:}运行结果:1-1-190025-12-2001实验2:Java基本数据类型一、实验目的(1)掌握javadoc文档化工具的使用方法。
程序设计语言编译原理第三版答案【篇一:西北工业大学版(蒋立源第三版)编译原理课后习题答案】解:源程序是指以某种程序设计语言所编写的程序。
目标程序是指编译程序(或解释程序)将源程序处理加工而得的另一种语言(目标语言)的程序。
翻译程序是将某种语言翻译成另一种语言的程序的统称。
编译程序与解释程序均为翻译程序,但二者工作方法不同。
解释程序的特点是并不先将高级语言程序全部翻译成机器代码,而是每读入一条高级语言程序语句,就用解释程序将其翻译成一段机器指令并执行之,然后再读入下一条语句继续进行解释、执行,如此反复。
即边解释边执行,翻译所得的指令序列并不保存。
编译程序的特点是先将高级语言程序翻译成机器语言程序,将其保存到指定的空间中,在用户需要时再执行之。
即先翻译、后执行。
2解:一般说来,编译程序主要由词法分析程序、语法分析程序、语义分析程序、中间代码生成程序、代码优化程序、目标代码生成程序、信息表管理程序、错误检查处理程序组成。
3解:c语言的关键字有:auto break case char constcontinue 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。
上述关键字在c语言中均为保留字。
4解:c语言中括号有三种:{},[],()。
其中,{}用于语句括号;[]用于数组;()用于函数(定义与调用)及表达式运算(改变运算顺序)。
c语言中无end关键字。
逗号在c语言中被视为分隔符和运算符,作为优先级最低的运算符,运算结果为逗号表达式最右侧子表达式的值(如:(a,b,c,d)的值为d)。
5略第二章习题解答1.(1)答:26*26=676(2)答:26*10=260(3)答:{a,b,c,...,z,a0,a1,...,a9,aa,...,az,...,zz,a00,a01,...,zzz},共26+26*36+26*36*36=34658个2.构造产生下列语言的文法(1){anbn|n≥0}(2){anbmcp|n,m,p≥0}(3){an # bn|n≥0}∪{cn # dn|n≥0}解:对应文法为g(s) = ({s,x,y},{a,b,c,d,#}, {s→x,s→y,x→axb|#,y→cyd|# },s)(4){w#wr# | w?{0,1}*,wr是w的逆序排列}解:g(s) = ({s,w,r},{0,1,#}, {s→w#, w→0w0|1w1|# },s)(5)任何不是以0打头的所有奇整数所组成的集合(6)所有偶数个0和偶数个1所组成的符号串集合解:对应文法为s→0a|1b|e,a→0s|1c b→0c|1s c→1a|0b3.描述语言特点(1)s→10s0s→aaa→baa→a解:本文法构成的语言集为:l(g)={(10)nabma0n|n, m≥0}。
Java Programming Fundamentals, 10th Edition CourseDesign (English Version)IntroductionJava Programming Fundamentals is a comprehensive course that covers the basic concepts and principles of Java programming. In this course, students will learn to design, code, and test Java programs while developing a strong foundation in programming logic and object-oriented programming concepts. This course is designed for students who are new to programming and want to learn Java programming from scratch.Course ObjectivesThe mn objective of this course is to provide students with a solid foundation in programming using the Java language. Upon completion of this course, students will be able to:•Understand the basic syntax and structure of the Java programming language•Design, code, and test simple Java programs•Use decision structures and loops in Java programming•Work with arrays and arraylists•Understand object-oriented programming concepts•Implement inheritance and polymorphism in Java programming•Understand Java class libraries and use them in Java programming•Develop event-driven programs using graphical user interfacesCourse OutlineThe course is divided into several chapters, each covering adifferent aspect of Java programming fundamentals. The following is a detled outline of the course:Chapter 1: Getting Started with Java•Introduction to Java programming language•Understanding the basic structure of a Java program•Writing and running a Java program•Understanding variables, data types, and constants•Basic Input/Output operationsChapter 2: Control Structures•Understanding decision structures•Using if statement, if-else statement, and nested if statements•Understanding loops and using while, do-while, and for loops•Understanding break and continue statements•Using switch statementChapter 3: Arrays and Arraylists•Understanding arrays•Declaring and initializing arrays•Multidimensional arrays•Understanding arraylist•Using arraylist class methodsChapter 4: Object-Oriented Programming Concepts•Introduction to object-oriented programming•Understanding classes and objects•Encapsulation: Access modifiers, getters, and setters•Constructors and overloading•Methods and method overloadingChapter 5: Inheritance and Polymorphism•Understanding inheritance•Using superclass and subclass•Polymorphism: Method overloading and overriding•Casting objects•Abstract classes and interfacesChapter 6: Java Class Libraries•Understanding Java class libraries•Using the String class•Using the Math class•Using the Date class•Using the File classChapter 7: Graphical User Interfaces•Understanding event-driven programming•Using the Swing library•Designing a user interface using JFrame, JDialog, and JPanel •Using event listeners•Designing a GUI-based applicationCourse Requirements•Basic computer skills•Basic understanding of programming concepts is helpful but not required•Java Development Kit (JDK) version 8 or later•Integrated Development Environment (IDE) such as Eclipse or NetBeansGrading PolicyThe final grade for this course will be calculated based on the following components:•Assignments (50%)•Midterm Exam (20%)•Final Exam (30%)ConclusionJava Programming Fundamentals, 10th Edition course is designed to provide students with a solid foundation in Java programming language and object-oriented programming concepts. By the end of this course, students will be able to write simple Java programs, use decision constructs and loops, work with arrays and arraylists, implement inheritance and polymorphism, understand Java class libraries, and develop graphical user interfaces. This course is intended for anyone who is interested in learning Java programming from scratch.。