CS149D Elements of Computer Science

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Computer Programming w/ Eng. Applications
ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Lecture 17: 10/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
ECE 264 Object-Oriented Software Development Instructor: Dr. Michael Geiger Spring 2009 Lecture 2: Basic C++ Programs.
Lecture 18: 10/31/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Basic Elements of C++ Chapter 1.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Introduction ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
2/4/2016Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs.
Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Lecture 24: 12/3/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Basic concepts of C++ Presented by Prof. Satyajit De
Topic Pre-processor cout To output a message.
What Actions Do We Have Part 1
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
1-1 Logic and Syntax A computer program is a solution to a problem.
Chapter 2 part #1 C++ Program Structure
Functions, Part 2 of 2 Topics Functions That Return a Value
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
CS149D Elements of Computer Science
CS170 Computer Organization and Architecture I
Programming Right from the Start with Visual Basic .NET 1/e
Functions, Part 2 of 3 Topics Functions That Return a Value
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
CS148 Introduction to Programming II
Wednesday 09/23/13.
Introduction to C++ Programming
CS148 Introduction to Programming II
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
CS149D Elements of Computer Science
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Arithmetic Operations
CS149D Elements of Computer Science
CS149D Elements of Computer Science
CS148 Introduction to Programming II
CS148 Introduction to Programming II
Reading from and Writing to Files
CS149D Elements of Computer Science
CS149D Elements of Computer Science
COMS 261 Computer Science I
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Reading from and Writing to Files Part 2
Functions, Part 2 of 3 Topics Functions That Return a Value
CS148 Introduction to Programming II
Functions, Part 2 of 3 Topics Functions That Return a Value
CS148 Introduction to Programming II
Reading from and Writing to Files
Presentation transcript:

CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture 14: 10/17/2002 Lecture 14: 10/17/2002 CS149D Fall 2002

Outline Simple C++ programs Program structure A simple C++ program: Hello World Program! A longer C++ program: Compute distance between two points Lecture 14: 10/17/2002 CS149D Fall 2002

The main() function body C++ Program Structure Global area The main() function body Another function Another function Lecture 14: 10/17/2002 CS149D Fall 2002

A Simple C++ Example White Space? /* Author: Ayman Abdel-Hamid */ // This is your first C++ program // The program will only print hello on the command line #include <iostream.h> #include <stdlib.h> int main() { cout << “Hello” ; return 0; } Comments Preprocessor directives White Space? Any C++ program must have a main function All C++ statements must end with a ; Lecture 14: 10/17/2002 CS149D Fall 2002

A Longer Example1/3 Problem Statement Input Output Compute the straight line distance between two points in a plane Input A point has an x and y coordinates. We need 2 points Assume (x1, y1) = (1,5) & (x2, y2) = (4,7) Output The distance between the 2 points. How? (x1, y1) (x2, y2) x1 x2 y1 y2 side1 side2 distance Calculate side1 = x2 - x1 Calculate side2 = y2 - y1 Calculate distance = Square root (side12 + side22) Lecture 14: 10/17/2002 CS149D Fall 2002

A Longer Example2/3 Algorithm Assign x1 the value 1 Assign y1 the value 5 Assign x2 the value 4 Assign y2 the value 7 Assign side1 the value x2 –x1 Assign side2 the value y2-y1 Assign distance the value sqrt (side12 + side22) Write distance on the screen Stop Lecture 14: 10/17/2002 CS149D Fall 2002

A Longer Example3/3 // This program computes the distance between two points. A point has an x and y coordinate //Program from Etter Text, chapter 2, page 22 (also chapter 1, page 17) //Preprocessor directives #include <iostream.h> #include <stdlib.h> #include <math.h> int main() { // Define and initialize variables. double x1=1, y1=5, x2=4, y2=7, side_1, side_2, distance; // Compute length of sides of right triangle. side_1 = x2 - x1; side_2 = y2 - y1; distance = sqrt( side_1 * side_1 + side_2 * side_2 ); // Print distance. cout << "The distance between the two points is "<< distance << " cm." << endl; // Exit program. return EXIT_SUCCESS; } Lecture 14: 10/17/2002 CS149D Fall 2002