Pitanja Za Kolokvijum Iz Programiranja 1

Embed Size (px)

Citation preview

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    1/26

    1

    1

    1. C# ?........................................... 4

    2. .NET Framework? ............................................................................................ 4

    3. ?........................... 4

    4. ?........................................... 4

    5. ......................................................................... 5

    6. . ............................................................................. 5

    7. ? .............................................................................. 5

    2.............................................................................................................................................. 6

    8. ?................................ 6

    9. , 1 = 2.54 cm. ............. 6

    10. ........................................................ 7

    11. Main() ? ................................................................................... 7

    12. C# ?..................... 7

    13. ?.................................................................. 8

    14. .................................................................................................................................... 8

    3.............................................................................................................................................. 8

    15. ? ............................................................................ 8

    16. C#

    ?............................................. 817. ?............................................................ 8

    18. ?................... 9

    19. ? ................................................................... 9

    20. ? ...................................................................................... 9

    21. Parse ? .............................................................................................. 9

    22. String ? ......................................................... 9

    4............................................................................................................................................ 10

    23. ? ...................................................... 10

    24. ? ............................................................................. 10

    25. if else ...............................................................11

    26. while do. ................................11

    27. 32. ...........11

    28. 24. .......... 12

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    2/26

    2

    2

    29. for................................................................................................. 12

    30. . ............................. 12

    31. swi tch case . .......................................................................... 13

    32. switch................................. 13

    33. break, continue. ............................................................................ 14

    5............................................................................................................................................ 14

    34. .............................................. 14

    35. 6 ................................................................................................................. 14

    36. . ............................................ 15

    37. . ................................ 15

    38. ? ........................................................................................... 15

    39. ? ........................................................ 1540. foreach .............. 15

    41. Queue . ....................................................... 15

    42. Stack . ........................................................... 16

    43. ? ...................................................................................... 16

    44. a ? ........................................................ 16

    45.

    ............................................................................................................................ 17

    6............................................................................................................................................ 17

    46. - ? ..... 17

    47. c . .......................................................... 17

    48. ? ................................................................... 17

    49. , .................................................... 18

    50. ? ...................................... 18

    51. ? ......................................................................... 18

    52. set get? ............ 18

    53. ? .............................................................................................. 18

    54. ? ................................................................................... 18

    7............................................................................................................................................ 18

    55. ? .................................................................................................. 18

    56. ? ................................................................... 19

    57. . ....................................................... 19

    58. ? ................................................ 20

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    3/26

    3

    3

    59. ? ....................................................................... 20

    60. . ........................................................... 20

    8............................................................................................................................................ 22

    61. ? ................................................................................ 22

    62. ? ................................................................................... 22

    63. ? ................................... 22

    64. . .............................................. 22

    65. Breakpoint ? ........................................ 22

    66. ? ............................................. 23

    67. . ...................................................... 23

    9............................................................................................................................................ 24

    68. ?....................................... 24

    69. ? ...................................................................................................... 2470. ..................................................................... 24

    71. . ...... 25

    72. . .................................................................................................................................... 25

    73. f inally............................................................................ 25

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    4/26

    4

    4

    1. C# ?

    - C# . 2002. MS .NET Framework- 1.0. C#

    (C++, Java ),

    .NET Framework .

    2. .NET Framework?

    NET Framework Microsoft- . NET Framework

    Windows, . , -

    NET Framework- C# , , Linux- Mac OS.NET Framework Windows , Web ,

    Web .

    3. ?

    :

    Windows applications- , Microsoft Office, , Windows Forms ( , ,

    ) Windows- (UI);

    Web applications- Web Web browser-, .NET Framework

    Web , ,

    . ASP.NET (Active Server Pages.NET), C#, Web ;

    Web services- Web ,

    Web .

    , ADO.NET (Active Data Objects.NET) NET Framework- LINQ (Language Integrated Query)

    C#. , , ,

    , .

    4. ?

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    5/26

    5

    5

    - .NET (assembly).

    , .

    ,

    , ,

    .

    5. .- :

    a) C#b) Microsoft- (Microsoft

    Intermediate Language)

    c)

    (Just In Time JIT )d)

    6.

    .-

    (namespaces),

    . ,

    .NET Framework-a System ,

    . : System, System.Data, System.Data.SqlClient.

    7. ?- :

    System ,

    .NET .

    System.Collections

    ArrayList, SortedList, Queue, Stack.

    System.ComponentModel

    , .

    System.Data ,

    .

    System.Data.Common .NET

    System.Data.OleDb OLE DB

    .

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    6/26

    6

    6

    System.Data.SQLClient

    MicrosoftSQL Server-.

    System.Drawing GDI+

    .System.IO I/O.

    System.Math

    .

    System.Reflection

    System.Security

    , , .

    System.Threading .

    System.Windows.Forms

    Windows

    .

    2

    8. ?1) Visual Studio NET.

    2) File > New >Project.

    3) ( ), .

    4) Program cs ain ,

    .

    .

    9. ,

    1 = 2.54 cm. .

    static void Main(string[] args)

    {

    double inci, cantimetri;Console.WriteLine (Unesite vrednost u cantimetrima (cm):);

    cantimetri = double.Parse (Console.ReadLine());

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    7/26

    7

    7

    inci = cantimetri / 2.54;

    Console.WriteLine ( Vrednost u incima je + inci + inca);

    }

    10.

    1)

    2) .

    :

    1) static void Main(string[] args)

    {ouble Pkvadrata, stranicakvadra;

    Console.WriteLine("Uneti duzinu stranice kvadrata D(mm):);

    stranicakvadrata = double.Parse(Console.ReadLine());

    Pkvadrata =stranicakvadrata * stranicakvadrata;

    Console.WriteLine("Zapremina kvadrata iznosi +Pkvadrata + milimetarakvadratnih);

    }

    2) static void Main(string[] args){

    ouble Ppravougaonika, stranicaA, stranicaB;

    Console.WriteLine(Uneti duzinu stranice A(mm):);

    Console.WriteLine(Uneti duzinu stranice B(mm):);stranicaA = double.Parse(Console.ReadLine());

    stranicaB = double.Parse(Console.ReadLine());

    Ppravougaonika = stranicaA * stranicaB;Console.WriteLine(Povrsina pravougaonuka iznosi +Ppravougaonika +

    kvadratnih milimetara );

    }

    11. Main() ?- .

    12. C# ?

    1)

    \- ;2) \- ;

    3) \\-

    4) \ f- ;5) \ b- ;

    6) \ n- ;

    7) \ r- ;8) \ t- ;

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    8/26

    8

    8

    9) \v- .

    13. ?

    - , o ,

    ,

    .14.

    .- static void Main(string[] args)

    {ouble zapkup, stranicakup,stranicakup1, visinakupH;

    Console.WriteLine("Uneti duzinu Stranice kupe A(mm):);

    Console.WriteLine("Uneti duzinu Stranice kupe A1(mm):);

    Console.WriteLine("Uneti visinu kupe H(mm):);

    stranicakup = double.Parse(Console.ReadLine());

    stranicakup1= double.Parse(Console.ReadLine());

    visinakupH = double.Parse(Console.ReadLine());

    zapkup = visinakupH / 3 * ( stranicakup * stranicakup + stranicakup1 *

    stranicakup1 + stranicakup * stranicakup1);

    Console.WriteLine("Zapremina pravilne cetvorostrane piramide isnosi +zapkup +

    milimetara kubnih);

    }

    3

    15.

    ?- ,

    .

    , .

    16. C# ?- C# , ,Boolean

    .

    17. 1?

    - intbrojdzakova;

    :brojdzakova = 27;

    :

    1 (long, short, int). , float (

    , 7 ), decimall ( 28

    ) double ( ) e .

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    9/26

    9

    9

    Code.WriteLine(brojucenika);

    18. ? -

    2,

    3

    .

    19. ?

    - , .

    public ,

    , private . Friend

    assembly , Protected .

    20.

    ?-

    ,

    .

    21. Parse ?

    - Parse .

    , string. Parse

    .

    22. String ?

    -

    :

    String.Insert

    String.PadLeft, String.PadRight

    String.Remove

    .

    String.Replace

    String.Split

    String.Substring

    2 .3 , . , long int.

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    10/26

    10

    10

    String.ToCharArray

    String.ToLower, String.ToUpper

    String.TrimEnd,String.TrimStart,String.Trim

    4

    23. ?-

    4

    5

    . .

    24. ?-

    , .

    - C# : & & (and)

    || (or)

    ! (not)

    .

    = =

    ! =

    >

    >=

    Ma = 5) && (VrNivoa = true))

    Console.WriteLine("Ulaz Vam je dopusten. Dobrodosli i prijatan rad! ");else

    {

    Console.WriteLine("PRISTUP ODBIJEN! Imate neodgovarajuci nivo pristupa");

    Console.WriteLine("Pritisnite taster Enter da napustite program");}

    }

    }

    26. while do. .

    static void M ain()

    {

    int i = 1;

    do

    {

    Console.WriteLine(i);

    i++;

    }

    whil e (i < 12);

    }

    27. 32. .

    - static void M ain()

    {

    int i = 1;

    do

    {

    Console.WriteLine(i);

    i++;

    }

    while (i < 32);

    }

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    12/26

    12

    12

    28. 24. . - static public void Main()

    {int sum = 0;

    for (int y = 1; y < 32; ++y)

    {if (y%2 == 0)sum = sum + y;

    }

    Console.WriteLine("Suma parnih brojeva je " + sum);}

    29. for.

    - static public void Main()

    {

    int sum = 0;for (int y = 1; y < 24; ++y)

    {

    if (y%2 != 0)

    sum = sum + y;}

    Console.WriteLine("Suma neparnih brojeva je " + sum);

    }

    30. .

    - static void Main()

    {for (int y = 1; y < 12; ++y)

    {

    Console.WriteLine(y);if (y != 6)

    continue;

    elsebreak;

    }

    }

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    13/26

    13

    13

    31. swi tch case .- static void Main(string[] args)

    {short izbor;

    int strkocke, duzkvadr, sirkvadra, viskvadra;

    Console.WriteLine("(1)Kocka, (2)Kvadar");izbor = short.Parse(Console.ReadLine());switch (izbor)

    {

    case 1:Console.WriteLine("Unesite stranicu kocke");

    strkocke = int.Parse(Console.ReadLine());

    Console.WriteLine("Povrsina kocke je {0}", 6 * (strkocke * strkocke));

    break;case 2:

    Console.WriteLine("Unesite duzinu kvadra");

    duzkvadr = int.Parse(Console.ReadLine());Console.WriteLine("Unesite sirinu kvadra");

    sirkvadra = int.Parse(Console.ReadLine());

    Console.WriteLine("Unesite visinu kvadra");

    viskvadra = int.Parse(Console.ReadLine());Console.WriteLine("Povrsina kvadra je {0}", 2 * (duzkvadr * sirkvadra +

    duzkvadr * viskvadra + sirkvadra * viskvadra));

    break;default:

    Console.WriteLine("Potrebno je izabrati 1-2!");

    break;

    32.

    switch - static void Main()

    {Console.WriteLine("Izaberite hranu: 1=Pica 2=Sendvic 3=Pljeskavica

    4=Hotdog");

    Console.Write("Molim vas napravite izbor: ");string s = Console.ReadLine();

    int n = int.Parse(s);

    int cost = 0;

    switch (n){

    case 1:

    cost += 15;

    break;case 2:

    cost += 20;

    break;case 3:

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    14/26

    14

    14

    cost += 25;

    break;

    case 4:cost += 48;

    break;

    default:Console.WriteLine("Niste napravili dobar izbor. Molim Vas izaberite 1, 2, 3 ili4.");

    break;

    }if (cost != 0)

    Console.WriteLine("Molim Vas da unesete {0} dinara.", cost);

    Console.WriteLine("Hvala i dodjite ponovo.");

    }

    33. break, continue.

    -

    static void Main(){

    for (int y = 1; y < 12; ++y)

    {

    Console.WriteLine(y);if (y != 6)

    continue;

    elsebreak;

    }

    }

    5.

    34. .- Proizvoljniniz p = new Random();

    Int[] niz = new int[10]

    35. 6

    .

    - static void Main(){

    int[] arr = new int[6] { 1, 2, 3, 4, 5, 6 };

    Console.WriteLine(arr[3]);}

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    15/26

    15

    15

    36. .- static void Main()

    {double [ ] niz = new double [13 ] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

    double sum = 0;

    for ( int i = 0 ; i != niz.Length; i++){sum = sum + niz [ i ];

    }

    Double Prosek = sum /13;Console.WriteLine (Prosek) ;

    Console.WriteLine( "Pritisnite Enter da zavrsite program");

    Console.Read();

    }

    37. .

    -

    static void Main(){

    int[,] visniz = new int[,] { { 1, 2 }, { 3, 4 },

    { 5, 6 }, { 7, 8 } };

    Console.WriteLine(visniz[2,1]);}

    38. ?-

    ArrayList.

    39. ?-

    Add.

    Remove.

    40. foreach .- foreach (int broj in new int[6] { 11, 16, 18, 22, 26, 29 })

    Console.Write(" {0}", broj);Console.WriteLine();

    }

    41. Queue .- using System;

    using System.Collections;

    ......

    public static void Main(){

    // Kreira i inicijalizuje novu klasu

    Queue mojQ = new Queue();// Prikazuje niz

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    16/26

    16

    16

    Console.Write("Elementi niza su:");

    StampajVrednosti(mojQ);

    }public static void StampajVrednosti(IEnumerable myCollection)

    {

    42. Stack .- using System;

    using System.Collections;

    ..................public static void Main()

    {

    Stack numbers = new Stack();

    numbers.Push(1);numbers.Push(2);

    numbers.Push(3);

    numbers.Push(4);numbers.Push(6);

    foreach (int number in numbers)

    {

    Console.WriteLine(number + " je stavljen na stek");}

    }

    43. ?- C# ,

    . String

    :Public sealed class String:

    Icomparable, Icloneable, Iconvertible, Ienumerable

    string, ,

    @,

    ToString().

    44. a ?

    - static void Main()

    {string s1 = "Prvi niz ";

    string s2 = "nadovezan je na drugi niz,";

    string s3 = "i nadovezan na treci niz.";

    // Knkatenacija odnosno nadovezivanje nizovas s1, s2 i s3s1 += s2;

    s2 += s3;

    System.Console.WriteLine(s2);}

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    17/26

    17

    17

    45.

    .

    - static void Main()

    {

    string kolone = "Kolona 1\tKolona 2\tKolona 3\tKolona4";

    //Izlaz: Kolona 1 Kolona 2 Kolona 3 Kolona 4Console.WriteLine("Izlazni rezultati: {0}", kolone);string redovi = "Red1\r\nRed 2\r\nRed 3\r\nRed 4";

    /* Izlaz:

    Red 1Red 2

    Red 3

    Red 4

    */Console.WriteLine("Izlazni rezultati: {0}", redovi);

    string naslov = "\"Ov\u0041kav je pravi naslov\", knjige";

    Console.WriteLine("Izlazni rezultati: {0}", naslov);}

    6

    46. - ?

    1) 2)

    3)

    4)

    5)

    47. c .

    - public class Computer{

    public string Model;

    public string Proizvodjac;public int BrojProcesora;

    public int BrojUsbPortova;

    }

    48.

    ?- ,

    ,.

    ,,

    .

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    18/26

    18

    18

    49. , .-

    ,

    . e

    : .

    50. ?-

    , .

    51. ?

    - , .

    52.

    set get?-

    get ,

    . get

    .

    - set , void. .

    53. ?-

    .

    54. ?-

    new, ,

    :Class1 MojaKlasa = new Class1();

    7

    55. ?-

    , .

    .

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    19/26

    19

    19

    56. ?- :

    - // 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

    }

    }

    57. .- 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){

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    20/26

    20

    20

    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();

    }}

    }

    }

    58. ?- Point, Rectangle, Color.

    ,

    Point.

    59. ?

    - struct ( RomanNumeral i BinaryNumeral).

    60. .- :

    struct RomanNumeral

    {

    private int value;public RomanNumeral(int value) //konstruktor

    {

    this.value = value;

    }static public implicit operator RomanNumeral(int value)

    {

    return new RomanNumeral(value);}

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    21/26

    21

    21

    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;

    // I zvodi konverzij u i z RomanNumeral u BinaryNumeral:binary = (BinaryNumeral)(int)roman;

    // I zvodi konverzij u i z BinaryNumeral u RomanNumeral:

    roman = binary;System.Console.WriteLine((int)binary);

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    22/26

    22

    22

    System.Console.WriteLine(binary);

    // Ostaviti otvoren konzoln i prozor.

    System.Console.WriteLine("Press any key to exit.");

    System.Console.ReadKey();}

    }

    8

    61. ?- .

    : ,

    , .

    62. ?-

    , :

    Publi c void Greska()

    Console.Write.Line(Ovo je poruka)

    63. ?-

    .

    ,

    :

    public float IzracunavanjeBrojaSekundi(float BrojSekundi)

    {float BrojSekundi;

    BrojSekundi = 24 * 1 * 360;

    return BrojSekundi;}

    64. .-

    .

    F11, Step Into

    Debug .

    65. Breakpoint ?

    - Breakpoint : Name, Condition, Address.

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    23/26

    23

    23

    66. ?- :

    setup Windows

    setupweb

    67.

    .1) C# project/solution ( project/solution Visual Studio

    ). 'File -> Open -> Project/Solution' ( Ctrl+Shift+O).

    2) . setup project . 'F ile -> Add ->

    New Proj ect...'3) 'Project types' 'Other Projects -> Setup and Deployment'

    'Setup Wizard' template

    4) 4 . #1:

    #2:

    ( #2) setup project .

    : setup program :

    setup Windows

    setup web

    :

    merge Windows I nstall er

    CABfile

    #3:

    . 'Primary output', DLL EXE.

    #4

    5) setup .

    Setup1

    'Solution Explorer'.

    6) Start

    .

    7) .

    8)

    .

    9)

    10) 11)

    12) 'Setup1',

    'Build' .

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    24/26

    24

    24

    9

    68. ?- (bugs)

    ,

    (errors) (exceptions)

    .

    69. ?-

    , .

    70.

    -

    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.");}

    }

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    25/26

    25

    25

    }

    }

    71. .- public static void Main()

    {

    int z = 0;try{

    int y = 20 + 3*z/z;

    }catch (ArithmeticException e)

    {

    Console.WriteLine("ArithmeticException Handler: {0}", e.ToString());

    }}

    72. .

    .-

    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.");

    }

    73. 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);}

  • 7/25/2019 Pitanja Za Kolokvijum Iz Programiranja 1

    26/26

    26

    catch(System.UnauthorizedAccessException e)

    {

    System.Console.WriteLine(e.Message);}

    finally

    {if (file != null){

    file.Close();

    }}

    }