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

Slides:



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

Lecture 1: Overview of Computers & Programming
Chapter 1: An Overview of Computers and Programming Languages
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.
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.
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.
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.
Chapter 1 An Overview of Computers and Programming Languages.
EGR 2261 Engineering Problem Solving Using C and C++ Professor Nick Reeder.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
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.
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, Third 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.
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.
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.
Chapter 1: Introduction to Computers and Programming.
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.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
Java Programming: From the Ground Up
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Engineering Problem Solving With C An Object Based Approach
Chapter 1: An Overview of Computers and Programming Languages
BASIC PROGRAMMING C SCP1103 (02)
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
C++ Programming: From Problem Analysis to Program Design
Chapter 1: Introduction to Computers and Programming
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Topics Introduction Hardware and Software How Computers Store Data
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
Chapter 1: An Overview of Computers and Programming Languages
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Reminders Please turn off cell phones.
ICS103 Programming in C 1: Overview of Computers And Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Engineering Problem Solving Using C and C++ Professor Nick Reeder EGR 2261 Engineering Problem Solving Using C and C++ Professor Nick Reeder Handouts: syllabus, Lab 1

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. -Ask them about their programming experience. -Go over syllabus -Have them log on to website

Introduction Without software, the computer is useless. Software is developed with programming languages. C++ is one of the most popular programming languages. TIOBE Index IEEE Top 10 Programming Languages for 20176 PYPL Index C++ is suited for a wide variety of programming tasks. C++ 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++. Most of this course will focus on material that is common to C++ and C. 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 C++ Programming: From Problem Analysis to Program Design, Seventh Edition

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

Central Processing Unit and Main Memory (cont’d.) 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. C++ 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. C++ 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 CDs & DVDs Tapes C++ 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 C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Software Software: programs that do specific tasks. System programs control the computer. Operating system (such as Windows or macOS) 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 for the user. Word processors Spreadsheets Games C and C++ are well-suited for both kinds of programs. C++ 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: 01101100 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): 210 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. C++ Programming: From Problem Analysis to Program Design, Seventh Edition

The Language of a Computer (cont’d.) C++ 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. Example: to calculate wages = rate * hours in machine language, you might type: 100100 010001 //Load 100110 010010 //Multiply 100010 010011 //Store C++ 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). Example: Using assembly language instructions, wages = rate * hours might be typed as: LOAD rate MULT hour STOR wages C++ 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++, Java, C#, and Python. Programs written in these language look much more like English. The equation wages = rate * hours can be written in C++ as: wages = rate * hours; Compiler: translates a program written in a high-level language into machine language. C++ 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. It’s powerful, complex software used by professional programmers. On campus, it’s on the computers in the EET Resource Center (room 1-242H) and on some computers in the library.

Signing in to Microsoft Visual Studio Visual Studio is free, but to use it you must have a Microsoft account. If you don’t already have one, go to https://signup.live.com/signup

Development Settings and Color Theme The first time you use Visual Studio, you’ll see the following dialog box. Change the Development Settings from General to Visual C++. To change development settings later, Tools > Import and Export Settings… > Reset all settings > No> Visual C++. To change color them later, Tools > Options > Environment > General > Color theme.

A Simple C++ Program //******************************************************** // Name: Week1FirstProgram // Author: Nick Reeder // Date: 07/13/2015 // This program computes and displays wages, based on // hard-coded values for hourly rate and number of hours. #include <iostream> using namespace std; int main() { int rate = 15; int hours = 40; int wages = rate * hours; cout << wages << "\n"; return 0; } Have them create new project named Week1FirstProgram (console app, empty project), then enter and run it, starting with couting 15*40, then adding variable names, then adding program title block. Also show some of the many errors that can occur (misspelled variable name, missing semicolon, no 0 after return…). C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Title Block //******************************************************** // Name: Week1FirstProgram // Author: Nick Reeder // Date: 07/13/2015 // This program computes and displays wages, based on // hard-coded values for hourly rate and number of hours. Each program should contain a title block listing the program’s name, your name, the date, and a description that uses proper spelling and grammar. At a minimum, the description should say what input values the user is expected to provide, and what output values the program will produce. Use as many lines as needed for the description so that you can read it without scrolling to the right.

Finding Your Files in Windows Here is the file that contains the source code that you typed. Have them close Visual Studio to find these files.

Displaying the File Extensions in Windows To make Windows 7 display file extensions, select Tools > Folder Options… > View, then remove the check mark next to Hide extensions for known file types.

Caution: Be Sure to Open the Right File To resume work on an existing program, one way is by double-clicking a file in Windows, without first opening Visual Studio. But you must double-click either the solution file (Week1FirstProgram.sln) or the project file (Week1FirstProgram.vcxproj), not the source-code file (Week1FirstProgram.cpp). Show them different ways to re-open the project in Visual Studio.

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. For example, you can’t use parentheses where you’re supposed to use braces.

Processing a C++ Program C++ 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). C++ 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. C++ 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). Steps 2 through 6 on the previous slides take place when you press Ctrl+F5. Another popular free C++ IDE is Bloodshed’s Dev-C++ at http://www.bloodshed.net/devcpp.html.

Programming with the Analysis–Coding–Execution Cycle An algorithm is a step-by-step process for solving a specific type of problem. Programming is a process of problem solving. C++ 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. C++ 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 C++ 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 C++ Programming: From Problem Analysis to Program Design, Seventh Edition