Programming test 1) You can use any of the following languages: c++, c#, java, PHP, javascript to answer the questions Data structures 1) Define a node of a binary tree. 2) How can you store a graph (V, E), where V is the set of vertices and E is the set of edges, in a data structure? 3) Reverse the order of the contents of a queue. For example, if the queue has 1,2,3,4 change it to 4,3,2,1. You do not need to write any code for this, just the logic/algorithm. Using a vector/list. a) Declare a vector/list, which will store integers. b) Insert 10 random integers into the vector/list. The random number should be -/+ 5 to the second power of the index you are inserting to. For example if you are inserting at position 5, your random number should be in the range [5^2 – 5, 5^2 + 5]. c) After your insertion process is complete, you have to randomly shuffle the vector/list. d) Lastly, delete the smallest number in the vector/list. e) Assume you have the following statements and functions: 1) vector<T> name, list<T> name 2) vector.insert(type value) – inserts value at the next available spot 3) vector.insert(int index, type value) – inserts value at the given index 4) void srand(int) – seed random number generator 5) int rand() – returns a random number 6) vectors/lists have overloaded assignment(=) operator 7) vector.remove(int index) – index to be deleted from 8) assume all functions for vector<t> are present in list<T> moving images in a loop, pixels and size awareness a) Assume you have a function draw(image img, point position,rect rectangle). It takes three parameters: the image to be drawn, the position on the screen it will be drawn to in pixels, and the rectangle representing the image. b) The screen size of all displays is in pixels(integer), (screen-width, screenheight). The width X height is basically the resolution of the phone. For example, the resolution of iphone 4 is 640x960. So the screen width is 640 pixels and the screen height is 960 pixels. c) The point is a struct, with two data members; x and y. x denoted the position on the x axis and y denoted the position on the y axis. If you draw an image on point (0,0), it will be drawn on the origin. The image is always drawn starting from its top left corner. So, if you draw the image at point (640,960), you would not see the image on the screen. This is the declaration of the struct point: struct point { int x,y; }; this is how a screen looks like. d) the rect is a struct. Here is the definition of the struct rect: struct rect { int top, left; // top and left corners of the image. Usually 0 if taking the image from the origin. int width, height; // width and height of the image }; e) Your task 1: Assume you have an image ball. The width and height of the ball are 100x100. You have to draw the ball in the middle of the screen of resolution 640x960. Hint: just do not draw at point 320,480. As the image is drawn starting from its top left corner, do not forget to take its height and width into account. f) You task 2: Now assume you have the screen height and screen width stored in variables screenHeight and screenWidth. You have to draw the image in the middle of the screen. g) Your task 3: Assume you have a class game. Put the code to draw the image in the center in the default constructor of the class game. Do not worry about decalrig the variables in the constructor. The variables: image ball, point position, rect rectangle are declared as data member of the class. h) Your task 4: Assume you have a function void update() in class game, which is called in a loop every 20 ms. You task is to move the ball on the +x axis of the screen starting from the center of the screen. Hint: just increase the point.x value in the loop. i) Your task 5: If you just increment the value of poin.x, your ball will go out of the screen when the point.x value goes beyond the width of the screen. Now, make the ball turn its direction when it collides with the right wall (x coordinate screenWidth) and the left wall (x coordinate 0). Hint: keep a variable direction with two possible values -1 and to denote the direction of travel on the x axis. Just change the direction when colliding with the walls. Formal logic 1) Give a regex over [a,b]* in which the number of a’s is a multiple of 3. 2) How would you know if a binary number is divisible by 8? 3) Give a DFA over [a]*, which will accept any string other than aaaa. SQL Design 1) Give a database diagram to manage an online chat service. You have to keep information about users, users’ conversations, users’ groups, messages between 2 people and among groups, and blocked users. Include information of how the data will be stored. 2) Each user has a name, username, id (auto increment), email, and phone number 3) A conversation stores information about two people. 4) A group stores information about more than two people. 5) Each message has some text, image link, type (sent/received), read (true/false), time in Unix time stamp, and id (auto increment) 6) A user cannot send a message to the person who has blocked him. SQL Queries: Use any language to mix your queries with variables/conditions From the diagram you created, write sql queries for the following problems: 1) Get the names of the first 10 users of the service 2) Delete all users who have been blocked by more than 5 people 3) Get names of all users who have had a conversation with username “hello112” 4) Send a message from user with username “abc” to username “bcd” saying “hello” 5) Block all users with name “random” from user with username “abc” 6) Get names of the user who have had the highest number of conversations 7) Delete users who have not sent a message since 24 hours 8) User with username “abc” changed his country, which is 2 hours ahead in time. Change all the times of his received messages. OOP Design 1) Consider a game consisting of circles, and squares. If you touch a circle, it disappears. If you touch a square, its height is doubled. The circles are moving vertically with a speed of 5 pixels/frame and the squares are moving horizontally with a speed of 8 pixels/frame. The aim of the game is the clear out all the circles without touching the squares. If the squares keep expanding and occupy more than 50% of the screen, the game is over. You tasks: a) Design a class to represent an object (both circle and square). HINT: keep in mind the variables you used in question 3 to represent objects. b) Derive classes circle and square from class object, and add their properties. NOTE: I am not looking at how you write the code. I just want to see how you will design your classes with objects and methods to represent the objects. I also do not want you to implement the methods, just declare them. Give them a name that makes sense, and tells me what it will do.