So I'm trying to right a code to output some simple data using classes. Everything works accept the retail price function. It's suppose to calculate and output the retail price but it only outputs 0 no matter what numbers I eneter. Can anyone give me some suggestions on how to fix this?
Header
#ifndef STORE_H
#define STORE_H
#include <iostream>
#include <iomanip>
using namespace std;
class Store
{
public:
Store( );
Store (int, char[], int, double, double, int, double);
int GetProductIDNumber ( )const;
char const* GetDescription ( )const;
int GetManufacturersIDNumber ( )const;
double GetPrice ( )const;
double GetPercentage ( )const;
int GetInventory ( )const;
void Display ()const;
double const &RetailPrice ( )const;
private:
int ProductIDNumber;
char Description [25];
int ManufacturersIDNumber;
double Price;
double Percentage;
int Inventory;
};
#endif
Implementation file
#include "Store.h"
Store::Store()
{
ProductIDNumber = 0;
Description[24] = '\0';
ManufacturersIDNumber = 0;
Price = 0;
Percentage = 0;
Inventory = 0;
}
Store::Store (int InitProductIDNumber, char InitDescription[], int InitManufacturersIDNumber,
double InitPrice, double InitPercentage, int InitInventory, double InitRetailPrice)
{
ProductIDNumber = InitProductIDNumber;
strcpy_s( Description, InitDescription );
ManufacturersIDNumber = InitManufacturersIDNumber;
Price = InitPrice;
Percentage = InitPercentage;
Inventory = InitInventory;
}
int Store::GetProductIDNumber() const
{
return( ProductIDNumber );
}
char const* Store::GetDescription() const
{
return( Description );
}
int Store::GetManufacturersIDNumber() const
{
return( ManufacturersIDNumber );
}
double Store::GetPrice() const
{
return ( Price );
}
double Store::GetPercentage() const
{
return( Percentage );
}
int Store::GetInventory() const
{
return( Inventory );
}
void Store::Display() const
{
cout<<"12345678901234567890123456789012345678901234567890"<<endl;
cout<<endl;
cout<<"============================================================="<<endl;
cout<<setw(45)<<"Office Supply Product Information"<<endl;
cout<<"============================================================="<<endl;
cout<<"============================================================="<<endl;
cout<<setw(30)<<setfill(' ')
<<"Identification Number: "
<<setw (15)<< GetProductIDNumber()<<endl;
cout<<setw(20)<<setfill(' ')
<<"Description: "
<<setw (23) << GetDescription()<<endl;
cout<<setw(21)<<setfill(' ')
<<"Manufacturer: "
<<setw(22)<< GetManufacturersIDNumber()<<endl;
cout<<setw(24)<<setfill(' ')
<<"Wholesale Price: "
<<setw(19)<< GetPrice ()<<endl;
cout<<setw(22)<<setfill(' ')
<<"Mark-up Price: "
<<setw(21)<< GetPercentage()<<endl;
cout<<setw(25)<<setfill(' ')
<<"Quanity In stock: "
<<setw(18)<<GetInventory()<<endl;
cout<<"============================================================="<<endl;
}
double const &Store::RetailPrice()const
{
return((Price*Percentage)+Price);
}
Client Code
#include "Store.h"
int main()
{
int InitProductIDNumber = 0;
char InitDescription[24] = "\0";
int InitManufacturersIDNumber = 0;
double InitPrice = 0;
double InitPercentage = 0;
int InitInventory = 0;
double InitRetailPrice = 0;
char NextChar= '\0';
char ContinuationFlag = 'Y';
while (toupper(ContinuationFlag) == 'Y')
{
cout<<endl;
cout<< "Enter the products ID Number: "<<endl;
cin>> InitProductIDNumber;
cout<< "Enter the products Manufacturer's ID Number: "<<endl;
cin>> InitManufacturersIDNumber;
cout<< "Enter the products wholesale price: "<<endl;
cin>> InitPrice;
cout<< "Enter the product's mark-up percentage: "<<endl;
cin>> InitPercentage;
cout<< "Enter the product's description: "<<endl;
NextChar = cin.peek();
if ( NextChar =='\n')
{
cin.ignore( );
}
cin.get (InitDescription, 24);
cout<< "Enter the quantity of the product in stock: "<<endl;
cin>> InitInventory;
Store InventoryItem (InitProductIDNumber, InitDescription, InitManufacturersIDNumber, InitPrice, InitPercentage,
InitInventory, &RetailPrice);
InventoryItem.Display();
cout<<endl;
**cout<< "Office Supply Product Retail Price: "<<&RetailPrice()<<endl;** //This is where the output of retail function should be
cout<<endl;
cout<<" Do you wish to enter any more products?"<<endl;
cout<<endl;
cout<< "Enter 'Y' or 'N'"<<endl;
cin>> ContinuationFlag;
}
return 0;
}