Problem Solving and Program Design. COMP104 Problem Solving / Slide 2 Our First Program // a simple program #include using namespace std; int main() {

Slides:



Advertisements
Similar presentations
The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or.
Advertisements

LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
Problem Solving and Program Design Programming. COMP102 Prog Fundamentals I : Problem Solving and Program Design/Slide 2 Problem Solving Process l Define.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Problem Solving and Program Design Programming. COMP104 Lecture 3 / Slide 2 Problem Solving Process l Define and analyze the problem. l Develop a solution.
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.
Writing and Testing Programs Drivers and Stubs Supplement to text.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
C++ Basics. COMP104 C++ Basics / Slide 2 Introduction to C++ * C++ is a programming language for manipulating numbers and user-defined objects. * C++
Three types of computer languages
Computer Science 1620 Programming & Problem Solving.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Chapter 6: Functions.
Software Engineering 1 (Chap. 1) Object-Centered Design.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
COMPUTER SCIENCE I C++ INTRODUCTION
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
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.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
First steps Jordi Cortadella Department of Computer Science.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
1 C++ Programming Basics Chapter 1 Lecture CSIS 10A.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Chapter 2 part #1 C++ Program Structure
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
Hardware and Software Programming. COMP104 Lecture 2 / Slide 2 Hardware and Software l Why should we bother with hardware, while we are having a programming.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Software Engineering Algorithms, Compilers, & Lifecycle.
By Kundang K Juman Hardware & Software. COMP102 Prog. Fundamentals I: Software / Slide 2 l Four components of a computer system: n CPU - central processing.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Problem Solving and Program Design. Problem Solving Process Define and analyze the problem. Develop a solution. Write down the solution steps in detail.
Engineering Problem Solving With C An Object Based Approach
Completing the Problem-Solving Process
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
C++ Programming: From Problem Analysis to Program Design
1.13 The Key Software Trend: Object Technology
Hardware & Software Programming. COMP102 Prog. Fundamentals I: Software / Slide 2 l Four components of a computer system: n CPU - central processing unit.
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.
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Life is Full of Alternatives
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Capitolo 1 – Introduction C++ Programming
Computer Terms Review from what language did C++ originate?
COMS 261 Computer Science I
Presentation transcript:

Problem Solving and Program Design

COMP104 Problem Solving / Slide 2 Our First Program // a simple program #include using namespace std; int main() { cout << "Hello world!" << endl; return 0; } Preprocessor statements Print statement Ends execution of main() which ends program Comments Function Function named main() indicates start of program

COMP104 Problem Solving / Slide 3 C++ Software Development * Major activities Editing (to write the program) Compiling (creates.obj file) Linking with compiled files (creates.exe file)  Object files  Library modules Loading and executing Testing the program

COMP104 Problem Solving / Slide 4 Problem Solving * Define the problem. * Develop a solution. n Outline solution first. n Then write down the solution steps in detail. * Test the solution and revise if necessary. * Document and maintain the solution.

COMP104 Problem Solving / Slide 5 Example 1 * Define Problem: n Find the best way to travel from HKUST to Central quickly and cheaply.

COMP104 Problem Solving / Slide 6 Example 1 * Develop Solution: n Evaluate all possible routes and modes of transportation n Select the route that meets our goal (fastest and cheapest)

COMP104 Problem Solving / Slide 7 Example 1 * Testing: n Test the route and make sure conditions have not changed (e.g., increased bus fares, road construction). * Documentation: n Give description of solution and explain it. * Maintenance: n Test and revise the route as needed.

COMP104 Problem Solving / Slide 8 Programming as Problem Solving * Define the problem. n What is the input & output? n What constraints must be satisfied? n What information is essential? * Develop a solution n Construct an algorithm (steps that must be done) n Implement a program. * Compile, test, and debug the program. * Document and maintain the program.

COMP104 Problem Solving / Slide 9 Example 2 * Problem Statement: n Convert US dollars into Hong Kong dollars. * Problem Analysis: n Input: Amount in US$ n Output: Amount in HK$ n Apply official currency exchange rates.

COMP104 Problem Solving / Slide 10 Example 2 * Algorithm n Read in amount in US$ n Calculate the HK$ amount n Display the results

COMP104 Problem Solving / Slide 11 Example 2 // converts US$ to HK$ #include using namespace std; int main(){ double usdollars; double hkdollars; // read in amount in US$ cout <<"Enter US$ amount and press return: "; cin >> usdollars; // calculate the HK$ amount hkdollars = 7.8 * usdollars; // display the results cout << "US$" << usdollars << " = HK$" << hkdollars << endl; return 0; }

COMP104 Problem Solving / Slide 12 Example 2 * Program Implementation: Program comments: // Library reference: #include Function type: int Function name and (lack of) parameters: main( ) Statement braces: { } Variable declaration: double Input/output functions: cin, cout

COMP104 Problem Solving / Slide 13 What Makes a Good Program? * Correctness n Meets the problem requirements n Produces correct results * Easy to read and understand * Easy to modify * Easy to debug * Efficient n Fast n Requires less memory