Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

C++
 #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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900