COS120 Software Development Using C++ AUBG Fall semester 2010 Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot Koffman, http://www.aw.com/cssupport Course lecturer: Assoc. Prof. Stoyan Bonev, PhD Lecture 6: Computer Languages. Programming Environments (IDE) Lecture Contents: Programming environments. Integrated Development Environments (IDE) Borland C++ IDE The C++ PL elements The elements of Programming Style Sample programs in C++ 3 IDE MS Visual Studio 2010 4 Introduction to MS Visual C++ 2010 When you activate IDE for the first time, it’s time for you to make your choice: 5 Intro to MS Visual C++ 2010 Creating Unmanaged Application To build a console application that will run without .NET framework, follow these steps: 1. Open Visual Studio .NET 2010. 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 6 7 8 9 10 11 12 13 14 Intro to MS Visual C++ 2010 Creating Managed Application To build a console application that will run within .NET framework, follow these steps: 1. Open Visual Studio .NET 2010. 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 15 16 17 IDE Borland C++ 18 Intro to Borland C++ How to compile and execute C++ applications? Click Start from Task bar, Select Run… and click on it Enter cmd command and click OK or press Enter to open an MSDOS window Change current device to Q: drive and call command H:\borlandc\bin\bc.exe Press F10 >> Options >> Directories. Check Drive letter for Include and Library directories to be H, Drive letter for output and source directory to be Q Press F10 >> File >> New, enter the source text of your program Press 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. 19 20 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) directives using namespace std; int main() { definition (declaration) statements executable statements } 21 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. 22 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.h> #include <iomanip.h> or #include <iostream> #include <iomanip> using namespace std; 23 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. 24 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 25 Overview of C++ Open to read slides 5-64 from Lecture 5 COS120lec5_VisualC.ppt 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+32 To convert Fahrenheit degrees to Celsius degrees Cel = 5./9.*(Fahr-32) To convert meters to feet and inches; 27 Exercise 6.2 Build and run a program: To convert miles to kilometers 28 Exercise 6.3 Build and run a program: To find the value of coins (quarters, dimes, nickels, pennies) in dollars/cents. 29 Homework 1 Paper record to be presented before the end of next class Tasks: – See .doc file. 30 Reminder Quiz #1 On Algorithms and Elementary C++ will take place next lesson 31 Before lecture end Lecture: Computer Languages. Programming environments (IDE) More to read: Friedman/Koffman, Chapter 02 32 Thank You For Your Attention 33