Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions and methods A method is a function that is a member of a class A method is a function that is a member of a class FCL(Framework Class Library)

Similar presentations


Presentation on theme: "Functions and methods A method is a function that is a member of a class A method is a function that is a member of a class FCL(Framework Class Library)"— Presentation transcript:

1 Functions and methods A method is a function that is a member of a class A method is a function that is a member of a class FCL(Framework Class Library) provides a rich collection of classes and methods FCL(Framework Class Library) provides a rich collection of classes and methods Console Console String String Programmer defined functions Programmer defined functions

2 Math class methods Abs(x) absolute value of x Abs(x) absolute value of x Ceiling(x) round x to smallest integer not less than x Ceiling(x) round x to smallest integer not less than x Cos(x) cosine of x Cos(x) cosine of x Exp(x) exponential e^x Exp(x) exponential e^x Floor(x) rounds x to the largest integer not greater than x Floor(x) rounds x to the largest integer not greater than x Log(x) natural logarithm of x ( base e) Log(x) natural logarithm of x ( base e) Max(x,y) larger value of x and y Max(x,y) larger value of x and y Min(x,y) smaller value of x and y Min(x,y) smaller value of x and y Pow( x, y) x raised to power y Pow( x, y) x raised to power y Sin(x) sine of x Sin(x) sine of x Sqrt( x) square root of x Sqrt( x) square root of x Tan( x) tangent of x Tan( x) tangent of x

3 Example b = 5;a = 2;c = -2; b = 5;a = 2;c = -2; Console::WriteLine( Math::Sqrt(b*b – 4*a*c)); Console::WriteLine( Math::Sqrt(b*b – 4*a*c));

4 Random number generation Class Random located in namespace System Class Random located in namespace System Create a object of class Random Create a object of class Random Random *ran = new Random(); Random *ran = new Random(); A random integer number between 0 and constant Int32::MaxValue ( 2,147,483,647) A random integer number between 0 and constant Int32::MaxValue ( 2,147,483,647) int num = ran->Next(); int num = ran->Next(); Random number between 0 and 5 Random number between 0 and 5 int num2 = ran->Next(6); int num2 = ran->Next(6);

5 String String::Concat(x.ToString(), S”\t”, (x+y).ToString()); String::Concat(x.ToString(), S”\t”, (x+y).ToString());

6 namespace The Standard C++ Library includes many names for the various classes, functions, variables, and other code it contains The Standard C++ Library includes many names for the various classes, functions, variables, and other code it contains In addition, you can define your own custom names for the programmatic elements in your applications In addition, you can define your own custom names for the programmatic elements in your applications The using directive informs your program that you intend to use a namespace The using directive informs your program that you intend to use a namespace using namespace name; using namespace name;

7 Namespaces in MC++ Systemessential class and types Systemessential class and types System::Dataclasses form ADO.NET, used for database access and manipulation System::Dataclasses form ADO.NET, used for database access and manipulation System::Drawingclasses used for drawing and graphic System::Drawingclasses used for drawing and graphic System::IOclasses for input and output of data System::IOclasses for input and output of data System::Threadingclasses for multithreading, used to run multiple parts of a program simultanously System::Threadingclasses for multithreading, used to run multiple parts of a program simultanously System::Windows::Formsclasses used to create GUI System::Windows::Formsclasses used to create GUI System::Xmlclasses used to process XML data System::Xmlclasses used to process XML data


Download ppt "Functions and methods A method is a function that is a member of a class A method is a function that is a member of a class FCL(Framework Class Library)"

Similar presentations


Ads by Google