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

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

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Chapter One Introduction to Programming

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

Variables, Constants, and Data Types

Introduction to Java

Chapter 2: Elements of Java

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

C++ Language Tutorial

Appendix K Introduction to Microsoft Visual C++ 6.0

VB.NET Programming Fundamentals

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Example of a Java program

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

Pemrograman Dasar. Basic Elements Of Java

Outline Basic concepts of Python language

Sources: On the Web: Slides will be available on:

Informatica e Sistemi in Tempo Reale

Introduction to Python

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

Lecture 5: Java Fundamentals III

CS 106 Introduction to Computer Science I

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

J a v a Quiz (Unit 3, Test 0 Practice)

Lecture 1 Introduction to Java

Introduction to Java. CS 3: Computer Programming in Java

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Introduction to Java Applets (Deitel chapter 3)

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

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

Java Crash Course Part I

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Appendix M: Introduction to Microsoft Visual C Express Edition

Visual Basic Programming. An Introduction

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Moving from CS 61A Scheme to CS 61B Java

Java Basics: Data Types, Variables, and Loops

Chapter 2 Introduction to Java programming

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

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

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

CS106A, Stanford Handout #38. Strings and Chars

Visual Studio 2008 Express Editions

SQL Server An Overview

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Chapter 3. Input and output. 3.1 The System class

A Simple Introduction to Game Programming With C# and XNA 3.1

JavaScript: Control Statements I

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

I PUC - Computer Science. Practical s Syllabus. Contents

Programming Project 1: Lexical Analyzer (Scanner)

X1 Professional Client

Moving from C++ to VBA

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Welcome to Introduction to programming in Python

Advanced GMAT Math Questions

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

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

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Object Oriented Software Design

How to translate VisualPlace

Repetition Using the End of File Condition

First Bytes Programming Lab 2

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

Chapter 2 Elementary Programming

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Lab 5 Introduction to Java Scripts

SOME EXCEL FORMULAS AND FUNCTIONS

Exercise 4 Learning Python language fundamentals

.NET Standard DateTime Format Strings

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

MAT 2170: Laboratory 3

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

( ) FACTORING. x In this polynomial the only variable in common to all is x.

Demo: Controlling.NET Windows Forms from a Java Application. Version 7.3

Creating a Simple Visual C++ Program

Crash Course in Java

Formulas, Functions and Charts

Importing Xerox LAN Fax Phonebook Data from Microsoft Outlook

Visual Basic 2010 Essentials

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

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

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

C++ INTERVIEW QUESTIONS

C / C++ Programming Lab manual

Programming and Data Structures with Java and JUnit. Rick Mercer

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

Transcription:

ECE 114-2 Introduction to Visual C++.NET Programming Dr. Z. Aliyazicioglu Cal Poly Pomona Electrical & Computer Engineering Cal Poly Pomona Electrical & Computer Engineering 1 Using.NET Environment Start up Microsoft Visual studio.net. The following window should be displayed Click New Project or Under the File menu, point to New, and then click Project Cal Poly Pomona ECE 114-1 2 1

New Project dialog box will be displayed Select Visual C++ Project in the Project Types pane, Select Console Application (.NET) in the temples pane. Type project Name in Name box Choose location for your project. Then, Click OK Cal Poly Pomona ECE 114-1 3 Double click the your cpp file under Solution Explore (on the right side) Cal Poly Pomona ECE 114-1 4 2

Cal Poly Pomona ECE 114-1 5 A simple Program:Printing a Line of Text // First Program in Visual C++.NET #include "stdafx.h" #using <mscorlib.dll> using namespace System; // indicates that the remainder of line is a comment Directive, instruct the compiler to treat the comments of a specific file Imports prepackaged unit of code, (dll file) Declares the use of namespace in the program int _tmain() Main is a program building block called a function { // Display string Print on the screen the string of characters Console::WriteLine( S Welcome to Visual C++.NET Programming! ); return 0 ; } // end _tmain S prefix indicates that string literal follows MC++) Cal Poly Pomona ECE 114-1 6 3

Notes about the simple program comment line // indicates that the remainder of each line is a command. That is a documentation for programmer or other people to understand your program easily. Comments are ignored by the Visual C++.NET compiler. // is called a single line comment The command for many line: begin with /* and and with */. Anything between /* and */ will be comment. Cal Poly Pomona ECE 114-1 7 Display Line of Text Console::WriteLine( S"Welcome to" ); Console::WriteLine( S"Visual C++.NET Programming!" ); Console::WriteLine( S"Welcome to \nvisual C++.NET \nprogramming!" ); Cal Poly Pomona ECE 114-1 8 4

Some common escape Sequence Escape Sequence \n \t \r \\ \ \a Description Newline, moves to beginning of new line Horizontal tab, move to next tab Carriage return, moves to beginning of current line Backslash, prints (\) character Double quote, prints ( ) character Alert. Sound the system Cal Poly Pomona ECE 114-1 9 Adding Integer Enter two integer number typed by a user at the keyboard number1 number2 Compute the total sum=number1+number2 Dislay the result Source Code // An addition program that adds two integer // Z. Aliyazicoglu #include "stdafx.h" #using <mscorlib.dll> using namespace System; (Next slide) Cal Poly Pomona ECE 114-1 10 5

