1 CS161 Introduction to Computer Science Topic #3.

Slides:



Advertisements
Similar presentations
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
Advertisements

What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
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.
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
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 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Basic Elements of C++ Chapter 2.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 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.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
1 C++ Syntax and Semantics, and the Program Development Process.
Week 1 Algorithmization and Programming Languages.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
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!
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
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.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
 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.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
What Actions Do We Have Part 1
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
CPS120: Introduction to Computer Science
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
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.
Basic Elements of C++ Chapter 2.
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Today in CS161 Week #3 Learn about… Writing our First Program
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.
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
CS150 Introduction to Computer Science 1
C++ Programming Lecture 3 C++ Basics – Part I
Programs written in C and C++ can run on many different computers
What Actions Do We Have Part 1
Capitolo 1 – Introduction C++ Programming
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

1 CS161 Introduction to Computer Science Topic #3

CS161 Topic #32 Today in CS161 Lecture –Solving Problems with Computers Write a short Program Basic Form of all C++ programs What are Variables, Data Types, Statements How do we perform input and output Assignments/Questions –Questions on Program #1 ?

CS161 Topic #33 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 #34 Preprocessor Directives #include This is a preprocessor directive #include allows our programs to copy the contents of some other file (iostream, for example) and have it behave as if that file was typed at the beginning of our programs! iostream allows our programs to perform input from the keyboard (standard in) and output to the screen (standard out)

CS161 Topic #35 Header Comments... // *********************************** //Karla S. Fant These are in line comments and provide for documentation in our programs Once encountered, the rest of the line is taken as documentation. If you want to surround them by asterisks -- MAKE SURE to place at least one space between the // and the asterisks.... otherwise, your entire program will be mistaken as a comment!?!?!

CS161 Topic #36 (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 #37 (Different Kind of Comment...) /* *********************************** Karla S. Fant ********************************* */ This type of comment is best used when writing a large block of comments. They begin with a /* and end when you type a */ If you forget the ending */ your entire program is taken as a comment!!! I recommend placing a space between the /* and any other asterisks....

CS161 Topic #38 Variable Definitions //Define variables float inches;//to save # inches float mm;//to save the result What are variables? How are they defined? data_type variable_name What is a data type and why is it important? What kind of variable names can we use?

CS161 Topic #39 Variable Definitions What are variables? –Allocate Memory to store data How are they defined? data_type variable_name What is a data type and why is it important? –float, int, char, boolare the fundamental ones –double, short, longare additional ones What kind of variable names can we use? –must start with a letter, be any combination of letters, digits, or underscores.

CS161 Topic #310 Convert inches to millimeters int main() { //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 #311 Displaying Output cout << “message” <<endl; Pronounced see out << is the insertion operator Think of << as an arrow. The message you want to display is being sent to the OUTPUT device in the direction of the arrow: output_device message in double quotes

CS161 Topic #312 Output after first cout Welcome! We will be converting inches to mm today

CS161 Topic #313 (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 #314 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 #315 Output after 2nd cout Welcome! We will be converting inches to mm today Please enter the number of inches that you wish to convert:

CS161 Topic #316 Output after 2nd cout Welcome! We will be converting inches to mm today Please enter the number of inches that you wish to convert: 2

CS161 Topic #317 Output after 2nd cout Welcome! We will be converting inches to mm today Please enter the number of inches that you wish to convert: 2 You entered: 2in

CS161 Topic #318 Receiving Input cin >> inches; Pronounced see in >> is the extraction operator Think of >> as an arrow. The data you want to receive is coming from the input device in the direction of the arrow and being saved in memory: input_device variable_name

CS161 Topic #319 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 #320 Assignment Operation //Step #3 Convert inches to millimeters mm = 25.4 * inches; Multiplication requires the asterisk –can’t leave it out like we do in math –3x would be written 3 * x in C++ = is the assignment operation –takes the value on the right and saves it in the memory for the variable on the left

CS161 Topic #321 CS161 Introduction to Computer Science Program #1 Questions?

CS161 Topic #322 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 countvscout watch your semicolons!