Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help on C programming please: bold texts are my assignment below that i wrote some codes on main.c, sporkpr0file.c and sporkprofile.h but in

I need help on C programming please: bold texts are my assignment below that i wrote some codes on main.c, sporkpr0file.c and sporkprofile.h but in some lines, i am cinfused. thank for your help.

Usage

Spork program finds nearby and good restaurants/businesses.

Usage:

spork inputSporkFile resultsFile userLocX userLocY maxDistMiles minAvgRating

Requirements Summary

Spork program will help user find nearby good restaurants and business, similar to apps such as Yelp or Urbanspoon. The

Spork program will read business profiles from an input Spork file, calculate the distance between the user's location and

each business, determine if each business is nearby based on a user's specified maximum distance, determine if each

business is good based on the user's specified minimum rating, find the nearby and good business with the highest advertising

level to output that business first, and store the results in an output file.

Assignment Name

The assignment name for this assignment is:

spork

1.

Input Spork File

The input Spork file format will provide a list of businesses, in which one business profile will be specified per line, using the

following format:

BusinessName X.XX Y.YY R.RR A

With the following definitions for abbreviations in the format:

BusinessName

: Name of the restaurant/business. The business name will not include any whitespace characters

X.XX

: Business' X location in miles using a Cartesian coordinate system

Y.YY

: Business' Y location in miles using a Cartesian coordinate system

R.RR

: Business' average rating for the business

A

: Business' advertising level, which must be 0, 1, or 2

Each entry will be separated by one or more whitespace characters.

The program should read up to

MAX_SPORK_PROFILES

entries, which is defined to be 500.

All erroneous entries that do not match the required Spork file format should be silently ignored. You should also ensure your

program will not crash at runtime due to issues such as these, or due to issues such as opening an empty file, or reading in an

invalid file format.

2.

SporkProfile Data Structure

SporkProfile

is a data structure for representing Spork profiles for businesses. The typedef and struct definitions for the

SporkProfile

data type are:

typedef

struct

SporkProfile_struct {

char

businessName[

MAX_BUSINESSNAME_LEN

];

double

locX;

double

locY;

double

distMiles;

double

avgRating;

int

adLevel;

bool

isNearby;

bool

isGood;

} SporkProfile;

businessName

is the name of the restaurant/business.

locX

and

locY

are the x and y coordinates of the business.

avgRating

is the average rating for the business.

adLevel

is a value ranging from 0 to 2 describing the business'

advertising level.

isNearby

is used to indicate if the business is near the user's location.

isGood

indicates if the business

is greater than or equal to the user's minimum desired rating.

For storing Spork profiles in your program, your program must use an array of

SporkProfile

elements, defined within

main as:

SporkProfile sporkProfiles[MAX_SPORK_PROFILES];

MAX_SPORK_PROFILES

is defined to be 500.

3.

Searching for Businesses

The following sections discuss the various searching algorithms you should use to find business matching the user's

requirements.

3.1 Calculating Distance and Searching for Nearby Businesses

Your program should search the

sporkProfiles

array determine the distance of each business from the user's location,

storing the distance in the Spork profile's

distMiles

member variable. The program should also determine if each business

is nearby the user and set the Spork profile

isNearby

member variable to

true

(if the business is nearby) or

false

(if the

business is not nearby). A business is neary if the Euclidean distance between the user's location and the business location is

less than or equal to the user's specified maximum distance.

The Euclidean distance is calculate as:

EuclideanDistance

(

userLoc

,

busLoc

)

=

(

userLocX

busLocX

)

2

+

(

userLocY

busLocY

)

2

This functionality should be implemented in

FindNearbyBusinesses()

function.

3.1 Searching for Good Businesses

Your program should search the

sporkProfiles

array determine if each business is good based on the user's minimum

required average rating. The program will set the Spork profile

isGood

member variable to

true

if the business average

rating is greater than or equal to the user's minimum required average rating, and

false

otherwise.

This functionality should be implemented in

FindGoodBusinesses()

function.

3.1 Searching for Business with Highest Advertising Level

After determining is businesses are nearby and good, your program should find the business that is both nearby, good, and

has the highest advertising level. If more than one good, nearby business has the highest advertising level (i.e., there's is a

tie), the first business found with that advertising level should be found. When outputting the Spork results, the business with

