Comp1000 - unix and c programming assignment questions -


UNIX AND C PROGRAMMING ASSIGNMENT QUESTIONS -

ATTEMPT ALL QUESTIONS.

Question 1 -

Write a C function (not a whole program) called calcPrices that will calculate final prices in a fishing/camping store.

Your colleagues have written several functions for applying discounts to a single product. They'd like your function to be able to call any one of their functions for each product. Your function must also ensure that the price remains positive. It should disregard any discounts that would make the price zero or negative.

Your function must return nothing, and accept the following parameters:

  • nCategories - The number of categories of products.
  • averageDiscount - The average discount applied to all products across all categories (as a pointer, for export purposes).
  • discountCalc - A pointer to one of your colleagues' discounting functions.

All of their functions takes a pointer to a float, representing a price. The function updates (reduces) the value stored at that location, or leaves it alone. The function returns nothing.

Each product category contains a number of different types of products. Categories are identified by an integer index, between zero and nCategories minus one. Within each category, products are also identified by an integer index, starting at zero. Your function must step through each product in each category, setting the new price. Your function should also calculate the average discount.

You will need to use three more functions which are provided for you. ie you do not need to write these:

  • To retrieve the number of different types of products in a category: int getNProducts(int category);
  • To retrieve the original product price: float getPrice(int category, int product);
  • To set the new price: void setPrice(int category, int product, float newPrice);

Question 2 -

NASA is designing a new space probe to search for life on other planets. The probe will be sent to a given planet. It will orbit the planet, map the surface and take sensor readings. The probe will look for promising locations on the surface for further exploration.

Your job is to design the software to analyse the probe's measurements. The probe will divide the planetary surface into a rectangular grid (excluding the polar regions).

The non-negative grid coordinates x and y will identify each grid square. The probe will take one set of readings in each grid square. Speci?cally, it will record:

  • temperature (oC),
  • wind speed (km/h),
  • oxygen concentration (%), and
  • volcanic activity (yes/no).

For each set of readings (i.e. for each grid square), your software must compute a "life rating". For the planet/grid as a whole, it must also compute an "exploration risk" (an indicator of the danger faced by further, surface exploration).

If there is no volcanic activity in a given grid square, the life rating is as follows:

life rating = (temperature x oxygen concentration)/wind speed

With volcanic activity, life rating is calculated the same way, but then divided by 3.5. For each grid square containing volcanic activity, exploration risk goes up by 1.

Write a C function (not a whole program) to do the following:

1. Retrieve the sensor readings from the probe, using the getReadings() function.

2. Calculate the life rating and exploration risk, as described above.

3. Report each life rating by calling another function (through a given function pointer).

4. Report the exploration risk (via an int* parameter).

The getReadings() function is declared as follows: void getReadings(int x, int y, double* temp, double* windSpeed, double* oxygen, int* volcanism);

Your function should return void and take four parameters:

  • width - an int, the width of the grid (0 ≤ x < width).
  • height - an int, the height of the grid (0 ≤ y < height).
  • explorationRisk - a pointer to an int.
  • reportFunc - a pointer to a function used to report the life rating. The function takes two ints (grid coordinates) and a double (the life rating), and returns void.

Question 3 -

A private investigator has asked you to help develop software to analyse fingerprint data. The software will have access to the left and right index fingerprints for a group of people, and also a collection of unidentified prints. The investigator wishes to know how many of the as-yet unidentified prints "possibly" or "definitely" belong to known individuals.

Each person is identified by an integer ID, ranging from zero to the number of people minus one. Each unidentified print is also identified by an integer ID, in the same fashion.

The left and right fingerprint data for each person is stored in a highly-reduced / compressed form - a "template". Each template takes only 64 bits to store.

Write a C function (not a whole program) called countMatches to do the following:

1. Retrieve each person's template fingerprints using the getTemplates function, which is declared as follows: void getTemplates(int person, double* left, double* right);

If getTemplates() places -1 in both *left and *right, no template fingerprint exists for that person. Such people cannot be tested, of course. For efficiency purposes, your function should skip over them.

2. If template fingerprints have been recorded for a given person, test them against each unidentified fingerprint. Your function will be supplied with a callback (function pointer) parameter for this purpose.

3. Report the total number of "possible" and "definite" fingerprint matches, via two int* (pass-by-reference) parameters.

Your function should return void, and take five (5) parameters:

  • nPeople - an int, the number of people in the database;
  • nPrints - an int, the number of unidentified fingerprints;
  • nPossible - a pointer to an int, the number of "possible" fingerprint matches;
  • nDefinite - a pointer to an int, the number of "definite" fingerprint matches; and
  • check - a pointer to a function used to check fingerprint templates against unidentified prints.

The callback function takes an int - the ID of the unidentified print - and two doubles-the left and right templates. It returns one of three int values: 0, indicating no match; 1, indicating a possible match; or 2, indicating a definite match.

Do not attempt to write the getTemplates() function or the callback function yourself. (These have already been implemented.)

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Comp1000 - unix and c programming assignment questions -
Reference No:- TGS02714564

Expected delivery within 24 Hours