lecture 6: computer languages. programming environments (ide) cos120 software development using c++...

37
Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

Upload: susan-hancock

Post on 13-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

Lecture 6: Computer Languages.Programming Environments

(IDE)

COS120 Software Development Using C++ AUBG, COS dept

Page 2: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

2

Lecture Contents:

Programming environments. Integrated Development Environments (IDE)

MS Visual Studio Code::Blocks Borland C++ IDE The C++ PL elements The elements of Programming Style Sample programs in C++

Page 3: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

3

IDE

MS Visual Studio

Page 4: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

4

Intro to MS Visual C++ Creating Native Code Application

To build a console application that will run without .NET framework, follow these steps:1. Open Visual Studio.2. On the Start Page, click New Project… . If the Start Page isn’t visible, Choose File,

New, Project.3. Select the Visual C++\Win32 from Installed Project Templates on the left and

select Win32 Console Application Project type on the right.4. Enter project name, for example ConsoleApplication1, project location, for

example Q: drive and click OK.5. Click Finish from the wizard that appears.The wizard generates the skeleton of an unmanaged C++ application.

To build the project, follow these steps:1. Choose Build, Build Solution or press F7

To run the project, follow these steps:1. Choose Debug, Start Without Debugging or press Ctrl+F5

Page 5: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

5

Intro to MS Visual C++Creating Native Code Application

Topic already introduced.

For details see previous lecture.

Page 6: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

6

Intro to MS Visual C++ Creating Managed Application

To build a console application that will run within .NET framework, follow these steps:1. Open Visual Studio .NET 2. On the Start Page, click New Project… . If the Start Page isn’t visible, Choose File,

New, Project.3. Select the Visual C++\CLR from Installed Project Templates on the left and select

CLR Console Application Project type on the right.4. Enter project name, for example ConsoleApplication1, project location, for

example Q: drive and click OK.5. The wizard generates the skeleton of a managed C++ application.

To build the project, follow these steps:1. Choose Build, Build Solution or press F7

To run the project, follow these steps:1. Choose Debug, Start Without Debugging or press Ctrl+F5

Page 7: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

7

Page 8: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

8

Page 9: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

9

IDEBloodshed Dev-C++

(nowadays obsolete IDE)

Code::Blocks IDEto be used as substitute

Page 10: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

10

Intro to BloodShed Dev C++

How to compile and execute C++ console applications?

Open Bloodshed Dev C++.1. On the Start Page, click New Project. If Start Page not visible, Choose File, New, Project.2. Click Basic tab if not opened and select Console Application.3. Type project name, for example ConsoleApplication1, select C++ project type, click OK.4. Select project location, for example Q: drive, rename the default project .dev file name

(not recommended) and click Save.The wizard opens text editor pane with generated skeleton of C++ application.

To build the project, follow these steps:1. Choose Execute, Compile or press Ctrl+F9

To run the project, follow these steps:1. Choose Execute, Run or press Ctrl+F10

Page 11: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

11

IDE

Code::Blocks

Page 12: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

12

Intro to Code::Blocks IDE

How to compile and execute C++ console applications?Open Code::Blocks1. On the Start Page, click Create New Project. OR Choose File, New, Project.2. Project template box opens. Select Console Application. Click Go.3. Select C++ as a language that you want to use. Click Next.4. Type project title, for example ConsoleApplication1. Select project location, for example

Q: drive, rename the default project .cbp file name (not recommended) and click Next.5. Compiler selection box opens. Click Finish.The wizard opens text editor pane with generated skeleton of C++ application.

To build the project, follow these steps:1. Choose Build, Build or press Ctrl+F9

To run the project, follow these steps:1. Choose Build, Run or press Ctrl+F10

To build and run the project, follow these steps:1. Choose Build, Build and Run or press F9

Page 13: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

13

Page 14: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

14

Page 15: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

15

Page 16: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

16

Page 17: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

17

Page 18: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

18

Page 19: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

19

Page 20: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

20

Page 21: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

21

Page 22: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

22

Page 23: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

23

IDEBorland C++

(nowadays obsolete IDE)

MS Visual Studio or Code::Blocks IDEto be used as substitute

Page 24: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

24

Intro to Borland C++

How to compile and execute C++ applications?

Click Start from Task bar, Select Run… and click on itEnter cmd command and click OK or press Enter to open an MSDOS windowChange current device to Q: drive and call command H:\borlandc\bin\bc.exePress F10 >> Options >> Directories. Check Drive letter for Include and Library

directories to be H, Drive letter for output and source directory to be QPress F10 >> File >> New, enter the source text of your programPress F10 >> Save As… to name and save your program as a source file (.cpp).Press F10 >> Compile >> Compile (or Alt+F9) and look at the compiler messages. In

case of errors and/or warnings, you should edit and recompile your source text until “0 warnings, 0 errors, Success” is displayed

Press F10 >> Run >> Run (or Ctrl+F9) to run your program.

Page 25: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

25

Page 26: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

26

C++ programs topics

Compiler (preprocessor) directives; Names: reserved words (keywords), standard defined

and user defined identifiers; Variable declarations and data types; Executable statements; General structure of a C++ program;

compiler (preprocessor) directivesusing namespace std;int main(){ definition (declaration) statements executable statements}

Page 27: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

27

Elements of programming style

Spaces in a program; Using comments; Mnemonic identifiers; Arithmetic expressions. Rules for expressions

evaluation:– Parentheses rule – (sub expressions) first;

– Precedence rule – highest priority first;

– Association rule – left or right associative operators.

Page 28: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

28

input/output manipulators

I/O manipulators are used to control and modify data that is extracted from input stream or inserted to output stream.

I/O manipulators are active after including the following header files:

#include <iostream>

#include <iomanip>

Page 29: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

29

Input/output manipulators

endl Inserts the newline character into an output stream.

setw(n) Controls the width of an output field. dec, hex, oct Controls the numeric system base (10, 16, 8)

used to display values. fixed, scientific Causes real numbers to display in decimal

or in scientific notation. showpoint Ensures decimal point and trailing zeros if

necessary always to appear. setprecision(n) Sets the precision to n decimal places. left, right Left-adjust or right-adjust output in field.

Page 30: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

30

Previous lecture reminder

Title:

A Tutorial Introduction to C/C++

Source: Friedman/Koffman, Chapter 02

Have a quick look at next slide to refresh your knowledge on previous lecture

Page 31: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

Overview of C++

Open to read slides 5-64 from Lecture 5COS120lec5_VisualC.ppt

Page 32: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

32

Exercise 6.1

Build and run all programs from lecture 5:To compute and display the volume of a pool; To add, subtract, multiply and divide two numeric

values;To convert Celsius degrees to Fahrenheit degrees

Fahr = 9./5.*Cel+32To convert Fahrenheit degrees to Celsius degrees

Cel = 5./9.*(Fahr-32)To convert meters to feet and inches;

Page 33: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

33

Exercise 6.2

Build and run a program: To convert miles to kilometers

Page 34: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

34

Exercise 6.3

Build and run a program: To find the value of coins (quarters, dimes, nickels, pennies) in dollars/cents.

Page 35: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

35

Homework 1

Paper record to be presented before the end of next class

Tasks:– See .doc file.

Page 36: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

36

Before lecture end

Lecture:Computer Languages.

Programming environments (IDE)

More to read:Friedman/Koffman, Chapter 02

Page 37: Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept

37

Thank You

For

Your Attention