the highest advertising level will be output.

This functionality should be implemented in

GetIndexMaxSponsor()

function. The function will return the index of the

business, if found, and -1 otherwise.

4.

Spork Results File

Your program should store all business that are both nearby and good in the Spork output file. The nearby and good business

with the highest advertising level, if one exists, should be output first. All other nearby and good businesses should be output

in the order they are stored in the

sporkProfiles

array. The Spork output file should be formatted with one valid entry

per line using the following format:

BusinessName R.RR D.DD

Where:

BusinessName

: Name of business.

R.RR

: Business' average rating with exactly two decimal digits of precision.

D.DD

: Business' distance in miles from user with exactly two decimal digits of precision.

Each entry should be separated by

a single tab character (\t)

, and each line should end with

a single newline ( )

.

5.

Alpha Submission

A top level design is provided for this assignment that includes sources files, partially complete main function, and function

stubs for all required functions. For the alpha submission, your assignment should complete the

ReadSporkDataFromFile()

and

WriteSporkResultsToFile()

functions.

For the alpha submission, the

ReadSporkDataFromFile()

function should initialize

isNearby

and

isGood

to

true

and initialize

distMiles

to 0.0 for all profile entries.

Note

: This requirement is different for the final submission.

Deliverables

(main.c,

sporkprofile.c, and sporkprofile.h)

Usage

Spork program finds nearby and good restaurants/businesses.

Usage:

spork inputSporkFile resultsFile userLocX userLocY maxDistMiles minAvgRating

Requirements Summary

Spork program will help user find nearby good restaurants and business, similar to apps such as Yelp or Urbanspoon. The

Spork program will read business profiles from an input Spork file, calculate the distance between the user's location and

each business, determine if each business is nearby based on a user's specified maximum distance, determine if each

business is good based on the user's specified minimum rating, find the nearby and good business with the highest advertising

level to output that business first, and store the results in an output file.

Assignment Name

The assignment name for this assignment is:

spork

1.

Input Spork File

The input Spork file format will provide a list of businesses, in which one business profile will be specified per line, using the

following format:

BusinessName X.XX Y.YY R.RR A

With the following definitions for abbreviations in the format:

BusinessName

: Name of the restaurant/business. The business name will not include any whitespace characters

X.XX

: Business' X location in miles using a Cartesian coordinate system

Y.YY

: Business' Y location in miles using a Cartesian coordinate system

R.RR

: Business' average rating for the business

A

: Business' advertising level, which must be 0, 1, or 2

Each entry will be separated by one or more whitespace characters.

The program should read up to

MAX_SPORK_PROFILES

entries, which is defined to be 500.

All erroneous entries that do not match the required Spork file format should be silently ignored. You should also ensure your

program will not crash at runtime due to issues such as these, or due to issues such as opening an empty file, or reading in an

invalid file format.

2.

SporkProfile Data Structure

SporkProfile

is a data structure for representing Spork profiles for businesses. The typedef and struct definitions for the

SporkProfile

data type are:

typedef

struct

SporkProfile_struct {

char

businessName[

MAX_BUSINESSNAME_LEN

];

double

locX;

double

locY;

double

distMiles;

double

avgRating;

int

adLevel;

bool

isNearby;

bool

isGood;

} SporkProfile;

businessName

is the name of the restaurant/business.

locX

and

locY

are the x and y coordinates of the business.

avgRating

is the average rating for the business.

adLevel

is a value ranging from 0 to 2 describing the business'

advertising level.

isNearby

is used to indicate if the business is near the user's location.

isGood

indicates if the business

is greater than or equal to the user's minimum desired rating.

For storing Spork profiles in your program, your program must use an array of

SporkProfile

elements, defined within

main as:

SporkProfile sporkProfiles[MAX_SPORK_PROFILES];

MAX_SPORK_PROFILES

is defined to be 500.

3.

Searching for Businesses

The following sections discuss the various searching algorithms you should use to find business matching the user's

requirements.

3.1 Calculating Distance and Searching for Nearby Businesses

Your program should search the

sporkProfiles

array determine the distance of each business from the user's location,

storing the distance in the Spork profile's

distMiles

