Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Programming Fundamentals How to Program in C++ How to Program in C++

Similar presentations


Presentation on theme: "1 Programming Fundamentals How to Program in C++ How to Program in C++"— Presentation transcript:

1 1 Programming Fundamentals How to Program in C++ How to Program in C++

2 2 What is Computer System ? Computer System is a system capable of Computer System is a system capable of –Performing computations –Making logical decisions –Works billions of times faster than human beings Components of a computer system: Components of a computer system: –Hardware –Software

3 3 Hardware The hardware components are the electronic and mechanical parts. The hardware components are the electronic and mechanical parts. hardware devices hardware devices Keyboard, mouse, etc. Keyboard, mouse, etc. Screen (monitor) Screen (monitor) Disks Disks Memory Memory Processing Units Processing Units

4 4 Input devices Input devices –Obtains data from outside of the computer. –Usually a keyboard, mouse, disk or scanner Output devices Output devices –Makes info available outside the computer. –Screens, paper printouts, speakers Major Hardware Components

5 5 Processor Processor –Central Processing Unit or CPU –The brain of a computer system. –It does the fundamental computing within the system. Responds to and processes the basic instructions that drive a computer. Responds to and processes the basic instructions that drive a computer. –Directly or indirectly controls all the other components.

6 6 Memory Memory –holds data and programs that CPU is using, and save results of programs. –Rapid access, low capacity, short-term, temporary “ warehouse ”. –Often called main memory, primary memory, or Random Access Memory (RAM) – “ 4 gigabytes (4GB) of RAM ” One megabyte of memory is enough to hold approximately one million characters of a word processing document. One megabyte of memory is enough to hold approximately one million characters of a word processing document. I Kb = 1024 bytes I Kb = 1024 bytes 1024 2 bytes = 1 megabyte & 1024 3 bytes = 1 gigabyte 1024 2 bytes = 1 megabyte & 1024 3 bytes = 1 gigabyte Major Hardware Components

7 7 Secondary storage Secondary storage –Stores programs or data not currently being used by other units on secondary storage devices (like hard disk and floppy disks) –Long-term, high-capacity “ warehouse ” –Takes longer to access than primary memory Major Hardware Components

8 8 Question Imagine that you are using a word processor program to write a letter. Imagine that you are using a word processor program to write a letter. –Where (in the computer system) is the program you are running? –Where are the characters you have typed before you hit “ save ” button? After you hit “ save ” button?

9 9 Answer Where (in the computer system) is the program you are running? Where (in the computer system) is the program you are running? –In main memory. (A permanent copy will also be in secondary storage--the hard disk). Where are the characters you have typed? Where are the characters you have typed? –In main memory. (When you "save" your document, they will be copied to a file on the hard disk or the place you specified.)

10 10 What is Computer Program ? Computer Programs are called software Computer Programs are called software –sets of instructions that process data –guide computer through orderly sets of actions specified by computer programmers –Programmers write instructions that comprise software in various programming languages

11 11 Problem solving Problem solving Problem programmer

12 12 Types of Programs There are two categories of programs. There are two categories of programs. –Application programs are programs that people use to get their work done. Word Processor, Web Browsers, etc. Word Processor, Web Browsers, etc. –System programs keep all the hardware and software running together smoothly. Operating System is a kind of software system which is developed to make using computers more convenient. Windows, Unix, Linux, Macintosh. Operating System is a kind of software system which is developed to make using computers more convenient. Windows, Unix, Linux, Macintosh.

13 13 Machine Languages, Assembly Languages, and High-level Languages Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Strings of numbers giving machine specific instructions Natural language of the computer Natural language of the computer –0-1 corresponding to high or low voltage Instructions and data are encoded into binary numbers Instructions and data are encoded into binary numbers Example: Example:+1300042774+1400593419+1200274027

14 14 Machine Languages, Assembly Languages, and High-level Languages Three types of programming languages 1.Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) English-like abbreviations representing elementary computer operations (translated via assemblers) Example: Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

15 15 Machine Languages, Assembly Languages, and High-level Languages Three types of programming languages (continued) 3.High-level languages Codes similar to everyday English Codes similar to everyday English Use mathematical notations (translated via compilers) Use mathematical notations (translated via compilers) Example: Example: grossPay = basePay + overTimePay

16 16 Types of Programming Languages Three general types of programming languages Three general types of programming languages –Machine languages machine dependent machine dependent –Assembly languages machine dependent machine dependent –High-level languages most are portable most are portable Specific languages include C, C++, Visual Basic and Java Specific languages include C, C++, Visual Basic and Java

