Chapter 1 Introduction

Similar documents
Chapter 7 Functions. As an example, let us write some code to make a virtual cup of coffee.

C++ Support Classes (Data and Variables)

Chapter 1 - What s in a program?

Lesson 1: Hello, world! Line by line explanation

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

CS 177 Recitation. Week 1 Intro to Java

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

1) Log on to the computer using your PU net ID and password.

Lab 2 Building on Linux

Lab: Supplying Inputs to Programs

CHAPTER 2 A FIRST LOOK AT C++ SOURCE PROGRAMS

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Program Organization and Comments

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

(0) introduction to the course. how to learn a programming language. (0) course structure

Understanding main() function Input/Output Streams

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

Probably the best way to start learning a programming language is with a program. So here is our first program:

This chapter is intended to take you through the basic steps of using the Visual Basic

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

Basic Computer Skills: An Overview

Creating Hair Textures with highlights using The GIMP

How to program with Matlab (PART 1/3)

APPM 2460 Matlab Basics

Computers for Beginners

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

Computer Science 62 Lab 8

Lab 6 Vectors and functions

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

CSCE 121 ENGR 112 List of Topics for Exam 1

The Definitive Guide to Fractal Awesomeness with J-WildFire!

Chapter 2. Editing And Compiling

Depending on the computer you find yourself in front of, here s what you ll need to do to open SPSS.

HOW TO EXPORT BUYER NAMES & ADDRESSES FROM PAYPAL TO A CSV FILE

My First Command-Line Program

Science One CS : Getting Started

Introduction to C Programming. What is a C program?

06ESFContacts 1 message

Honors Computer Science C++ Mr. Clausen Program 6A, 6B, 6C, & 6G

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

You just told Matlab to create two strings of letters 'I have no idea what I m doing' and to name those strings str1 and str2.

contain a geometry package, and so on). All Java classes should belong to a package, and you specify that package by typing:

CS Prof J.P.Morrison

RIS shading Series #2 Meet The Plugins

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #03 The Programming Cycle

Basic Keywords Practice Session

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

How To Upload Your Newsletter

How To Get Your Word Document. Ready For Your Editor

COSC2430 Hw2: Name list management (Linked lists practice)

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

The first program: Little Crab

Using Photoshop Actions in Batches

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

Seema Sirpal Delhi University Computer Centre

Programming for Kids

Understanding Recursion

USING DRUPAL. Hampshire College Website Editors Guide

The Very Basics of the R Interpreter

3. Simple Types, Variables, and Constants

THE 18 POINT CHECKLIST TO BUILDING THE PERFECT LANDING PAGE

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Things to note: Each week Xampp will need to be installed. Xampp is Windows software, similar software is available for Mac, called Mamp.

Getting Started with Visual Studio

the NXT-G programming environment

I put a shortcut onto your desktop, the screen that you look at after you log in.

Object Oriented Design

CSS Crash Course for Fearless Bloggers by Gill Andrews

1 Getting started with Processing

Exercise: Inventing Language

Programming for Beginners

Java/RealJ Troubleshooting Guide

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

5. Control Statements

Lesson 01 Introduction

Creating a new form with check boxes, drop-down list boxes, and text box fill-ins. Customizing each of the three form fields.

COMP s1 Lecture 1

These are notes for the third lecture; if statements and loops.

Applying for Jobs by

Lab # 02. Basic Elements of C++ _ Part1

Getting Started with Command Prompts

Sitefinity Manual. Webmasters. University of Vermont College of Medicine. Medical Communications

Intro to Python Programming

It is written in plain language: no jargon, nor formality. Information gets across faster when it s written in words that our users actually use.

CSS worksheet. JMC 105 Drake University

Website Design and Development CSCI 311

Lab 1: Introduction to Java

Introduction to Computing using C++ Biomedical applications WELCOME TO CIS 1.5. Introduction to the course. Course structure

Python lab session 1

HTML 5 Form Processing

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

SPSS Tutorial - How to Perform an Offline License Activation on a Windows Computer

My First iphone App (for Xcode version 6.4)

Transcription:

