Failing to draw polygrams?

Here is a class that draws stars, as part of Chapter 13 Exercise 19 of Bjarne Stroustrup’s C++ Programming: Principles and Practice.

Class Star uses penta-, hexa-, hepta- and octa-gram as basis together with a property (rotational symmetry) that stars with multiple vertices (10, 12, 14, 18, etc) have, to draw n-grams1:

Chapter13Exercise19.cpp

#include "GUI.h"
#include "Simple_window.h"
#include <iostream>
#include "Chapter13Exercise19.h"

int main(){
     // window parameters
     int winWidth = 800;
     int winHeight = 600;
     Point centerPoint((x_max() - winWidth) / 2, (y_max() - winHeight) / 2);
     Simple_window* siw = new Simple_window(centerPoint, winWidth,
                                            winHeight, "Chapter 13 Exercise 19");

 try{
     Point center(siw->x_max()/2, siw->y_max()/2);
     int radius = 150;
     // Currenly: sides > 5, sides =! 13, 17, 19 and multiples
     int sides = 16;

     Graph_lib::Star st(center, radius, sides);
     siw->attach(st);
     siw->wait_for_button();
 }catch(exception& e){
    cerr << e.what() << endl;
    getchar();
 }catch(const std::invalid_argument& e){ 
     cerr << e.what() << endl;
     getchar();
 }catch(...){
    cerr <<"Defaul exception!"<< endl;
    getchar();
 }

}

read more

Why we need use streams in Java?

Suppose, I need get file. Why I need use streams?

File file = new File(directory, "image_name.jpg"); 

FileInputStream streamIn = new FileInputStream(file);

Bitmap bitmap = BitmapFactory.decodeStream(streamIn);

streamIn.close();

Why it’s to complicated? When I need copy of array I just call clone() and all bytes of array a copy to variable .

int[] a = new int[]{1,2,3,4...1000};
int[] b = a.clone();

Why we can’t get copy of file in similar simple way:

read more

swift keyboard moves up twice

I use the following code to move up the view when the keyboard appears.
This works fine but I have the problem that if I tapp on a textfield and directly tap on the next textfield it moves my view up twice.
How can I make it moving the view up only one time?

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)

func keyboardWillShow(notification: NSNotification) {
     print(self.view.frame.origin.y)


    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {

        self.view.frame.origin.y -= keyboardSize.height

    }

    print(self.view.frame.origin.y)
}

func keyboardWillHide(notification: NSNotification) {
    print("is dissapaering now")
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {

        self.view.frame.origin.y += keyboardSize.height
    }
}

read more

attach numbers to the closest one in a list

I have a file of terms with their index in context in two languages, as this format

1. (2- human rights, 10- workers rights)>> (3- droits de l'homme, 7- droit des travailleurs)
2. (2- human rights, 10- workers rights, 19- women rights)>> (5- droits de l'homme, 15- les droits des femmes)

The goal is to attach every word in the first language(English) to the closest word in the sentence in the other language (French), so the output will be

1. human rights> droits de l'homme: since the n.2(position of "human rights" in English sentence) is close to n.3 (position of "droits de l'homme" in French sentence), compared to the other numbers present in the French list (in this case n.7); and in the same way "workers rights">"droit des travailleurs"
2. human rights> droits de l'homme: since the n.2(position of "human rights" in English sentence) is close to n.5 (position of "droits de l'homme" in French sentence), compared to the other numbers present in the French list (in this case n.15); and in the same way "women rights"> "les droits des femmes": since the n.19 is close to n.15 (compared to the n.10)

read more