Presentation is loading. Please wait.

Presentation is loading. Please wait.

EGR 2261 Engineering Problem Solving Using C and C++ Professor Nick Reeder.

Similar presentations


Presentation on theme: "EGR 2261 Engineering Problem Solving Using C and C++ Professor Nick Reeder."— Presentation transcript:

1 EGR 2261 Engineering Problem Solving Using C and C++ Professor Nick Reeder

2 Reminders  Please turn off cell phones.  No food or soft drinks in the classroom.  Stow water bottles at floor level.

3 EGR 2261 Unit 1 Overview  Read Malik, Chapter 1.  Homework #1 and Lab #1 due next week.  Quiz next week.

4 Chapter 1: An Overview of Computers and Programming Languages

5 Introduction Without software, the computer is useless. Software is developed with programming languages. C++ is one of the most popular programming languages. – TIOBE Index TIOBE Index – LangPop.com LangPop.com – IEEE IEEE C++ is suited for a wide variety of programming tasks. 5C++ Programming: From Problem Analysis to Program Design, Seventh Edition

6 C++ Versus C C++ evolved from C, and you can think of C as being a subset of C++. So in learning C++, you’re also learning C (and then some). Other popular languages that evolved from C include Java, C#, Objective-C. C++ C

7 Elements of a Computer System Hardware – CPU – Main memory – Secondary storage – Input/Output devices Software 7C++ Programming: From Problem Analysis to Program Design, Seventh Edition

8 Central Processing Unit and Main Memory Central processing unit – Brain of the computer – Most expensive piece of hardware – Carries out arithmetic and logical operations 8C++ Programming: From Problem Analysis to Program Design, Seventh Edition

9 Central Processing Unit and Main Memory (cont’d.) Main memory – Directly connected to the CPU All programs must be loaded into main memory before they can be executed. All data must be brought into main memory before it can be manipulated. When computer power is turned off, everything in main memory is lost. 9C++ Programming: From Problem Analysis to Program Design, Seventh Edition

10 Central Processing Unit and Main Memory (cont’d.) Main memory is an ordered sequence of memory cells. – Each cell has a unique location in main memory, called the address of the cell. Each cell can contain either a programming instruction or data. 10C++ Programming: From Problem Analysis to Program Design, Seventh Edition

11 Secondary Storage Secondary storage: device that stores information permanently Examples of secondary storage: – Hard disks – Flash drives – Floppy disks – Zip disks – CD-ROMs – Tapes 11C++ Programming: From Problem Analysis to Program Design, Seventh Edition

12 Input/Output Devices Input devices feed data and programs into computers. – Keyboard – Mouse Output devices display results. – Monitor – Printer 12C++ Programming: From Problem Analysis to Program Design, Seventh Edition

13 Software Software: programs that do specific tasks. System programs control the computer. – Operating system monitors the overall activity of the computer and provides services such as: Memory management Input/output activities Storage management Application programs perform a specific task. – Word processors – Spreadsheets – Games 13C++ Programming: From Problem Analysis to Program Design, Seventh Edition

14 The Language of a Computer Digital devices (computers, iPods, cell phones, …) use binary code to represent information. This means they store all information (numbers, text, images, music, …) as sequences of 0s and 1s. Each 0 or 1 in such a sequence is called a bit (short for binary digit). Example of an 8-bit sequence: 01101100 A typical song in an MP3 file might contain 40 million bits.

15 The Language of a Computer (cont’d.) Byte: – A sequence of eight bits Kilobyte (KB): 2 10 bytes = 1024 bytes Table 1-1 on page 6 (next slide) shows some other related terms. This is useful general information, but not critical to what we’ll do in this course. 15C++ Programming: From Problem Analysis to Program Design, Seventh Edition

16 16C++ Programming: From Problem Analysis to Program Design, Seventh Edition The Language of a Computer (cont’d.)

17 At least three different encodings have been used to represent text as sequences of 0s and 1s. ASCII (American Standard Code for Information Interchange) – 128 characters; see Appendix C in textbook. EBCDIC – Formerly used by IBM; obsolete. Unicode – 65,536 characters; covers most modern alphabets. 17C++ Programming: From Problem Analysis to Program Design, Seventh Edition

18 The Evolution of Programming Languages Early computers were programmed in machine language., which required the programmer to type sequences of 0s and 1s. To calculate wages = rate * hours in machine language: 100100 010001 //Load 100110 010010 //Multiply 100010 010011 //Store 18C++ Programming: From Problem Analysis to Program Design, Seventh Edition

19 The Evolution of Programming Languages (cont’d.) Assembly language replaces sequences of 0s and 1s with mnemonics (abbreviations such as LOAD or MULT). Using assembly language instructions, wages = rate * hours can be written as: LOAD rate MULThour STORwages 19C++ Programming: From Problem Analysis to Program Design, Seventh Edition

20 The Evolution of Programming Languages (cont’d.) High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, C#, and Java. Programs written in these language look much more like English. Compiler: translates a program written in a high-level language into machine language. The equation wages = rate * hours can be written in C++ as: wages = rate * hours; 20C++ Programming: From Problem Analysis to Program Design, Seventh Edition

