1. The First Visual C++ Program

Similar documents
MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

Appendix K Introduction to Microsoft Visual C++ 6.0

Visual Studio 2008 Express Editions

Creating a Simple Visual C++ Program

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

How to Compile, Link, and Execute C or C++ Codes Using Microsoft Visual C++

William Paterson University Department of Computer Science. Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0

C++ Essentials. Sharam Hekmat PragSoft Corporation

Using Visual C++ and Pelles C

Passing 1D arrays to functions.

Microsoft Visual Studio 2010 Instructions For C Programs

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter 8 Selection 8-1

Data Structures using OOP C++ Lecture 1

Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?

Object Oriented Software Design

F ahrenheit = 9 Celsius + 32

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Example of a Java program

Sequential Program Execution

Chapter One Introduction to Programming

Common Beginner C++ Programming Mistakes

Appendix M: Introduction to Microsoft Visual C Express Edition

Visual C Tutorial

CS170 Lab 11 Abstract Data Types & Objects

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Introduction to the use of the environment of Microsoft Visual Studio 2008

How To Write Portable Programs In C

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Basics of I/O Streams and File I/O

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Beginning to Program Python

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

While Loop. 6. Iteration

Computer Programming C++ Classes and Objects 15 th Lecture

Using Microsoft Visual Studio API Reference

Using Windows Task Scheduler instead of the Backup Express Scheduler

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Deitel Dive-Into Series: Dive Into Microsoft Visual C++ 6

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Developing, Deploying, and Debugging Applications on Windows Embedded Standard 7

1. Create SQL Database in Visual Studio

CISC 181 Project 3 Designing Classes for Bank Accounts

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

COMPUTER SCIENCE 1999 (Delhi Board)

Comp151. Definitions & Declarations

5 Arrays and Pointers

6. Control Structures

Chapter 2: Elements of Java

C++ Input/Output: Streams

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

JAVS Scheduled Publishing. Installation/Configuration... 4 Manual Operation... 6 Automating Scheduled Publishing... 7 Windows XP... 7 Windows 7...

Member Functions of the istream Class

Informatica e Sistemi in Tempo Reale

Answers to Review Questions Chapter 7

Conditions & Boolean Expressions

if and if-else: Part 1

Object Oriented Software Design

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

COSC 181 Foundations of Computer Programming. Class 6

Illustration 1: Diagram of program function and data flow

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

Formatting Numbers with C++ Output Streams

Building Java Programs

An Incomplete C++ Primer. University of Wyoming MA 5310

7.7 Case Study: Calculating Depreciation

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

13 Classes & Objects with Constructors/Destructors

Creating Database Tables in Microsoft SQL Server

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Introduction to Java

C++ INTERVIEW QUESTIONS

Generating Visual Studio Project Files

Handle Tool. User Manual

Introduction to Java Applets (Deitel chapter 3)

2.2: Bitwise Logical Operations

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Visual C++.NET Programming. Using.NET Environment

CS106B Handout #5P Winter January 14, 2008

Visual Logic Instructions and Assignments

Creating OpenGL applications that use GLUT

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

The if Statement and Practice Problems

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Ch 7-1. Object-Oriented Programming and Classes

Building Java Programs

Transcription:

1. The First Visual C++ Program Application and name it as HelloWorld, and unselect the Create directory for solution. Press [OK] button to confirm. 2. Select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. Press [Finish] to continue. Copyright 2010 Lo Chi Wing 1

3. In order to create the C++ file, select Project Add New Item. 4. Select C++ File (.cpp) and name it as HelloWorld.cpp, and then press [Add] button to continue. Copyright 2010 Lo Chi Wing 2

5. A blank screen will appear showing the contents of "HelloWorld. Type the following code into this blank white area. // initializing C++ //main function void main () // Declare a variable char ch; // Print the statement to screen cout << "Hello World!! Press any key to continue:"; // Capture the user input cin >> ch; 6. Compile the program by selecting Build Build Solution. Copyright 2010 Lo Chi Wing 3

7. Select Start Run in your Windows, then type CMD.EXE to call up the DOS prompt. Then use command CD to go to \My Documents\Visual Studio 2008\Projects\HelloWorld\Debug and execute the command HelloWorld.exe. On the other hand, you can also select Debug Start Debugging to execute the program. The statement "Hello World!! Press any key to continue:" is displayed in the console, and you can press [X] with the [Enter] button to quit. Copyright 2010 Lo Chi Wing 4

2. Output Steam using cout Application and name it as cout_demo. Remember to select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. 2. Create a C++ File (.cpp) and name it as cout_demo.cpp by selecting Project Add New Item, and then type the following code inside. // Program demonstrating the use of cout. void main() cout << "Hello there.\n"; cout << "Here is 5: " << 5 << "\n"; cout << "The manipulator endl writes a new line to the screen." << endl; cout << "Here is a very big number:\t" << 70000 << endl; cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl; cout << "Here's a fraction:\t\t" << (float) 5/8 << endl; cout << "And a very very big number:\t" << (double) 7000 * 7000 << endl; cout << "Don't forget to put your name here...\n"; 3. Use Build Solution to compile and build the solution, and then execute it. Copyright 2010 Lo Chi Wing 5

