Programming Fundamental

Slides:



Advertisements
Similar presentations
Types and Variables. Computer Programming 2 C++ in one page!
Advertisements

COSC 120 Computer Programming
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Three types of computer languages
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.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
COMPUTER SCIENCE I C++ INTRODUCTION
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
COMPSCI 174- Introduction to C++ Class hour Section 01: MWF 9:55am – 10:45am. Hyer Hall 210.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 2 Overview of C++ Lecture Notes Prepared By: Blaise W. Liffick, PhD Department of Computer Science Millersville University Millersville, PA
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
برمجه حاسبات 2 أ. بيان غزلان الفصل الدراسي هـ.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
Bill Tucker Austin Community College COSC 1315
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
Chapter 2: Introduction to C++
Chapter 1: An Overview of Computers and Programming Languages
Completing the Problem-Solving Process
Documentation Need to have documentation in all programs
Computing Fundamentals
Basic Elements of C++.
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Beginning C++ Programming
Computer Engineering 1nd Semester
Introduction to C++ October 2, 2017.
Basic Elements of C++ Chapter 2.
Chapter 1: Introduction to Computers and Programming
Introduction to C++ Programming
1.13 The Key Software Trend: Object Technology
Chapter 1: An Overview of Computers and Programming Languages
CS150 Introduction to Computer Science 1
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 2: Introduction to C++.
C++ Programming Lecture 3 C++ Basics – Part I
Programs written in C and C++ can run on many different computers
Chapter 2: Overview of C++
Introduction to C Programming
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Programming Fundamental Introduction to Programming

Objectives Define the terminology of used in programming Explain the tasks performed by a programmer Understand the employment opportunities for programmers and software engineers Become aware of structured design methodologies

Objectives A typical C++ program development environment. Study variables How to declare How to use Become familiar with the basic components of a C++ program, including identifiers

Programming a Computer It is important to understand the relationship between the terms programs, programmers, and programming languages. Programs – The directions that humans give to computers Programmers – The people who create these directions Programming Languages – Special languages used by programmers to communicate directions to a computer Programs – Test 2013/2014

The Programmer’s Job Programmers help solve computer problems Employee or freelance Typical steps involved Meet with user to determine problem Convert the problem into a program Test the program Provide user manual help solve computer problems – Test 2012 Employee or freelance – Final 2013, 2014 Typical steps – Quiz 2013

What Traits Should a Software Developer Possess? Analytical Skills Communication Skills Creativity Customer-service skills Detail oriented Problem-solving skills Teamwork Technical skills

Employment Opportunities Computer software engineers: designs an appropriate solution to a user’s problem Computer programmer: codes a computer solution Coding is the process of translating a computer solution into a language a computer can understand Some positions call for both engineering and programming Computer software engineers – Test 2014 Computer programmer – Test 2013, 2014 Coding – Test 2014

Flowcharting

Flowcharting

Flowchart Example

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

Implementation #include <iostream> using namespace std; int main() { const float KM_PER_MILE = 1.609; float miles, kms; cout << “Enter the distance in miles: “; cin >> miles; kms = KM_PER_MILE * miles; cout << “The distance in kilometers is “ << kms << endl; return 0; }

Testing, Execution, Debugging Common error sources Violations of grammar rules of the high level language Errors that occur during execution Errors in the design of the algorithm

Typical C++ Development Environment C++ systems generally consist of three parts: a program development environment, the language and the C++ Standard Library. C++ programs typically go through six phases: edit, preprocess, compile, link, load and execute.

Typical C++ Development Environment (Cont.) Phase 1 consists of editing a file with an editor program, normally known simply as an editor. Type a C++ program (source code) using the editor. Make any necessary corrections. Save the program. C++ source code filenames often end with the .cpp, .cxx, .cc or .C extensions, which indicate that a file contains C++ source code.

Typical C++ Development Environment (Cont.) Linux editors: vi and emacs. You can also use a simple text editor, such as Notepad in Windows, to write your C++ code. integrated development environments (IDEs) Provide tools that support the software-development process, including editors for writing and editing programs and debuggers for locating logic errors-errors that cause programs to execute incorrectly.

Typical C++ Development Environment (Cont.) Popular IDEs Microsoft® Visual Studio 2015 Community Edition NetBeans Eclipse Apple’s Xcode CodeLite Clion

Typical C++ Development Environment (Cont.) In phase 2, you give the command to compile the program. A preprocessor program executes automatically before the compiler’s translation phase begins (so we call preprocessing Phase 2 and compiling Phase 3). The C++ preprocessor obeys commands called preprocessing directives, which indicate that certain manipulations are to be performed on the program before compilation. These manipulations usually include (copy into the program file) other text files to be compiled, and perform various text replacements.

Typical C++ Development Environment (Cont.) In Phase 3, the compiler translates the C++ program into machine-language code-also referred to as object code.

