1. Homepage
  2. Programming
  3. FEEG6002 Advanced Computational Methods I: Develop a database

FEEG6002 Advanced Computational Methods I: Develop a database

Engage in a Conversation
UKUniversity of SouthamptonFEEG6002Advanced Computational Methods IStack Overflow Developer SurveyC++

FEEG6002 Advanced Computational Methods I

Question 3:

This question will develop a database to hold data collected from The Public 2022 Stack Overflow Developer Survey (https://survey.stackoverflow.co/2022). The results can be downloaded from this website in the so-called comma separated value (csv) file. Amended copy of this file survey_results_public_short.csv is added to support this question. Opening this file in a text editor allows to quickly explore its content: CourseNana.COM

ResponseId,MainBranch,Country,LanguageHaveWorkedWith,OpSysProfessional use
1,None of these,NA,NA,NA
2,I am a developer by profession,Canada,JavaScript;TypeScript,macOS
4,I am a developer by profession,Israel,C#;JavaScript;SQL;TypeScript,Windows
5,I am a developer by profession,United States of
America,C#;HTML/CSS;JavaScript;SQL;Swift;TypeScript,Windows
7,I code primarily as a hobby,India,C++;HTML/CSS;JavaScript;PHP;Python;TypeScript,macOS
8,I am a developer by profession,India,C;C++;HTML/CSS;Java;JavaScript;SQL,Linux-based;macOS
...

It contains many lines and five columns separated by commas “,”. Thus, “,” is the column separator in this case. The first column is the response ID of the survey respondent, followed by a brief description of the profession, country of origin, programming language skills, and the used operating system in the last column. The task in this question is to process this file and extract some information from it. 1) You are asked to download the file survey_results_public_short.csv from the assessment page on blackboard. Explore this file using your favourite text editor such as Notepad on Windows or TextEdit on Mac, for example. Note that the csv files also open natively in spreadsheet applications such as Microsoft Excel. However, make sure you don’t modify this file in any way to answer the questions below correctly. 2) Implement the structure data: CourseNana.COM

typedef struct {
char country[MAXLEN];
char language[MAXLEN];
char opsys[MAXLEN];
} data;

where the member country[] is to hold a string extracted from a particular line in the file and only from the column “Country” (e.g. Canada, see the 3rd line in the file example above), the member language[] is to hold a string only from the column “LanguageHaveWorkedWith” (e.g. JavaScript;TypeScript), and the member opsys[] is to hold a string only from the column “OpSysProfessional use” (e.g. macOS). CourseNana.COM

3) Implement a function num_lines(…) which takes a filename as input, opens and processes that file, and counts the number of lines available in the file. It returns an integer corresponding to the total count of the lines in the file. This functions will be used to count the number of lines in the file survey_results_public_short.csv. 4) Implement a function string_in(…) which takes as input two strings s1 and s2 and returns an integer. It returns integer 1 if s2 is a substring of s1, and 0 otherwise. 5) Implement a function build_database(…) which takes as input the filename survey_results_public_short.csv, then a pointer to an array dbs of structures of type data, and also an integer corresponding to the size of the array dbs. The function should return type void. The computed output will be returned through the pointer dbs. The size of the array dbs will be determined in main(…) as corresponding to the number of lines in the csv file. The function build_database(…) should process the content of the csv file and populate the members of each structure in the array dbs by the information from the corresponding line in the file, as explained in part 2) above. For example, the third line in the file should map onto the third element of the array dbs as: dbs[2].country = "Canada" dbs[2].language = "JavaScript;TypeScript" dbs[2].opsys = "macOS" CourseNana.COM

