Example: bankruptcy

Introduction to Visual C++.NET Programming

11 Cal Poly PomonaElectrical & Computer EngineeringIntroduction to Visual C++.NET Introduction to Visual C++.NET ProgrammingProgrammingECE 114 - 2Dr. Z. AliyaziciogluCal Poly PomonaElectrical & Computer EngineeringCal Poly PomonaECE 114-1 2 Using .NET Environment Start up Microsoft Visual The following window should be displayedClick New ProjectorUnder the File menu, point to New, and then click Project2 Cal Poly PomonaECE 114-1 3 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 OKCal Poly PomonaECE 114-1 4 Double click the your cpp file under Solution Explore (on the right side)3 Cal Poly PomonaECE 114-1 5 Cal Poly PomonaECE 114-1 6A simple Program:Printing a Line of TextA simple Program:Printing a Line of Text// First Program in Visual C++.NET #include" "#using< >usingnamespace System;int_tmain(){// Display stringConsole::WriteLine( S Welcome to Visual C++.)}

2 Cal Poly Pomona ECE 114-1 3 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 4 Double click the your cpp file under Solution Explore (on the right side)

Tags:

  Introduction, Programming, Visual, Introduction to visual c, Net programming

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Introduction to Visual C++.NET Programming

1 11 Cal Poly PomonaElectrical & Computer EngineeringIntroduction to Visual C++.NET Introduction to Visual C++.NET ProgrammingProgrammingECE 114 - 2Dr. Z. AliyaziciogluCal Poly PomonaElectrical & Computer EngineeringCal Poly PomonaECE 114-1 2 Using .NET Environment Start up Microsoft Visual The following window should be displayedClick New ProjectorUnder the File menu, point to New, and then click Project2 Cal Poly PomonaECE 114-1 3 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 OKCal Poly PomonaECE 114-1 4 Double click the your cpp file under Solution Explore (on the right side)3 Cal Poly PomonaECE 114-1 5 Cal Poly PomonaECE 114-1 6A simple Program:Printing a Line of TextA simple Program:Printing a Line of Text// First Program in Visual C++.NET #include" "#using< >usingnamespace System;int_tmain(){// Display stringConsole::WriteLine( S Welcome to Visual C++.)}

2 NET Programming ! );return0 ;}// end _tmain// indicates that the remainder of line is a commentDirective, instruct the compiler to treat the comments of a specific file Main is a program building block called a functionPrint on the screen the string of characters Imports prepackaged unit of code, (dll file) Declares the use of namespace in the program S prefix indicates that string literal follows MC++) 4 Cal Poly PomonaECE 114-1 7 Notes about the simple programcomment 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 PomonaECE 114-1 8 Console::WriteLine( S"Welcome to \nVisual C++.NET \nProgramming!" );Display Line of TextConsole::WriteLine( S"Welcome to" );Console::WriteLine( S" Visual C++.

3 NET Programming !" );5 Cal Poly PomonaECE 114-1 9 Some common escape SequenceAlert. Sound the system\aDouble quote, prints ( ) character\ Backslash, prints (\) character\\Carriage return, moves to beginning of current line\rHorizontal tab, move to next tab\tNewline, moves to beginning of new line\nDescriptionEscape SequenceCal Poly PomonaECE 114-1 10 Adding Integer// An addition program that adds two integer // Z. Aliyazicoglu#include " "#using < >using namespace System;Enter two integer number typed by a user at the keyboardnumber1 number2 Compute the totalsum=number1+number2 Dislay the resultSource Code(Next slide)6 Cal Poly PomonaECE 114-1 11continueint_tmain(){String *firstNumber, // First user input*secondNumber; // Second user inputintnumber1,// First ,// Second numbersum;// sum of both numberConsole::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 integernumber1 = Int32::Parse( firstNumber );number2 = Int32::Parse( secondNumber );sum=number1+number2;Console::WriteLine ( S"\nThe sum is {0}.}

4 ", () );return0;}DeclarationsCal Poly PomonaECE 114-1 12 ResultConsole::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 () );Combining the input and conversion operations 7 Cal Poly PomonaECE 114-1 13#include " "#using < >using namespace System;int _tmain(){int number1,// First ,// Second numbersum;// sum of both numberConsole::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}.", () );return 0;Alternative source codeCal Poly PomonaECE 114-1 14 Declaration Types already defined in the .NET Framework Some Primitive types int, for integer numbers float, doublereal numbers _wchart_tcharacter data8 Cal Poly PomonaECE 114-1 15 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 PomonaECE 114-1 16 Display the resultConsole::WriteLine( S"\nThe sum is {0}.

5 ", () ); Obtain the string representation of variable sumusing method ToString. Use {0}to indicate a placeholder for variable valuesConsole::WriteLine( "The number entered are {0} and {1}. , (), () ); The value of () would replace {0} The value of () would replace {1}9 Cal Poly PomonaECE 114-1 17 Memory Displaynumber1 = 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 compilersum=number1+number2; Performs the addition and replaces sum s previous value in the LocationCal Poly PomonaECE 114-1 18 Arithmetic OperationsR % xR mod x%Modulusx / yx / y/Divisionx * yxy*MultiplicationP - cp - c-SubtractionF + 7f + 7+AdditionMC++ expressionAlgebraic expressionArithmetic operationMC++ Operation10 Cal Poly PomonaECE 114-1 19 Precedence of Arithmetic OperatorsOperatorsOperationsOrder of Evaluation( )ParenthesesEvaluate first. If there are several, evaluate left to right*,/,or %MultiplicationDivisionModulusEvaluate second.

6 If there are several evaluate left to right+ or -AdditionSubtractionEvaluate last. If there are several, evaluate left to rightCal Poly PomonaECE 114-1 20 Decision Makingx is greater than yx is less than yx is greater than or equal to yx is less than or equal to yx > yx < yx >= yx <= y> <>=<=relational operators> < x is equal to yx is not equal to yx = = yx != y= =!=equality operator= Meaning of C++ conditionExample of C++ conditionC++ equality or relational operatorStandard algebraic equality operator or relational operators11 Cal Poly PomonaECE 114-1 21 Data Types in .NET FrameworkString *Fixed-length string of charStringwcher_t or _wchar_tUnicode (16-bit) characterCharboolBoolean value (true and false)BooleandoubleDouble-precision(64-bits) floating point numberDoublefloatSingle-precision(32-bits) floating point numberSingle_int6464-bits signed integerInt64int or long32-bits signed integerInt32short16-bits signed integerInt16MC++ TypeDescriptionFLC Structure Class nameCal Poly PomonaECE 114-1 22 Case StudyFinding the Area and circumference of a circle1- Take the radius of a circle and compute and print its area and circumference2- Inputs: Circle radiusOutputs: Area of the circle Circumference of the circleConstants: PI = :area = r2circumference = 2 r3- Get circle radiusCalculate areaCalculate circumferenceDisplay area and circumference12 Cal Poly PomonaECE 114-1 23// Calculate and displays the area and circumference of a circle// Z.

7 Aliyazicoglu#include " "#using < >using namespace System;#define PI _tmain(){double radius , area= , circum= ;/* Get the circle radius */Console::Write( S"Please enter the radius : " );radius = Double::Parse(Console::ReadLine () );/* 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}.", () );Console::WriteLine( S"\nThe circumference is {0}.", () );return 0;}Source CodeCal Poly PomonaECE 114-1 24 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 fallowInput three different integers:13 27 14 Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is 2713 Cal Poly PomonaECE 114-1 25 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 SquareCube000111248392741664525 125


Related search queries