Chapter 1: An Overview of Computers and Programming Languages

Slides:



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

Chapter 1: An Overview of Computers and Programming Languages
Overview of Computers & Programming Languages Chapter 1.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
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.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
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 © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
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
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.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
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
CS2301:Computer Programming 2
1 Original Source : and Problem and Problem Solving.ppt.
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.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
Introduction to Computers and C++ Programming
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
Computer Terms Review from what language did C++ originate?
Engineering Problem Solving With C An Object Based Approach
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
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
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)
Lab 1 Introduction to C++.
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.
Computer Terms Review from what language did C++ originate?
ICS103 Programming in C 1: Overview of Computers And Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Chapter 1: An Overview of Computers and Programming Languages

Outlines In this chapter, you will study: The Language of a Computer The Evolution of Programming Languages Processing a C++ Program Programming with the Problem Analysis–Coding–Execution Cycle

Introduction Without software, the computer is useless Software is developed with programming languages C++ is a programming language C++ suited for a wide variety of programming tasks C++ Programming: From Problem Analysis to Program Design, Sixth Edition

Elements of a Computer System Hardware CPU Main memory Secondary storage Input/Output devices Software C++ Programming: From Problem Analysis to Program Design, Sixth 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

The Language of a Computer Analog signals: continuous wave forms Digital signals: sequences of 0s and 1s Machine language: language of a computer; a sequence of 0s and 1s Binary digit (bit): the digit 0 or 1 Binary code (binary number): a sequence of 0s and 1s

The Language of a Computer (cont’d.) Byte: A sequence of eight bits Kilobyte (KB): 210 bytes = 1024 bytes ASCII (American Standard Code for Information Interchange) 128 characters A is encoded as 1000001 (65th character) 3 is encoded as 0110011

Processing a C++ Program #include <iostream> using namespace std; int main() { cout << "My first C++ program." << endl; return 0; } Sample Run: My first C++ program.

Processing a C++ Program (cont’d.) To execute a C++ program: Use an editor to create a source program in C++ Preprocessor directives begin with # and are processed by the preprocessor Use the compiler to: Check that the program obeys the language rules Translate into machine language (object program)

Processing a C++ Program (cont’d.) To execute a C++ program (cont'd.): Linker: Combines object program with other programs provided by the SDK 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 Some IDEs do all this with a Build or Rebuild command

Processing a C++ Program (cont’d.)

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

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: Maintenance Use and modify the program if the problem domain changes

The Problem Analysis–Coding–Execution Cycle (cont’d.) Thoroughly understand the problem and all requirements Does program require user interaction? Does program manipulate data? What is the output? If the problem is complex, divide it into subproblems Analyze and design algorithms for each subproblem Check the correctness of algorithm Can test using sample data Some mathematical analysis might be required

The Problem Analysis–Coding–Execution Cycle (cont’d.) Once the algorithm is designed and correctness verified Write the equivalent code in high-level language Enter the program using text editor

The Problem Analysis–Coding–Execution Cycle (cont’d.) Run code through compiler If compiler generates errors Look at code and remove errors Run code again through compiler If there are no syntax errors Compiler generates equivalent machine code Linker links machine code with system resources

The Problem Analysis–Coding–Execution Cycle (cont’d.) Once compiled and linked, loader can place program into main memory for execution The final step is to execute the program Compiler guarantees that the program follows the rules of the language Does not guarantee that the program will run correctly

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

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

Example 1-3 Design an algorithm to calculates the monthly paycheck of a salesperson at a local department store. payCheck = baseSalary + bonus + additionalBonus Data: base salary The number of years that the salesperson has been with the company The total sales made by the salesperson for that month

Example 1-3 (cont’d.) Algorithm to calculate the bonus Suppose noOfServiceYears denotes the number of years that the salesperson has been with the store Suppose bonus denotes the bonus. Algorithm to calculate the bonus if (noOfServiceYears is less than or equal to five) bonus = 10 * noOfServiceYears otherwise bonus = 20 * noOfServiceYears

Example 1-3 (cont’d.) Algorithm to calculate additional bonus Suppose totalSales denotes the total sales made by the salesperson for the month Suppose additionalBonus denotes the additional bonus. Algorithm to calculate additional bonus if (totalSales is less than 5000) additionalBonus = 0 otherwise if (totalSales is greater than or equal to 5000 and totalSales is less than 10000) additionalBonus = totalSales (0.03) additionalBonus = totalSales (0.06)

Example 1-3 (cont’d.) The algorithm to calculate a salesperson’s monthly paycheck: Get baseSalary. Get noOfServiceYears. Calculate bonus using calculate bonus algorithm Get totalSales. Calculate additionalBonus using the algorithm to calculate additional bonus Calculate payCheck using the equation: payCheck = baseSalary + bonus + additionalBonus

Example 1-5 Calculate each student’s grade Design algorithms to: 10 students in a class; each student has taken five tests; each test is worth 100 points Design algorithms to: Calculate the grade for each student and class average Find the average test score Determine the grade Data: students’ names; test scores

Example 1-5 (cont’d.) Algorithm to determine the average test score: Get the five test scores Add the five test scores Suppose sum stands for the sum of the test scores Suppose average stands for the average test score: average = sum / 5;

Example 1-5 (cont’d.) Algorithm to determine the grade: if average is greater than or equal to 90 grade = A otherwise if average is greater than or equal to 80 and less than 90 grade = B if average is greater than or equal to 70 and less than 80 grade = C if average is greater than or equal to 60 and less than 70 grade = D grade = F

Example 1-5 (cont’d.) Main algorithm is as follows: totalAverage = 0; Repeat the following for each student: Get student’s name Use the algorithm to find the average test score Use the algorithm to find the grade Update totalAverage by adding current student’s average test score Determine the class average as follows: classAverage = totalAverage / 10

Refer to text book and read examples 1-2, and 1-4

Compiling C++ Code Self Study Slides

Some examples on C++ IDEs Online IDEs https://www.codechef.com/ide https://www.onlinegdb.com/ https://www.jdoodle.com/online-compiler-c++ Offline IDEs Microsoft visual studio (will be explained in this slides) Eclipse Code::Blocks CodeLite

Microsoft visual studio 2015 home screen

Before you create your first C++ project in Visual Studio, you need to install Visual C++ 2015 Tools for Windows Desktop:

To create your HelloWorld project => File ->new->project, you can choose the Win32 Console Application template, Name your project and click “ok”

When this window appears click next

Choose Empty project and click finish

From solution explorer window, right click on source files and choose to add new item as follows

Select C++ File, give it a name and click add

Write your code in the .cpp file and click on the green triangle to run your program

This window will appear