Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Language is C So far in this course we've learned pointers, arrays, and loops. The exercise I need help on is in the pictures

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedThe Language is C

So far in this course we've learned pointers, arrays, and loops. The exercise I need help on is in the pictures below. The starter code is included below the pictures. Thanks! This week we will be practising working with strings using the library as well as working with loops, and arrays. This is a very limited version of what SQL does on database tables when you ask for it to go and look for information that matches in some way across database tables. Basically, you'll be getting information from two tables and correlating it. The Data We have a table that matches people's names to their nationalities. For this example, there is a unique entry for any given individual, but notice that names such as 'Paco Estrada' and 'pAcO estrAdA' are considered different people. Here's an example of this 'Nationalities' table: Name Nationality Paco Estrada Joe Armitage Angela Zavaleta Nyah Way Mexico England Peru Canada We also have another table that matches names to their favourite food(s). Once more, each unique individual has only one entry in the table, note that not every individual in the Nationalities table has to appear in the Foods table, and there may be individuals in the Food table that don't appear in the Nationalities table. Here's an example of this 'Foods' table: Name Favourite Food Paco Estrada Joe Armitage Angela Zavaleta Jack Long Fish Chocolate Green Eggs Ham The structure of the tables (known as the 'schema') is fixed. This means there will always be two columns (also known as fields) per table. Spelling and capitalization matter. The Task The Task We would like to produce a single result table that contains, for each individual in both tables, the nationality as well as the favourite food. - We can see above that Paco is from Mexico: he likes Fish. - We can also see that Joe is from England: he likes Chocolate, - We cannot tell where Jack is from: we know he likes Ham - We know Nyah is from Canada: we don't know her favourite food. We only want to join data for which we know both pieces of information (favourite food and nationality). Thus we'll ignore Jack and Nyah's data (but not them if they're your TAS!). So, we expect the final table to be (for the example tables above): Name Paco Estrada Joe Armitage Angela Zavaleta Nationality Mexico England Peru Favourite Food Fish Chocolate Green Eggs This is the result of the finner join' that we want you to implement. This is the result of the inner join' that we want you to implement. Only joining where we have data from both tables is what the inner part of inner join' means. Your Task Download the starter code: inner_join_starter.c Implement the function: innerJoin() (see the comments at the top of that function) The Implementation Details An example of the C implementation of a pair of these tables (that we chose) is given in the starter code (in main(), make sure you look at it and understand how it stores information). Note that: - The delimiter that separates columns of the table is called "DELIMITER. - All data separated by the delimiters are relevant, including leading and trailing whitespace. (e.g." Paco Estrada,"Fish!" indicates the name is 'Paco Estrada' with the extra spaces up to the DELIMITER, and he likes Fish!' including all punctuation or spaces as well) - Every row will have exactly one delimiter. - The order of the rows is irrelevant; we will accept any order for the result table. - Assume sufficient memory has been allocated for each of the tables. - The output order of the columns must be "Name, Nationality, Favourite Food". - Notice that the tables themselves do not contain the column names! Submission - Do not modify anything other than the function you're supposed to implement - Remove any printf() statements you added while testing/debugging your solution - The 'innerJoin function should print nothing! - Do not post any partial solutions or descriptions of your solution algorithm to the Piazza forum. If you have questions, please bring these to office hours! Like every other exercise - please submit only your..cfile with the name: inner_join_studentNo. (mind the underscore before studentNo, many people have forgotten to add that one) Testing: We will test your code on different tables than the ones you were given, and it must work correctly - so be sure to test thoroughly, and change the contents of the example tables to run any tests that will convince you your code does the right thing. Our solution produces the following output for the example tables: ./a.out Paco Estrada, Mexico, Chocolate Joe Armitage, England, Chocolate Angela Zavaleta, Peru, Green Eggs Brian Harrington, Canada, Avocado Salad You could actually save that output as a file with extension .csv, and it would load into Excel (or Open Office Calc) as a table ! The starter code is: #include #include #include #include #include #include #include // You can use the string library! // The values for the constants below could change, so make sure your Il program is using them where appropriate! #define MAX_STRING_LENGTH 128 #define MAX_ROW_COUNT 100 #define DELIMITER * Joins two tables (produces a larger table with combined information from both). t the input tables each have fields (chunks of test) separated by "DELIMITER * The first field in each table is a person's name see the example tables in main() * and the second field records appropriate information for the corresponding individual. * This function will create a combined (joined) table such that the first field is the * person's name, the second is the nationality (from the nationality table), and the * third is their favorite food (from the food table) * This requires you to match the person's name in the two tables, and to do a bit of string manipulation to build the combined row containing name, nationality, food, * and then putting that joined result into the joined table. * Your joined table must not contain any rows from either table for which there is no * corresponding row in the other table (eg. in the sample input from main(). * 'Nyah Way' appears only on the nationality table, and not in the food table, so there * will NOT be any rows in the joined table for this individual. * Person's names in the first field must be *unique* within each table (e.g. 'Paco Estrada' * can only appear once in the nationality table, and only once in the food table) * But 'Paco Estrada' is not the same name as 'paco estradA' (these are considered * different people) * INPUT * nationalities_table: * . an array of strings, each string has 2 DELIMITER-separated columns *- represents Name -> Nationality mappings * foods_table: * - an array of strings, each string has 2 DELIMITER-separated columns *- represents Name -> Favourite Food mappings * OUTPUT * joined_table: * - an array of strings, each with 3 DELIMITER-separated columns * -represents the combined information for a person: name, nationality, food * - The ORDER of the rows in this output table does not matter, so don't worry * about it, as long as the rows are all there that should be there. void innerJoin(char nationalities_table(MAX_ROW_COUNTIMAX_STRING_LENGTH). char foods_table[MAX_ROW_COUNT][MAX_STRING LENGTH). char joined_table[MAX_ROW_COUNT][MAX_STRING_LENGTH * 2]) // TODO: implement this function, satisfying the description above // Feel free to add rows to either table to test your solution, but mind the fact // that the names of individuals must be unique! Il Later on in your studies (or perhaps during your Coop term, or maybe you have II already used this) you'll see that what we're asking you to do is equivalent Il to what SQL does with database tables when we ask for // SELECT Nationalities.name, Nationalities.country, Foods.favourite // FROM Nationalities // SELECT Nationalities.name, Nationalities.country, Foods favourite // FROM Nationalities // INNER JOIN Foods II ON Nationalities.name=Foods.name: // NOTE: Please use the DELIMITER constant! // Ideally, this function should work even if all the constants above were changed Il We NEED this compiler directive to test your code with our own main(). Don't break it. #ifndef _TESTING // this compiler directive int main() Il Please note that these are JUST EXAMPLES! // You will be tested on a wide range of data // IMPORTANT: The join function above doesn't know how many rows are in Il each table, so, we add an empty string as the last row Il of the tables below. You can assume any input tables we Il use to test your program will contain an empty string Il at the last row so you can tell you've reached the end Il of the table // As before you are expected to make reasonable assumptions Il regarding any information not given in these instructions. char example_nationalities_table[MAX_ROW_COUNT][MAX_STRING_LENGTH] = { "Paco Estrada, Mexico", "Joe Armitage, England", "Angela ZavaletaPeru", "Nyah Way, Canada", "Anya Tafliovich, Ukraine", "Brian Harrington, Canada", ", Il -- Empty string signals end of table char example_foods_table[MAX_ROW_COUNT][MAX_STRING_LENGTH] = { "Brian Harrington Avocado Salad", "Paco Estrada, Chocolate "Joe Armitage Chocolate", "Angela Zavaleta Green Eggs", "Jack Long, Ham", **, 11 library as well as working with loops, and arrays. This is a very limited version of what SQL does on database tables when you ask for it to go and look for information that matches in some way across database tables. Basically, you'll be getting information from two tables and correlating it. The Data We have a table that matches people's names to their nationalities. For this example, there is a unique entry for any given individual, but notice that names such as 'Paco Estrada' and 'pAcO estrAdA' are considered different people. Here's an example of this 'Nationalities' table: Name Nationality Paco Estrada Joe Armitage Angela Zavaleta Nyah Way Mexico England Peru Canada We also have another table that matches names to their favourite food(s). Once more, each unique individual has only one entry in the table, note that not every individual in the Nationalities table has to appear in the Foods table, and there may be individuals in the Food table that don't appear in the Nationalities table. Here's an example of this 'Foods' table: Name Favourite Food Paco Estrada Joe Armitage Angela Zavaleta Jack Long Fish Chocolate Green Eggs Ham The structure of the tables (known as the 'schema') is fixed. This means there will always be two columns (also known as fields) per table. Spelling and capitalization matter. The Task The Task We would like to produce a single result table that contains, for each individual in both tables, the nationality as well as the favourite food. - We can see above that Paco is from Mexico: he likes Fish. - We can also see that Joe is from England: he likes Chocolate, - We cannot tell where Jack is from: we know he likes Ham - We know Nyah is from Canada: we don't know her favourite food. We only want to join data for which we know both pieces of information (favourite food and nationality). Thus we'll ignore Jack and Nyah's data (but not them if they're your TAS!). So, we expect the final table to be (for the example tables above): Name Paco Estrada Joe Armitage Angela Zavaleta Nationality Mexico England Peru Favourite Food Fish Chocolate Green Eggs This is the result of the finner join' that we want you to implement. This is the result of the inner join' that we want you to implement. Only joining where we have data from both tables is what the inner part of inner join' means. Your Task Download the starter code: inner_join_starter.c Implement the function: innerJoin() (see the comments at the top of that function) The Implementation Details An example of the C implementation of a pair of these tables (that we chose) is given in the starter code (in main(), make sure you look at it and understand how it stores information). Note that: - The delimiter that separates columns of the table is called "DELIMITER. - All data separated by the delimiters are relevant, including leading and trailing whitespace. (e.g." Paco Estrada,"Fish!" indicates the name is 'Paco Estrada' with the extra spaces up to the DELIMITER, and he likes Fish!' including all punctuation or spaces as well) - Every row will have exactly one delimiter. - The order of the rows is irrelevant; we will accept any order for the result table. - Assume sufficient memory has been allocated for each of the tables. - The output order of the columns must be "Name, Nationality, Favourite Food". - Notice that the tables themselves do not contain the column names! Submission - Do not modify anything other than the function you're supposed to implement - Remove any printf() statements you added while testing/debugging your solution - The 'innerJoin function should print nothing! - Do not post any partial solutions or descriptions of your solution algorithm to the Piazza forum. If you have questions, please bring these to office hours! Like every other exercise - please submit only your..cfile with the name: inner_join_studentNo. (mind the underscore before studentNo, many people have forgotten to add that one) Testing: We will test your code on different tables than the ones you were given, and it must work correctly - so be sure to test thoroughly, and change the contents of the example tables to run any tests that will convince you your code does the right thing. Our solution produces the following output for the example tables: ./a.out Paco Estrada, Mexico, Chocolate Joe Armitage, England, Chocolate Angela Zavaleta, Peru, Green Eggs Brian Harrington, Canada, Avocado Salad You could actually save that output as a file with extension .csv, and it would load into Excel (or Open Office Calc) as a table ! The starter code is: #include #include #include #include #include #include #include // You can use the string library! // The values for the constants below could change, so make sure your Il program is using them where appropriate! #define MAX_STRING_LENGTH 128 #define MAX_ROW_COUNT 100 #define DELIMITER * Joins two tables (produces a larger table with combined information from both). t the input tables each have fields (chunks of test) separated by "DELIMITER * The first field in each table is a person's name see the example tables in main() * and the second field records appropriate information for the corresponding individual. * This function will create a combined (joined) table such that the first field is the * person's name, the second is the nationality (from the nationality table), and the * third is their favorite food (from the food table) * This requires you to match the person's name in the two tables, and to do a bit of string manipulation to build the combined row containing name, nationality, food, * and then putting that joined result into the joined table. * Your joined table must not contain any rows from either table for which there is no * corresponding row in the other table (eg. in the sample input from main(). * 'Nyah Way' appears only on the nationality table, and not in the food table, so there * will NOT be any rows in the joined table for this individual. * Person's names in the first field must be *unique* within each table (e.g. 'Paco Estrada' * can only appear once in the nationality table, and only once in the food table) * But 'Paco Estrada' is not the same name as 'paco estradA' (these are considered * different people) * INPUT * nationalities_table: * . an array of strings, each string has 2 DELIMITER-separated columns *- represents Name -> Nationality mappings * foods_table: * - an array of strings, each string has 2 DELIMITER-separated columns *- represents Name -> Favourite Food mappings * OUTPUT * joined_table: * - an array of strings, each with 3 DELIMITER-separated columns * -represents the combined information for a person: name, nationality, food * - The ORDER of the rows in this output table does not matter, so don't worry * about it, as long as the rows are all there that should be there. void innerJoin(char nationalities_table(MAX_ROW_COUNTIMAX_STRING_LENGTH). char foods_table[MAX_ROW_COUNT][MAX_STRING LENGTH). char joined_table[MAX_ROW_COUNT][MAX_STRING_LENGTH * 2]) // TODO: implement this function, satisfying the description above // Feel free to add rows to either table to test your solution, but mind the fact // that the names of individuals must be unique! Il Later on in your studies (or perhaps during your Coop term, or maybe you have II already used this) you'll see that what we're asking you to do is equivalent Il to what SQL does with database tables when we ask for // SELECT Nationalities.name, Nationalities.country, Foods.favourite // FROM Nationalities // SELECT Nationalities.name, Nationalities.country, Foods favourite // FROM Nationalities // INNER JOIN Foods II ON Nationalities.name=Foods.name: // NOTE: Please use the DELIMITER constant! // Ideally, this function should work even if all the constants above were changed Il We NEED this compiler directive to test your code with our own main(). Don't break it. #ifndef _TESTING // this compiler directive int main() Il Please note that these are JUST EXAMPLES! // You will be tested on a wide range of data // IMPORTANT: The join function above doesn't know how many rows are in Il each table, so, we add an empty string as the last row Il of the tables below. You can assume any input tables we Il use to test your program will contain an empty string Il at the last row so you can tell you've reached the end Il of the table // As before you are expected to make reasonable assumptions Il regarding any information not given in these instructions. char example_nationalities_table[MAX_ROW_COUNT][MAX_STRING_LENGTH] = { "Paco Estrada, Mexico", "Joe Armitage, England", "Angela ZavaletaPeru", "Nyah Way, Canada", "Anya Tafliovich, Ukraine", "Brian Harrington, Canada", ", Il -- Empty string signals end of table char example_foods_table[MAX_ROW_COUNT][MAX_STRING_LENGTH] = { "Brian Harrington Avocado Salad", "Paco Estrada, Chocolate "Joe Armitage Chocolate", "Angela Zavaleta Green Eggs", "Jack Long, Ham", **, 11

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

46. GivenMX(t).2.3et.5e3t, ndp(x), E(X), V(X).

Answered: 1 week ago