Chapter 1 Introduction Hi! Welcome to my beginners guide to C++. If you are starting to program for the first time, I hope that you find the chapters I have written useful. C++ is an excellent language to start programming in a lot of applications that you use are probably written in c++ and once you learn some basic concepts, learning other languages, like java for example, will be much easier. There are 8 chapters altogether, including this one. I have kept the chapters short and concise so you won t get bored or weighed down by too much information. After each chapter you can rearrange the code in the examples provided or make up your own code. Programming is very much a practical subject so you will learn a lot by messing about with code or even looking at other people s code. What is a computer program? A computer program is a set of instructions that a programmer writes to tell a computer how to carry out a certain task. The instructions, however, must be in a language that the computer understands. Computers only understand binary language i.e. that composed of 1 s and 0 s. This is a low level language and very hard to program in. So humans invented higher level languages such as C++ or Pascal to make the job easier. As you will see, these languages are nearly like English but you don t have the freedom to write what you like there are still rules you have to follow. To convert a program in C++ to a binary or executable file that the computer can understand we use a compiler. The compiler which I recommend using for this guide is Borland s command line compiler. This compiler is completely free to use and can be downloaded from: http://www.borland.com/products/downloads/download_cbuilder.html Or you could do a search on google for a free Borland compiler.

Setting up Borland s command line compiler Now I will show you how to set up the Borland compiler as it can be a bit confusing if you are new to this stuff. When you download the Borland compiler you will see a file like the following: Step 1: Click on the file and install it to the default directory C:\Borland\BCC55 Step 2: Open notepad and type the following lines: -I"c:\Borland\Bcc55\include" -L"c:\Borland\Bcc55\lib" Save this file in C:\Borland\BCC55\BIN as bcc32.cfg Make sure you choose All Files when saving or it will be saved as a text file.

Step 3: Open notepad again and type: -L"c:\Borland\Bcc55\lib" Save this file in C:\Borland\BCC55\BIN as ilink32.cfg Again, make sure you choose All Files when saving or it will be saved as a text file. That s it! All the paths are set up and now you can get stuck into some programming! Writing your first program in C++ With the Borland compiler, you type your program into a text editor such as notepad then you compile and run it from the command line. So open notepad and type the following code into it. 1 #include<iostream.h> 2 3 int main() 4 { 5 6 cout<<"hello World!"<<endl; 7 8 return 0; 9 10 } Example 1a Save it in C:\Borland\BCC55\BIN as p1.cpp Remember to choose All files when saving. Compiling your first program in C++ Now your program is saved and we need to compile it. First we need to open up a command line.

Click on Start, and then run. In the box that comes up type command and a command line will pop up. Navigate to the folder where your file is saved by typing cd c:\borland\bcc55\bin and press enter. The name of the compiler is bcc32.exe so to compile a program all we need to do is type bcc32 followed by the name of the program. In our case we should type: bcc32 p1 (you don t have to type the.cpp bit here). Now press enter and the program will be compiled. You shouldn t get any errors if you typed the program correctly but if you did you will be notified here. To run the program just type p1 and bingo! Hello World! is printed on the screen. Congratulations! You ve just written and compiled your first program in C++! To run the program again just type p1 followed by enter. You only need to re-compile the program if you make any changes.

Understanding your first program The first line tells the compiler to include a file called "iostrem.h". You will find this file in a folder called "include" in C:\Borland\BCC55\. This file tells the compiler what certain keywords mean, such as "cout" on line 6. For instance later on you will see that you will have to include <math.h> in order to use reserved or keywords like "sine" and "rad". You will probably start all of your programs with <iostream.h> Line three, "int main()", is the header for the main function- where most of the programming stuff happens. Later on you will learn to write your own functions which can be called from the main function. Notice that the body of the function is enclosed in brackets, {...}. At the end of the function there is a line "return 0;". This tells the computer that when main() is finished what it is doing it returns or does nothing. Line 6, cout<<"hello World!"; is called a statement. All statements end with a semi colon. It is very easy to forget to put this in when you begin programming. "cout" tells the computer to print on the screen the text between the pair of quotes. cout stands for

"Channel OUT". Also notice the two pairs of arrows after cout and their direction. To remember their direction, think of data flowing "out" to be printed on the screen. "endl" tells the computer to go onto a new line after it prints the current one. This is useful if you want different sentences on different lines. To put a space in between lines printed on the screen, type cout<<" "<<endl; in between the code lines. So now that you know how to write a program that prints something, you can edit the above program to output whatever you like. Repeat line 6 above to print out a few sentences in the same program. As you read through the various sections of this guide let me know what you think. You can email me at dermot.mceneaney2@mail.dcu.ie