3. Variable Size Application and name it as Variable_Size. Remember to select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. 2. Create a C++ File (.cpp) and name it as main.cpp by selecting Project Add New Item, and then type the following code inside. // A program to determine the size of variable types on your computer. void main() cout << "The size of an int is:\t\t" << sizeof(int) << " bytes.\n"; cout << "The size of a short int is:\t" << sizeof(short) << " bytes.\n"; cout << "The size of a long int is:\t" << sizeof(long) << " bytes.\n"; cout << "The size of a char is:\t\t" << sizeof(char) << " bytes.\n"; cout << "The size of a float is:\t\t" << sizeof(float) << " bytes.\n"; cout << "The size of a double is:\t" << sizeof(double) << " bytes.\n"; 3. Use Build Solution to compile and build the solution, and then execute it. The one feature is the use of the sizeof() function in lines 6 through 11. sizeof() is provided by your compiler, and it tells you the size of the object you pass in as a parameter. Copyright 2010 Lo Chi Wing 6

4. Use of Variables Application and name it as Use_of_Variable. Remember to select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. 2. Create a C++ File (.cpp) and name it as main.cpp by selecting Project Add New Item, and then type the following code inside. // Demonstration of use variables void main() unsigned short int Width = 5, Length; Length = 10; // create an unsigned short and initialize with result // of multiplying Width by Length unsigned short int Area = Width * Length; cout << "Width:" << Width << "\n"; cout << "Length: " << Length << endl; cout << "Area: " << Area << endl; 3. Use Build Solution to compile and build the solution, and then execute it. Copyright 2010 Lo Chi Wing 7

5. Demonstration of Overflow for Unsigned Integer Application and name it as Var_Value_too_Large. Remember to select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. 2. Create a C++ File (.cpp) and name it as main.cpp by selecting Project Add New Item, and then type the following code inside. // A demonstration of putting too large a value in an unsigned integer. void main() unsigned short int small_number; small_number = 65535; cout << "small number:" << small_number << endl; small_number++; cout << "small number:" << small_number << endl; small_number++; cout << "small number:" << small_number << endl; 3. Use Build Solution to compile and build the solution, and then execute it. Please note that the small_number is declared to be an unsigned short int, which on my computer is a two-bytes (it varies on different computer) variable, able to hold a value between 0 and 65,535. Then the maximum value is assigned to small_number, and it is printed on screen. Copyright 2010 Lo Chi Wing 8

6. Demonstrates Subtraction and Integer Overflow Application and name it as Operator_Unsigned. Remember to select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. 2. Create a C++ File (.cpp) and name it as main.cpp by selecting Project Add New Item, and then type the following code inside. // demonstrates use of prefix and postfix increment and decrement operators void main() int myage = 18; // initialize two integers int yourage = 18; cout << "I am: " << myage << " years old.\n"; cout << "You are: " << yourage << " years old\n"; myage++; // postfix increment ++yourage; // prefix increment cout << "One year passes...\n"; cout << "I am: " << myage << " years old.\n"; cout << "You are: " << yourage << " years old\n"; cout << "Another year passes\n"; cout << "I am: " << myage++ << " years old.\n"; cout << "You are: " << ++yourage << " years old\n"; cout << "Let's print it again.\n"; cout << "I am: " << myage << " years old.\n"; cout << "You are: " << yourage << " years old\n"; Copyright 2010 Lo Chi Wing 9

3. Use Build Solution to compile and build the solution, and then execute it. Please note that two integer variables are declared, and each is initialized with the value 18. Their values are printed on lines 9 and 10. On line 11, myage is incremented using the postfix increment operator, and on line 12, yourage is incremented using the prefix increment operator. The results are printed on lines 14 and 15, and they are identical (both 19). myage is incremented as part of the printing statement, using the postfix increment operator. Because it is postfix, the increment happens after the print, and so the value 19 is printed again. In contrast, on line 18, yourage is incremented using the prefix increment operator. Thus, it is incremented before being printed, and the value displays as 20. Finally, the values are printed again. Because the increment statement has completed, the value in myage is now 20, as is the value in yourage.. Copyright 2010 Lo Chi Wing 10

7. Compile Errors Application and name it as Error. Remember to select Application Setting in the Win32 Application Wizard, then select Console Application and select Empty Project. 2. Create a C++ File (.cpp) and name it as main.cpp by selecting Project Add New Item, and then type the following code inside. // Error.cpp void main () int i; float j=0.9 // a missing ";" i=j; cout << "test" << endl; cout << "test 2 i: << i << endl; // only a warning here, note that the value of i // will become 0 since the.9 will be truncated // a missing double quote // a missing "" 3. Use Build Solution to compile and build the solution, and then execute it. Can you successfully execute the program? Copyright 2010 Lo Chi Wing 11