Demo 9 (ei tutkimusta)

Palauta viimeistään ma klo 11:59.

DEMOTILAISUUS ZOOMISSA MAANANTAINA.

Klikkaa tästä itsesi kokoukseen: https://jyufi.zoom.us/j/227987027 (alk. ma klo 12:10)

Your time usage this week (0.5 p.)

Submitting time usage grants 0.5 points. Use the Set Custom Points feature to set your points.

This includes all course-related work during the week (lectures, reading the course material, completing the exercises etc.)

# d9tunnit


Huomautus tehtävien pisteytyksistä

PP5, perjantai 11.3.

PP-assignments (points are only given for those who attend the PP-group on Friday. The PP-assignments are given on Friday.) What are PP-assignments?

Task 1*

M: 15. Arrays.

Create a Function PisinNouseva, which returns the length of the longest strictly increasing subset of numbers from an int-array.

Note that if the subsequent numbers are equals, the subset is not strictly increasing. Test you function.

Note, that the function returns the lentgh of the set, namely a single integer.

Example: The longest strictly increasing subset of the following array 3, 3, 4, 4, 4, 0, 3, 4, 6, 6, 2 is 0, 3, 4, 6. The lenght of the subset is 4, so function's return value in this incstance is 4.

You must not assume that the array would always be the one given above, but the function should work with any array of integers. You are free to ''test'' your functions with the given array using Comtest for example.

Pisteytys: 0.5 pistettä kun funktio kääntyy, 0.4 pistettä itse tehdyistä ja läpi menevistä testeistä, ja 0.1 pistettä dokumentaatiosivun luomisesta ja tämän sivun avaamisesta (Document-linkki vastauslaatikon alapuolella).

Avaa vinkki, jos tehtävä vaikuttaa hankalalta.

# D9T1

Tip: If the algortihm is not crystal clear, practise using Tauno (below) or pen and paper.

# D1T1Tauno

Task 2*

Remember the box task earlier. Rewrite the program so that PiirraNelio (DrawSquare)-subroutine receives Vector-object instead of two real numbers (and size). This vector represents the bottom left corner of the box. The function draws the box and returns the coordinates of the top right corner. This makes it simple because the starting point is whatever the previous call returned.

Begin-subroutine could look like this.

public override void Begin() 
{
  Vector piste = new Vector(0, 0);
  piste = PiirraNelio(piste);
  piste = PiirraNelio(piste);
  piste = PiirraNelio(piste);
}

Add a small red circle to (0, 0). To ensure circle visibility you can add it to an upper layer.

Add(pallo, 1); 
// Huomaa: luku 1 tarkoittaa tasoa numero 1. 
// Add(pallo) lisäisi pallon tasolle 0

A picture example:

Example picture
Example picture
# D9T2

TODO: Ilmaise laatikon koko selkeämmin.

Task 3 (1-2 p.)

Basic part of the assignment (1 p.): Create the function OnkoSummaa, which accepts two parameters: int-array and int-integer. The function returns a bool value based on the following: true if the integer is the sum of any two numbers of the array.

For example the call

int[] t = new int[] {1, 2, 3, 9};
OnkoSummaa(t, 8);

would return false, because there are no two numbers inside the array which add up to 8.

int[] t = new int[] {1, 2, 4, 4};
OnkoSummaa(t, 8);

would return true, since 4 + 4 = 8.

# D9T3

Bonus part (+ 1 p.): Copy/paste the code below to Visual Studio to test the speed of your function with an array size of 100,000 elements. If the time is below 50 milliseconds, you may assign another point for yourself.

Mallikoodi ajastinta varten.

Task 4

M: 23. Dynamic data sttructures.

Phase 1 (create a new function): Create a function PisinJono(Longest String), which finds the longest string in a list of strings and returns it (as a string).

Phase 2 (create PoistaSanat(remove words)-method): Print the longest string in the Main-mehtod, and then remove all instances of the string from the list. The purpose is to remove the strings using a loop and the Remove-method of a List-object. Make sure you understand the return type of the Remove-method (bool) as well as the documentation below:

Return Value: true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the List (ks. MSDN)

This is also a great opportunity to practise using ComTest and to earn TDD-points by testing the functions.

Pisteytys: 0.9 pistettä kun funktio kääntyy, 1 piste oikeasta tulostuksesta ja 0.1 pistettä dokumentaatiosivun luomisesta ja tämän sivun avaamisesta (Document-linkki vastauslaatikon alapuolella).

# D9T5

Task 5 (1-2p.)

Preparations: Download Kotus' Finnish wordlist (choose it with the right mouse button and choose Save as...).

Create new Console Application -project and add the file you downloaded into the project: right mouse button over the project \(\rightarrow\) Add \(\rightarrow\) Existing Item \(\rightarrow\) Bottom right "All files" \(\rightarrow\) look for the .txt-file you just downloaded. Once you have added the file to the project click it with the right mouse button \(\rightarrow\) Properties \(\rightarrow\) Copy to output directory -choose Copy if newer.

