Welcome! Log In Create A New Profile

Advanced

Assignment 2 Question 4

Posted by Michelle1@3 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 2 Question 4
March 30, 2011 03:33PM
Hi there,

Anybody that is busy with or done with assignment 2, Question 4...
I am a bit confused about question 4b where you must calculate the actual amount spent per child. Can this be done with a nested if statement or is there an better way of doing this.
How do you actually get the actualAmountSpent?

Here is part of my code:
#include <iostream>
using namespace std;

const float maxPerUnit = 20000.00;
//minPerChild includes a standard gift consisting of a bath towel and a facecloth
const float minPerChild = 100.00;
const float maxPerChild = 180.00;
//depending on the amount, the child may also get one or more of the following:
const float TOOTHBRUSH = 29.95;
const float HIGHLIGHTERS = 25.95;
const float CRAYONS = 17.95;
const float NOTEBOOK = 12.95;
const float PEN = 9.99;

float calcAllowedPerChild(int nrChildrenP)
{
return((maxPerUnit / nrChildrenP));
}

float calcActualAmount(float amtGiftP, int nrChildrenP)
{
... .... ... ... ... ... ... ... .. .. .... .... ....
}

int main()
{
float amtGift; //Allowed amount per child
float amtSpentPerChild = 0.00; //Actual amount spent per child
float totalSpent = 0.00; //Total spent for one orphanage
float totalAll = 0.00; //Total spent for all 4 orphanages
int nrChildren; //Number of children per orphanage

cout << "Enter the number of children: " << endl;
cin >> nrChildren;
amtGift = calcAllowedPerChild(nrChildren);
cout.setf(ios::fixed);
cout.precision(2);
cout << endl << "Allowable amount per child : R" << amtGift;
cout << endl << endl;
amtSpentPerChild = calcActualAmount(amtGift, nrChildren);
cout << endl << "Actual amount spent per child : R";
cout << amtSpentPerChild << endl << endl;

return 0;
avatar Re: Assignment 2 Question 4
March 31, 2011 01:38PM
That will depend on the rules for deciding what a child gets from the extras and how you decide which ones to allocate given your funding available.

If your rule is that, given the amount of money extra per child, allocate the most expensive item and see how much is left over, allocate the next most expensive item and so on until the extra funds are exhausted. If that is the case, you'll use sequencial if statements

Language: C++
float outstanding = ...; if (outstanding >= TOOTHBRUSH){ // allocate toothbrush funds outstanding -= TOOTHBRUSH; } if (outstanding >= HIGHLIGHTERS){ // allocate highlighters outstanding -= HIGHLIGHTERS; } /// and so on ...

I hope this helps.
Sorry, only registered users may post in this forum.

Click here to login