int _tmain() { String *firstnumber, *secondnumber; int number1, number2, sum; continue // First user input // Second user input // First number. // Second number // sum of both number Declarations Console::Write( S"Please enter the first integer : " ); firstnumber = Console::ReadLine (); Console::Write( S"Please enter the second integer : " ); secondnumber = Console::ReadLine (); //Convert numbers from type string * to type integer number1 = Int32::Parse( firstnumber ); number2 = Int32::Parse( secondnumber ); sum=number1+number2; Console::WriteLine( S"\nThe sum is {0}.",sum.ToString() ); return 0; Cal Poly Pomona ECE 114-1 11 } Result Combining the input and conversion operations Console::Write( S"Please enter the first integer : " ); number1 = Int32::Parse(Console::ReadLine () ); Console::Write( S"Please enter the second integer : " ); number2 = Int32::Parse(Console::ReadLine () ); Cal Poly Pomona ECE 114-1 12 6

#include "stdafx.h" #using <mscorlib.dll> Alternative source code using namespace System; int _tmain() { int number1, number2, sum; // First number. // Second number // sum of both number Console::Write( S"Please enter the first integer : " ); number1 = Int32::Parse(Console::ReadLine () ); Console::Write( S"Please enter the second integer : " ); number2 = Int32::Parse(Console::ReadLine () ); sum=number1+number2; Console::WriteLine( S"\nThe sum is {0}.",sum.ToString() ); return 0; Cal Poly Pomona ECE 114-1 13 Declaration Types already defined in the.net Framework Some Primitive types» int, for integer numbers» float, double real numbers» _wchart_t character data Cal Poly Pomona ECE 114-1 14 7

Variable Name Can be any valid identifier Series of characters Underscore Start with character Case sensitive No keyword Example: Name7, _number, name_lastname Declaration separated by a comma and end with semicolon (;) Cal Poly Pomona ECE 114-1 15 Display the result Console::WriteLine( S"\nThe sum is {0}.",sum.ToString() ); Obtain the string representation of variable sum using method ToString. Use {0} to indicate a placeholder for variable values Console::WriteLine( "The number entered are {0} and {1}.,number1.ToString(), number2.tostring() ); The value of number1.tostring() would replace {0} The value of number2.tostring() would replace {1} Cal Poly Pomona ECE 114-1 16 8

Memory Display number1 = Int32::Parse( firstnumber ); number2 = Int32::Parse( secondnumber ); Convert the string to int int is placed into a memory location assigned for number1 and number2 by the compiler sum=number1+number2; Performs the addition and replaces sum s previous value in the memory. number1 number2 sum 45 35 80 Memory Location Cal Poly Pomona ECE 114-1 17 Arithmetic Operations MC++ Operation Arithmetic operation Algebraic expression MC++ expression Addition + f + 7 F + 7 Subtraction - p - c P - c Multiplication * xy x * y Division / x / y x / y Modulus % R mod x R % x Cal Poly Pomona ECE 114-1 18 9

Precedence of Arithmetic Operators Operators Operations Order of Evaluation ( ) Parentheses Evaluate first. If there are several, evaluate left to right *,/,or % + or - Multiplication Division Modulus Addition Subtraction Evaluate second. If there are several evaluate left to right Evaluate last. If there are several, evaluate left to right Cal Poly Pomona ECE 114-1 19 Standard algebraic equality operator or relational operators Decision Making C++ equality or relational operator Example of C++ condition Meaning of C++ condition equality operator = = =!= x = = y x!= y x is equal to y x is not equal to y relational operators > < > < >= <= x > y x < y x >= y x <= y x is greater than y x is less than y x is greater than or equal to y x is less than or equal to y Cal Poly Pomona ECE 114-1 20 10

Data Types in.net Framework FLC Structure Class name Int16 Int32 Int64 Single Double Boolean Char String Description 16-bits signed integer 32-bits signed integer 64-bits signed integer Single-precision(32-bits) floating point number Double-precision(64-bits) floating point number Boolean value (true and false) Unicode (16-bit) character Fixed-length string of char MC++ Type short int or long _int64 float double bool wcher_t or _wchar_t String * Cal Poly Pomona ECE 114-1 21 Case Study Finding the Area and circumference of a circle 1- Take the radius of a circle and compute and print its area and circumference 2- Inputs: Circle radius Outputs: Area of the circle Circumference of the circle Constants: PI = 3.14159 Formula: area = π r 2 circumference = 2 π r 3- Get circle radius Calculate area Calculate circumference Display area and circumference Cal Poly Pomona ECE 114-1 22 11

// Calculate and displays the area and circumference of a circle // Z. Aliyazicoglu #include "stdafx.h" #using <mscorlib.dll> using namespace System; #define PI 3.14159 int _tmain() { double radius, area=0.0, circum=0.0 ; /* Get the circle radius */ Console::Write( S"Please enter the radius : " ); radius = Double::Parse(Console::ReadLine () ); Source Code /* Calculate the area */ area = PI * radius * radius ; /* Calculate the circumference */ circum = 2 * PI * radius ; /* Display the area and circumference */ Console::WriteLine( S"\nThe area is {0}.",area.ToString() ); Console::WriteLine( S"\nThe circumference is {0}.",circum.ToString() ); return 0; } Cal Poly Pomona ECE 114-1 23 Homework #2 Problem 1 Write a program that inputs three integer from the keyboard and print the sum, average, product, smallest, and largest of these numbers. The screen dialogue should appear as fallow Input three different integers:13 27 14 Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is 27 Cal Poly Pomona ECE 114-1 24 12

Homework #2 Problem 2 Using only the techniques you learned in this chapter, write a program that calculates the squares and cubes of the number from 0 to 10 and uses tabs to print the following table of values. Number Square Cube 0 0 0 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 Cal Poly Pomona ECE 114-1 25 13