Coding C++ Sample Final Exam Question

by - September 07, 2013



Write a complete program


class Product {
private:
    int prodID;
protected:
    float total_price;
public:
    Product() { total_price = 0.0; }
    void input_prodID()
    {
        cout << "Enter product ID : ";
        cin >> prodID;
    }
    int get_prodID() { return prodID; }
};
class canFood : protected Product {
private:
    float unit_price;
    int order_unit;
public:
    void get_Product()
    {
        input_prodID();
        cout << "Enter price : ";
        cin >> unit_price;
        cout << "Enter order unit : ";
        cin >> order_unit;
        cout << endl;
    }
    void calculate_Total() { total_price = unit_price * order_unit; }
    void display_product()
    {
        cout << "\nProduct ID : " << get_prodID() << endl;
        cout << "Total price : " << total_price << endl;
    }
};
void main()
{
    int num, i;
    cout << "How many types of canned food? ";
    cin >> num;
    cout << endl;
    canFood* tp;
    tp = new canFood[num];
    for (i = 0; i < num; i++) {
        tp[i].get_Product();
        tp[i].calculate_Total();
    }
    for (i = 0; i < num; i++) {
        tp[i].display_product();
    }
    system("PAUSE");
} /* Marks are allocated based on overall correctness and students may choose any array pointer notations */

You May Also Like

0 comments