490 likes | 511 Views
This course introduces the general concepts of programming, teaches how to design and code structured programs, and provides an introduction to C++. Topics covered include algorithms, software, computers, and program execution.
E N D
310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com Fundamental Programming: 2006
Session times • Lectures • Workshops Fundamental Programming: 2006
Resources • Textbook • CPP-tutorial.pdf Available at http://www.cplusplus.com/doc/tutorial/ • Structured and Object-Oriented Programming, Staugaard, 3rd edition • Study Guides • Software • G++ based on Linux OS Fundamental Programming: 2006
Essential resources • Web page for the subject – find from • http://www.cs.buu.ac.th/~krisana • check at least TWICE EACH WEEK • Email • TO ckrisana@gmail.com • Topic: 310201 studentID Fundamental Programming: 2006
Assessment • Three assignments • 20%, due Week 5 • 40%, due Week 8 • 40%, due Week 12 • Online assignment submission • No examination Fundamental Programming: 2006
Plagiarism & Deadlines & Extensions • Plagiarism of any kind is not permitted • Penalties will be applied • Extensions must be requested before the deadline • Requests must be in writing (email is fine) Fundamental Programming: 2006
In this course... • in Fundamental Programming, you will learn how to design, code and test simpleprograms • in this course we develop “structured programs” – programs broken into chunks to make them easier to understand • we do not cover “object-oriented programming” - that comes later • a program is a piece of software - a few things about software... Fundamental Programming: 2006
Goals of this Course • Introduce general concepts of programming • Begin to thing like a programmer • Learn to appreciate programming and computer science • Start programming in C++ Fundamental Programming: 2006
What is programming? • Given a problem: • Find an algorithm to solve a problem. • Express that algorithm in a way that the computer canexecute it. Fundamental Programming: 2006
Algorithms • In simple terms, an algorithm is a sequence of instructionsto solve a problem, such that: • Each instruction is unambiguous, and is something thecomputer can do. • After an instruction is finished, there is no ambiguity about which instruction is to be executed next. • Execution finishes in a finite number of steps. • The description of the algorithm is finite. • Think of the computer as a meticulous moron. Fundamental Programming: 2006
Software • Software sits between the user and the hardware • it enables the user to do something useful with the hardware • some pieces of software are very big – Windows 2000 • 30 million lines of code • 15 million of which are new • Windows 2000 is a collection of programs that work together – one is File Explorer Fundamental Programming: 2006
Software Fundamental Programming: 2006
Software • Windows also has components that can be used by other programs • Microsoft Word uses the file services component of the operating system to read data from files, and write data to files • most programs use other software to perform their task(s)... Fundamental Programming: 2006
Software Software Operating System File Hardware Explorer Hardware WinWord.exe File Services Fundamental Programming: 2006
Computers • computers are data processing devices • main input device: keyboard • main output device: display • processor performs operations on input data to produce output data Fundamental Programming: 2006
Computers Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Student's mark ==> 30 Student's percentage: 60 Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display Fundamental Programming: 2006
Programs => output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: ? M2: ? M3: ? M4: ? Fundamental Programming: 2006
Programs Number of marks in exam ==> Fundamental Programming: 2006
Programs => output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: ? M2: ? M3: ? M4: ? Fundamental Programming: 2006
Programs Number of marks in exam ==> Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Fundamental Programming: 2006
Programs => output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: ? M2: ? M3: ? M4: ? Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: ? M3: ? M4: ? => Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Student's mark ==> Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: ? M3: ? M4: ? => Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Student's mark ==> Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Student's mark ==> 30 Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: ? M3: ? M4: ? => Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: 30 M3: ? M4: ? => Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: 30 M3: 0.6 M4: ? => Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: 30 M3: 0.6 M4: 60 => Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Student's mark ==> 30 Student's percentage: Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: 30 M3: 0.6 M4: 60 => Fundamental Programming: 2006
Programs Number of marks in exam ==> 50 Student's mark ==> 30 Student's percentage: 60 Fundamental Programming: 2006
Programs output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to display output number in M4 to display M1: 50 M2: 30 M3: 0.6 M4: 60 => Fundamental Programming: 2006
Data • we said that “data” is numbers and text • data is stored as strings of 1s and 0s • standard unit of storage is a byte- 8 bits • numbers are stored in binary form: 1 is stored as 00000001, 2 is stored as 00000010, 3 is stored as 00000011, etc... • the ASCII coding system is used for text: a is stored as 01100001, A is stored as 01000001, b is stored as 01100010, B is stored as 01000010, c is stored as 01100011, etc... Fundamental Programming: 2006
Data • two main data storage areas in a computer: • memory • disk • main differences: • (main) memory: • fast, but expensive, • volatile - data lost when power turned off • (secondary memory) disk: • slow, but cheap • persistent - data retained when power turned off Fundamental Programming: 2006
Languages • processors perform very simple operations • most programs are written in high-level languages (C++, Visual Basic, COBOL, etc) • each high-level language statement translates to several machine code statements • a compiler converts the high-level language statements to machine code statements • programs are written in a high-level language as they are easier to code and understand Fundamental Programming: 2006
Language Translators: Interpreter Interpreter Machine language statement Program Statement+Data Statement execution Fundamental Programming: 2006
Language Translators (Compilers) Step1: Convert program(Compile Time) Machine language Program Computer program Compiler Step2: Execute program(Run time) Data Machine language program Program Output Fundamental Programming: 2006
Program Development cycle • Design • Edit: vi, emacs, tools • Compile and link: gcc • Preprocessor • Compiler • Linker • Execute: ./a.exe • Loader • Your program! Fundamental Programming: 2006
Software Development • when you code a program in C++, it is easy to make mistakes that cause compiler errors • but this task is only a small part of s/w development process • before coding a program, it must be designed • if the design is going to work, the task the program will perform must be understood • the Study Guide describes a 5-step software development process Fundamental Programming: 2006
Software Development • task analysis and specification • analysis the task(s) the program must perform and produce a written statement of the requirements • algorithm design • develop the logic that the program will perform to accomplish it’s task(s) • coding • testing • it must do what you want (no bugs) - verification • it must do what the client wants - validation • maintenance Fundamental Programming: 2006
Software Development • by “maintenance” we mean: • fixing bugs –distributed as Service Release • making improvements - eg. Win95 user interface • changes/extensions - eg. Win98 support for USB • around 75% of programming time is spent maintaining software – so it’s important to use simple designs that are easy to understand • important: coding is just a small part of the software development process - analysis, design and testing are more important stepsin the process Fundamental Programming: 2006
SDLC • Study Guide talks about a software development life cycle - SDLC • idea is that each version of a program involves a rotation through the 5 stages analysis and specification algorithm design maintenance testing coding Fundamental Programming: 2006
Summary • in 310201 you will design & code C++ programs • a program is a piece of software • computers input, process and output data • a compiler translates C++ into machine code • coding is a small part of development process • analysis,designand testing more important • use simple designs to reduce maintenance • Study Guide describes a 5-step SDLC Fundamental Programming: 2006