In: Computer Science
C++ Fill in the blanks please
You are required to fill in the blanks in this program. Consider that: -In main, the variables price and quantity were given the names of p (double) and q (int), respectively. -In the getData function, the parameters associated with the main variables p and q were called pp and pq, respectively.
// Prototype: Do not include the names // of the variables in the prototype
void getData (FILLTHEBLANK , FILLTHEBLANK);
int main ()
{
double p; // p = price of the item
int q; // q = number of articles
double total;
// Call of the function getData - complete
// Remember that p and q want to pass as redeference,
// pointers mode.
getData (FILLTHEBLANK , FILLTHEBLANK);
// Complete the formula that multiplies price and quantity.
total = FILLINTHEBLANK * FILLINTHEBLANK;
cout << "Total to pay =" << total << "\ n \ n";
return 0;
}
// Heading of the function - fill in the data type of the parameters. Note that the parameter names must be pp and pq.
void getData (FILLTHEBLANK, FILLTHEBLANK)
{
cout << "Enter the price of the item:";
cin >> FILLTHEBLANK;
// This is where the price validation would go. Code
not included.
cout << "Enter the number of items purchased:";
cin >> FILLTHEBLANK;
// This is where the quantity validation would go. Code no included. }
#include <iostream>
using namespace std;
// Prototype: Do not include the names // of the variables in the
prototype
void getData (double& , int&);
int main ()
{
double p; // p = price of the item
int q; // q = number of articles
double total;
// Call of the function getData - complete
// Remember that p and q want to pass as redeference,
// pointers mode.
getData (p, q);
// Complete the formula that multiplies price and quantity.
total = p * q;
cout << "Total to pay =" << total << "\n\n";
return 0;
}
// Heading of the function - fill in the data type of the parameters. Note that the parameter names must be pp and pq.
void getData (double &price, int &quantity)
{
cout << "Enter the price of the item:";
cin >> price;
// This is where the price validation would go. Code not included.
cout << "Enter the number of items purchased:";
cin >> quantity;
// This is where the quantity validation would go. Code no
included.
}
Output:
Enter the price of the item:34.12 Enter the number of items purchased: 5 Total to pay =170.6
Do ask if any doubt. Please up-vote.