programiranje1_seminarski

11
ТЕСТ 7 1. Шта су то структуре? Структуре су вредносни типови за разлику од класа које су референцни типови, и оне не подржавају наслеђивање. Оне се користе за мале типове који су једноставни и који су слични њима самима. 2. Како се врши декларисање структура? Коришћење и декларисање структура је приказано следећим кодом: // struct1.cs using System; struct SimpleStruct { private int xval; public int X { get { return xval; } set { if (value < 100) xval = value; } } public void DisplayX() { Console.WriteLine("Sacuvana vrednost je: {0}", xval); } } class TestClass { public static void Main() { SimpleStruct ss = new SimpleStruct(); ss.X = 5; ss.DisplayX(); 88 } }

Upload: nikoladjordjevic

Post on 17-Sep-2015

2 views

Category:

Documents


1 download

DESCRIPTION

Programiranje 1 Seminarski

TRANSCRIPT

71. ? , . .

2. ? :// struct1.csusing System;struct SimpleStruct{private int xval;public int X{get{return xval;}set{if (value < 100)xval = value;}}public void DisplayX(){Console.WriteLine("Sacuvana vrednost je: {0}", xval);}}class TestClass{public static void Main(){SimpleStruct ss = new SimpleStruct();ss.X = 5;ss.DisplayX();88}}

3. .using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Strukture{public struct CoOrds{public int x, y;public CoOrds(int p1, int p2){x = p1;y = p2;}}class Program{static void Main(){{// Inicijalizacija:CoOrds coords1 = new CoOrds();CoOrds coords2 = new CoOrds(10, 10);// Prikaz rezultata:Console.Write("CoOrds 1: ");Console.WriteLine("x = {0}, y = {1}", coords1.x, coords1.y);Console.Write("CoOrds 2: ");Console.WriteLine("x = {0}, y = {1}", coords2.x,coords2.y);// Ostaviti prozor konzole otvoren u Debug modu.Console.WriteLine("Press any key to exit.");Console.ReadKey();}}}}

4. ? Point, Rectangle, Color. , Point

5. ? struct ( RomanNumeral i BinaryNumeral)

6. . :

struct RomanNumeral{private int value;public RomanNumeral(int value) //konstruktor{this.value = value;}static public implicit operator RomanNumeral(int value){return new RomanNumeral(value);}static public implicit operator RomanNumeral(BinaryNumeral binary){return new RomanNumeral((int)binary);}static public explicit operator int(RomanNumeral roman){return roman.value;}static public implicit operator string(RomanNumeral roman){return ("Ne primenjuje se konverzija u string");}}struct BinaryNumeral{private int value;public BinaryNumeral(int value) //konstruktor{this.value = value;}static public implicit operator BinaryNumeral(int value){return new BinaryNumeral(value);}static public explicit operator int(BinaryNumeral binary){return (binary.value);91}static public implicit operator string(BinaryNumeral binary){return ("Ne primenjuje se konverzija u string ");}}class TestConversions{static void Main(){RomanNumeral roman;BinaryNumeral binary;roman = 10;// Izvodi konverziju iz RomanNumeral u BinaryNumeral:binary = (BinaryNumeral)(int)roman;// Izvodi konverziju iz BinaryNumeral u RomanNumeral:roman = binary;System.Console.WriteLine((int)binary);System.Console.WriteLine(binary);// Ostaviti otvoren konzolni prozor.System.Console.WriteLine("Press any key to exit.");System.Console.ReadKey();}}

81. ?

. : , ,

2. ?

, :

Public void Greska()Console.Write.Line(Ovo je poruka)

3. ? . , :

public float IzracunavanjeBrojaSekundi(float BrojSekundi){float BrojSekundi;BrojSekundi = 24 * 1 * 360;return BrojSekundi;}

4. .

. F11, Step Into Debug .

5. Breakpoint ?

Breakpoint : Name, Condition, Address.

6. ?

:setup Windows setup web

7. .1. C# project/solution ( project/solution Visual Studio ). 'File -> Open -> Project/Solution' ( Ctrl+Shift+O)2. setup project . 'File -> Add -> New Project...'

3. 'Project types' 'Other Projects -> Setup and Deployment' 'Setup Wizard' template4. 4 . #1: #2: setup project . : setup program : setup Windows setup web : merge Windows Installer CAB file #3: . 'Primary output', DLL EXE. #4 5. setup . Setup1 'SolutionExplorer' 6. Start7.

8.

9. 10. 11. 12. 'Setup1', 'Build' )

T 91. ?

(bugs) , (errors) (exceptions) .

2. ?

, .

3. .

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace DeljenjeNulom{class ExceptionTest{static double SafeDivision(double x, double y){if (y == 0)throw new System.DivideByZeroException();return x / y;}static void Main()104{// Unete ulazne velicine u cilju testiranjadouble a = 98, b = 0;double result = 0;try{result = SafeDivision(a, b);Console.WriteLine("{0} podeljeno sa {1} = {2}", a, b, result);}catch (DivideByZeroException e){Console.WriteLine("Pokusaj deljenja nulom.");}}}}

4. .public static void Main(){int z = 0;try{int y = 20 + 3*z/z;}catch (ArithmeticException e){Console.WriteLine("ArithmeticException Handler: {0}", e.ToString());}}

5. . .

catch (exception){Console.WriteLine("Izuzetak 1);}catch (exception){Console.WriteLine(Izuzetak 2);}catch (exception){Console.WriteLine(Izuzetak 3);108}Finally{Console.WriteLine("Izvrsavanje finalnog bloka.");}

6. finally.static void CodeWithCleanup(){System.IO.FileStream file = null;System.IO.FileInfo fileInfo = null;try{fileInfo = new System.IO.FileInfo("C:\\primer.txt");file = fileInfo.OpenWrite();file.WriteByte(0xF);}catch(System.UnauthorizedAccessException e){System.Console.WriteLine(e.Message);}finally{if (file != null){file.Close();}}}