Write a C function that will calculate final prices

Assignment Help C/C++ Programming
Reference no: EM131919085

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.)

Reference no: EM131919085

Questions Cloud

Positions for professional typists : A law firm has open several positions for professional typists. The number of words per minute (wpm) typed by the group of applicants
Calculate the coordinates of the center-of-gravity : Johnson's Department Store has decided to build a warehouse to serve its store locations. It has three large stores, one each located in the cities of Sparta.
Why is disclosure rule likely to benefit average consumer : Suppose the government is thinking of requiring pharmaceutical companies to print. Why is the new disclosure rule likely to benefit the average consumer?
Calculate the expected value of for a random sample : Data about the price of a round-trip ticket Atlanta-Barcelona, suggests that a plausible model, for X = price, is a population distribution having mean.
Write a C function that will calculate final prices : COMP1000 - UNIX AND C PROGRAMMING ASSIGNMENT QUESTIONS - Write a C function called calcPrices that will calculate final prices in a fishing/camping store
Explain why insurers ask student drivers about the grades : Consider the market for auto insurance. Explain why insurers ask student drivers about their grades.
What will be the total shipping and transit inventory cost : If the shipment could be delivered in only 2 days at a cost of $100, should the manager do it? How much money would be saved or lost?
Estimate the value of the standard error : The mean number of hours worked per week is 39.04, with a standard deviation of 11.51. The sample size is 83. Estimate the value of the standard error.
Who happily describe the characteristics of goods received : Advertising often features testimonials from satisfied customers, who happily describe the characteristics of the goods or services they received.

Reviews

len1919085

3/28/2018 6:58:10 AM

Urgent help with practise exam questions, could you give me worked solutions, in particular for the last question for each exam? Use the following blank pages to answer this question. Ensure your code conforms to the standards emphasised in the lectures and tutorials. Hint: write pseudo code first! Also, space out your answer as much as possible. You can amend your answer to insert extra code, but you must make it neat and legible. There are two blank pages for working out.

len1919085

3/28/2018 6:58:02 AM

This is a CLOSED BOOK test. Put away all books, notes, etc. Turn off and put away all electronic devices, including calculators and watches. (Make sure your phone is switched off.) You must write in blue or black pen – pencil will not be accepted. The real test will follow approximately the same format and will cover the same material. However, the questions will be different (so trying to memorise answers will get you nowhere!) The real test will also be closed book – no books, notes, electronic devices, etc.

Write a Review

C/C++ Programming Questions & Answers

  Write a program that reads numbers

Write a C++ program that reads N positive numbers from the keyboard, calculates and shows the smallest number of all numbers

  How is the execution time different and why is it different

How is the execution time different? Why is it different? How does the result change your expectations of improving performance by dividing work into threads?

  Write the definitions of the member functions

Write the definitions of the member functions of the class complexType as designed and Rewrite the definition of the class complexType

  Variables should be private and the class functions public

All the class variables should be private and the class functions public. The class functions should be implemented in a file Inventory.cpp which should be linked with the inventory.hpp file.

  Prepare a program for a retail-mart company

Prepare a program for a company Retail-Mart.

  Main function to input twenty integers in given range

Write a main function to input 20 integers in range of 1-6, function should count number of times the numbers 2 and 5 occur. function must declare statics variables count2 and count5.

  Write c program that will input two values from the user

write c program that will input two values from the user with a prompt ? that are a value and a base with which you

  Create a bitoutputstream

Implement a class named BitOutputStream, as shown in Figure for writing bits to an output stream. The writeBit(charbit) method stores the bit in a byte variable. When you create a BitOutputStream, the byte is empty

  What is the big-o run-time of the c++ function

What is the big-O run-time of the following C++ function

  Discuss how the given issues are dealt in the given standard

The principal issues in IAS 16 are the recognition of the assets. Discuss how these issues are dealt in this standard.

  Implement the value iteration algorithm for mdp

Implement the value iteration algorithm for MDP which computes the solution to the situation shown below. You may write your code in either C or C++. Your code must be implemented as a self-contained single source code file which does not require..

  Find the pairs in any given matrix

write a c program which will find the pairs in any given matrix, whose sum of pairs are 10.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd