How this code can be done without #define STOCK 5 #include #include #define STOCKS 5 using namespace std; class receipt { private: string name; double price [STOCKS]; public: receipt( ){ for(int i=0;iname = name; int size=sizeof(s)/sizeof(int); for(int i=0;iprice[i]=s[i]; } void setStocks(int i, double pr) { price[i]=pr; } double getStocks(int i) { return price[i]; } void show (){ cout<<"Magazin: "<
How this code can be done without #define STOCK 5
#include <iostream>
#include<iomanip>
#define STOCKS 5
using namespace std;
class receipt {
private:
string name;
double price [STOCKS];
public:
receipt( ){
for(int i=0;i<STOCKS;i++)
price[i]=0;
}
receipt(string name, double s[] ){
this->name = name;
int size=sizeof(s)/sizeof(int);
for(int i=0;i<STOCKS;i++)
this->price[i]=s[i];
}
void setStocks(int i, double pr) {
price[i]=pr;
}
double getStocks(int i) {
return price[i];
}
void show (){
cout<<"Magazin: "<<name<<endl;
for(int i=0; i<STOCKS;i++)
cout<<"Product #"<<i+1<<" "<<fixed<<setprecision(2)<<price[i]<<": lev"<<endl;
cout<<endl;
}
double total() {
double total=0;
for(int i=0; i<STOCKS;i++)
total+=price[i];
return total;
}
void remove(int i){
for(int t=i;t<STOCKS;t++)
price[t]=price[t+1];
}
void discount(int i,double per){
price[i]+=-price[i]*per*0.01;
}
};
int main (){
double pr[]={10.20, 13.40, 15.10, 16.20, 40.50 };
receipt r1("LIDL",pr);
cout<<"Kasova belejka: "<<endl;
r1.show();
cout<<"Stoinostta na 3 indeks e : ";
cout<<r1.getStocks(3)<<endl<<endl;
r1.setStocks(2,30.0);
cout<<"Sled promianata Product #3 = 30.0 "<<endl;
r1.show();
r1.discount(4, 15);
cout<<"Sled namalenieto 15% na Product #5"<<endl;
r1.show();
cout<<"Obshta cena = "<<r1.total();
}
Step by step
Solved in 2 steps with 1 images