member variable. The program should also determine if each business

is nearby the user and set the Spork profile

isNearby

member variable to

true

(if the business is nearby) or

false

(if the

business is not nearby). A business is neary if the Euclidean distance between the user's location and the business location is

less than or equal to the user's specified maximum distance.

The Euclidean distance is calculate as:

EuclideanDistance

(

userLoc

,

busLoc

)

=

(

userLocX

busLocX

)

2

+

(

userLocY

busLocY

)

2

This functionality should be implemented in

FindNearbyBusinesses()

function.

3.1 Searching for Good Businesses

Your program should search the

sporkProfiles

array determine if each business is good based on the user's minimum

required average rating. The program will set the Spork profile

isGood

member variable to

true

if the business average

rating is greater than or equal to the user's minimum required average rating, and

false

otherwise.

This functionality should be implemented in

FindGoodBusinesses()

function.

3.1 Searching for Business with Highest Advertising Level

After determining is businesses are nearby and good, your program should find the business that is both nearby, good, and

has the highest advertising level. If more than one good, nearby business has the highest advertising level (i.e., there's is a

tie), the first business found with that advertising level should be found. When outputting the Spork results, the business with

the highest advertising level will be output.

This functionality should be implemented in

GetIndexMaxSponsor()

function. The function will return the index of the

business, if found, and -1 otherwise.

4.

Spork Results File

Your program should store all business that are both nearby and good in the Spork output file. The nearby and good business

with the highest advertising level, if one exists, should be output first. All other nearby and good businesses should be output

in the order they are stored in the

sporkProfiles

array. The Spork output file should be formatted with one valid entry

per line using the following format:

BusinessName R.RR D.DD

Where:

BusinessName

: Name of business.

R.RR

: Business' average rating with exactly two decimal digits of precision.

D.DD

: Business' distance in miles from user with exactly two decimal digits of precision.

Each entry should be separated by

a single tab character (\t)

, and each line should end with

a single newline ( )

.

5.

Alpha Submission

A top level design is provided for this assignment that includes sources files, partially complete main function, and function

stubs for all required functions. For the alpha submission, your assignment should complete the

ReadSporkDataFromFile()

and

WriteSporkResultsToFile()

functions.

For the alpha submission, the

ReadSporkDataFromFile()

function should initialize

isNearby

and

isGood

to

true

and initialize

distMiles

to 0.0 for all profile entries.

Note

: This requirement is different for the final submission.

Deliverables

(main.c,

sporkprofile.c, and sporkprofile.h)

Main.c file: #include #include #include #include "sporkprofile.h" /**************************************************************************************************/ /* Reads up to maxProfiles Spork profiles from an input file specified by fileName. Functions reads * the input file line-by-line using the format: * * BusinessName X.XX Y.YY R.RR A * * BusinessName is the name of the restauarant/business. The buseiness name will not include any * whitespace characters * * X.XX represents the X location in miles using a Cartesian coodinate system * * Y.YY represents the Y location in miles using a Cartesian coodinate system * * R.RR represents the average rating for the business * * A is the advertising level, which should 0, 1, or 2 * * Alpha submission: ReadSporkDataFromFile() function should initialize isNearby and isGood * to true and initialize distMiles to 0.0 for all profile entries. * Note: This requirement is different for the final project submission. * * Project submission: ReadSporkDataFromFile() function should initialize isNearby and isGood * to false for all profile entries. * Note: This requirement is different for the alpha project submission. * * Returns: The number of Spork profiles read from the file. If the input file could not be opened, * the function returns -1. * */ int ReadSporkDataFromFile(SporkProfile sporkProfiles[], int maxProfiles, char *fileName) { return -1; } /**************************************************************************************************/ /* * Determines if each business is nearby the user, sets the Spork profile's isNearby flag to * true (is nearby) or false (not nearby), and stores the distance in miles in the Spork profile. * * userLocX, userLocY: Indicates the x and y coordiante of the user's location * maxDist: Indicates the maxmimum distance between the user and a nearby business * */ void FindNearbyBusinesses(SporkProfile sporkProfiles[], int numProfiles, double userLocX, double userLocY, double maxDist) { } /**************************************************************************************************/ /* * Determines if each business is good based on the user's minimum required average rating. * Sets the Spork profile's isGood flag to true if the business' avgRating is greater than or * equal to minRating, and false otherwise. * */ void FindGoodBusinesses(SporkProfile sporkProfiles[], int numProfiles, double minRating) { } /**************************************************************************************************/ /* * Returns the index of the Spork profile that is neary, good, and has the highest adLevel. If * there is a tie, the index of the first entry found with the highest ad level should be returned. * If no businesses are nearby and good, the function will return -1. * */ int GetIndexMaxSponsor(SporkProfile sporkProfiles[], int numProfiles) { return -1; } /**************************************************************************************************/ /* * Writes all good and nearby business to an output file specified by fileName using the format: * * BusinessName R.RR D.DD * * R.RR is the average rating with exactly two decimal digits of precision. * D.DD is the distance in miles with exactly two decimal digits of precision. * * If maxSponsorIndex is not -1, the cooresponding profile entry will be output first. All other * nearby and good profiles will be output in the order they are stored in the sporkProfiles array. * * Each entry should be separated by a single tab character (\t), and each line should end * with a single newline ( ). * * Returns: -1 if the output file could not be opened, and 0 otherwise. * */ int WriteSporkResultsToFile(SporkProfile sporkProfiles[], int numProfiles, int maxSponsorIndex, char *fileName) { return 0; }

