CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Algorithms Series of mathematical or variable manipulations Integer a,b,c a = 12 b = 22 c = a * b (what is c?) 12 * 22 = 264.
CSE202: Lecture 1The Ohio State University1 Introduction to C++
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
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.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
Computer Science 117 Intro to C++ 08/26/13. Today Discuss Syllabus Brief History of C++ How to Execute a C++ program. Reading assignment.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Computer Science 1620 Programming & Problem Solving.
CS 201 Functions Debzani Deb.
Introduction to a Programming Environment
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Basic Elements of C++ Chapter 2.
CS161 Topic #14 1 Today in CS161 Lecture #14 Practicing! Writing Programs to Practice Write a program that counts the number of vowels in a sentence, ended.
Computer Science 101 Introduction to Programming.
Chapter Introduction to Computers and Programming 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Today in CS161 Lecture #4 Solving Problems with Computers Walk through the Tic Tac Toe Algorithm Getting ready for Creating Programs Turn the Inches to.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Computer Science 101 Introduction to Programming.
A1 Visual C++.NET Intro Programming in C++ Computer Science Dept Va Tech August, 2002 © Barnette ND & McQuain WD 1 Quick Introduction The following.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Creating your first C++ program
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
1 CS161 Introduction to Computer Science Topic #3.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Creating Programs on UNIX This term you can create programs on UNIX or you can create programs using a C++ compiler on your PC. This set of slides steps.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Chapter 2 part #1 C++ Program Structure
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
1 CS161 Introduction to Computer Science Topic #9.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Program #2 Algorithm for Parking at PSU. Understanding the Assignment You will be writing a program to find out how much someone at PSU might be spending.
1 CS161 Introduction to Computer Science Topic #8.
Today in CS161 Week #2 Solving Problems with Computers What are Algorithms Write a short Algorithm Preparing to write programs On Unix and Mac systems.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Today in CS161 Lecture #5 Learn about… Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
CSE1222: Lecture 1The Ohio State University1. Computing Basics  Computers CPU, Memory & Input/Output (IO)  Program Sequence of instructions for the.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Completing the Problem-Solving Process
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Today in CS161 Week #2 Preparing to write programs Assignments
Creating Programs on UNIX
Basic Elements of C++ Chapter 2.
Today in CS161 Week #3 Learn about… Writing our First Program
Unit 3: Variables in Java
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

CS161 Topic #21 CS161 Introduction to Computer Science Topic #2

CS161 Topic #22 Today in CS161 Lecture –Handouts you should have –Solving Problems with Computers Write a short Algorithm Assignments –Walk through Program #1 -- step by step Question Session

CS161 Topic #23 CS161 Handouts: From the web site, make sure to look at: ( Syllabus Course Outline Style Sheet C++ Style Requirements Program Cover Sheet

CS161 Topic #24 Solving Problems w/ Computers Programs are... –an expression of a series of instructions that the computer must perform –written in precise languages, called programming languages Programming languages... –translate your ideas into specific language that the computer will understand –C, C++, Java, Pascal, Visual Basic, Cobol, Fortran

CS161 Topic #25 Solving Problems w/ Computers The most difficult part of programming is figuring out how to design a method to solve a problem Only then do we translate this into C++! Therefore, start by writing an algorithm once you understand the problem

CS161 Topic #26 Solving Problems w/ Computers An algorithm is a sequence of step by step instructions for performing some task -- usually for computation An algorithm must... –accomplish the task –be clear and easy to understand –define the sequence of steps needed to accomplish the task in the order specified

CS161 Topic #27 Algorithms It is best to ignore the details of your programming language (C++) when trying to solve a problem Instead, figure out the steps you need to go thru to solve the problem Write these steps down in English These steps are called the algorithm!

CS161 Topic #28 Algorithms Think of your algorithm as a tool for creating the instructions for solving a problem....as if you were to tell them to another person. Remember an algorithm is a sequence of step by step instructions for performing some tasks

CS161 Topic #29 For Example...solve a problem Convert inches to millimeters –First understand the problem where do the inches come from (the user) what is the math needed for the conversion –mm = 25.4 times inches how do we want to display the results – 2in convert to 50.8mm

CS161 Topic #210 Convert inches to millimeters Next, write the algorithm –Step 1: Welcome the user tell them what to expect tell them the purpose of the program

