Državna matura riješeni zadaci- matematika A razina, LJETO 2016. god. (postupak)

Hrvatski:

U prilogu se nalaze riješeni zadaci (Matematika A razina) sa državne mature, ljeto 2016.god.
U prvom prilogu se nalazi prvih 15 zadataka dok u drugom ostali zadaci.

Ukoliko ima kakvih nejasnoća pošaljite mail na eugen.sunic@live.com

Link na maturu, Matematika A razina 2016, ljeto: https://www.scribd.com/doc/316830479/MAT-A-razina-pitanja

English

In the attachment below you can find solved problems from the 2016 (summer) math exam, level A.
Students across the country must pass this exam in order to inscribe them-self to a desired faculty.

If you have any question, refer to eugen.sunic@live.com

Exam link, Mathematics A level, 2016, summer: https://www.scribd.com/doc/316830479/MAT-A-razina-pitanja

Riješeni zadaci s postupkom, 1.dio/solved problems with steps, first part:
MAT A, viša razina, ljeto 2016.god. 1.dio

Riješeni zadaci s postupkom, 2.dio/solved problems with steps, second part:

MAT A, viša razina, ljeto 2016.god. 2.dio

Insert data to database using Java-Android (MySql)

Copy and paste the following class to insert data to mysql database.

If you want to use more POST parameters just concatenate the variable urlParameters with appropriate values and POST variable names.