sporkprofile.c file: #include #include #include #include "sporkprofile.h" /**************************************************************************************************/ /* Reads up to maxProfiles Spork profiles from an input file specified by fileName. Functions reads * the input file line-by-line using the format: * * BusinessName X.XX Y.YY R.RR A * * BusinessName is the name of the restauarant/business. The buseiness name will not include any * whitespace characters * * X.XX represents the X location in miles using a Cartesian coodinate system * * Y.YY represents the Y location in miles using a Cartesian coodinate system * * R.RR represents the average rating for the business * * A is the advertising level, which should 0, 1, or 2 * * Alpha submission: ReadSporkDataFromFile() function should initialize isNearby and isGood * to true and initialize distMiles to 0.0 for all profile entries. * Note: This requirement is different for the final project submission. * * Project submission: ReadSporkDataFromFile() function should initialize isNearby and isGood * to false for all profile entries. * Note: This requirement is different for the alpha project submission. * * Returns: The number of Spork profiles read from the file. If the input file could not be opened, * the function returns -1. * */ int ReadSporkDataFromFile(SporkProfile sporkProfiles[], int maxProfiles, char *fileName) { return -1; } /**************************************************************************************************/ /* * Determines if each business is nearby the user, sets the Spork profile's isNearby flag to * true (is nearby) or false (not nearby), and stores the distance in miles in the Spork profile. * * userLocX, userLocY: Indicates the x and y coordiante of the user's location * maxDist: Indicates the maxmimum distance between the user and a nearby business * */ void FindNearbyBusinesses(SporkProfile sporkProfiles[], int numProfiles, double userLocX, double userLocY, double maxDist) { } /**************************************************************************************************/ /* * Determines if each business is good based on the user's minimum required average rating. * Sets the Spork profile's isGood flag to true if the business' avgRating is greater than or * equal to minRating, and false otherwise. * */ void FindGoodBusinesses(SporkProfile sporkProfiles[], int numProfiles, double minRating) { } /**************************************************************************************************/ /* * Returns the index of the Spork profile that is neary, good, and has the highest adLevel. If * there is a tie, the index of the first entry found with the highest ad level should be returned. * If no businesses are nearby and good, the function will return -1. * */ int GetIndexMaxSponsor(SporkProfile sporkProfiles[], int numProfiles) { return -1; } /**************************************************************************************************/ /* * Writes all good and nearby business to an output file specified by fileName using the format: * * BusinessName R.RR D.DD * * R.RR is the average rating with exactly two decimal digits of precision. * D.DD is the distance in miles with exactly two decimal digits of precision. * * If maxSponsorIndex is not -1, the cooresponding profile entry will be output first. All other * nearby and good profiles will be output in the order they are stored in the sporkProfiles array. * * Each entry should be separated by a single tab character (\t), and each line should end * with a single newline ( ). * * Returns: -1 if the output file could not be opened, and 0 otherwise. * */ int WriteSporkResultsToFile(SporkProfile sporkProfiles[], int numProfiles, int maxSponsorIndex, char *fileName) { return 0; } /**************************************************************************************************/