CS161 Topic #211 Convert inches to millimeters Step 2: –Get the number of inches from the user display a prompt asking the user to enter read in the number of inches display what was read (echo) ask the user if this is really correct (confirm) if not, repeat this step until the user is satisfied

CS161 Topic #212 Convert inches to millimeters Continuing with Steps 3 and 4: –Convert the number of inches to mm mm = 25.4 times inches –Display the results –Provide a sign-off message

CS161 Topic #213 Convert inches to millimeters The next step is to turn this into a C++ program! All programs have the following “form” #include using namespace std; //header comments... int main() { //program body goes here... return 0; }

CS161 Topic #214 Convert inches to millimeters #include using namespace std; // *********************************** //Karla S. Fant //CS161 Programming Assignment #0 //Purpose of this program is to convert //inches entered in by the user into //millimeters and display the results //********************************** int main() {

CS161 Topic #215 (Different Kind of Comment...) #include using namespace std; /* *********************************** Karla S. Fant CS161 Programming Assignment #0 Purpose of this program is to convert inches entered in by the user into millimeters and display the results ********************************* */ int main() {

CS161 Topic #216 Convert inches to millimeters //Define variables float inches;//to save # inches float mm;//to save the result //Step #1, welcome the user cout <<“Welcome! We will be converting” <<“ inches to mm today” <<endl;

CS161 Topic #217 (A different way to do this...) //Define variables float inches,//to save # inches mm;//to save the result //Step #1, welcome the user cout <<“Welcome! We will be converting”; cout <<“ inches to mm today” <<endl; (NOTE: endl is end followed by a letter l)

CS161 Topic #218 Convert inches to millimeters //Step #2, Get the input (prompt, read) cout <<“Please enter the number of inches” <<“ that you wish to convert: “; cin >> inches;//read the # inches //echo what was entered cout <<“You entered: “ <<inches <<“in” <<endl;

CS161 Topic #219 Convert inches to millimeters //Step #3 Convert inches to millimeters mm = 25.4 * inches; //Step #4 Display the results cout <<inches <<“in converts to “ <<mm <<“mm” <<endl; //Step #5 Sign off message cout <<“Thank you for using CONVERT” <<endl; return 0; }

CS161 Topic #220 CS161 Introduction to Computer Science ASSIGNMENTS!!!

CS161 Topic #221 Programming Assignment #1 First, get an ODIN account Next, learn how to login Try sending ! Learn how to exit the ODIN menu and enter the UNIX shell Meet with TA’s to get a hand’s on tutorial. Their office hours are posted on the web site:

CS161 Topic #222 Programming Assignment #1 Put the #include in column #1 endl is “e n d” followed by lower case L spaces inside double quotes ARE important

CS161 Topic #223 Steps to Enter a Program Login to ODIN Exit the Menu Now you are at the UNIX prompt It is time to enter your program! vi prog1.cpp Now it is time to start inserting our program. To do so, type i, for insert:

CS161 Topic #224 Steps to Enter a Program Now start typing your program. Line by line. When done hit the escape key. If the program is perfect, it is time to write it to the file. Type :w To quit the editor, type :q

CS161 Topic #225 Steps to Enter a Program We are now back to the UNIX prompt. To compile the program we type the following. g++ prog1.cpp At this point, there will either be error messages displayed (with line numbers), or not (if it is correct!).

CS161 Topic #226 Steps to Enter a Program To fix a program, we must edit it. Type: vi prog1.cpp Now, if you want to go to the line where the error occurred, type the line number followed by the enter key. For example, to go to line number 10 type: 10

CS161 Topic #227 Steps to Enter a Program To add something at the end (like a semicolon), type a for append: Now you are in append mode. You can type what you want. When you are done typing hit the escape key When you are done, type the following to write the changes back to the file and quit the editor :wq!

CS161 Topic #228 Steps to Enter a Program Other things to type while in the editor: –h goes left –kgoes up –jgoes down –lgoes right –xdelete the character you are at –dddelete the line that you are at

CS161 Topic #229 Steps to Enter a Program Again, we are at the unix prompt. To compile your program type: g++ prog1.cpp If it compiles without any errors, it is time to run the program to see it actually work! Type./a.out

CS161 Topic #230 CS161 Introduction to Computer Science Are you Ready?