with the column separator commas “,” excluded (i.e. "Canada" not "Canada,"). 6) Implement a function find_percent(…) which takes as input an array perc having 3 elements of type double, a pointer to array dbs of structures of type data populated in part 5), and an integer corresponding to the size of the array dbs. The function return type void, and the computed output is returned through the 3-element vector perc. The first element should store the percentage of users using C programming language (not C++ nor C#). The second element should store the percentage of users using C that are in the United Kingdom. The last third element of perc should store the percentage of users using C and Windows. 7) An example of an implementation of function main(…) can be given as: int main() { char filename[] = "survey_results_public_short.csv"; double percent[3]; data *database; … … number_lines = num_lines(filename); printf("\nNum lines: %d\n", number_lines); … … build_database(filename, database, number_lines); printf("\nPrint the first entry in the database:\n"); printf("%s | %s | %s\n", database[0].country, database[0].language, database[0].opsys); printf("\nPrint the last entry in the database:\n"); printf("%s | %s | %s\n", database[number_lines].country, database[number_lines].language, database[number_lines].opsys); find_percent(percent, database, number_lines); printf("\nPercent using C: %.2f%%\n", percent[0]); printf("Percent using C and in the UK: %.2f%%\n", percent[1]); printf("Percent using C and Windows: %.2f%%\n", percent[2]); printf("\n"); … … return 0; } CourseNana.COM

8) If the missing parts are populated correctly compiling and running the program produces the following output: Num lines: 548 Print the first entry in the database: Country | LanguageHaveWorkedWith | OpSysProfessional use Print the last entry in the database: Australia | Bash/Shell;C;HTML/CSS;JavaScript;PHP;SQL | macOS Percent using C: 20.62% Percent using C and in the UK: 2.55% Percent using C and Windows: 10.40% CourseNana.COM

Question 4:

This question develops a set of routines suitable for root finding. For example, equation: ? 2  = 1 has two roots, x = -1 and x = 1. Denoting ?(? )  =  ? 2  − 1, the root finding problem can be defined as finding the solution of a generic equation f(x) = 0. We study two methods for solving f(x) = 0: Bisection and Newton methods. The bisection method finds the root by iteratively “bracketing” the root from left and right. The initial guess for the bracketing interval [a, b] containing the root is provided as input. The Newton method finds the root based on the initial guess x0 provided as input and uses the slope of the curve f(x) to converge “downhill” towards the root. 1) Write a function bisect(…) that takes as input the function f(x), then two variables a and b of type double, and an integer maxint specifying the maximum allowed number of iterations. The function bisect returns the root as type double. The pseudocode describing the algorithm is: Function: bisect(f, a, b) Assumptions: Given: a (double) Given: b (double) Given: f(x), continuous with single root in the interval [a,b], i.e. f(a)f(b) < 0 Given: ftol (float), for example ftol=1e-6 Algorithm: The bisection method returns root x so that |f(x)| < ftol 1: x = (a+b) / 2 2: while |f(x)| > ftol, do if f(x)f(a) > 0 then a = x (i.e. throw away left half) else b = x (throw away right half) x = (a + b) / 2 3: return x CourseNana.COM

Note that ftol can be provided to the function as a symbolic variable at the beginning of the code. If the number of iterations required for the algorithm to converge towards the solution exceeds maxint, return nan (nan can be programmed as 0.0/0.0). CourseNana.COM

2) Implement a function newton(…) that takes as input the function f(x), the initial value x0 of type double, and an integer maxint defining the maximum allowed number of iterations. The function newton returns the root as type double. Function: newton(f, x0) Given: x0 (float) Given: f(x), continuous with root in the proximity of x0 Given: ftol (float), for example ftol=1e-6 Algorithm: while |f(x)| > ftol, do x = x - f(x)/f'(x) where f'(x) is the derivative df/dx. CourseNana.COM

The tolerance ftol can be provided as a symbolic variable at the beginning of the code. For calculating the numerical derivative, use the forward finite difference approximation: ?? (? ) ?(? + Δ? ) − ? (? ) ≈ ?? Δ? with ∆x = 1e-4. If the number of iterations required for the algorithm to converge towards the solution exceeds maxint, return nan (nan can be programmed as 0.0/0.0). 3) Implement the function parab(...) having one input of the type of double and returning the type double satisfying the following mathematical formula: ? (? )  =  ? 2 − 1 4) Implement the function cosxx(...) having one input of type double and returning the type of double satisfying the following mathematical formula: ? (? )  =   cos ?   − ? 5) An example of function main(…) could look like this: CourseNana.COM

Question 5:

Consider a damped harmonic oscillator system with dynamics described by the ordinary differential equation (ODE): CourseNana.COM

where x is the position, t is time, and M, C, G is the mass, damping constant and gravitational constant respectively. The function ?? (? ) is the spring force and we will consider two cases: a linear case with ?? (? ) = −??, and a nonlinear case with ?? (? ) = −?? 3 , where k is the spring constant. Defining the velocity variable as ?̇ = ? (where the dot represents the time derivative), the above equations can be written as: Linear ODE Case: CourseNana.COM