sporkprofile.h file: #ifndef SPORKPROFILE_H #define SPORKPROFILE_H /**************************************************************************************************/ #include /**************************************************************************************************/ #define MAX_BUSINESSNAME_LEN 100 /**************************************************************************************************/ /* * Data structure for representing a Spork profile for restauarant/business. businessName is the * name of the restauarant/business. locX and locY are the x and y coordinates of the business. * avgRating is the average rating for the business. adLevel is a value ranging from 0 to 2 * describing the business advertising level. isNearby is used to indicate if the business is near * the user's location. isGood indicates if the business is greater than or equal to * the user's minimum desired rating. * */ typedef struct SporkProfile_struct { char businessName[MAX_BUSINESSNAME_LEN]; double locX; double locY; double distMiles; double avgRating; int adLevel; bool isNearby; bool isGood; } SporkProfile; /**************************************************************************************************/ /* Reads up to maxProfiles Spork profiles from an input file specified by fileName. Functions reads * the input file line-by-line using the format: * * BusinessName X.XX Y.YY R.RR A * * BusinessName is the name of the restaurant/business. The business name will not include any * whitespace characters * * X.XX represents the X location in miles using a Cartesian coodinate system * * Y.YY represents the Y location in miles using a Cartesian coodinate system * * R.RR represents the average rating for the business * * A is the advertising level, which should 0, 1, or 2 * * Alpha submission: ReadSporkDataFromFile() function should initialize isNearby and isGood * to true and initialize distMiles to 0.0 for all profile entries. * Note: This requirement is different for the final project submission. * * Project submission: ReadSporkDataFromFile() function should initialize isNearby and isGood * to false for all profile entries. * Note: This requirement is different for the alpha project submission. * * Returns: The number of Sprok profiles read from the file. If the input file could not be opened, * the function returns -1. * */ int ReadSporkDataFromFile(SporkProfile sporkProfiles[], int maxProfiles, char *fileName); /**************************************************************************************************/ /* * Determines if each business is nearby the user, sets the Spork profile's isNearby flag to * true (is nearby) or false (not nearby), and stores the distance in miles in the Spork profile. * * userLocX, userLocY: Indicates the x and y coordiante of the user's location * maxDist: Indicates the maxmimum distance between the user and a nearby business * */ void FindNearbyBusinesses(SporkProfile sporkProfiles[], int numProfiles, double userLocX, double userLocY, double maxDist); /**************************************************************************************************/ /* * Determines if each business is good based on the user's minimum required average rating. * Sets the Spork profile's isGood flag to true if the business' avgRating is greater than or * equal to minRating, and false otherwise. * */ void FindGoodBusinesses(SporkProfile sporkProfiles[], int numProfiles, double minRating); /**************************************************************************************************/ /* * Returns the index of the Spork profile that is neary, good, and has the highest adLevel. If * there is a tie, the index of the first entry found with the highest ad level should be returned. * If no businesses are nearby and good, the function will return -1. * */ int GetIndexMaxSponsor(SporkProfile sporkProfiles[], int numProfiles); /**************************************************************************************************/ /* * Writes all good and nearby business to an output file specified by fileName using the format: * * BusinessName R.RR D.DD * * R.RR is the average rating with exactly two decimal digits of precision. * D.DD is the distance in miles with exactly two decimal digits of precision. * * If maxSponsorIndex is not -1, the cooresponding profile entry will be output first. All other * nearby and good profiles will be output in the order they are stored in the sporkProfiles array. * * Each entry should be separated by a single tab character (\t), and each line should end * with a single newline ( ). * * Returns: -1 if the output file could not be opened, and 0 otherwise. * */ int WriteSporkResultsToFile(SporkProfile sporkProfiles[], int numProfiles, int maxSponsorIndex, char *fileName); /**************************************************************************************************/ #endif /**************************************************************************************************/

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

Students also viewed these Databases questions

Question

How do psychologists use traits to describe personality?

Answered: 1 week ago

Question

Are my points each supported by at least two subpoints?

Answered: 1 week ago