Lecture 3 -- 1Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.

Slides:



Advertisements
Similar presentations
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
C++ Basics. COMP104 C++ Basics / Slide 2 Introduction to C++ * C++ is a programming language for manipulating numbers and user-defined objects. * C++
Outline Java program structure Basic program elements
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
KEAN UNIVERSITY Visual C++ Dr. K. Shahrabi. Developer studio Is a self-contain environment for creating, compiling, linking and testing windows program.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Java Language and SW Dev’t
C Tokens Identifiers Keywords Constants Operators Special symbols.
 Programming Languages  First Generation Languages (Machine Language)  We Actually have to do a few things. First we have to find the operating code,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
1 More C++ Basics Chapter 3 Lecture CSIS 10A. 2 Agenda Review  C++ Standard Numeric Types Arithmetic–way more than you want! Character (char) data type.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
C++ Programming, Namiq Sultan1 Chapter 2 Introduction to C++ Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin Reference:
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Basic Types, Variables, Literals, Constants. What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet)
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Variables, Identifiers, Assignments, Input/Output
Working with Java.
Data types Data types Basic types
LESSON 3 IO, Variables and Operators
Programming Introduction to C++.
Compiler Construction
Computing with C# and the .NET Framework
CMSC 104, Section 4 Richard Chang
Reserved Words.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
null, true, and false are also reserved.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
C++ Basics.
פרטים נוספים בסילבוס של הקורס
درس برنامه‌سازي کامپيوتر
Variables in C Topics Naming Variables Declaring Variables
Chapter 1: Computer Systems
פרטים נוספים בסילבוס של הקורס
Keywords.
Govt. Polytechnic,Dhangar
Variables, Identifiers, Assignments, Input/Output
Variables in C Topics Naming Variables Declaring Variables
Prof. Bhushan Trivedi Director GLS Institute of Computer Technology
Variables in C Declaring , Naming, and Using Variables.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of the program rUse a compiler to convert the source file into a machine code file (object file). l convert from English to binary with machine operations rUse a linker to convert the object file into an executable file. l include other machine code that the program requires l In Visual C++ make sure you create an empty project or you will get linker errors rRun the executable file. rIterate from any point as needed. Editor Program.cpp Compiler Program.obj Libraries Linker Program.exe Run the Program Done success errors

Lecture Computer Science I - Martin Hardwick The First C++ Program // Hello World Program // Author: Martin Hardwick #include using namespace std; int main () { cout << Hello World! << endl; return 0; } rAnything following // is a comment intended to improve the readability of the program. r#include is used to tell the compiler and linker what library resources the program uses. l the resource defines everything you need to display messages on the screen rThe line using namespace std; says you want to use standard c++ names for things rThis program contains one function named main.

Lecture Computer Science I - Martin Hardwick Defining A C++ Function rA C++ function has the following form: rThe name of this function is main. rThe word int, means that this functions returns an integer number. l usually 0 to indicate that the program ran correctly. l this is what the return statement does at the end of the function rThe braces define the beginning and the end of the function. rThe first line of the function is called the function header. int main ( ) { sequence of statements separated by semicolons... return 0; }

Lecture Computer Science I - Martin Hardwick Displaying Messages On The Screen rTo display a message on the computer screen use the cout statement. rThe << operator says to display whatever immediately follows it. l the << operator applies only to the first thing following it l to display two things, use the << operator twice, once immediately before each rThe word endl means to start a new line. rText strings must always be surrounded by double quotes. rMore examples: cout << This is a message to display << endl; cout << Hello World! << endl; cout << First part of long message << Second part of long message << endl;

Lecture Computer Science I - Martin Hardwick C++ Variables rA computer does not remember numbers from one statement in your program to the next. l you must save any number that you will need later in a word of memory (called a variable in C++) rEach variable that a C++ program uses must be declared. l specify a name for the variable l specify the type of the variable –valid types include:int-- one word integer double -- two word floating-point (real) rThe variable declarations in a C++ function are usually placed at the beginning of that function by convention. rExamples double radius; int quantity;

Lecture Computer Science I - Martin Hardwick Assignment Statement rAn assignment statement is used to put a value into a variable. l The previous value is replaced rSyntax: = ; l is any declared variable in the program l is anything that produces a value of the appropriate type (more on this later) l the number produced by the is assigned as the new value for the variable rExamples: size = 10; width = length - 2; count = count + 1;

Lecture Computer Science I - Martin Hardwick The cin Object rUsed to assign a value typed on the keyboard to a variable. rThe >> operator says to assign the next value typed on the keyboard to the variable appearing immediately after the >> operator. rThe user must type a value followed by the Enter Key. rAn integer number is converted to a real number for assignment to a double variable. cin >> x; cin >> y; cin >> z; equivalent to: cin >> x >> y >> z; If x, y and z are double variables and the user types: x is assigned 10.2 y is assigned -5.2 z is assigned 6.0 The user can also type:

Lecture Computer Science I - Martin Hardwick Names In C++ rVariable names in C++ are called identifiers. l identifiers are used for many other things as well rRules for constructing valid identifiers in C++: l can contain letters (upper and lower case), digits, and the underscore ( _ ) character l cannot start with a digit l cannot be a reserved word l can be at most 256 characters long l are case sensitive l Must not already be used rReserved words in C++: asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast delete else enum explicit extern false float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while union unsigned

Lecture Computer Science I - Martin Hardwick Putting it all together rLets write a program to convert dollars to euros l Find out current exchange rate l Get amount in dollars l Apply formula to convert from dollars to euros l Display amount in euros int main () { } rQuiz 1 Monday after Labor Day (September 14)