Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program.

Slides:



Advertisements
Similar presentations
CSE202: Lecture 1The Ohio State University1 Introduction to C++
Advertisements

Objectives You should be able to describe: Introduction to Programming
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
CSCI-1411 F UNDAMENTALS O F C OMPUTING L AB Shane Transue Summer
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.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 2: Introduction to C++.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Introduction to C Topics Compilation Using the gcc Compiler
Programming Introduction to C++.
Introduction to C/C++ Programming This lecture has major focus on programming, compilation.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Programs A program is a stored set of instructions that can be interpreted and executed by a computer. This applies to the written program which is just.
Chapter 3 Getting Started with C++
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
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.
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
Programming With C.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
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:
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Basic Program Construction
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Chapter 2 part #1 C++ Program Structure
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Introduction to C Programming
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Introduction to C Topics Compilation Using the gcc Compiler
Great way to learn is by example so fire up Visual Studios C (at home make sure you custom install with C++ - no longer default) by Deborah R. Fowler.
Programming what is C++
CMPT 201.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Completing the Problem-Solving Process
Chapter 2 part #1 C++ Program Structure
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Topics Compilation Using the gcc Compiler
2.1 Parts of a C++ Program.
Creating your first C program
Anatomy of a Java Program
Chapter 2: Introduction to C++.
Programming Introduction to C++.
CPS120: Introduction to Computer Science
Introduction to Programming - 1
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program

Today We Are Going To: Review our “KM_PER_MILE ” program Review our “KM_PER_MILE ” program Define the structure of a C++ program Define the structure of a C++ program Enumerate the types of information (Data) with which we will work Enumerate the types of information (Data) with which we will work Describe the operations which may be performed on those types of data Describe the operations which may be performed on those types of data

Topic A 2nd C++ Program

Hello, World! Recall the program we wrote Recall the program we wrote Here were the steps we took: Here were the steps we took: determined the purpose (write a message) determined the purpose (write a message) determine inputs (none)/outputs (message) determine inputs (none)/outputs (message) design algorithm (print statement) design algorithm (print statement) write code write code compile/fix/re-compile compile/fix/re-compile run program run program

Program Structure A C++ program requires a main function A C++ program requires a main function The main function can appear with different signatures The main function can appear with different signatures Important to exit properly Important to exit properly Blocks of code enclosed in braces {...} Blocks of code enclosed in braces {...} Provide lots of comments Provide lots of comments /*...*/ /*...*/ // //

C++ Syntax Reserved words are the language with which you write instructions Reserved words are the language with which you write instructions Examples: int, return Examples: int, return Punctuation: Punctuation: semi-colon (;) at end of each line semi-colon (;) at end of each line parentheses for method arguments parentheses for method arguments quotation marks quotation marks

External Components Often necessary to use components (code) provided by someone else Often necessary to use components (code) provided by someone else Examples are the I/O objects we use to print at the command line: cout, endl Examples are the I/O objects we use to print at the command line: cout, endl NOT reserved words NOT reserved words Use the #include to bring external code into our program Use the #include to bring external code into our program Must be careful to avoid giving the same name to different objects: namespaces Must be careful to avoid giving the same name to different objects: namespaces

Compiler Behavior Pre-processor directives: Pre-processor directives: describe the way the compiler behaves describe the way the compiler behaves #include is most common #include is most common examined before compilation begins examined before compilation begins Compilation: Compilation: translate into machine code (optimize) translate into machine code (optimize) search for errors search for errors Linking: Linking: combine components into an executable combine components into an executable

Topic Style and Readability

Importance of Style Do you remember the Y2K problem? Do you know why it happened? Do you remember the Y2K problem? Do you know why it happened? 80% to 85% of an application's life is spent in MAINTAINENCE, that is: FIXING BUGS 80% to 85% of an application's life is spent in MAINTAINENCE, that is: FIXING BUGS You MUST make your programs readable You MUST make your programs readable

Comments There is (almost) no such thing as too much commentary: explain to others, yourself, what you are doing There is (almost) no such thing as too much commentary: explain to others, yourself, what you are doing // is useful for brief notations about the logic of the program // is useful for brief notations about the logic of the program /*... */ is better for longer descriptions /*... */ is better for longer descriptions

Indentation and Spacing Almost as important as comments as an aid to understanding code Almost as important as comments as an aid to understanding code Show statements contained within a block by indenting them Show statements contained within a block by indenting them Add white space to demark new thoughts (like paragraphs of logic) Add white space to demark new thoughts (like paragraphs of logic) Block styles: you will have noticed that I use the “next line” block style Block styles: you will have noticed that I use the “next line” block style

Naming Conventions Capitalize first letter in a class name Capitalize first letter in a class name Do NOT capitalize first letter of members Do NOT capitalize first letter of members If a class or member name contains several words concatenate them and capitalize each successive word: theElmTree If a class or member name contains several words concatenate them and capitalize each successive word: theElmTree Use all caps for a constant: PI Use all caps for a constant: PI Separate the words in a constant with an underscore: MAX_VALUE Separate the words in a constant with an underscore: MAX_VALUE

Topic Development Environment

Working With Visual Studio.net C++ Visual Studio uses “projects” Visual Studio uses “projects” FIND the code you have written: FIND the code you have written: C:\Program Files\Microsoft Visual Studio\MyProjects C:\Program Files\Microsoft Visual Studio\MyProjects Look for the project you created Look for the project you created The files you need are the CPP files The files you need are the CPP files Others are aids for the environment Others are aids for the environment Watch carefully when you import and export files from a project Watch carefully when you import and export files from a project

More About Visual C++ Often useful to build in stages: compile, then build Often useful to build in stages: compile, then build NOTE: There is a difference between including a file in a project and using the file in your program. NOTE: There is a difference between including a file in a project and using the file in your program. Compilation order is important in C++ Compilation order is important in C++

Using Another Compiler Can obtain the Borland compiler for free from the Internet Can obtain the Borland compiler for free from the Internet Installation is straightforward Installation is straightforward Must set some Environment Variables Must set some Environment Variables Compile from a DOS prompt Compile from a DOS prompt Run from a DOS prompt Run from a DOS prompt

Questions