public class BackgroundWorker extends AsyncTask {
    private Context context;
    //in constructor:
    public BackgroundWorker(Context context){
        this.context=context;
    }
    @Override
    protected String doInBackground(String... params) {

        URL url;
        HttpURLConnection connection = null;
        try {
            //Create connection
            url = new URL(params[0]);
            String urlParameters= URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(params[1], "UTF-8");
            urlParameters += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(params[2], "UTF-8");

            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded");

            connection.setRequestProperty("Content-Length", "" +
                    Integer.toString(urlParameters.getBytes().length));
            connection.setRequestProperty("Content-Language", "en-US");

            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);

            //Send request
            DataOutputStream wr = new DataOutputStream(
                    connection.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();

            //Get Response
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();
            return response.toString();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (ProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
       return null;
    }
        @Override
    protected void onPreExecute() {
        //super.onPreExecute();
    }

    @Override
    protected void onPostExecute(String s) {
        Toast.makeText(context, "Success",
                Toast.LENGTH_LONG).show();
        //super.onPostExecute(s);
    }
}

To call the above class use the following code:

BackgroundWorker backgroundWorker= new BackgroundWorker(this);
backgroundWorker.execute("server_url_with_php_file", "param1_value", "param2_value");

Here is the link to the initial stackoverflow problem: http://stackoverflow.com/questions/38317614/http-post-via-android-java-does-not-work/38318341#38318341

Math function classes (injection, surjection, bijection)

Let’s start with the definition first:

(1) In mathematicsinjectionssurjections and bijections are classes of functions distinguished by the manner in which arguments (input expressions from the domain) and images (output expressions from the codomain) are related or mapped to each other (taken from Wikipedia: https://en.wikipedia.org/wiki/Bijection,_injection_and_surjection).

Now let’s simplify the definition:

In mathematics injectionssurjections and bijections are classes of functions which tell us how functions behave. By applying a class we can easily distinguish a function’s order in most cases (f(x)= x, f(x)=x2 etc.)

(2) Domain and codomain simplified

Domain is a set where x values are stored and the codomain is a set where y values are stored.

(3) Injection: the injection class means that each x value/element of the 2d coordinate system has a corresponding y value of the coordinate system, in other words every x value in a set (this set is called the domain) is connected to an appropriate/corresponding y value in the other set (this set is called the codomain). In order for a function to be injective all of the values from x must be connected to all of the appropriate/corresponding values to y. Injection is also called one to one relationship since every x value MUST match the corresponding y value. If a value remains without a connection in any of the sets (domain & codomain) or if there are multiple connections for example from the x values/elements from the domain to one y value from the codomain (vice versa) then the function is NOT injective.

Proof formula:

proof1_injection

Example picture:

injection_set

(4) Surjection: the surjection class means that each x value/element in the domain of the 2d coordinate system has AT LEAST ONE (but can have multiple, most often two) corresponding values/elements in the codomain. It is important to say that all y values of the coordinate system must be used in order for a function to be surjective. This means that when you look at the function and decide to draw numerous horizontal lines (both negative and positive sections of the coordinate system, y0) the horizontal line that you have drawn will have to touch AT LEAST ONCE the given function. If this is not the case then the function is not surjective.

Proof formula:

proof2_surjection

Example picture:

surjection_set

(5) Bijection: the bijection function class represents the injection and surjection combined, both of these two criteria’s have to be met in order for a function to be bijective. We write the bijection in the following way, Bijection=Injection AND Surjection.

(6) If a function is neither injective, surjective nor bijective, then the function is just called: General function

Example picture:

xsquared

 

(7) A function is not defined if for one value in the domain there exists multiple values in the codomain. For example, if we have one x value on the coordinate system (let x be 3) and for that SAME x we have 2 or more y values, then the given graph is not a function because we don’t know which y values should we use and there must only exist one y value for one x value (surjection principal). See the horizontal and vertical test below (9).

Example picture (not a function):

(8) Note: When defining a function it is important to limit the function (set x border values) because borders depend on the surjectivness, injectivness, bijectivness.

(9) Vertical and Horizontal test lines,

Vertical lines are used to evaluate the existence of a function. This means that they determine if the graph inside a coordinate system is really a function or  isn’t.

Example picture (taken from: http://mathonline.wikidot.com/different-types-of-functions)

vertical-line-test

The picture says it all but let’s add a few words: If a vertical line crosses the graph MORE THAN ONCE, then the graph is NOT A FUNCTION.

Horizontal lines are used to evaluate the function classHorizontal lines actually tell us which class does NOT BELONG TO THE FUNCTION (injection, surjection)

Example picture (taken from: http://mathonline.wikidot.com/different-types-of-functions)

Screen Shot 2014-08-28 at 10.40.11 AM

Changing border-color of HTML input element to red if an error occurs

On November 7th a question was posted on SO where the OP wanted to change the border color of the input elements to red when both inputs didn’t match a condition.

I combined the JavaScript and a little bit of JQuery to solve this.

Here is the code:

var index_one;
var index_two;

    $('#Location, #LocationTo').change(function (e) {

        index_one = $("#Location")[0].selectedIndex;
        index_two = $("#LocationTo")[0].selectedIndex;
    });
    $("#submit").click(function () {
        if ($("#Location>option").eq(index_one).text() == $("#LocationTo>option").eq(index_two).text()) {
            $('#Location, #LocationTo').css("border-color", "red");
        } else {
            $('#Location, #LocationTo').css("border-color", "black");
        }
    });

As you can see, I first fetched the indexes of the selected items and after that gave the index to the eq(index) JQuery function in order to get the element as an object and then get the text via the .text() function. If the same options were selected in both input tags then the red border color would be displayed, otherwise the black default color remains.

If you want to handle all the possible cases then add the following code:

else if($("#Location>option").eq(index_one).text() =="Please Select")
    {
        alert ("Select an option");
    }
      else if($("#LocationTo>option").eq(index_one).text() =="Please Select")
    {
        alert ("Select an option");
    }

Here is the fiddle to see the code in action: http://jsfiddle.net/eugensunic/eg8k4vL7/1/

Installing Windows 7/8/10 on a new DELL laptop (using CD)

For those who do not want to read:

When installing windows 7,8,10 on DELL Inspiron 

  • press F2 to enter BIOS
  • disable the secure boot first in the secure boot tab
  • adjust the BIOS to by changing the UEFI to legacy under the boot sequence tab
  • select the priority by clicking on the arrow above so that the CD/DVD comes first.
  • apply the settings
  • click EXIT
  • when the computer restarts quickly hit F12 numerous times
  • click  CD/DVD/CD-RW Drive
  • the windows installation starts.

After the installation is done go back to the BIOS and change the boot sequence order again by letting the hard drive (since your OS is located their) to be the first hardware component to start.

YOU ARE DONE

———————————————————————————————————————

A friend of mine asked me If I could install Windows on his machine because he was not quite certain how to use the BIOS (basic input output system) and to configure the boot sequence. I must say that I was quite surprised with the DELL BIOS configuration and also I want to say that the HP and Lenovo BIOS is much more comfortable to work with.

In this article I want to quickly explain the following things:

  • FIRMWARE
  • NTFS
  • LEGACY
  • UEFI
  • MBR
  • GPT
  • Boot sequence
  • Secure boot
  • SATA

Let’s start:

FIRMWARE: represents the BIOS software which you can see if you press F2 on a dell laptop. You can make all sorts of configuration inside. It looks like a software from the seventies. It is located in ROM and you “cannot” delete it.

NTFS: represents a file system, system which takes care of the order of the files in the hard disk as well as maintaining space inside the hard disk.

LEGACY: a mode which refers to BIOS firmware. It also allows you to see the list of all available devices that you computer has. When installing any OS it is still a good advice to enable LEGACY and disable UEFI because you can have the authorization to use the CD/DVD and hence install your OS.

UEFI: Unified Extensible Firmware Interface(UEFI) is a “upgraded BIOS software”. UEFI offers secure boot which can have some repercussions when installing any OS (you have to disable it sometimes to allow your OS to boot properly). UEFI is a good upgrade since it prevents boot viruses from loading. UEFI offers many useful features as well.

MBR & GPT: both formats specify physical partitioning information on the hard disk. Often when installing windows you will have to convert MBR to GPT in order to put your OS in a desired partition. MBR stands for Master Boot record and GPT stands for GUID partition table.

Boot sequence: pretty much straight forward. You will definitely interact with this inside the BIOS when installing a new OS via CD/DVD or USB. It allows you to change the order pf the device which will first boot. It is mandatory to adjust this setting otherwise when installing OS and when the restart event takes place your computer will start the whole process rather than proceed with the installation.

Secure boot: associated with the UEFI part, the upgraded BIOS software which makes some restriction when booting up anything the system. This is usually turned off in DELL when you are installing a new OS to the device.

System reserved: This can be seen after your write the 25 character key when installing a windows OS (7,8,10). Don’t be afraid to erase it because you don’t need it. It represents the default OS that came with the laptop/computer which your bought. When formatting and deleting the system reserved you will then be allowed to install your OS.

Solving problems with cmd: When you come to the section where you have to enter the 25 character key press  FN->SHIFT->F10

  • type diskpart, click enter
  • type list, click enter
  • type select disk 0_or_1 (usually 0 or 1, look at the table above in cmd), click enter
  • type clean, click enter

OPTIONAL (type after entered the above immediately )

  • type convert gpt, click enter
  • type exit, click enter
  • close the CMD window

Here is a youtube tutorial if you get stuck in any of the steps above: https://www.youtube.com/watch?v=hlYjNbiVB-0

SATA: the standard hardware interface for connecting hard drives, solid state drives (SSDs) and CD/DVD drives to the computer. Introduced in 2001, nearly all computers use SATA drives (taken from: http://www.pcmag.com/encyclopedia/term/50811/sata).

Output the following sequence in c# (DaniWeb problem)

On December year 2013, a question was posted on DaniWeb asking to print out the following result

Using loop print the following output on console.
1
121
12321
1234321
123454321
1234321
12321
121
1

The question (and the results) seems pretty easy to reproduce but once you start thinking (without knowing the best solution) you get stuck a bit.

Although at DaniWeb you are not allowed to give answers if the OP (original poster) hasn’t made any effort. Frequent problem solvers including myself decided to show the art of programming (knowledge and creativity).

My solution


static void Main(string[] args)
{
    string number = "12345";
    int counter = -1;
    string output = "";
    int counter2 = 0;
    int pad = (2 * (number.Length - 1)) + 1;
    List list = new List();
    for (int i = 0; i = 0; j--)//   reverse concatenation
        {
            counter2 = output.Length;
            output = output + number[j];
            if (output[output.Length - 1] == number[0])
            {
                Console.WriteLine(output.PadLeft(pad));
                list.Add(output);
                output = output.Remove(counter + 2);
            }
        }
        counter++;
    }
    list.RemoveAt(list.Count - 1);
    list.Reverse();
    foreach (var item in list)
    {
        Console.WriteLine(item.PadLeft(pad));
    }
    Console.ReadLine();
}

Here is how this should be done (trick revealed) code. As you can see the Math.Pow() gives the desired sequence.

static void Main(string[] args)
        {
            double powValue = 0;
            double sqrtvalue = 0;
            int NumberOfValues = 9;
            for (int i = 1; i  0; i = (i - 1) / 10)
            {
                sqrtvalue = Math.Pow(i, 2);
                Console.WriteLine(sqrtvalue.ToString().PadLeft(NumberOfValues));
            }
            Console.ReadKey();
        }

And here is the final solution that was given by a guy called Ketsuekiama which is a awesome C# problem solver (he made the solution using only one line of code with LINQ)

 static void Main(string[] args)
        {
Enumerable.Range(1,5).Select(x => new string('1', x)).Concat(Enumerable.Range(1,4).Reverse().Select(x => new string('1', x))).Select(int.Parse).ToList().ForEach(y => Console.WriteLine("{0,9}", y*y));
            Console.ReadKey();
        }

and here is his evaluation of the code that he wrote (many of us were interested how this actually works)

Okay, so the Enumerable.Range(start, count) generates a sequence of numbers. When you do the select on this it will perform the lambda of the select for each number in the sequence. I’m not really that interested in the number that the Enumerable outputs, that’s a means to an end. This is because, as we know already, the sequence can be nicely calculated using a series of 1s squared.

The string constructor allows you to tell it to repeat a character x amount of times. The lambda, is essentially building the sequence of “1” for me. A common misconception with LINQ is that you have to get out what you put in, but this isn’t true. So I put in an integer (3 for example) and get out a string (for 3 would be “111”)

The Select method builds a new List of strings for me.

Unfortunately, you can’t make Enumerable.Range count down, I tried experimenting with TakeWhile but simply using .Reverse().Select() gave better output, simpler. So to join the two currently non-existent lists together I had to use Concat. If you were to execute this query now, you’d get a list out that looked like

“1”
“11”
“111”
“1111”
“11111”
“1111”
“111”
“11”
“1”
So now we have the string of 1s that can be used for the calculation. As the easiest way to generate them was as strings, they needed to be parsed back to int so I could work on them mathematically, so input list of strings and select the integer back out (Select(int.Parse)). So my list of strings is now a list of ints, the last one is pretty self explanatory, for each of those ints, write out the value of that int squared.

DaniWeb problem

Count number of words in text

Quite a while ago, my friend had a task to write a program which would count how many words does a text contain. He was unsure how to tackle the problem. He wasn’t allowed to use any system function. He had to write all of the code by himself. As I love problems, I decided to do it for him.

The code is written in C# although he had to write in C.

static void Main(string[] args)
        {
            char[] polje;
            string recenica = "";
            string path = "C:\\Users\\some\\Desktop\\sample_file.txt";
            try
            {
                StreamReader str = new StreamReader(path);
                int counter = 0;

                while (!str.EndOfStream)
                {

                    recenica = str.ReadLine();
                    Console.WriteLine(recenica);
                    polje = recenica.ToCharArray();
                    for (int i = 0; i = 97 && (int)polje2[index + 1] = 64 && (int)polje2[index + 1] = 32 && (int)polje2[index] = 58 && (int)polje2[index] <= 64))
            {
                return true;
            }
            return false;
        }

Display, overflow, positioning, float

DISPLAY

The display property specifies if/how an element is displayed, and the visibility property specifies if an element should be visible or hidden.

There are 4 values of the „display“property: inline, block, hidden, none

inline: displays elements, object whatever they are all in one line.

block: displays elements, objects whatever they in a block (square model, like a special box.

inline-block: displays an element as an inline-level block container. The inside of this block is formatted as block-level box, and the element itself is formatted as an inline-level box. Or we can just say when the inline element’s reach the end of the section (can be a div) the next elements which can’t be inserted on that line will go on the next line. This attribute value produces some extra space.

none: removes all elements, objects.

Elements also have a property called visible which have values of: hidden, collapse (elements are self-explanatory and easy to use).

OVERFLOW

Every single element on a page is a rectangular box. The sizing, positioning, and behavior of these boxes can all be controlled via CSS. By behavior, I mean how the box handles it when the content inside and around it changes. For example, if you don’t set the height of a box, the height of that box will grow as large as it needs to be to accommodate the content. But what happens when you do set a specific height or width on a box, and the content inside cannot fit? That is where the CSS overflow property comes in, allowing you to specify how you would like that handled.

There are four values for the overflow property: visible (default), hidden, scroll, and auto. There are also sister properties overflow-y and overflow-x, which enjoy less widespread adoption.

hidden: hides the actual content after the content overlaps the section

scroll: a box forms when the content inside the section gets too big and a scrolled appears

visible: the content inside the section overlaps

https://css-tricks.com/the-css-overflow-property/

POSITIONING

static: the default position of an element, object, the normal position

fixed: primarily used for navigation (scroll up-down) purposes, an element which is fixed positioned stays there no matter how much you scroll your page

absolute: absolute positioning allows you to remove an object from the typical flow of the document and place it at a specific point on the page. When applying this property you must specify the left or top or bottom or right position, without it, it won’t work. Absolute position starts from the upper left corner only if not placed in a container with relative positioning. When something has absolute positioning applied, it neither affects nor is affected by other elements in the normal flow of the page.

relative: relative positioning works similarly to absolute positioning in that you can use top, bottom, left and right to scoot an object to a specific point on the page. The primary difference is the origin or starting point for the element. As we saw above, with absolute positioning, the starting point was at the very top left of the browser window. The origin also known as the starting points depends on the position of the object where it would normally be (normally be means that position: static is applied or no position is applied

FLOAT

When you apply float css style, the object that flows is completely removed from the normal element flow. For instance if you apply float to an element and start to write a paragraph from the top of the document proceeding to the bottom the float element will just float there.

Elements are floated horizontally, this means that an element can only be floated left or right, not up or down. The floated elements pushes all the other horizontal elements around the floated element.

It represents kind of isolation which can’t be reached no matter what.

A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element.

The elements after the floating element will flow around it.The elements before the floating element will not be affected.

If an image is floated to the right, a following text flows around it, to the left:

You will often see the attribute clear in use. The clear attribute removes the float, so when you want again to position elements, to have the elements in the flow then use clear.

The elements which do not have the clear property will be pushed by the floated element as long as the non-floated elements match the height of the floated elements. After they leave the floated scope they will automatically gain the attribute clear.

Example
Good video of CSS-float ever: Click here

 

Programming every day usage differences PART 2

Difference between name-spaces and classes?

Namespaces represent scopes {} where variables, classes, structs and other types reside. Classes are just types which also have to reside inside of a scope and this scope is called namespace. If you want to look at it as a hierarchy, namespaces go first here after that all the other elements/types go, in this case classes.

Other thing which should be mentioned are:

– You can reopen namespaces unlike classes

– You can create an instance of classes unlike with namespaces

– Namespaces can be unnamed unlike with classes which must have a name.

Difference between classes and objects?

Classes and objects are the “same thing”. Basically this is a parameter-argument problem. Classes can be considered as when writing a function. Once you call that class (instantiate) the class becomes an Object.

Difference between arrays and lists?

Both of them can store multiple values and that’s their purpose, to store multiple values. Arrays, however have a fixed storage, so once you declare them you cannot add more cells to it whereas lists are re-sizable.  The other important thing is that arrays are more efficient since they are primitive types and do not need a wrapper around them. List’s represents interfaces (not primitive types) and interfaces have therefore multiple implementations.

Difference between inheritance and interfaces?

Inheritance assumes having an existing class (let’s say a base class, general class like human) which will then be adopted by the newly created class which is related to the base (existing) class and therefore the new class as now access to all properties and methods from the inherited class. It is easier to build the new class or just extend it so it serves to its purpose.

Interface can be seen as blocks or scopes which contain unimplemented variables and methods. A class can inherit multiple interfaces whereas only one class can be inherited. There is no method implementation inside an interface. This is done inside the class once the interface is inherited by it.

Note: The reason why you can’t inherit multiple classes is because you could get a collision between two elements, for example methods. Let’s assume that you can inherit two classes and let the first be “Automobile” class and the second “Robot” class. Suppose both methods have a same method called Run(); When you try to call the method Run() which one should be called? Robots class method or Automobile class method. Because of such problem (which was quite expressed/conspicuous in c++ language) code engineers of languages C# and Java ect. decided not to allow multiple inheritance.

Difference between switch statement, if statements and ternary operators?

There isn’t any better performance in any of the above. Use whatever you like. However it is advised to use switch statement if there are more than 6 if’s. Ternary operators just give a concise syntax and it looks better.

Difference between multidimensional array and jagged array?

Multidimensional arrays are fixed arrays. Once you declare it you are done. Jagged arrays are arrays which contain arrays. This can be also said for the multidimensional array but every row has a same size as does column. Jagged arrays row and column do not have to have same sizes.

Jagged arrays are faster than multidimensional arrays.

Google maps API usage limits (2015)

Do I need an API key?

Answer: in the early days of google maps you did not require an API key (it is still possible to not have one due to backwards compatibility) however, today it is recommended that you generate an API key for google maps V3. Also, have in mind that some features are not available without the API key.

Generate your google maps API key HERE.

If you want to inform your self more about the API key, here is the official page that will tell you how to get started with it and how to include it to your project,

url: https://developers.google.com/maps/documentation/javascript/tutorial

What are the usage limits?

Answer: If your site gets 25 000 map loads or more every single day, for more than 90 days in a row, the google team will get in touch with you (they are well aware of your google maps usage). If however you don’t think your google maps will generate such an amount of traffic then do the following:

  • Modify your application so that your usage is less than 25 000 map loads per day.
  • Enroll for automated billing of excess map loads in the Google Developers Console.
  • Purchase a Google Maps API for Work license.

Here is the official page for the limits,

url: https://developers.google.com/maps/documentation/javascript/usage#quota

To sum it all up: If you can predict huge traffic on your website (and using the google maps API within your website), then once again read carefully the docs and see what further steps need to be taken, otherwise you can experiment with google maps as much as you want.