17 17 Steps of Software Development Problem definition Problem definition Analysing the problem Analysing the problem Development of algorithm and flow chart Development of algorithm and flow chart Programming Programming Testing the program Testing the program Implementing Implementing

18 18 History of C and C++ C –Evolved by Ritchie from two previous programming languages, BCPL and B –Used to develop UNIX –Used to write modern operating systems –Hardware independent (portable) –By late 1970's C had evolved to "Traditional C" Standardization Standardization –Many slight variations of C existed, and were incompatible –Committee formed to create a "unambiguous, machine-independent" definition –Standard created in 1989, updated in 1999

19 19 The C Standard Library C programs consist of pieces/modules called functions C programs consist of pieces/modules called functions –A programmer can create his own functions Advantage: the programmer knows exactly how it works Advantage: the programmer knows exactly how it works Disadvantage: time consuming Disadvantage: time consuming –Programmers will often use the C library functions Use these as building blocks Use these as building blocks –Avoid re-inventing the wheel If a premade function exists, generally best to use it rather than write your own If a premade function exists, generally best to use it rather than write your own Library functions carefully written, efficient, and portable Library functions carefully written, efficient, and portable

20 20 History of C and C++ C++ C++ C++, an extension of C, was developed in the early 1980s. C++, an extension of C, was developed in the early 1980s. C++ provides a number of features that "spruce up" the C language, but more importantly, it provides capabilities for object-oriented programming. C++ provides a number of features that "spruce up" the C language, but more importantly, it provides capabilities for object-oriented programming. Objects are essentially reusable software components that model items in the real world. Objects are essentially reusable software components that model items in the real world. A modular, object-oriented design and implementation is easy to understand, correct and modify A modular, object-oriented design and implementation is easy to understand, correct and modify Object-oriented programs are easier to understand, correct and modify. Object-oriented programs are easier to understand, correct and modify.

21 21 The C++ Standard Library C++ programs consist of pieces called classes and functions C++ programs consist of pieces called classes and functions C++ Standard Library : C++ Standard Library : –Rich collections of existing classes and functions Reusable in new applications Reusable in new applications Two parts to learning the C++ "world." Two parts to learning the C++ "world." –Learning the C++ language itself; –Learning how to use the classes and functions in the C++ Standard Library.

22 22 Typical C++ Development Environment 1. Edit : Programmer writes program (and stores source code on disk) 2. Preprocess : Perform certain manipulations before compilation 3. Compile : Compiler translates C++ programs into machine languages 4. Link : Link object code with the libraries ( missing functions and data) 5. Load : Transfer executable image to memory 6. Execute : Execute the program one instruction at a time

23 23

24 24 Flowchart It is a graphical way to describe the solution of the problem. Flow Chart Symbols Start and End Input / output Selection Calculation Data Flow

25 25 Input a,b S = a + b Output s Problem : Compute and print the summation of two numbers.

26 26 Input n1,n2,n3 S = n1+n2+n3 Average = s / 3 Output average Problem : Compute and print the average of three numbers.

27 27 Input r A = 3.14 * R *R Output A Problem : Compute the area of the circle. Where area = 3.14 x R2

28 28 Input Num Output “Positive” Num>0 True False Problem : Read any number from the user, then print positive if it is positive.

29 29 Input Num Output “Positive” Num>0 TrueFalse Output “Negative” Problem : Read any number from the user, then print positive if it is positive and print negative otherwise.

30 30 Input x, y Output x X>y TrueFalse Output y Problem : Read Two numbers from the user, then print the greatest one.

31 31 Output “UIIT” Count<=5 True False Count = 1 Count = Count + 1 Problem : Print the word “ UIIT ” five times.

32 32 Output I I<=11 True False I = 1 I = I + 2 Problem : Print the following numbers. 1357911

33 33 Output I I>=2 True False I = 20 I = I - 3 Problem : Print the following numbers. 20171411852

34 34 I<=10 True False I = 1 I = I + 1 S = 0 S = S + Num Output S INPUT Num Problem : Compute and print summation of any 10 numbers entered by the user.

35 35 In Next Lecture Introduction to C++ Programming Introduction to C++ Programming Books: Books: –Text book: Object-Oriented Programming in C++ by Robert Lafore –Reference book: C++, How to Program by Deitel & Deitel Latest Editions of Both. Latest Editions of Both.


Download ppt "1 Programming Fundamentals How to Program in C++ How to Program in C++"

Similar presentations


Ads by Google