ניתוח מערכות מידע ב

  • View
    45

  • Download
    0

Embed Size (px)

DESCRIPTION

. ... C#. '. - " " : " http://www.jct.ac.il/~rosenfa/nituach2 . . - PowerPoint PPT Presentation

Transcript

  • *

    ... C#

  • ' - " " : "

    http://www.jct.ac.il/~rosenfa/nituach2

  • C# Polymorphism, composition, association UML ADO C#

  • Requirements Analysis and System Design, 3rded. Leszek A. MaciaszekObject-Oriented Systems Analysis and Design Using UML, 3rded. , Simon Bennett, Steve Mcrobb, Ray Farmer#C . Object Oriented Design .net framework. .Visual C# 2010, How to Program (4thEdition), Deitel and Deitel.Pro Asp.Net 4 in C# 2010, 4thed. Matthew MacDonald, Adam Freeman, and Mario Szpuszta.

  • * C#

  • * - using System;

    class IOProgram{static void Main(string[] args){Console.WriteLine("Please Type Something:");String x;x = Console.ReadLine();Console.WriteLine("You typed {0}" , x );Console. ReadKey();}}

  • * using System;

    class numberProgram{static void Main(string[] args){String x;int y;Console.WriteLine("Enter a number:");x = Console.ReadLine();y = int.Parse(x);Console.WriteLine("You typed {0}" ,x);Console.WriteLine("Adding 2 makes: {0} or {1}", x+2, y+2 );Console. ReadKey();}}

  • * - ifusing System;

    class ifProgram{static void Main(string[] args){string x;x = Console.ReadLine();if (x == "a" || x == "A")Console.WriteLine("A is for apple");else if (x == "b" || x == "B")Console.WriteLine("B is for Boy");elseConsole.WriteLine("Not defined");Console.ReadKey();}}

  • * - forusing System;

    class ifProgram{static void Main(string[] args){for (int i = 0; i < 100; i++) Console.WriteLine("The square root of {0} is {1} ", i, Math.Sqrt(i) );Console.ReadKey();}}

  • * - whileusing System;class FirstProgram{static void Main(string[] args){int NUM_GAMES = 12;int won;double ratio;

    Console.WriteLine("Enter num of games won (0 to {0})", NUM_GAMES);string tmp = Console.ReadLine();won = int.Parse(tmp);while (won < 0 || won > NUM_GAMES){Console.WriteLine ("Invalid input. Please reenter: ");tmp = Console.ReadLine();won = int.Parse(tmp);}ratio = (double)won / NUM_GAMES;Console.WriteLine ("Winning percentage is: {0}", ratio);}}

  • *int grade, category;

    Console.WriteLine("Enter a numeric grade (0 to 100): ");string tmp = Console.ReadLine();grade = int.Parse(tmp);

    category = grade / 10;

    switch (category){case 10:Console.WriteLine("Perfect score. Well done.");break;case 9:Console.WriteLine("Well above average. Excellent.");break;case 8:Console.WriteLine("Above average. Nice job."); break;case 7:Console.WriteLine("Average.");break;default:Console.WriteLine("Study some more.");break;}

  • * VB C#

  • * VB C#...

  • *

  • *

    encapsulation

    inheritance

    - polymorphism

  • * (/)() +

  • *

  • * (encapsulation) ,

  • * (encapsulation) ,

  • *public - public public

  • *get, set , getX - X ( accessor)setX - X ( mutator) get - set get set

  • VOID*namespace ConsoleApplication1{ class Program { public static void XYZ() { Console.WriteLine("There"); } public static void Do(int x) { Console.WriteLine(x+2); } static void Main(string[] args) { XYZ(); Do(4); int y = 3; Do(y); Console.WriteLine("Hi"); } }}

  • *namespace ConsoleApplication1{ class Program { public static int XYZ(int x) { return x + 2; } static void Main(string[] args) { XYZ(4); int y = 3; XYZ(y); Console.WriteLine("Hi"); } }}

  • *namespace ConsoleApplication1{ class Program { static void Main(string[] args) { int[] numbers = new int[10]; // numbers is a 10-element array numbers[0] = 1; numbers[2] = -3; for (int i = 0; i < 10; i++) Console.WriteLine("pos " + i + " is " + numbers[i]); } }}

  • * C# BankAccountusing System;public class BankAccount{private String name;private float balance; public BankAccount(String name) { //constructor body }

    public float getBalance( ) { //method body }public void deposit(float sum) { //method body }public void draw(float sum) { //method body }} () (constructor)

  • * 1using System;

    public class BankAccount{//attributesprivate String _name;private float _balance;

    //constructorpublic BankAccount(String name){_name = name;_balance = 0;}

  • * 2//methodspublic float getBalance( ){return _balance;}public void deposit(float sum){_balance += sum;}

    public void draw(float sum){_balance -= sum;}

    }

  • * -

  • * public int calc (int num1, int num2)

  • * public int calc (int num1, int num2){ int sum = num1 + num2;

    return sum;} sum

  • * return

    void

    public int calc (int num1, int num2)public void calc (int num1, int num2){ int X; // do something return X;}{ // do something}

  • * return() -return

    X "

    public int calc (int num1, int num2){ int X; // do something return X;}public bool calc (int num1, int num2){ return num1

  • * - contructor (constructor)

  • * , public class BankAccount{private String _name;private float _balance;

    //constructor without parameterspublic BankAccount(){_name = null;_balance = 0;}

    //constructor with parameterspublic BankAccount(String name){_name = name;_balance = 0;}}

  • * - !!! void :

  • *

  • * , ()

  • * C# BankAccount using System; public class test {

    static void Main(String[] args) { BankAccount Account1 = new BankAccount("Tamar"); BankAccount Account2 = new BankAccount("Moshe");

    Account1.deposit(20000); Account2.deposit(100); Account2.draw(600);

    }

    }

  • * (int, float ) Circle circ1; "!! " new circ1 = new Circle ();Circle circ1 = new Circle (); : diameter = 30;xPosition = 20;yPosition = 60;color = "blue";isVisible = false;circ1

  • * '.' .int size=0;Circle circ1; circ1 = new Circle();circ1.moveHorizontal(10);size = circ1.getSize(); ( getSize() ) " "

  • * (overloading) (signature) , : , " - overloading

  • * " static float tryMe(int x){ return x + 10;}static float tryMe(int x, int y){return x*y;}

  • *null null " " (int, float, ) null Nothing VB null :String s = null; null:if (s == null) // Do something - null. null null

  • *Enumerated Types enum Enum VB Seasonenum Season {winter, spring, summer, fall}; Season time; time = Season.fall;

  • *

  • * Point Point . , X Ypublic class Point{ private double _x,_y; public Point(double x, double y) { _x = x; _y = y;} public double getX() { return _x; } public double getY() { return _y; } public void setX(double x) { _x = x; } public void setY(double y) { _y = y; }}

  • * toStringpublic class Point{ private double _x,_y; public Point(double x, double y) { _x = x; _y = y;} public double getX() { return _x; } public double getY() { return _y; } public void setX(double x) { _x = x; } public void setY(double y) { _y = y; }

    public String toString() {//return the relevant string return _x + "," + _y; }}

  • * Point p2 = p1;p2.setX(5);

  • * : Point p2 = new Point(p1)p2.setX(5);

  • *: copy constructor

  • * (copy constructor)public class Point{ private double _x,_y; public Point(double x, double y) { _x = x; _y = y;} //copy constructor public Point(Point otherPoint) { _x = otherPoint._x; _y = otherPoint._y; }

    public double getX() { return _x; } public double getY() { return _y; } public void setX(double x) { _x = x; } public void setY(double y) { _y = y; } public String toString() {//return the relevant string return _x + "," + _y; }}

  • *

  • * - Point 2 :public double distance(Point otherPoint) { double diffX = Math.Pow(_x-otherPoint._x,2); double diffY = Math.Pow(_y-otherPoint._y,2); return Math.Sqrt(diffX+diffY); }

  • * Point (0,0) (10,4) (5,2) (4,7) (2,3.5)

    public Point halfPoint(){ double halfX = _x/2; double halfY = _y/2; Point halfPoint = new Point(halfX, halfY); return halfPoint;}

  • * :public Point halfPoint(){ return new Point(_x/2,_y/2);} new return

  • * halfPointPoint p1 = new Point(10,4);Point p2 = new Point(4,7);

    Point middlePoint = p1.halfPoint();

    Console.WriteLine(p2.halfPoint());: 2.0,3.5

  • * Aggregation

  • * . Point 1: ( Point) 2: radius Point

  • * public class Circle { private double _radius; private Point _center;

    //constructor 1 public Circle(double r, double x, double y) { _radius = r; _center = new Point(x