Background For many, Easter is a time for receiving chocolate eggs. Large ones, small ones, solid...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Background For many, Easter is a time for receiving chocolate eggs. Large ones, small ones, solid ones, hollow ones, filled ones. Dark chocolate ones, milk chocolate ones, white chocolate ones. Stripy wrapped ones, spotty wrapped ones, plain wrapped ones. Chocolate eggs! How many did you get? Which did you get the most of? Which did you get the least of? The Easter Bunny has asked you to develop an app to manage my collection of Easter eggs, to analyse the data and illustrate various distributions. You will need to show the number of eggs per chocolatier, the total weight of chocolate per chocolatier, and these values for a specified type of chocolate. Eggs are characterised by their maker, i.e. Lindt, Cadbury, Pink Lady, Darrell Lea, Kinder, Ferrero, or Mars. Only eggs from these seven chocolatiers will be stored. All others should be discarded. All eggs of the same chocolatier should be stored in the computerised collection together for ease of access. Each egg should have its volume in cubic centimetres (a double), weight in grams (an int), filling (an enumeration), wrapper style (an enumeration), and blend of chocolate (an enumeration) stored. The collection of eggs for each chocolatier should be stored in increasing order of volume (smallest first). A text file exists with the basic data of the Easter eggs I received. I will give you code to read this into your program. You will need to illustrate (using a bar chart and/or some print outs) various information. Task Based only on the information above (and not what is in the text file): a b C d Which underlying data structure (array or linked-list) will you use as a basis to model the collection of eggs for each of the seven chocolatiers? In two-three sentences, justify your answer. Which kind of abstract data type (binary tree, general tree, array, stack, priority queue, double-ended queue, set, list, etc.) would you use to model the collection of eggs I received for each of the chocolatiers? In two-three sentences, justify your answer by indicating the functionality required. Which underlying data structure (array or linked-list) will you use as a basis to model the collection of chocolatiers? In two-three sentences, justify your answer. Which kind of abstract data type (binary tree, general tree, array, stack, priority queue, double-ended queue, set, list, etc.) would you use to model the collection of chocolatiers? In two-three sentences, justify your answer by indicating the functionality required. To implement this you would need to define a type called collection to implement your answer to (a) and (b) above to represent the collection of eggs for a single chocolatier, and also another type (called chocolatiers) to implement your answer to (c) and (d) above to create a cluster of collections. From this, the whole haul of eggs could be defined as a global variable as follows: chocolatiers basket; An egg is defined as follows: struct egg_int { double volume; int weight; chocolate choc; wrapping wrap; filling fill; typedef struct egg_int *egg; and you may assume the existence of those types and the following types: typedef enum (dark, milk, white chocolate; typedef enum (stripy, spotty, plain) wrapping; typedef enum (solid, hollow, filled) filling; Eggs can be collected together by chocolatier as follows: typedef struct { char *name; collection eggs; } chocolatier; collection and chocolatiers can be defined as an array or a linked-list. Given the linked-list node from lectures: and/or struct node_int; typedef struct node_int *node; struct node_int { void *data; node next; you would either define chocolatiers and/or collection as a linked-list, e.g. typedef node chocolatiers; and/or typedef node collection; or you would define chocolatiers and/or collection as an array, e.g. typedef chocolatier chocolatiers [200]; typedef egg collection [200]; where you replace 200 by appropriate upper-bound(s). You may assume the existence of those egg functions: void init_egg (egg *e, double v, int *w, wrapping r, filling f); double get_volume (egg e); int get_weight (egg e); chocolate get_choc (egg e); wrapping *get_wrap (egg e); filling get_fill (egg e); void set_volume (egg e, double v); void get_weight (egg e, int w); void set_choc (egg e, chocolate c); chocolate c, Lindt | Cadbury | Pink Lady 1 Darrell Lea | Kinder | Ferrero | Mars | Invalid eggs: 1886 Lindt | Cadbury I Pink Lady | Darrell Lea And the most common chocolatier for stripy wrap eggs is... Easter Eggs -- plain wrap Kinder Ferrero | Mars | Invalid eggs: 1886 Lindt Cadbury I Pink Lady | Darrell Lea Kinder | Ferrero | Mars | Invalid eggs: 1886 And the most common chocolatier for plain wrap eggs is..... .Mars! Easter Eggs spotty wrap 585 643 Lindt | Cadbury I Pink Lady I Darrell Lea I Kinder | Ferrero Mars | Invalid eggs: 1886 Lindt | Cadbury | Pink Lady I Darrell Lea 1 663 639 629 641 Kinder | Ferrero 811 587 673 -- And the most common chocolatier for spotty wrap eggs is. Easter Eggs -- solid Mars | Invalid eggs: 1886 611 629 614 Lindt | 609 610 640 603 617 646 611 829 And the most common chocolatier for solid eggs is......Cadbury! Easter Eggs 598 649 625 643 624 823 625 --filled 630 812 610 587 Mars! 616 597 682 Kinder! And the most common chocolatier for filled eggs is......Mars! Easter Eggs -- hollow 631 Lindt Cadbury | Pink Lady Darrell Lea Kinder Ferrero | Mars 1 Invalid eggs: 1886 Lindt | Cadbury | Pink Lady | Darrell Lea | Kinder | Ferrero | Mars Invalid eggs: 1886 And the most common chocolatier for summed volume eggs is....Cadbury! Easter Eggs -- summed weight Lindt Cadbury | Pink Lady Darrell Lea | Kinder | Ferrero | Mars Invalid eggs: 1886 And the most common chocolatier for summed weight eggs is....Cadbury! Easter Eggs -- dark chocolate Lindt Cadbury I Pink Lady Darrell Lea Kinder Ferrero Mars | Invalid eggs: 1886 Lindt Cadbury I And the most common chocolatier for dark chocolate eggs is...Mars! Easter Eggs milk chocolate Pink Lady Darrell Lea 3887245.910 4024133.045 3876976.102 3940421,478 Kinder Ferrero Easter Eggs summed volume 3853535.410 3989328.427 3982688.109 Mars 1 7676788 8127868 7892665 7941238 Invalid eggs: 1886 7820 631 611 571 644 And the most common chocolatier for milk chocolate eggs is... Cadbury! Easter Eggs - white chocolate 645 613 678 665 850 619 608 640 657 591 635 625 604 614 569 607 And the most common chocolatier for white chocolate eggs is.... Cadbury! Easter Eggs -- stripy wrap Cadbury 1 Pink Lady I Darrell Lea Kinder | Ferrero | Mars | Invalid eggs: 1886 And the most common chocolatier for hollow eggs is.... Mars! Program Style The program you write for this assignment must be contained in five files as follows: egg.h and egg.c for managing a chocolate egg: node.h and node.c for nodes of linked lists (if relevant); . . . Your program should follow the following coding conventions: . . 650 611 637 627 602 855 . assig_two222.c for the main algorithm which controls the reading of the data, the management of the collections, the calculation of the results, and the display of the histogram. No function should be longer than about half a screen-full or so of code. . const variable identifiers should be used as much as possible, should be written all in upper case and should be declared before all other variables; #defined symbols should only be used for constant values if const is inappropriate, for example the size of an array. global variables should be used sparingly with parameter lists used to pass information in and out of functions. local variables should only be defined at the beginning of functions and their identifiers should start with a lower case letter; every if and if-else statement should have a block of code (i.e. collections of lines surrounded by { and }) for both the if part and the else part (if used) every do, for, and while loop should have a block of code (i.e. {}s) the keyword continue should not be used; the keyword break should only be used as part of a switch statement; opening and closing braces of a block should be aligned; all code within a block should be aligned and indented 1 tab stop (or 4 spaces) from the braces marking this block; commenting: A Visual Studio project is available on MyLO for you to download and use as a starting point. This comprises the following files: node.h and node.c-the Node ADT from lectures as the building blocks for linked lists (should you need them). These files are complete; egg.h and egg.c-the Egg ADT as specified above. These files are complete; e void set_wrap (egg e, wrapping I); void set_fill (egg e, filling f); char *to_string (egg e); assig_two222.c- the file which contains the main () function and other functions which implement the required task (including reading eggs from the text file) as well as constants, types, and global variables. You must complete assig_two222.c Start by adding the collection and chocolatiers types from above. You may add other types, constants and variables as necessary. For example, the following might be useful: const char *MAKERS [] = { "Lindt", "Cadbury", "Pink Lady", "Darrell Lea", "Kinder", "Ferrero", "Mars" }; Then, complete the following functions: . . get_chocolatier () - which takes a chocolatier name, locates it in the MAKERS array and returns its index (or-1 if it is not present); add_existing () - which takes the address of a non-empty collection of eggs for a particular chocolatier and an egg to add to that chocolatier's collection and which adds the egg to the collection in increasing order of volume; add_egg () - which takes the name of a chocolatier and an egg and which either stores the name and egg in basket if there are none for that chocolatier yet, or which calls add_existing () to do so if there are already eggs for that chocolatier; process_category () - which takes a collection of eggs for a particular chocolatier, a letter indicating which category should be processed, and an int indicating which value in the category the processing should occur for. Possible letters, values and actions are: 't'- - calculate the total number of eggs in the collection: 'w' - calculate the total weight of eggs in the collection; O 'v' - calculate the total volume of eggs in the collection; 'c' - calculate the number of eggs of that particular chocolate value (dark, milk, or white); o'r' - calculate the number of eggs of that particular wrap value (stripy, spotty, or plain); and o 'f' calculate the number of eggs of that particular fill value (solid, hollow, filled). The answer (a double) should be returned. show_graph () which takes a letter (see above), a string description of the output to be displayed (see sample output), and a value for the category (see above) or -1 if the category is total, weight, or volume, and which displays the histogram of titles, asterisks (unless weight or volume), and totals (which can be obtained using process_category () for each chocolatier); and main () - which should initialize basket, call read_in_data(), and call show_graph (). The project also contains the data file. This is just a text file which can be opened and read with most applications. It contains details of eggs that I received over Easter, but sometimes my little sister created some false data-these have a chocolatier name which is not one of the valid seven stated above. Program specification First you must obtain the eggs from a text file. The data must be stored in appropriate collections. At the top level there should be the chocolatiers and then for each of those there should be a collection of eggs (stored in ascending order of volume). As an egg is read from the file, the details should be checked for validity. If invalid, it should be counted, but discarded (i.e. not stored). If valid, its data should be stored in the appropriate place of the relevant collection (depending upon the chocolatier). Once the data have been read in and stored in the collections, output should be provided. This could be the total number of eggs, the total volume, the total weight, the number of eggs per different chocolate type (dark, milk, white), the number of eggs per different wrapping (stripy, spotty, plain), or the number of eggs per fill type (solid, hollow, filled). Each of these should be calculated per chocolatier (see below). A histogram illustrating the results per chocolatier should be displayed with one asterisk printed for every 25 eggs (other than for volume and weight - see sample output below). Each histogram should state the count of "invalid eggs beneath it. The output of your program should look something like the following (with the bold added in this document for emphasis only): Easter Eggs -- total number Linde I Cadbury Pink Lady I Darrell Lea I Kinder I Ferrero Mars Invalid eggs: 1886 And the most common chocolatier for total number eggs is. Mars! 185 1867 Project: Tools rental store Section A - Setup Python for database connection Project overview The project includes two phases: o Phase #1: Database creation, which includes o Database creation o Table creation o Table population o Data management: Queries (select), Insert, Delete Submission: Text files with extension *.sql with SQL statements, all required screenshots o Phase #2: Python program to manage database Submission: Python script, demo by providing all required screenshots Phase #1 - Database conceptual design Data requirements The following data has to be managed for the tool rental store: customer information, tools information, rental information. This will require 5 tables. Tools and Jobs: What is cardinality? tools hammer Crow bar saw hammer wrench snake pliers hammer pliers Screw driver Digital meter jobs roofing roofing roofing plumbing plumbing plumbing plumbing electrical electrical electrical electrical 1 2 3 4 1 2 A 3 start R = -150 hot zone Start -10 -150 hot zone -160 B -10 Rock Correct Answer Value Iteration 1. Fill in the utility after the first iteration (t = 1). Remember to round to the sixth decimal place. A B D E -10 Rock -10 116 200 large gemstone -10 116 D 200 large gemstone Rock Rock Rock Rock E 100 small gemstone 116 R = -50 hot zone 100 small gemstone 53 -10 -50 hot zone -60 PROJECT - PHASE #2 Database implementation: SQL statements INSERT INTO table tool_jobs (tool_id, job id) VALUES ((SELECT tool id FROM tools WHERE tool name 'Hammer' ), (SELECT job_id FROM jobs WHERE job_name 'roofing')); = PROJECT DESIGN - PHASE #1 Logical design: Relation model Step #1: Identify entities Resolve many-to-many relationships Resolve multi-valued attributes Step #2: Describe relations Identify relations Identify attributes Identify keys: primary, foreign Note: Once RDBMS system is selected (PostgreSQL) include data types for attributes Describe relationships - cardinality, optionality PROJECT - PHASE #3 Database connection At beginning of code Create connection At end of code Close connection: connection.cl Database) connection - should be declared in the outer scope so that it can be accessed from everywhere PROJECT - PHASE #2 Database implementation: SQL statements Insert/Delete Input o Get user input O Validate user input Output Display relevant information Insert example: current rentals and available tools, updated rentals Delete example: current rentals, updated rentals Processing Insert/delete based in primary key PROJECT - PHASE #3 Data management Execute SQL statements Syntax: cursor.execute (SQL_statement, SQL_data) Display query result Syntax: tuple Commit changes to database = cursor.fetchone () Syntax: To be executed after any changes to database: insert, update, delete connection.commit() PROJECT - PHASE #3 Decomposition Output functions Display menus Display formatted query output (optional) Getter functions Get user input: user input must be validated Get a field from a tuple: does tuple exist? PROJECT Data management Execute SQL statements Example to retrieve all records: cursor.execute('SELECT * FROM customer; ') Example to retrieve records based on data: cursor.execute('SELECT id FROM tools %s;', ('saw',)) PHASE #3 WHERE tool_name Display query result tuple = cursor.fetchone () while tuple != None: print tuple # prints the entire tuple = = print tuple [0] # prints first field (usually ID) tuple cursor.fetchone () With the current settings the metal detector was able to find most metal objects regardless of type. With such a high sensitivity this would cause many follow up searches which increase the amount of time someone would need to spend to go through the security check. Using all the same items as before, more tests were conducted with lower sensitivity. 3. 7. The following table shows the results of their testing, but it is not complete yet. Copy your answers from p. 2 (p. 258 in packet) questions 3, 4, 5, and 6, into the correspondingly numbered cells in the top row of the table. (1 pt) Sensitivity 86.00% 76.00% 62.00% 4. False Negative Rate 14.00% 24.00% 38.00% 5. Specificity 33.75% 47.50% 62.50% 6. False Positive Rate 66.25% 52.50% 37.50% Answer the following questions in complete sentences. Mention specific column names and/or values to support your conclusions. 8. As the sensitivity of the metal detector decreases, does it become more likely or less likely that the machine will not sound an alarm when a weapon is present? Explain. (3 pts) 9. As the sensitivity of the metal detector decreases, does the specificity of the metal detector increase or decrease? Explain. (2 pts) 10. As the sensitivity of the metal detector decreases, does it become more likely or less likely that the machine will sound an alarm when a weapon is not present? Explain. (3 pts) #2. Functions Decomposition To give you an idea I used the following functions (function parameters not listed) for my solution: Display functions: display_main_menu () display_query_menu() display_query() Getter functions o get_menu_selection () o get_customer_name () o get_customer_id () o get_tool_name() o get_tool_id () o get_rental_days () Query functions o query_customers () o query_tools () o query_tools_by_job () #optional o query_rentals () o query_rentals_by_customer () o query_overdue_rentals () o is_tool_rented_by_customer () Insert/delete functions o delete_rental () o insert_rental () PROJECT - PHASE #2 Database implementation: SQL statements Relations Use serial for primary keys where an auto- incrementing integer data type is required serial is an integer data type that is auto- incremented by PostgreSQL using a "sequence". When used as a foreign key, use the integer data type: you don't want to create another sequence. Inserting a tuple with a serial PK: list the column headings and the corresponding values explicitly Example: INSERT INTO customer 1_name) VALUES ('Jane', (f name, 'Austen'); Queries, as per project description Insert rental Delete rental o o Display all rentals, including: customer first and last name, tool_name, rental date, rental return date. Display all overdue rentals with customer phone number, tool name and dates Phase #3 - Create Python script New concepts: Database connection You will need to install a driver to connect from Python program to the database Install the database driver: psycopq2 o Install postgresql-devel with yum. o Install python-devel with yum. o Install python-psycopg2 with yum. Enter the python interpreter and verify you can import driver with "import psycopg2". You should not be getting any import errors. Exit the interpreter. In Python script o Import the driver Import the driver into your python program with: import psycopg2 o Create the database connection Syntax: connection = psycopg2.connect (database 'name', user = 'dbadmin') Example: connection = psycopg2.connect (database = 'tool_rental_db', user = 'dbadmin') Once you have connection object, you derive a cursor object from it. Cursor object is the object which executes SQL statements. Typically you would derive cursor, execute statement, read results if needed, close it. Phase #2 - Setting up database Database creation Database Database name: You can select a name for your tool rental store or call it "tool_store_MN". Tables Setup all required tables using SQL statements written to one or more text file(s). Use .sql extension to save files. Use the psql input feature (\i file) to setup the database in PostgreSQL. Set up all tables. Populate all tables with a minimum of 8 tuples per table. Prepare the following SQL queries to: o Display all customer information. o Display all tools information, including jobs (sorted by tool_name and jobs). o Display all rentals, including: customer first and last name, tool_name, rental date, rental return date. o Display all overdue rentals with customer phone number, tool name and dates Prepare the following SQL data management statements: insert, delete: o Insert a tool rental based on: tool ID, customer ID, rental date (use SQL current_date function) and return date (based on rental days added to current date: current_date + rental_days). o Delete a tool rental based on tool ID and customer ID. Submission All files on your Linux system that include your SQL statements to setup the database: One text file (extension .sql) to populate all tables. (5 marks) One (or two) text file(s) that contains the following statements: o One insert statement to create a new rental record. (1 mark) o One delete statement to delete an existing rental record. (1 mark) One (or more) text file(s) that contains the following query statements (select): (4 marks) o Display all customer information. o Display all tools information, including jobs (sorted by tool_name and jobs). Save "hw3.mat" in your Matlab working directory. In Matlab, type "load hw3.mat" Then type "who", you will find three matrices named "hw3_1, hw3_2_1 and on at a time "hw3_2_2". Each of these matrices has a size of 2100, i.e. 2 rows and 100 columns. Each column is a 2-D observation vector. If you are using Python, you can load the mat data using the following lines: import numpy as np import scipy.io as io hw3_1 io.loadmat ("hw3.mat") ['hw3_1'] hw3_2_1 io.loadmat ("hw3.mat") ['hw3_2_1'] hw3_2_2= io.loadmat ("hw3.mat") ['hw3_2_2] Problem 1: The sample vectors in "hw3_1" are drawn from a Gaussian Mixture Model (GMM) with two mixtures, which can be expressed as p(x) = pp(x)+(1 p)p (x) P(x) ~ N() and p(x) ~N(, E ), where .x, , are 21 vectors, and , are 22 matrices, and p is the mixing parameter. Use Expectation-Maximization (EM) algorithm to estimate the parameters M, M, 1, and p. Hint: Let the initial p=0.5, and assume the first 50 samples are from p(x) and the next 50 samples are from p(x). Use Maximum Likelihood method (CPE646-4, page 19) to estimate the initial 1. 1. . In this problem, we illustrate man-in-the-middle attack when Alice and Bob employ Diffie-Hellman key exchange. Answer the questions. Alice and Bob are sender and recipients of the message respectively. Darth is the attacker who acts as the middleman. Alice chooses a large prime number p. Let us choose p = 11. Choose an integer a = {2,3,4,...p-2). Let us choose a = 5. public Publish p and a to [Select] private Alice chooses a = {2,3,4,..,p-2); a is referred to as private key of Alice (Kpr. A). Let us choose a = 3. Alice computes X = a mod p. This is the public key of Alice (kpub. A). X = 4 [Select] Alice sends public key X to Bob. Darth captures the public key X from Alice. Captures public key X from Alice Alice 11 125 Captures public key X from Alice Alice Darth (Attacker) Darth generates a random prime number d1 = {2,3,4,..,p-2}; Let us assume d1 = 2. Darth computes X1 = a mod p. Darth replaces X as (kpub. A) with Xd1 as (kpub. D1) as the public key of Alice. XD1 = [Select] 2 3 25 Darth (Attacker) 5 9 Bob sends public key Y to Alice. Darth captures the public key from Bob. Bob chooses b = {2,3,4,...,p-2); b is referred to as private key of Bob (kpr.B). Let us choose b = 4. Bob computes Y = ba mod p. This is the public key of Bob (kpub.B). Y = [Select] Bob V 3 4 Sends Xa as public key from Alice Darth generates a random prime number d2 = {2,3,4,...p-2}; Let us assume d2 = 7. Darth computes Yd2 = qd mod p. Darth replaces Y as (Kpub, B) with Yd2 as (Kpub, D2) as the public key of Bob. YD2 = [Select] 9 Bob Background For many, Easter is a time for receiving chocolate eggs. Large ones, small ones, solid ones, hollow ones, filled ones. Dark chocolate ones, milk chocolate ones, white chocolate ones. Stripy wrapped ones, spotty wrapped ones, plain wrapped ones. Chocolate eggs! How many did you get? Which did you get the most of? Which did you get the least of? The Easter Bunny has asked you to develop an app to manage my collection of Easter eggs, to analyse the data and illustrate various distributions. You will need to show the number of eggs per chocolatier, the total weight of chocolate per chocolatier, and these values for a specified type of chocolate. Eggs are characterised by their maker, i.e. Lindt, Cadbury, Pink Lady, Darrell Lea, Kinder, Ferrero, or Mars. Only eggs from these seven chocolatiers will be stored. All others should be discarded. All eggs of the same chocolatier should be stored in the computerised collection together for ease of access. Each egg should have its volume in cubic centimetres (a double), weight in grams (an int), filling (an enumeration), wrapper style (an enumeration), and blend of chocolate (an enumeration) stored. The collection of eggs for each chocolatier should be stored in increasing order of volume (smallest first). A text file exists with the basic data of the Easter eggs I received. I will give you code to read this into your program. You will need to illustrate (using a bar chart and/or some print outs) various information. Task Based only on the information above (and not what is in the text file): a b C d Which underlying data structure (array or linked-list) will you use as a basis to model the collection of eggs for each of the seven chocolatiers? In two-three sentences, justify your answer. Which kind of abstract data type (binary tree, general tree, array, stack, priority queue, double-ended queue, set, list, etc.) would you use to model the collection of eggs I received for each of the chocolatiers? In two-three sentences, justify your answer by indicating the functionality required. Which underlying data structure (array or linked-list) will you use as a basis to model the collection of chocolatiers? In two-three sentences, justify your answer. Which kind of abstract data type (binary tree, general tree, array, stack, priority queue, double-ended queue, set, list, etc.) would you use to model the collection of chocolatiers? In two-three sentences, justify your answer by indicating the functionality required. To implement this you would need to define a type called collection to implement your answer to (a) and (b) above to represent the collection of eggs for a single chocolatier, and also another type (called chocolatiers) to implement your answer to (c) and (d) above to create a cluster of collections. From this, the whole haul of eggs could be defined as a global variable as follows: chocolatiers basket; An egg is defined as follows: struct egg_int { double volume; int weight; chocolate choc; wrapping wrap; filling fill; typedef struct egg_int *egg; and you may assume the existence of those types and the following types: typedef enum (dark, milk, white chocolate; typedef enum (stripy, spotty, plain) wrapping; typedef enum (solid, hollow, filled) filling; Eggs can be collected together by chocolatier as follows: typedef struct { char *name; collection eggs; } chocolatier; collection and chocolatiers can be defined as an array or a linked-list. Given the linked-list node from lectures: and/or struct node_int; typedef struct node_int *node; struct node_int { void *data; node next; you would either define chocolatiers and/or collection as a linked-list, e.g. typedef node chocolatiers; and/or typedef node collection; or you would define chocolatiers and/or collection as an array, e.g. typedef chocolatier chocolatiers [200]; typedef egg collection [200]; where you replace 200 by appropriate upper-bound(s). You may assume the existence of those egg functions: void init_egg (egg *e, double v, int *w, wrapping r, filling f); double get_volume (egg e); int get_weight (egg e); chocolate get_choc (egg e); wrapping *get_wrap (egg e); filling get_fill (egg e); void set_volume (egg e, double v); void get_weight (egg e, int w); void set_choc (egg e, chocolate c); chocolate c, Lindt | Cadbury | Pink Lady 1 Darrell Lea | Kinder | Ferrero | Mars | Invalid eggs: 1886 Lindt | Cadbury I Pink Lady | Darrell Lea And the most common chocolatier for stripy wrap eggs is... Easter Eggs -- plain wrap Kinder Ferrero | Mars | Invalid eggs: 1886 Lindt Cadbury I Pink Lady | Darrell Lea Kinder | Ferrero | Mars | Invalid eggs: 1886 And the most common chocolatier for plain wrap eggs is..... .Mars! Easter Eggs spotty wrap 585 643 Lindt | Cadbury I Pink Lady I Darrell Lea I Kinder | Ferrero Mars | Invalid eggs: 1886 Lindt | Cadbury | Pink Lady I Darrell Lea 1 663 639 629 641 Kinder | Ferrero 811 587 673 -- And the most common chocolatier for spotty wrap eggs is. Easter Eggs -- solid Mars | Invalid eggs: 1886 611 629 614 Lindt | 609 610 640 603 617 646 611 829 And the most common chocolatier for solid eggs is......Cadbury! Easter Eggs 598 649 625 643 624 823 625 --filled 630 812 610 587 Mars! 616 597 682 Kinder! And the most common chocolatier for filled eggs is......Mars! Easter Eggs -- hollow 631 Lindt Cadbury | Pink Lady Darrell Lea Kinder Ferrero | Mars 1 Invalid eggs: 1886 Lindt | Cadbury | Pink Lady | Darrell Lea | Kinder | Ferrero | Mars Invalid eggs: 1886 And the most common chocolatier for summed volume eggs is....Cadbury! Easter Eggs -- summed weight Lindt Cadbury | Pink Lady Darrell Lea | Kinder | Ferrero | Mars Invalid eggs: 1886 And the most common chocolatier for summed weight eggs is....Cadbury! Easter Eggs -- dark chocolate Lindt Cadbury I Pink Lady Darrell Lea Kinder Ferrero Mars | Invalid eggs: 1886 Lindt Cadbury I And the most common chocolatier for dark chocolate eggs is...Mars! Easter Eggs milk chocolate Pink Lady Darrell Lea 3887245.910 4024133.045 3876976.102 3940421,478 Kinder Ferrero Easter Eggs summed volume 3853535.410 3989328.427 3982688.109 Mars 1 7676788 8127868 7892665 7941238 Invalid eggs: 1886 7820 631 611 571 644 And the most common chocolatier for milk chocolate eggs is... Cadbury! Easter Eggs - white chocolate 645 613 678 665 850 619 608 640 657 591 635 625 604 614 569 607 And the most common chocolatier for white chocolate eggs is.... Cadbury! Easter Eggs -- stripy wrap Cadbury 1 Pink Lady I Darrell Lea Kinder | Ferrero | Mars | Invalid eggs: 1886 And the most common chocolatier for hollow eggs is.... Mars! Program Style The program you write for this assignment must be contained in five files as follows: egg.h and egg.c for managing a chocolate egg: node.h and node.c for nodes of linked lists (if relevant); . . . Your program should follow the following coding conventions: . . 650 611 637 627 602 855 . assig_two222.c for the main algorithm which controls the reading of the data, the management of the collections, the calculation of the results, and the display of the histogram. No function should be longer than about half a screen-full or so of code. . const variable identifiers should be used as much as possible, should be written all in upper case and should be declared before all other variables; #defined symbols should only be used for constant values if const is inappropriate, for example the size of an array. global variables should be used sparingly with parameter lists used to pass information in and out of functions. local variables should only be defined at the beginning of functions and their identifiers should start with a lower case letter; every if and if-else statement should have a block of code (i.e. collections of lines surrounded by { and }) for both the if part and the else part (if used) every do, for, and while loop should have a block of code (i.e. {}s) the keyword continue should not be used; the keyword break should only be used as part of a switch statement; opening and closing braces of a block should be aligned; all code within a block should be aligned and indented 1 tab stop (or 4 spaces) from the braces marking this block; commenting: A Visual Studio project is available on MyLO for you to download and use as a starting point. This comprises the following files: node.h and node.c-the Node ADT from lectures as the building blocks for linked lists (should you need them). These files are complete; egg.h and egg.c-the Egg ADT as specified above. These files are complete; e void set_wrap (egg e, wrapping I); void set_fill (egg e, filling f); char *to_string (egg e); assig_two222.c- the file which contains the main () function and other functions which implement the required task (including reading eggs from the text file) as well as constants, types, and global variables. You must complete assig_two222.c Start by adding the collection and chocolatiers types from above. You may add other types, constants and variables as necessary. For example, the following might be useful: const char *MAKERS [] = { "Lindt", "Cadbury", "Pink Lady", "Darrell Lea", "Kinder", "Ferrero", "Mars" }; Then, complete the following functions: . . get_chocolatier () - which takes a chocolatier name, locates it in the MAKERS array and returns its index (or-1 if it is not present); add_existing () - which takes the address of a non-empty collection of eggs for a particular chocolatier and an egg to add to that chocolatier's collection and which adds the egg to the collection in increasing order of volume; add_egg () - which takes the name of a chocolatier and an egg and which either stores the name and egg in basket if there are none for that chocolatier yet, or which calls add_existing () to do so if there are already eggs for that chocolatier; process_category () - which takes a collection of eggs for a particular chocolatier, a letter indicating which category should be processed, and an int indicating which value in the category the processing should occur for. Possible letters, values and actions are: 't'- - calculate the total number of eggs in the collection: 'w' - calculate the total weight of eggs in the collection; O 'v' - calculate the total volume of eggs in the collection; 'c' - calculate the number of eggs of that particular chocolate value (dark, milk, or white); o'r' - calculate the number of eggs of that particular wrap value (stripy, spotty, or plain); and o 'f' calculate the number of eggs of that particular fill value (solid, hollow, filled). The answer (a double) should be returned. show_graph () which takes a letter (see above), a string description of the output to be displayed (see sample output), and a value for the category (see above) or -1 if the category is total, weight, or volume, and which displays the histogram of titles, asterisks (unless weight or volume), and totals (which can be obtained using process_category () for each chocolatier); and main () - which should initialize basket, call read_in_data(), and call show_graph (). The project also contains the data file. This is just a text file which can be opened and read with most applications. It contains details of eggs that I received over Easter, but sometimes my little sister created some false data-these have a chocolatier name which is not one of the valid seven stated above. Program specification First you must obtain the eggs from a text file. The data must be stored in appropriate collections. At the top level there should be the chocolatiers and then for each of those there should be a collection of eggs (stored in ascending order of volume). As an egg is read from the file, the details should be checked for validity. If invalid, it should be counted, but discarded (i.e. not stored). If valid, its data should be stored in the appropriate place of the relevant collection (depending upon the chocolatier). Once the data have been read in and stored in the collections, output should be provided. This could be the total number of eggs, the total volume, the total weight, the number of eggs per different chocolate type (dark, milk, white), the number of eggs per different wrapping (stripy, spotty, plain), or the number of eggs per fill type (solid, hollow, filled). Each of these should be calculated per chocolatier (see below). A histogram illustrating the results per chocolatier should be displayed with one asterisk printed for every 25 eggs (other than for volume and weight - see sample output below). Each histogram should state the count of "invalid eggs beneath it. The output of your program should look something like the following (with the bold added in this document for emphasis only): Easter Eggs -- total number Linde I Cadbury Pink Lady I Darrell Lea I Kinder I Ferrero Mars Invalid eggs: 1886 And the most common chocolatier for total number eggs is. Mars! 185 1867 Project: Tools rental store Section A - Setup Python for database connection Project overview The project includes two phases: o Phase #1: Database creation, which includes o Database creation o Table creation o Table population o Data management: Queries (select), Insert, Delete Submission: Text files with extension *.sql with SQL statements, all required screenshots o Phase #2: Python program to manage database Submission: Python script, demo by providing all required screenshots Phase #1 - Database conceptual design Data requirements The following data has to be managed for the tool rental store: customer information, tools information, rental information. This will require 5 tables. Tools and Jobs: What is cardinality? tools hammer Crow bar saw hammer wrench snake pliers hammer pliers Screw driver Digital meter jobs roofing roofing roofing plumbing plumbing plumbing plumbing electrical electrical electrical electrical 1 2 3 4 1 2 A 3 start R = -150 hot zone Start -10 -150 hot zone -160 B -10 Rock Correct Answer Value Iteration 1. Fill in the utility after the first iteration (t = 1). Remember to round to the sixth decimal place. A B D E -10 Rock -10 116 200 large gemstone -10 116 D 200 large gemstone Rock Rock Rock Rock E 100 small gemstone 116 R = -50 hot zone 100 small gemstone 53 -10 -50 hot zone -60 PROJECT - PHASE #2 Database implementation: SQL statements INSERT INTO table tool_jobs (tool_id, job id) VALUES ((SELECT tool id FROM tools WHERE tool name 'Hammer' ), (SELECT job_id FROM jobs WHERE job_name 'roofing')); = PROJECT DESIGN - PHASE #1 Logical design: Relation model Step #1: Identify entities Resolve many-to-many relationships Resolve multi-valued attributes Step #2: Describe relations Identify relations Identify attributes Identify keys: primary, foreign Note: Once RDBMS system is selected (PostgreSQL) include data types for attributes Describe relationships - cardinality, optionality PROJECT - PHASE #3 Database connection At beginning of code Create connection At end of code Close connection: connection.cl Database) connection - should be declared in the outer scope so that it can be accessed from everywhere PROJECT - PHASE #2 Database implementation: SQL statements Insert/Delete Input o Get user input O Validate user input Output Display relevant information Insert example: current rentals and available tools, updated rentals Delete example: current rentals, updated rentals Processing Insert/delete based in primary key PROJECT - PHASE #3 Data management Execute SQL statements Syntax: cursor.execute (SQL_statement, SQL_data) Display query result Syntax: tuple Commit changes to database = cursor.fetchone () Syntax: To be executed after any changes to database: insert, update, delete connection.commit() PROJECT - PHASE #3 Decomposition Output functions Display menus Display formatted query output (optional) Getter functions Get user input: user input must be validated Get a field from a tuple: does tuple exist? PROJECT Data management Execute SQL statements Example to retrieve all records: cursor.execute('SELECT * FROM customer; ') Example to retrieve records based on data: cursor.execute('SELECT id FROM tools %s;', ('saw',)) PHASE #3 WHERE tool_name Display query result tuple = cursor.fetchone () while tuple != None: print tuple # prints the entire tuple = = print tuple [0] # prints first field (usually ID) tuple cursor.fetchone () With the current settings the metal detector was able to find most metal objects regardless of type. With such a high sensitivity this would cause many follow up searches which increase the amount of time someone would need to spend to go through the security check. Using all the same items as before, more tests were conducted with lower sensitivity. 3. 7. The following table shows the results of their testing, but it is not complete yet. Copy your answers from p. 2 (p. 258 in packet) questions 3, 4, 5, and 6, into the correspondingly numbered cells in the top row of the table. (1 pt) Sensitivity 86.00% 76.00% 62.00% 4. False Negative Rate 14.00% 24.00% 38.00% 5. Specificity 33.75% 47.50% 62.50% 6. False Positive Rate 66.25% 52.50% 37.50% Answer the following questions in complete sentences. Mention specific column names and/or values to support your conclusions. 8. As the sensitivity of the metal detector decreases, does it become more likely or less likely that the machine will not sound an alarm when a weapon is present? Explain. (3 pts) 9. As the sensitivity of the metal detector decreases, does the specificity of the metal detector increase or decrease? Explain. (2 pts) 10. As the sensitivity of the metal detector decreases, does it become more likely or less likely that the machine will sound an alarm when a weapon is not present? Explain. (3 pts) #2. Functions Decomposition To give you an idea I used the following functions (function parameters not listed) for my solution: Display functions: display_main_menu () display_query_menu() display_query() Getter functions o get_menu_selection () o get_customer_name () o get_customer_id () o get_tool_name() o get_tool_id () o get_rental_days () Query functions o query_customers () o query_tools () o query_tools_by_job () #optional o query_rentals () o query_rentals_by_customer () o query_overdue_rentals () o is_tool_rented_by_customer () Insert/delete functions o delete_rental () o insert_rental () PROJECT - PHASE #2 Database implementation: SQL statements Relations Use serial for primary keys where an auto- incrementing integer data type is required serial is an integer data type that is auto- incremented by PostgreSQL using a "sequence". When used as a foreign key, use the integer data type: you don't want to create another sequence. Inserting a tuple with a serial PK: list the column headings and the corresponding values explicitly Example: INSERT INTO customer 1_name) VALUES ('Jane', (f name, 'Austen'); Queries, as per project description Insert rental Delete rental o o Display all rentals, including: customer first and last name, tool_name, rental date, rental return date. Display all overdue rentals with customer phone number, tool name and dates Phase #3 - Create Python script New concepts: Database connection You will need to install a driver to connect from Python program to the database Install the database driver: psycopq2 o Install postgresql-devel with yum. o Install python-devel with yum. o Install python-psycopg2 with yum. Enter the python interpreter and verify you can import driver with "import psycopg2". You should not be getting any import errors. Exit the interpreter. In Python script o Import the driver Import the driver into your python program with: import psycopg2 o Create the database connection Syntax: connection = psycopg2.connect (database 'name', user = 'dbadmin') Example: connection = psycopg2.connect (database = 'tool_rental_db', user = 'dbadmin') Once you have connection object, you derive a cursor object from it. Cursor object is the object which executes SQL statements. Typically you would derive cursor, execute statement, read results if needed, close it. Phase #2 - Setting up database Database creation Database Database name: You can select a name for your tool rental store or call it "tool_store_MN". Tables Setup all required tables using SQL statements written to one or more text file(s). Use .sql extension to save files. Use the psql input feature (\i file) to setup the database in PostgreSQL. Set up all tables. Populate all tables with a minimum of 8 tuples per table. Prepare the following SQL queries to: o Display all customer information. o Display all tools information, including jobs (sorted by tool_name and jobs). o Display all rentals, including: customer first and last name, tool_name, rental date, rental return date. o Display all overdue rentals with customer phone number, tool name and dates Prepare the following SQL data management statements: insert, delete: o Insert a tool rental based on: tool ID, customer ID, rental date (use SQL current_date function) and return date (based on rental days added to current date: current_date + rental_days). o Delete a tool rental based on tool ID and customer ID. Submission All files on your Linux system that include your SQL statements to setup the database: One text file (extension .sql) to populate all tables. (5 marks) One (or two) text file(s) that contains the following statements: o One insert statement to create a new rental record. (1 mark) o One delete statement to delete an existing rental record. (1 mark) One (or more) text file(s) that contains the following query statements (select): (4 marks) o Display all customer information. o Display all tools information, including jobs (sorted by tool_name and jobs). Save "hw3.mat" in your Matlab working directory. In Matlab, type "load hw3.mat" Then type "who", you will find three matrices named "hw3_1, hw3_2_1 and on at a time "hw3_2_2". Each of these matrices has a size of 2100, i.e. 2 rows and 100 columns. Each column is a 2-D observation vector. If you are using Python, you can load the mat data using the following lines: import numpy as np import scipy.io as io hw3_1 io.loadmat ("hw3.mat") ['hw3_1'] hw3_2_1 io.loadmat ("hw3.mat") ['hw3_2_1'] hw3_2_2= io.loadmat ("hw3.mat") ['hw3_2_2] Problem 1: The sample vectors in "hw3_1" are drawn from a Gaussian Mixture Model (GMM) with two mixtures, which can be expressed as p(x) = pp(x)+(1 p)p (x) P(x) ~ N() and p(x) ~N(, E ), where .x, , are 21 vectors, and , are 22 matrices, and p is the mixing parameter. Use Expectation-Maximization (EM) algorithm to estimate the parameters M, M, 1, and p. Hint: Let the initial p=0.5, and assume the first 50 samples are from p(x) and the next 50 samples are from p(x). Use Maximum Likelihood method (CPE646-4, page 19) to estimate the initial 1. 1. . In this problem, we illustrate man-in-the-middle attack when Alice and Bob employ Diffie-Hellman key exchange. Answer the questions. Alice and Bob are sender and recipients of the message respectively. Darth is the attacker who acts as the middleman. Alice chooses a large prime number p. Let us choose p = 11. Choose an integer a = {2,3,4,...p-2). Let us choose a = 5. public Publish p and a to [Select] private Alice chooses a = {2,3,4,..,p-2); a is referred to as private key of Alice (Kpr. A). Let us choose a = 3. Alice computes X = a mod p. This is the public key of Alice (kpub. A). X = 4 [Select] Alice sends public key X to Bob. Darth captures the public key X from Alice. Captures public key X from Alice Alice 11 125 Captures public key X from Alice Alice Darth (Attacker) Darth generates a random prime number d1 = {2,3,4,..,p-2}; Let us assume d1 = 2. Darth computes X1 = a mod p. Darth replaces X as (kpub. A) with Xd1 as (kpub. D1) as the public key of Alice. XD1 = [Select] 2 3 25 Darth (Attacker) 5 9 Bob sends public key Y to Alice. Darth captures the public key from Bob. Bob chooses b = {2,3,4,...,p-2); b is referred to as private key of Bob (kpr.B). Let us choose b = 4. Bob computes Y = ba mod p. This is the public key of Bob (kpub.B). Y = [Select] Bob V 3 4 Sends Xa as public key from Alice Darth generates a random prime number d2 = {2,3,4,...p-2}; Let us assume d2 = 7. Darth computes Yd2 = qd mod p. Darth replaces Y as (Kpub, B) with Yd2 as (Kpub, D2) as the public key of Bob. YD2 = [Select] 9 Bob
Expert Answer:
Answer rating: 100% (QA)
To develop the app for managing the collection of Easter eggs and analyzing the data we can follow these steps 1 Data Collection and Storage Create a ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
A simple beam AB of span length L = 24ft is subjected to two wheel loads acting at distance = 5 ft apart (see figure). Each wheel transmits a load P = 3.0 k, and the carriage may occupy any position...
-
Nikkie and Jean have two children, Richard (age 4) and Roberta (age 3). For purposes of the tax on a child's unearned income, Richard has net unearned income of $6,000 and Roberta has net unearned...
-
In Exercises 7 through 10, find the distance between the given points. (3, 1) and (7, 1)
-
Reconsider Problem 56. Determine which oven should be purchased based on an incremental annual worth analysis. Data from problem 56 Octavia Bakery is planning to purchase one of two ovens. The...
-
Effects of Stockholders Equity Transactions on the Balance Sheet The following transactions occurred at Horton Inc. during its first year of operation: a. Issued 100,000 shares of common stock at $5...
-
8. A straight section of railroad track crosses two highways 400 m and 600 m from an intersection. Find the dimensions of the largest rectangular lot that can be laid out in the triangle formed by...
-
write program that prints Hello Fall 22 Run this program Add a class named Student private attributes String name; int id; Constructor that takes name and id Getters and Setters for name and id...
-
You are working at a company in the United States. Suppose the business that you work for wants to expand its vegetarian pizza business internationally, and the CEO of the company assigned you to...
-
Laker Company reported the following January purchases and sales data for its only product. The Company uses a perpetual inventory system. Required: 2. Determine the cost assigned to ending inventory...
-
Five (5) Journal Entries are required 3. Journal entries are to be done on communication essentials lectures only. 4. Journal entries are to be typed and double spaced 5. Be sure to include on each...
-
Talk to a sports fan at least two decades older than youa relative or a friend, for instanceand ask that person to recall how being a sports fan was different when he or she was the age you are...
-
All major airlines are faced with the issue of highly volatile oil price as jet fuel is the second largest expense in the airline industry. In order to better manage its operating costs, for example,...
-
Consider the problem 20 minER a2 subject to { 4- af az 22 +1/42 -1 20 A plot of the feasible region is given below. Which of the following statements are true about the point (0,1)7 (Check all that...
-
Use the method of Example 4.29 to compute the indicated power of the matrix. 1 0 1
-
Refer to the Arctic Springs Filtration Department Data Set and your answer to S5-16. 1. Record the journal entry to transfer the cost of the 160,000 liters completed and transferred out of the...
-
Excer Treads produces two types of exercise treadmills: Regular and Deluxe. The exercise craze and related demand is such that Excer Treads could use all of its available machine hours producing...
-
Royal Industries has one product. Information about the production and sales of that product for the past year follows. Selling price per unit...
-
The Lorenz curve for Bangladesh looks like this: How much income do individuals in the top income quintile in Bangladesh receive? Cumulative percentage of income 58.7% 37.4 21.3 8.9 20 40 60 80 100%...
-
What would the Lorenz curve for lawyers represent?
-
The accompanying table shows income distribution data for three countries: a. Using this information, draw a Lorenz curve for each country. b. Which country has the most equal distribution of income?...
Study smarter with the SolutionInn App