Session 1 - Introduction

Slides:



Advertisements
Similar presentations
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Advertisements

CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
CSE 332: C++ program structure and development environment C++ Program Structure (and tools) Today we’ll talk generally about C++ development (plus a few.
Basic Elements of C++ Chapter 2.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Introduction to C++ Programming
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Chapter 01: Introduction to Computer Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
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.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Chapter 02 (Part III) Introduction to C++ Programming.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
Week 1 Algorithmization and Programming Languages.
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.
Fundamental Programming: Fundamental Programming Introduction to C++
1 CS161 Introduction to Computer Science Topic #3.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Looping and Counting Lecture 3 Hartmut Kaiser
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
C++ / G4MICE Course Session 1 - Introduction Edit text files in a UNIX environment. Use the g++ compiler to compile a single C++ file. Understand the C++
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Lecture 3: Getting Started & Input / Output (I/O)
Chapter 15 - C++ As A "Better C"
Bill Tucker Austin Community College COSC 1315
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
Introduction to C++ (Extensions to 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
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Programming Fundamentals
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Beginning C++ Programming
Computer Engineering 1nd Semester
Introduction to C++ October 2, 2017.
Copyright © 2003 Pearson Education, Inc.
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
Chapter 2 Elementary Programming
Introduction to CS Your First C Programs
Console input.
1.13 The Key Software Trend: Object Technology
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to C++ Programming
C++ Programming Lecture 3 C++ Basics – Part I
Programming Introduction to C++.
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Capitolo 1 – Introduction C++ Programming
Chapter 2 part #3 C++ Input / Output
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Session 1 - Introduction C++ / G4MICE Course Session 1 - Introduction Edit text files in a UNIX environment. Use the g++ compiler to compile a single C++ file. Understand the C++ input and output streams. First exposure to simple C/C++ variables.

Course Format 12 Sessions (each one and a half hours) over three days. Each session consists of a 20-30 minute “lecture” followed by guided hands-on work.

Editing Text Files Hopefully everyone is already familiar with at least one UNIX/linux text editor. If not, there are several options, including: vi / vim emacs pico Use whichever editor you prefer. If you aren’t already familiar with one, we will start with that in the hands-on part of this session.

g++ compiler The standard G4MICE installation currently comes with version 3.2.3 or g++. In a future release we will migrate to version 4. The way that the compiler works is the same in both cases.

helloworld.cc // helloworld.cc // // Written for the C++ / G4MICE course // M. Ellis - March 2008 #include <iostream> int main() { std::cout << "Hello World!" << std::endl; exit(1); }

How to Compile g++ -o helloworld helloworld.cc This will produce an output executable file “helloworld” (helloworld.exe if you are using cygwin) from the source code helloworld.cc which can be run: ./helloworld

helloworld.cc - explanation // helloworld.cc // // Written for the C++ / G4MICE course // M. Ellis - March 2008 #include <iostream> int main() { std::cout << "Hello World!" << std::endl; exit(1); } C++ allows two types of comments, this example uses the characters // at the point in each line where the comments begin. This is a pre-processor command that Tells the compiler to insert code from The file iostream.

C++ Streams C++ streams can be used to send or receive data to/from files, the keyboard, terminal, other processes, devices, ... There are two key operators for streams: << >> These can be thought of as reading or writing.

cout / cin / cerr There are 3 variables defined for you that refer to specific streams that are commonly used: cout is the “standard output”. cin is the “standard input”. cerr is the “standard error”. Writing to the cout stream will result in text appearing on the screen. Reading from the cin stream will store whatever is typed on the keyboard in some variable(s).

echo.cc This is an example of the other kind // echo.cc /* Written for the C++ / G4MICE course M. Ellis - March 2008 */ #include <iostream> #include <string> int main() { std::string message; std::cout << "Please enter a message for me: "; std::cin >> message; std::cout << "Thank you, I have received your message: " << message << std::endl; exit(1); } This is an example of the other kind of comment which can cover more than one line. Additional #include so that we can use strings

How to Compile As with the first example: g++ -o echo echo.cc

Some C/C++ Variables int (unsigned int, long int, short int, ... ) Integers of varying size (number of bits) bool Boolean variable can only be true or false char A single character (8 bits) double (float, long double, ... ) Floating point numbers string String of characters

Variable Declaration <type> <variable name>; <type> <variable name> = <value>; int count; int numPlanes = 3; double pi = 3.141592654; bool ok; std::string name = “MICE”;

What are ; and std:: ??? Commands in C/C++ must end with a ; C/C++ is free format, so you can have as much or as little white space as you like. Later on in the course we will look at namespaces and scope. For now, it is sufficient to know that a number of types and variables that we are using are in a namespace called “std”: std::cout (the standard output stream variable) std::string (the string type)

variables.cc // variables.cc /* Written for the C++ / G4MICE course M. Ellis - March 2008 */ #include <iostream> #include <string> int main() { int age; double height; std::string name; std::cout << "Please tell me your name: "; std::cin >> name; std::cout << "Thank you " << name << ", what is your age? "; std::cin >> age; std::cout << "Finally, how tall are you in inches? "; std::cin >> height; std::cout << std::endl << std::endl; std::cout << name << " is " << age << " years old and is " << height << " inches tall" << std::endl; exit(1); }

Exercises Compile and run helloworld.cc Compile and run echo.cc Compile and run variables.cc Create your own code from scratch, have it use the standard input and standard output and at least 3 variables of different types.