#include #include // defined constant for price per apple #define PRICE_PER_APPLE 0.85 // defined constant for price per orange #define PRICE_PER_ORANGE 1.00 using namespace std;
// function prototypes void display_heading(void); void display_apple_item(int qty, double total); void display_orange_item(int qty, double total); void display_grand_total(double grand_total); int main(void) { int apple_qty, orange_qty; double apple_total, orange_total, grand_total; // get number of apples and oranges cout << "Enter number of apples: "; cin >> apple_qty; cout << "Enter number of oranges: "; cin >> orange_qty; // compute total for apples and oranges apple_total = apple_qty * PRICE_PER_APPLE; orange_total = orange_qty * PRICE_PER_ORANGE; // compute grand total grand_total = apple_total + orange_total; // write the function calls to display the result
return 0; } void display_heading(void) { cout << "=========My Fruit Store========\n"; cout << "Fruit Qty Price Total\n"; cout << "-------------------------------\n"; } void display_apple_item(int qty, double total) { cout << "Apple\t" << setw(3) << qty; cout << " RM" << setw(4) << fixed << setprecision(2) << PRICE_PER_APPLE; cout << "\tRM" << setw(5) << fixed << setprecision(2) << total << endl; } void display_orange_item(int qty, double total) { cout << "Orange\t" << setw(3) << qty; cout << " RM" << setw(4) << fixed << setprecision(2) << PRICE_PER_ORANGE; cout << "\tRM" << setw(5) << fixed << setprecision(2) << total << endl; }
void display_grand_total(double total) { cout << "-------------------------------\n"; cout << "Total\t\t\tRM" << setw(5) << fixed << setprecision(2) << total << endl; }
#include #include using namespace std; void get_data(double& velocity, double& time, double& accel); double get_distance(double velocity, double time, double accel); int main(void) { double init_velocity, time, acceleration, distance; get_data(init_velocity, time, acceleration); distance = get_distance(init_velocity, time, acceleration); cout << "Distance is " << distance << endl; return 0; } void get_data(double& velocity, double& time, double& accel) { cout << "Enter initial velocity: "; cin >> velocity; cout << "Enter time: "; cin >> time; cout << "Enter acceleration: "; cin >> accel; } double get_distance(double velocity, double time, double accel) { return(velocity * time + 0.5 * accel * pow(time, 2.0)); }