The task is to solve these equations and compare their solutions. The initial conditions to obtain the solutions are ? (0) = 1 and ?(0) = 0. 1) Implement function osclin(…) which returns type void and takes as input two two-element arrays of type double. The first array holds the values of variables x and v, and the second array holds the values of the right hand-side functions of the above set of Linear ODEs evaluated at those values of x and v. Thus, the first array serves as input and the second array serves as output of the function osclin. The parameters c, m, k, and g can be defined as symbolic constants (see the main program below). 2) Implement function oscnonl(…) which returns type void and takes as input two two-element arrays of type double. The first array holds the values of variables x and v, and the second array holds the values of the right hand-side functions of the above set of Nonlinear ODEs evaluated at those values of x and v. Thus, again, the first array serves as input and the second array serves as output of the function oscnonl. The parameters c, m, k, and g can be defined as symbolic constants (see the main program below). 3) Write function euler(…) which implements the Euler method to solve the oscillator equations defined above. The prototype of the function euler is given as: CourseNana.COM

void euler(double *p, double (f)(double, double), int n) CourseNana.COM

The double-pointer **p holds an array of size 2 x n to store the x, v solutions over n time instants, starting from the initial time Ti to the final time Tf and assuming the time step dT. The value of the integer n is passed to the function euler as the last argument. The second argument is expected to accept either the function osclin or function oscnonl implemented in parts 1) and 2) above. Note that the function euler does not require passing the time array as input. This is because the oscillator equations do not contain explicit time dependence. The initial conditions and the time parameters can be defined as symbolic constants at the beginning of the code (see the main program below). CourseNana.COM

4) Implement function diff(…) which returns void and takes as input a doublepointer **p and the integer n as in part 3) above. In addition, it takes as inputs both functions osclin and oscnonl. The function should use the Euler method developed in part 3) to compute the solutions x_osclin, v_osclin and x_oscnonl, v_oscnonl corresponding to functions osclin and oscnonl, respectively. It should then calculate the absolute differences xdiff = |x_osclin – x_oscnonl| and vdiff = |v_osclin - v_oscnonl| for every value in these arrays, and return xdiff and vdiff as individual columns of the input two-dimensional array p. 5) In main(…) run the function diff(…) with appropriate inputs, and export the data for time t and the absolute error differences to the output file data.txt. An example of incomplete function main(…) could look like this: CourseNana.COM

define Ti 0.0

define Tf 5.0

define dT 0.1

// initial time // final time // time step CourseNana.COM

define X0 1.0

define V0 0.0

// define time CourseNana.COM

// solve the ODE system diff(y, osclin, oscnonl, N); CourseNana.COM

6) When the missing parts have been populated correctly, the generated output file data.txt will contain data in three columns as: 0.000000 0.100000 CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UK代写,University of Southampton代写,FEEG6002代写,Advanced Computational Methods I代写,Stack Overflow Developer Survey代写,C++代写,UK代编,University of Southampton代编,FEEG6002代编,Advanced Computational Methods I代编,Stack Overflow Developer Survey代编,C++代编,UK代考,University of Southampton代考,FEEG6002代考,Advanced Computational Methods I代考,Stack Overflow Developer Survey代考,C++代考,UKhelp,University of Southamptonhelp,FEEG6002help,Advanced Computational Methods Ihelp,Stack Overflow Developer Surveyhelp,C++help,UK作业代写,University of Southampton作业代写,FEEG6002作业代写,Advanced Computational Methods I作业代写,Stack Overflow Developer Survey作业代写,C++作业代写,UK编程代写,University of Southampton编程代写,FEEG6002编程代写,Advanced Computational Methods I编程代写,Stack Overflow Developer Survey编程代写,C++编程代写,UKprogramming help,University of Southamptonprogramming help,FEEG6002programming help,Advanced Computational Methods Iprogramming help,Stack Overflow Developer Surveyprogramming help,C++programming help,UKassignment help,University of Southamptonassignment help,FEEG6002assignment help,Advanced Computational Methods Iassignment help,Stack Overflow Developer Surveyassignment help,C++assignment help,UKsolution,University of Southamptonsolution,FEEG6002solution,Advanced Computational Methods Isolution,Stack Overflow Developer Surveysolution,C++solution,