You can push the data in a String-array by writing the code below into Main-method:

String[] sanat = File.ReadAllLines("kotus_sanat.txt");

Also add the following to the beginning of your code: using System.IO;

Task:


(part a) (1 p.) create a program which asks the user for a string. Then create a function which returns a list of words from the Kotus-list, which include all the characters given by the user. The program would then print out the words it found.

Copy SisaltaaKaikkiMerkit(Includes all characters)-function (below) to your own program and use it. This function returns true or false depeding on whether a given (single) string includes all given characters.

Pisteytys: 0.9 pistettä kun funktio kääntyy ja 0.1 pistettä dokumentaatiosivun luomisesta ja tämän sivun avaamisesta (Document-linkki vastauslaatikon alapuolella).

SisaltaaKaikkiMerkit-funktion mallikoodi

# sanattxt
# D9T6A

V1

This week there will be no new Ville-assignments. However you may do 5 loop/array-tasks that you have not done before or other tasks that you have not understood before. Remember Ville user manual.

# demo9v1

TDD1

If you test at least two functions with an automatic test (ComTest), using Visual Studio or similar you can mark yourself one extra demo point. Tests cannot be the same as the ones you can copy from the TIM version. As an answer you will write which tasks and function/functions operations you have tested. You can also give feedback and improvement ideas for using ComTest.

If the ComTest does not work in the computer labs, try installing ComTest-VS-plugin. Then check to see that the ComTest path is correct: In Visual Studio choose Tools \(\rightarrow\) ComTest \(\rightarrow\) Options. Check that Path to ComTest.jar executable field has N:\bin\ComTest.jar and that you have connected your computer to the N-drive. Ask the tutor for help if needed.

# D9TDD1

B1

Tee tehtävän 6 ohjelmasta interaktiivinen siten, että käyttäjä voi syöttää sanan kirjain kerrallaan, ja ohjelma näyttää tulokset heti. Katso video.

# D9T6B

B2-3

Tee seuraava Console Application -peli.

Kaksi pelaajaa kilpailee siitä, kumpi saa noppaa heittämällä ensin 100 pistettä. Jokaisella vuorolla pelaaja heittää toistuvasti noppaa, kunnes saa joko numeron 1 tai pelaaja sanoo "pankki" jolloin hänen vuorollaan heitettyjen silmälukujen summa lisätään hänen kokonaispistemääräänsä.

Pelaaja kullakin heittokerralla joutuu siis tekemään seuraavan valinnan

  • heitto - arvotaan nopan silmäluku 1-6, ja jos tulos on
  • 1: pelaaja menettää kaikki omalla vuorollaan heittämänsä pisteet ja vuoro vaihtuu vastustajalle
  • 2-6: silmäluku lisätään pelaajan "turn totaliin" ja pelaajan vuoro jatkuu
  • pankki - pelaajan omalla vuorollaan heittämät pisteet (eli "turn total") lisätään hänen kokonaispistemääräänsä ja vuoro vaihtuu vastustajalle
# D9B2

B4

Tee algoritmi kokonaislukutaulukon sekoittamiseksi. Tee void-aliohjelma, joka ottaa parametrina int-taulukon ja sekoittaa sen alkiot. Testaa algoritmiasi taulukolla, johon on alustettu järjestyksessä luvut 1, 2, 3, ..., 52. Palauta toimiva ohjelmakoodi, jossa on hyvin kommentoituna mitä algoritmissa tehdään.

Lukuja 1, 2, 3, ..., 52 ei tietenkään kannata laittaa taulukkoon manuaalisesti, koska helpompiakin tapoja on jo opittu ;).

Huom: Tässä ei ole tarkoitus "keksiä" omaa algoritmia, vaan käyttää ideaa jostakin valmiista algoritmista sekoittamiseen. Hyvä algoritmi on esim: Fisher-Yates shuffle. Tästä on toteutus Jypelin RandomGen -luokan Shuffle-aliohjelmassa. Jos matkit tätä, niin vaihda T:n tilalle int ja listan tilalle int-taulukko. Funktion alkuun pitää lisätä nyt Random rand = new Random(); jotta Random-olio on olemassa. Jypelin esimerkissä se on luokan attribuutti.

# D9B1

G1-2

Tee aliohjelma ToistotonTaulukko, joka saa parametrinaan taulukon, jossa on kokonaislukuja, ja palauttaa taulukon, jossa on alkuperäisen taulukon alkiot kukin vain yhden kerran järjestettynä niiden esiintymiskertojen määrän mukaan nousevaan järjestykseen. (1,5 p.) Täysiä pisteitä varten kirjoita aliohjelmalle myös testit. (0,5 p.)

Esim. taulukosta {1, 2, 3, 34, 34, 2, 1, 34, 1, 1, 1} palautetaan {3, 2, 34, 1}.

# D9G12

These are the current permissions for this document; please modify if needed. You can always modify these permissions from the manage page.