1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hjlf
3 years ago
15

Write a function [change,flag] = makeChangeRecursive(cost,paid) that takes the cost of an item cost (a 1x1 double) and the amoun

t paid by the buyer paid (a 1x1 double), and returns a n x 1 column array of doubles change containing the bills that the seller should give back to the buyer in decreasing order and flag a 1x1 logical true or false saying whether the transaction was "completed". If paid is less than cost, flagis false and you should display a warning in the command window saying "That's not enough to buy that item." and change is assigned as an empty array. If cost and paid are equal the change is assigned as an empty array and flag is true. If paid is greater than cost, flag is true and change is the difference between the two made by combining the denominations: 100, 50, 20, 10, 5, 2, and 1.
Computers and Technology
1 answer:
vaieri [72.5K]3 years ago
5 0

Answer:

The answer to this question can be given as:

function [change,flag]=makeChangeRecursive(cost,paid)          

//define function

change=[];    

flag=false;                  //use flag for true or false.

if((paid-cost)>=100)         //checking condition value greater then equal to 100

[m,f]=makeChangeRecursive(cost,paid-100);

change=[100;m];

flag=true;

return;

elseif((paid-cost)>=50)     //checking condition value greater then equal to 50

[m,f]=makeChangeRecursive(cost,paid-50);       //holding value.

change=[50;m];    

flag=true;

return;

elseif((paid-cost)>=20)    //checking condition value greater then equal to 20

[m,f]=makeChangeRecursive(cost,paid-20);

change=[20;m];

flag=true;

return;

elseif((paid-cost)>=10)      //checking condition value greater then equal to 10

[m,f]=makeChangeRecursive(cost,paid-10);

change=[10;m];

flag=true;

return;

elseif((paid-cost)>=5)         //checking condition value greater then equal to 5

[m,f]=makeChangeRecursive(cost,paid-5);

change=[5;m];    

flag=true;

return;

elseif((paid-cost)>=2)   //checking condition value greater then equal to 2

[m,f]=makeChangeRecursive(cost,paid-2);

change=[2;m];

flag=true;

return;

elseif((paid-cost)>=1)  //checking condition value greater then equal to 1

[m,f]=makeChangeRecursive(cost,paid-1);

change=[1;m];    

flag=true;

return;

elseif((paid-cost)<0)                        //checking condition value less then 0

warning('That''s not enough to but an item.');         //print message

flag=false;

return;

elseif(paid==cost)               //checking condition if value is equal.

flag=1;                                   //falg value.

change=[];

return;    

end                              

end        //end function

Explanation:

In the above program code the function must use the recursion to change the variable.This function run in 4 case i.e. case 1  In this case when we pass the  value [change,flag]=makeChangeRecursive(2,100) in the function so the change value will be 50,20,20,5,2,1,and flag= ,1. In case 2 when we pass the value(3,20) in the function so the change value will be 10,5,2,and flag= ,1. In case 3 when we pass the value(20,20) in the function so the change value will be change= {},flag= 1. In case 4 when we pass the value(59,20) in the function so the change value will be warning message i.e That''s not enough to but an item.

You might be interested in
True or False?
Karo-lina-s [1.5K]

Answer:

The given statement is False

Explanation:

OSI or Open System Interconnection is a reference model around which the networks are built. OSI gives us all the information regarding movement of data from a software through physical means to another software. Generally it is used as a guidance tool. Seven layers combine to build an OSI model/

TCP/IP (Transmission control protocol/ Internet protocol) model is in a way implementation of the OSI model. It tells about the end-to-end transmission of data being transmitted using OSI model.

<h3>I hope it will help you! </h3>
5 0
3 years ago
History timeline: who developed what elements first Windows OS and Apple OS?
Harrizon [31]

Answer:

i think bill gates

Explanation:

5 0
3 years ago
Read 2 more answers
How does polymorphism enable you to program "in the general" rather than "in the specific"? Discuss the key advantages of progra
barxatty [35]

Answer:

Explanation:

When programming in an OOP language classes are created to represent real-life objects, people, places etc. from the real world. Programming in the general allows you to cut down your code and making it more efficient by applying the same necessary functions to all of the objects that classify under the same category. For example by programming "in the general" and creating an Animal class you can create all of the functions/behaviors that animals tend to have. Then you can apply these functions/behaviors to various animals such as a Cat, Dog, Horse, etc. But if you program in the specific you cannot apply a Cat class to a Dog since they are not the same thing.

4 0
3 years ago
The WAN connections to your regional offices are unfortunately extremely slow for your users and they are complaining about file
Zanzabum

Answer: (B) Branch cache

Explanation:

  The branch cache is the process of cache the data from the given file and the wen server on the wide area network. In the WAN connection, the branch code is the type of functionality which basically allow the window to providing the remote user support in the network. The branch cache basically work on the two mode that are:

  • The distributed mode
  • The host mode

The branch cache is the one of the technology that intend the cache data for reducing the network traffic in the wide are network.

Therefore, Option (B) is correct.

5 0
3 years ago
Electronic transmission of information standards, such as transaction and code sets and uniform identifiers, are covered underQu
Mila [183]

Answer:

option A

Explanation:

Option A.

With the use of Administrative simplification, we can transform all the paper work to electronic media such as electronic receipts or electronic mail. By shifting towards electronic means in Administrative simplification we are actually saving a lot of time by helping the human resource and from the laborious tasks of paper work and data management.

The management of electronic means is very easy and friendly, it is also a reason for implementing administration simplification as well.

3 0
3 years ago
Other questions:
  • In a word processor, Tariq chooses Options from the Tools menu and then selects the Track Changes tab. Which of the following ta
    14·1 answer
  • The Cisco IOS automatically modifies the dead interval when the _____ interval is changed. (Points : 2) hello
    13·1 answer
  • Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds.
    8·1 answer
  • Technologies designed to replace operating systems and services when they fail are called what?
    15·1 answer
  • Why is it a best practice of a remote access policy definition to require employees and users to fill in a separate VPN remote a
    14·1 answer
  • Edie wants to visit her university's website. What software application should she use?
    9·2 answers
  • FFFFFFFFFRRRRRRRRRRRRRRRRRREEEEEEEEEEEEEEEEEEEEEEE
    10·2 answers
  • How do we make a acount
    15·2 answers
  • Modern Computers compared to earlier computers are
    10·1 answer
  • Question 1 of 10
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!