(Solved) : Far Course Ve Learned Pointers Arrays Loops Exercise Need Help Pictures Starter Code Incl Q44173453 . . .
So far in this course we’ve learned pointers, arrays, andloops. The exercise I need help on is in the pictures below. Thestarter code is included below the pictures. Thanks!


The starter code is:
#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h> // You can use the stringlibrary!
// The values for the constants below could change, so makesure your// 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 combinedinformation from both).* Note that the input tables each have fields (chunks of test)separated by ‘DELIMITER’.* The first field in each table is a person’s name (see theexample tables in main())* and the second field records appropriate information for thecorresponding individual.** This function will create a combined (joined) table suchthat the first field is the* person’s name, the second is the nationality (from thenationality table), and the* third is their favorite food (from the food table).** This requires you to *match* the person’s name in the twotables, and to do a bit* of string manipulation to build the combined row containingname, nationality, food,* and then putting that joined result into the joinedtable.** Your joined table must not contain any rows from eithertable for which there is no* corresponding row in the other table (e.g. in the sampleinput from main(),* ‘Nyah Way’ appears only on the nationality table, and not inthe food table, so there* will NOT be any rows in the joined table for thisindividual.** Person’s names in the first field must be *unique* withineach table (e.g. ‘Paco Estrada’* can only appear once in the nationality table, and only oncein 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-separatedcolumns* – represents Name -> Nationality mappings* foods_table:* – an array of strings, each string has 2 DELIMITER-separatedcolumns* – represents Name -> Favourite Food mappings** OUTPUT:* joined_table:* – an array of strings, each with 3 DELIMITER-separatedcolumns* – represents the combined information for a person: name,nationality, food* – The ORDER of the rows in this output table does notmatter, so don’t worry* about it, as long as the rows are all there that should bethere.*/void innerJoin(charnationalities_table[MAX_ROW_COUNT][MAX_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 descriptionabove.// Feel free to add rows to either table to test yoursolution, but mind the fact// that the names of individuals must be unique!
// Later on in your studies (or perhaps during your CoOp term,or maybe you have// already used this) you’ll see that what we’re asking you todo is equivalent// to what SQL does with database tables when we ask for//// SELECT Nationalities.name, Nationalities.country,Foods.favourite// FROM Nationalities// INNER JOIN Foods// ON Nationalities.name=Foods.name;//
// NOTE: Please use the DELIMITER constant!// Ideally, this function should work even if all theconstants above were changed
}
// We NEED this compiler directive to test your code with ourown main(). Don’t break it.#ifndef __TESTING // this compiler directiveint main(){// 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 manyrows are in// each table, so, we add an *empty string* as the lastrow// of the tables below. You can assume any input tableswe// use to test your program will contain an empty string// at the last row so you can tell you’ve reached theend// of the table.//// As before – you are expected to make reasonableassumptions// regarding any information not given in theseinstructions.//
charexample_nationalities_table[MAX_ROW_COUNT][MAX_STRING_LENGTH] ={“Paco Estrada,Mexico”,”Joe Armitage,England”,”Angela Zavaleta,Peru”,”Nyah Way,Canada”,”Anya Tafliovich,Ukraine”,”Brian Harrington,Canada”,””, // <– 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”,””, // <– Empty string signals end of table};
// Notes on indexing an array of strings:// example_nationalities_table[i] <- gives you a pointer tothe string at row i of this table// example_nationalities_table[i][j] <- Is the actualcharacter at row i, position j in the table
// Note that the size of this output array could have theMAX_ROW_COUNT, but// the length of each row may be up to2*MAX_STRING_LENGTH.// We set the first row of this output table to “” (emptystring),// so we know the table doesn’t contain any *valid* rows.Remember though,// this is a large array of chars we haven’t actuallycleaned-up, so it// will contain JUNK – be sure your join function is fillingup each row with// proper strings, that all have their end-of-stringdelimiter.char joined[MAX_ROW_COUNT][MAX_STRING_LENGTH * 2] = {“”};
// calling your function…// This should create the example joined table from thehandout (and put it in `joined`).innerJoin(example_nationalities_table, example_foods_table,joined);
// Printing the table:// (leaving THIS print statement is fine, but leave NONE inthe `innerJoin` function!)for (int idx = 0; 0 != strcmp(“”, joined[idx]); idx++){printf(“%sn”, joined[idx]);}}#endif // and this compiler directiveThis week we will be practising working with strings using the <string.h> 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 | Favourite Food Mexico Fish England Peru Green Eggs 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: inner Join() (see the comments at the top of that function) The Implementation Details An example of the 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.c file with the name: inner_join_studentNo.c (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 ! Show transcribed image text 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 | Favourite Food Mexico Fish England Peru Green Eggs 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: inner Join() (see the comments at the top of that function) The Implementation Details An example of the 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.c file with the name: inner_join_studentNo.c (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 !
Expert Answer
Answer to So far in this course we’ve learned pointers, arrays, and loops. The exercise I need help on is in the pictures below. T…
OR