Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to calculate the Total amount including GST and Total GST paid.

Now I want to calculate the Total amount including GST and Total GST paid. But I am unable to do so as I have declared price variable as private. what is an alternative to calculate Total Price and Total amount of GST paid.

What I have tried:

 #include<iostream.h>
 #include<conio.h>
 int T;

class item
{
    int quantity;
    char name[100];
    float price;

public:
    float Total;
    void get_data();
    void put_data();

};



void item::get_data()
{

    cout<<"Enter the name of the item "<<T+1<<" = ";
    cin>>name;
    cout<<"Enter the quantity= ";
    cin>>quantity;
    cout<<"Enter the price= ";
    cin>>price;

    cout<<"\n";

}
void item::put_data()
{
    cout<<"\n"<<name<<"\t\t   "<<quantity<<"\t\t   "<<price<<"\t\t\t"<<"SR";
}


void main()
{
    int N;
    clrscr();
    cout<<"Enter the Total number of item = ";
    cin>>N;
    item i[100];
    for(T=0;T<N;T++)
    {
        i[T].get_data();
    }

    cout<<"\nName of items";
    cout<<"\t\tQuantity ";
    cout<<"\titem price ";
    cout<<"\t\tGST ";

    for(T=0;T<N;T++)
    {
    i[T].put_data();
    }
    //Total amount including GST= ?
   //Total amount GST paid=?
Now I want to calculate the Total amount including GST and Total GST paid. But I am unable to do so as I have declared price variable as private. what is an alternative to calculate Total Price and Total amount of GST paid.

    getch();

}
Posted
Updated 5-Sep-17 3:07am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Just add public methods to get the content of private (and protected) members:
class item
{
    // ...
public: 
    int getQuantity() const { return quantity; }
    float getPrice() const { return price; }
    const char* getName() const { return name; }
};
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100