Typical C++ Development Environment (Cont.) Phase 4 is called linking. The object code produced by the C++ compiler typically contains “holes” due to these missing parts. A linker links the object code with the code for the missing functions to produce an executable program. If the program compiles and links correctly, an executable image is produced.

Typical C++ Development Environment (Cont.) Phase 5 is called loading. Before a program can be executed, it must first be placed in memory. This is done by the loader, which takes the executable image from disk and transfers it to memory. Additional components from shared libraries that support the program are also loaded.

Typical C++ Development Environment (Cont.) Phase 6: Execution Finally, the computer, under the control of its CPU, executes the program one instruction at a time. Some modern computer architectures often execute several instructions in parallel.

Typical C++ Development Environment (Cont.) Problems That May Occur at Execution Time Programs might not work on the first try. Each of the preceding phases can fail because of various errors that we’ll discuss throughout this book. If this occurred, you’d have to return to the edit phase, make the necessary corrections and proceed through the remaining phases again to determine that the corrections fixed the problem(s). Most programs in C++ input or output data.

Typical C++ Development Environment (Cont.) Certain C++ functions take their input from cin (the standard input stream; pronounced “see-in”), which is normally the keyboard, but cin can be redirected to another device. Data is often output to cout (the standard output stream; pronounced “see-out”), which is normally the computer screen, but cout can be redirected to another device. When we say that a program prints a result, we normally mean that the result is displayed on a screen.

Typical C++ Development Environment (Cont.) Data may be output to other devices, such as disks, hardcopy printers or even transmitted over the Internet. There is also a standard error stream referred to as cerr. The cerr stream is used for displaying error messages.

Variables Give a name to a memory location Compiler accesses specific memory location when program uses a given variable Refer to objects in the program for which the value can change Declaration type variableName; // or type variableName = initializerExpression;

Variables Variables Declaration Examples: int age = 18; Can be either initialized or uninitialized… If variable is uninitialized Contents must be considered as “garbage value” Examples: int age = 18; double GPA = 3.25, credits; char letterGrade = ‘A’; bool ok, done = false;

Data Types Defines a set of values and operations that can be performed on those values integers positive and negative whole numbers, e.g. 5, -52, 343222 short, int, long represented internally in binary predefined constants in INT_MIN and INT_MAX

Data Types (con’t) Floating point (real) number has two parts, integral and fractional e.g. 2.5, 3.66666666, -0.000034, 5.0 float, double, long double stored internally in binary as mantissa and exponent 10.0 and 10 are stored differently in memory

Data Types (con’t) Boolean named for George Boole represent conditional values Return: true and false

Data Types (con’t) Characters represent individual character values E.g. ’A’ ’a’ ’2’ ’*’ ’”’ ’’ stored in 1 byte of memory special characters: escape sequences E.g. ’\n’ ’\b’ ’\r’ ’\t’ ‘\’’

string Class Strings not built-in, but come from library Classes extend C++ string literal enclosed in double quotes E.g.: “Enter speed:“ “ABC” “B” “true” “1234” #include <string> for using string identifiers, but not needed for literals

Identifiers (1 of 2) An identifier is the name of something that appears in a program Consists of letters, digits, and the underscore character (_) Must begin with a letter or underscore C++ is case sensitive NUMBER is not the same as number Two predefined identifiers are cout and cin Unlike reserved words, predefined identifiers may be redefined, but it is not a good idea

Identifiers (2 of 2) Legal identifiers in C++: first conversion payRate TABLE 1-1 Examples of Illegal Identifiers Illegal Identifier Reason A Correct Identifier employee Salary There can be no space between employee and Salary. employeeSalary Hello! The exclamation mark cannot be used in an identifier. Hello one+two The symbol + cannot be used in an identifier. onePlusTwo 2nd An identifier cannot begin with a digit. second

Summary Program are step-by-step instructions that tell a computer how to perform a task Programmers use programming languages to communicate with the computer Structured design Problem is divided into smaller subproblems Each subproblem is solved Combine solutions to all subproblems Identifiers consist of letters, digits and underscores, and begin with a letter or an underscore

Bibliography Adams, J. & Nyhoff, L. (2003). “C++ An Introduction to Computing.” 3rd ed. New Jersey. Pearson Education. Bronson, G. J. (2006). “A First Book of C++: From Here to There.” 3rd ed. Massachusetts. Course Technology. Deitel, H.M & Deitel, A.S (2017). “C++ How to Program (Early Objects Version).” Global 10th ed. London. Pearson Education. Friedman, F.L & Koffman, E.B (2011). “Problem Solving, Abstraction, and Design Using C++.” 6th International ed. Massachusetts. Pearson Education. Malik, D.S. (2018). “C++ Programming From Problem Analysis to Program Design.” 8th ed. United States of America. Cengage Learning. Zak, D. (2016). “An Introduction to Programming with C++.” 8th ed. Massachusetts. Course Technology.