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

Slides:



Advertisements
Similar presentations
Chapter 1 An Overview of Computers and Programming Languages.
Advertisements

ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
Chapter 1: An Overview of Computers and Programming Languages
Overview of Computers & Programming Languages Chapter 1.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CIS 260 Computer Programming I in C Prof. Timothy Arndt.
CHAPTER 1: AN OVERVIEW OF PROGRAMMING INSTRUCTOR: MOHAMMAD MOJADDAM How to Program in C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: Dr\Ali-Alnajjar.
CHAPTER 1 AN OVERVIEW OF COMPUTERS AND PROGRAMMING LANGUAGES.
CS102 Introduction to Computer Programming
Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
About the Presentations The presentations cover the objectives found in the opening of each chapter All chapter objectives are listed in the beginning.
Chapter 1 An Overview of Computers and Programming Languages.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Overview of Programming and Problem Solving. Objectives In this chapter you will: Learn about different types of computers Explore the hardware and software.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1: An Overview of Computers and Programming Languages
Overview of Programming and Problem Solving Textbook Chapter 1 1.
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Liang, Introduction to C++ Programming, (c) Chapter 1 Introduction to Computers, Programs, and C++
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS2301:Computer Programming 2
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 An Overview of Computers and Programming Languages.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1: An Overview of Computers and Programming Languages
Engineering Problem Solving Using C and C++ Professor Nick Reeder
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
About the Presentations
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Overview of Computers & Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Reminders Please turn off cell phones.
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

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

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

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

Chapter 1: An Overview of Computers and Programming Languages

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

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

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

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

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

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

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

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

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

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: A typical song in an MP3 file might contain 40 million bits.

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

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

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

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: //Load //Multiply //Store 18C++ Programming: From Problem Analysis to Program Design, Seventh Edition

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

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

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.

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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 C++ Programming: From Problem Analysis to Program Design, Seventh Edition