21 Microsoft Visual Studio In this course you’ll use Microsoft Visual Studio Community 2015 to enter, run, and test your programs. This is a free version of Visual Studio that you can install at home. Instructions on course website. Instructions on course website It’s powerful, complex software used by professional programmers.

22 A Simple C++ Program //*************************************************** // Name: SimpleWageProgram // Author: Nick Reeder // Date: 07/13/2015 // Computes weekly wages. //*************************************************** #include using namespace std; int main() { int rate = 15; int hours = 40; int wages = rate * hours; cout << wages << endl; return 0; } 22C++ Programming: From Problem Analysis to Program Design, Seventh Edition

23 Parentheses, Braces, and Brackets C++ uses the following symbols to enclose code: Parentheses ( ) Braces { } Square brackets [ ] Angle brackets Each pair of symbols has a specific use. They are not interchangeable. You can’t use parentheses where you’re supposed to use braces, and so on.

24 Processing a C++ Program 24C++ Programming: From Problem Analysis to Program Design, Seventh Edition

25 Processing a C++ Program (cont’d.) Steps in processing a C++ program: – Use an editor to create source code in C++. – Preprocessor directives begin with # and are processed by the preprocessor. – Compiler: Checks that the program obeys the language rules. Translates into machine language (object program). 25C++ Programming: From Problem Analysis to Program Design, Seventh Edition

26 Processing a C++ Program (cont’d.) Steps in processing a C++ program (cont’d.): – Linker: Combines object program with other files to create executable code. Library: contains prewritten code you can use. – Loader: Loads executable program into main memory. – The last step is to execute the program. 26C++ Programming: From Problem Analysis to Program Design, Seventh Edition

27 Integrated Development Environement In the old days you might need several computer programs to perform all of the steps listed above. But Visual Studio combines all of these into a single program. It’s an example of an Integrated Development Environment (IDE). Another popular free C++ IDE is Bloodshed’s Dev-C++ at http://www.bloodshed.net/devcpp.html. http://www.bloodshed.net/devcpp.html

28 Programming with the Problem Analysis–Coding–Execution Cycle Algorithm: – Step-by-step problem-solving process – Solution achieved in finite amount of time Programming is a process of problem solving. 28C++ Programming: From Problem Analysis to Program Design, Seventh Edition

29 The Problem Analysis–Coding– Execution Cycle (cont’d.) Step 1: Analyze the problem. – Outline the problem and its requirements. – Design steps (algorithm) to solve the problem. Step 2: Implement the algorithm. – Implement the algorithm in code. – Verify that the algorithm works. Step 3: Maintain. – Use and modify the program if the problem domain changes. 29C++ Programming: From Problem Analysis to Program Design, Seventh Edition

30 Example 1-1 Design an algorithm to find the perimeter and area of a rectangle. The perimeter and area of the rectangle are given by the following formulas: perimeter = 2 * (length + width) area = length * width 30C++ Programming: From Problem Analysis to Program Design, Seventh Edition

31 Example 1-1 (cont’d.) Algorithm: – Get length of the rectangle. – Get width of the rectangle. – Find the perimeter using the following equation: perimeter = 2 * (length + width) – Find the area using the following equation: area = length * width 31C++ Programming: From Problem Analysis to Program Design, Seventh Edition

32 Programming Methodologies Two popular approaches to programming design: – Structured – Object-oriented 32C++ Programming: From Problem Analysis to Program Design, Seventh Edition

33 Structured Programming Structured design: – Dividing a problem into smaller subproblems. Structured programming: – Implementing a structured design. The structured design approach is also called: – Top-down (or bottom-up) design – Stepwise refinement – Modular programming 33C++ Programming: From Problem Analysis to Program Design, Seventh Edition

34 Object-Oriented Programming Object-oriented design (OOD) – Identify components called objects. – Determine how objects interact with each other. Specify relevant data and possible operations to be performed on that data. Each object consists of data and operations on that data. 34C++ Programming: From Problem Analysis to Program Design, Seventh Edition

35 Object-Oriented Programming (cont’d.) An object combines data and operations on the data into a single unit. A programming language that implements OOD is called an object-oriented programming (OOP) language. Must learn how to represent data in computer memory, how to manipulate data, and how to implement operations. 35C++ Programming: From Problem Analysis to Program Design, Seventh Edition

36 Object-Oriented Programming (cont’d.) Write algorithms and implement them in a programming language. Use functions to implement algorithms. Learn how to combine data and operations on the data into a single unit called an object. C++ was designed to implement OOD. 36C++ Programming: From Problem Analysis to Program Design, Seventh Edition

37 ANSI/ISO Standard C++ C++ evolved from C. C++ designed by Bjarne Stroustrup at Bell Laboratories in early 1980s. – Many different C++ compilers were available. – C++ programs were not always portable from one compiler to another. In 1998, ANSI/ISO C++ language standards were approved. Second standard called C++11 approved in 2011. 37C++ Programming: From Problem Analysis to Program Design, Seventh Edition


Download ppt "EGR 2261 Engineering Problem Solving Using C and C++ Professor Nick Reeder."

Similar presentations


Ads by Google