1 C++ Programming Basics Chapter 1 Lecture CSIS 10A.

Slides:



Advertisements
Similar presentations
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
Advertisements

COSC 120 Computer Programming
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
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.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
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.
Three types of computer languages
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
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 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:
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
COMPUTER SCIENCE I C++ INTRODUCTION
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
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)
High-Level Programming Languages: C++
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
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.
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Course websites CS201 page link at my website: Lecture slides Assistant’s Information Recitations Office Hours Make-up.
Overview of Programming and Problem Solving Textbook Chapter 1 1.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
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.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Subject: Programming in C++ 1. LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 05, 2005 Lecture Number: 4.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Introduction ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Bill Tucker Austin Community College COSC 1315
What Actions Do We Have Part 1
Completing the Problem-Solving Process
Beginning C++ Programming
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Hardware & Software Programming. COMP102 Prog. Fundamentals I: Software / Slide 2 l Four components of a computer system: n CPU - central processing unit.
Programs written in C and C++ can run on many different computers
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

1 C++ Programming Basics Chapter 1 Lecture CSIS 10A

2 Agenda Hardware Basics  The IDE My First Program Its all G(r)eek to me Variables and Declarations Input and Output

3 Anatomy of a Computer MemoryOutput ALUControlInput Mouse Keyboard Scanner Hard Disk Floppy Disk Monitor Printer Speakers

4 The CPU uses machine language Assembly instructions to calculate the radius of a circle: LOAD radius LOAD pi MULTIPLY LOAD two MULTIPLY STORE circle

5 Compilers to the Rescue! High level languages like C++ allows writing code that is easier to understand and universally works on any CPU. circle=2.0*radius*pi; The compiler is what translates instructions from C++ into Machine language.

6 Agenda Hardware Basics The IDE  My First Program Its all G(r)eek to me Variables and Declarations Input and Output

7 THE MECHANICS OF WRITING A PROGRAM 1.Editing -- Writing a program 2.Compiling -- Translating from C++ into machine language 3.Linking -- Combining your program with other libraries 4.Running – Letting the computer execute a program 5.Debugging – Running step by step through a program searching for mistakes The Integrated Development Environment (IDE) combines 1-5.

8 Agenda Hardware Basics The IDE My First Program  Its all G(r)eek to me Variables and Declarations Input and Output

9 Hello World ! Lets start off the traditional way Program that prints out “Hello World” on your output console (your screen) Lets start off on our journey…..

10 Steps 1.Create new source file 2.Write the code 3.Create a workspace (only in MSVC++) 4.Compile 5.Link 6.Execute

11 Agenda Hardware Basics The IDE My First Program Its all G(r)eek to me  Variables and Declarations Input and Output

12 It’s all G(r)eek to me … actually, its C++ Lets dissect and analyze a simple program

13 20,000 ft. above sea level #include using namespace std; int main() { // This is my first program cout << "Hello World" << endl; system("pause"); return 0; }

14 20,000 leagues under the sea #include Actually includes some information into your code Contains some definitions that are needed for your code More of this later on in the course

15 22,000 leagues under the sea using namespace std; This line refers to a set of standard object name definitions For now, this is “boilerplate”—stick it in cause it makes everything work!!

16 … deeper…. int main() This is the piece of code (function) that is operated on first when a program is executed What’s a function ??? …. all that’s coming soon …

17 … even deeper…. //This is my first program This is a comment you write to yourself Useful when writing large programs Starts with a //

18 … and deeper….. Output operator cout << “Hi”<<endl; cout is the console monitor (your display) << is the output operator. Use to chain together your output message. “Hi” is a string literal endl means end-line (like enter key)

19 … getting sleepy?….. For the Bloodshed environment…Hold the display open so you can read it (pressing a key will continue) system("pause"); Finish up this program, return a 0 to operating system (everything ended OK) return 0;

20 … and even deeper …. {} delineates the code block Each line ends with a ;

21 Other types of cout statement cout<< “ my age is” <<endl << 39<<endl; cout<< “ my age is 39”; cout<< “ what’s your’s”; Escape with \ Output a “ cout<<“ \” ” <<endl; Output a endlcout<<“\n”;

22 Tom’s All Purpose Program Shell #include using namespace std; int main() { // Your code here... system("pause"); return 0; } Future slides may neglect some of the above components for clarity

23 You Do It Modify your hello world program to print your name, address and phone number (COULD BE FAKE!) on three lines: Tom Rebold 1600 Pennsylvania Ave Experiment with line breaks

24 Lets get moving….. We’ll learn as we proceed You’ll be saying “Aha!” or “Oho!” when you hear these terms again Let’s play around a bit more

25 What more ? Variables and Declarations Getting User Input

26 Variables and Declarations Variables represent storage locations in the computer’s memory variable = expression Assignment is from right to left n = 5; Would give n the value 5

27 Using int Variables int main() { int m,n; m = 44; cout << “m = “ << m; n = m + 33; cout << “ and n = “ << n << endl; }

28 Clearing the haze int m; m int m = 44.0; 44

29 Clearing the haze int m = 44, n; = 77 int n m n = m + 33;

30 Want more ? Variables and Declarations Getting User Input

31 User Input with cin How shall I feed in data ? Remember cout ? Meet cin cin >> m; Will put the value entered through the console (keyboard) into m

32 User Input with cin int main() { cout << "Enter the value of m:"; cin >> m; cout << "m = " << m << endl; }

33 User Input with cin int main() { cout << “Enter the value of m:”; cin >> m; cout << “m = “ << m << endl; } HEY THERE’S SOMETHING WRONG HERE !!!

34 User Input with cin int main() { int m; cout << "Enter the value of m:"; cin >> m; cout << "m = " << m << endl; }

35 Your turn () 1.from hello.cpp File>SaveAs age.cpp 2.Delete all the cout statements. Add lines to: a) Declare a variable called age b) Display a message asking for data (such as “tell me your age”) c) read the data into age d) display the variable age with a descriptive message. (refer to slide 34)

36 That’s a wrap ! What we learned so far: How to write a basic C++ program The structure of a program Displaying to the console ( cout ) Variables Getting user input via the console ( cin )