Below, you will find two Raptor programs. Both programs accomplish the same goal
ID: 3607338 • Letter: B
Question
Below, you will find two Raptor programs. Both programs accomplish the same goal. Compare and contrast each of the programs. What is the purpose of the program? What problem was the program expected to address? Based on the purpose you determined, logically, which project is better? Why? What technique or approach did you use to determine that one was logically better than the other? Are there benefits or drawbacks to one program over the other? How can this program be improved?
- FIRST PROGRAM (C++)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string raptor_prompt_variable_zzyz;
?? changedue;
?? cashreceived;
?? total;
?? itemcount;
?? changeremaining;
?? response;
?? subtotal;
clear_console;
itemcount =1;
subtotal =0;
raptor_prompt_variable_zzyz ="Enter the price for item #"+itemcount+". If there are no items, enter a negative number to quit,";
cout << raptor_prompt_variable_zzyz << endl;
cin >> response;
while (!(response<=0))
{
cout << "Item "+itemcount+": $"+response << endl; itemcount =itemcount+1;
subtotal =subtotal+response;
raptor_prompt_variable_zzyz ="Enter the price for item #"+itemcount+". If there are no items, enter a negative number to quit,";
cout << raptor_prompt_variable_zzyz << endl;
cin >> response;
}
if (subtotal<=0)
{
cout << "No items received. Program terminated." << endl; }
else
{
itemcount =itemcount-1;
cout << "Number of Items Purchased: "+itemcount << endl; cout << "Subtotal: $"+subtotal << endl; total =subtotal*1.06;
cout << "Total: $"+total << endl; raptor_prompt_variable_zzyz ="Enter how much you'd like to pay.";
cout << raptor_prompt_variable_zzyz << endl;
cin >> cashreceived;
cout << "Cash Received: $"+cashreceived << endl; changedue =cashreceived-total;
cout << "Change Due: $"+changedue << endl; if (cashreceived>total)
{
if (changedue>0)
{
if (changedue>=100)
{
changeremaining =changedue/100;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*100);
cout << changeremaining+" x $100 bills" << endl; }
else
{
}
if (changedue>=50)
{
changeremaining =changedue/50;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*50);
cout << changeremaining+" x $50 bills" << endl; }
else
{
}
if (changedue>=20)
{
changeremaining =changedue/20;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*20);
cout << changeremaining+" x $20 bills" << endl; }
else
{
}
if (changedue>=10)
{
changeremaining =changedue/10;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*10);
cout << changeremaining+" x $10 bills" << endl; }
else
{
}
if (changedue>=5)
{
changeremaining =changedue/5;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*5);
cout << changeremaining+" x $5 bills" << endl; }
else
{
}
if (changedue>=1)
{
changeremaining =changedue/1;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*1);
cout << changeremaining+" x $1 bills" << endl; }
else
{
}
if (changedue>=0.25)
{
changeremaining =changedue/0.25;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*0.25);
cout << changeremaining+" x $0.25 coins" << endl; }
else
{
}
if (changedue>=0.1)
{
changeremaining =changedue/0.1;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*0.1);
cout << changeremaining+" x $0.10 coins" << endl; }
else
{
}
if (changedue>=0.05)
{
changeremaining =changedue/0.05;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*0.05);
cout << changeremaining+" x $0.05 coins" << endl; }
else
{
}
if (changedue>=0)
{
changeremaining =changedue/0.01;
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*0.01);
cout << changeremaining+" x $0.01 coins" << endl; }
else
{
}
}
else
{
}
}
else
{
cout << "Invalid amount received." << endl; }
}
return 0;
}
- SECOND PROGRAM (C++)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string raptor_prompt_variable_zzyz;
?? changedue;
?? cashreceived;
?? total;
?? itemcount;
?? remaining;
?? bills;
?? response;
?? subtotal;
clear_console;
itemcount =1;
subtotal =0;
raptor_prompt_variable_zzyz ="Enter the price for item #"+itemcount+". If there are no items, enter a negative number to quit,";
cout << raptor_prompt_variable_zzyz << endl;
cin >> response;
while (!(response<=0))
{
cout << "Item "+itemcount+": $"+response << endl; itemcount =itemcount+1;
subtotal =subtotal+response;
raptor_prompt_variable_zzyz ="Enter the price for item #"+itemcount+". If there are no items, enter a negative number to quit,";
cout << raptor_prompt_variable_zzyz << endl;
cin >> response;
}
if (subtotal<=0)
{
cout << "No items received. Program terminated." << endl; }
else
{
itemcount =itemcount-1;
cout << "Number of Items Purchased: "+itemcount << endl; cout << "Subtotal: $"+subtotal << endl; total =subtotal*1.06;
cout << "Total: $"+total << endl; raptor_prompt_variable_zzyz ="Enter how much you'd like to pay.";
cout << raptor_prompt_variable_zzyz << endl;
cin >> cashreceived;
cout << "Cash Received: $"+cashreceived << endl; changedue =cashreceived-total;
cout << "Change Due: $"+changedue << endl; if (cashreceived>total)
{
if (changedue>0)
{
remaining =changedue;
bills =remaining/100;
bills =floor(bills);
cout << bills+" x $100 bills" << endl; remaining =remaining % 100;
bills =remaining/50;
bills =floor(bills);
cout << bills+" x $50 bills" << endl; remaining =remaining % 50;
bills =remaining/20;
bills =floor(bills);
cout << bills+" x $20 bills" << endl; remaining =remaining % 20;
bills =remaining/10;
bills =floor(bills);
cout << bills+" x $10 bills" << endl; remaining =remaining % 10;
bills =remaining/5;
bills =floor(bills);
cout << bills+" x $5 bills" << endl; remaining =remaining % 5;
bills =remaining/1;
bills =floor(bills);
cout << bills+" x $1 bills" << endl; remaining =remaining % 1;
bills =remaining/0.25;
bills =floor(bills);
cout << bills+" x $0.25 coins" << endl; remaining =remaining % 0.25;
bills =remaining/0.1;
bills =floor(bills);
cout << bills+" x $0.10 coins" << endl; remaining =remaining % 0.1;
bills =remaining/0.05;
bills =floor(bills);
cout << bills+" x $0.05 coins" << endl; remaining =remaining % 0.05;
bills =remaining/0.01;
bills =floor(bills);
cout << bills+" x $0.01 coins" << endl; remaining =remaining % 0.01;
}
else
{
}
}
else
{
cout << "Invalid amount received." << endl; }
}
return 0;
}
Explanation / Answer
All the answers are listed below:
int a[] = {100,20,20,10,5,...};
i=0;
while(changeremaining > 0){
changeremaining =changedue/a[i];
changeremaining =floor(changeremaining);
changedue =changedue-(changeremaining*a[i]);
cout << changeremaining<<" x $"<<a[i]<<" bills" << endl;
i++;
}
Please feel free to ask if you have any doubt and share the feedback too.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.