programming design ku-yaw chang [email protected] assistant professor, department of computer...
TRANSCRIPT
Programming DesignProgramming Design
Ku-Yaw ChangKu-Yaw [email protected]@mail.dyu.edu.tw
Assistant Professor, Department of Assistant Professor, Department of Computer Science and Information EngineeringComputer Science and Information Engineering
Da-Yeh UniversityDa-Yeh University
22Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
IntroductionIntroduction
Three types of programming languagesThree types of programming languagesMachine languagesMachine languages Strings of numbers giving machine specific instructionsStrings of numbers giving machine specific instructions Example:Example:
+1300042774+1300042774+1400593419+1400593419+1200274027+1200274027
Assembly languagesAssembly languages English-like abbreviations representing elementary computer English-like abbreviations representing elementary computer
operations (translated via assemblers)operations (translated via assemblers) Example:Example:
LOAD BASEPAYLOAD BASEPAYADD OVERPAYADD OVERPAYSTORE GROSSPAYSTORE GROSSPAY
33Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
IntroductionIntroduction
High-level languagesHigh-level languages Codes similar to everyday EnglishCodes similar to everyday English Use mathematical notations (translated via compilers)Use mathematical notations (translated via compilers) Example:Example:
grossPay = basePay + overTimePaygrossPay = basePay + overTimePay
44Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
IntroductionIntroduction
CC A general-purpose, high-level programming languageA general-purpose, high-level programming language A system programming languageA system programming language
Writing compilers and operating systemsWriting compilers and operating systems Unix, Linux, Windows….Unix, Linux, Windows….
Hardware independent (portable)Hardware independent (portable) Stem fromStem from
BCPL by Martin RichardsBCPL by Martin Richards
B by Ken ThompsonB by Ken Thompson Both are “typeless” languageBoth are “typeless” language
Provide a variety of data typesProvide a variety of data typescharacters, integers and floating numberscharacters, integers and floating numbers
55Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
IntroductionIntroduction
ANSI CANSI C In 1983, the American National Standards Institute (ANSI) In 1983, the American National Standards Institute (ANSI)
established a committee to provide a modern, comprehensive established a committee to provide a modern, comprehensive definition of Cdefinition of C
Completed late in 1988Completed late in 1988Most of the features are supported modern compilersMost of the features are supported modern compilers
ANSI/ISO CANSI/ISO C ANSI/ISO 9899:1990ANSI/ISO 9899:1990
66Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
IntroductionIntroduction
C++C++ Superset of C developed by Bjarne Stroustrup at Bell LabsSuperset of C developed by Bjarne Stroustrup at Bell Labs "Spruces up" C, and provides object-oriented capabilities"Spruces up" C, and provides object-oriented capabilities Object-oriented design very powerfulObject-oriented design very powerful 10 to 100 fold increase in productivity10 to 100 fold increase in productivity Dominant language in industry and academiaDominant language in industry and academia
Learning C++Learning C++ Because C++ includes C, some feel it is best to master C, then Because C++ includes C, some feel it is best to master C, then
learn C++learn C++
77Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
IntroductionIntroduction
Phases of C/C++ programs:Phases of C/C++ programs: EditEdit PreprocessPreprocess CompileCompile LinkLink LoadLoad ExecuteExecute
88Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
Preprocessor program processes the code.
Loader puts program in memory.
CPU takes each instruction and executes it, possibly storing new data values as the program executes.
Compiler creates object code and stores it on disk.
Linker links the object code with the libraries.
Loader
Primary Memory
Compiler
Editor
Preprocessor
Linker
Primary Memory
.
.
.
.
.
.
.
.
.
.
.
.
Disk
Disk
Disk
CPU
Disk
Disk
99Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
MS Visual C++MS Visual C++
Solution (*.sln)Solution (*.sln) Consist of one or more projects (*.vcproj)Consist of one or more projects (*.vcproj)
Project (*.vcproj)Project (*.vcproj) Consist of many modulesConsist of many modules
ModuleModule *.cpp/*.h*.cpp/*.h *.lib*.lib
1010Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
MS Visual C++MS Visual C++
1111Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
The First C ProgramThe First C Program
In C, the program to print “hello, world” isIn C, the program to print “hello, world” is#include <stdio.h>#include <stdio.h>
main() main()
{{
printf(“hello, world\n”);printf(“hello, world\n”);
}}
include information about standard libraryinclude information about standard library
define a function named main that define a function named main that receives no argument valuesreceives no argument values
Statements of main are enclosed in Statements of main are enclosed in bracesbraces
main calls library function printf to print main calls library function printf to print this sequence of characters;\n this sequence of characters;\n represents the newline characterrepresents the newline character
1212Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
Exercise 1-1Exercise 1-1
Run the “hello, world” program on your Run the “hello, world” program on your system. Experiment with leaving out parts system. Experiment with leaving out parts of the program, to see what error of the program, to see what error messages you get.messages you get.
1313Ku-Yaw ChangKu-Yaw Chang IntroductionIntroduction
Exercise 1-2Exercise 1-2
Experiment to find out what happens when Experiment to find out what happens when printf’s argument string contains \c, where printf’s argument string contains \c, where c is some character not listed above.c is some character not listed above. \t for tab\t for tab \b for backspace\b for backspace \” for double quote\” for double quote \\ for backslash\\ for backslash
The EndThe End