Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string.h>
- using namespace std;
- class Magazin;
- class Produs {
- private:
- char nume[64];
- float pret;//pretul este in Euro
- static float CURS_VALUTAR;
- public:
- Produs(const char *nume="",float pret=0 );
- void afisare();
- void setNume(char* nume);
- char *getNume();
- void setPret(float pret);
- float getPret();
- float getPretLei();
- };
- float Produs:: CURS_VALUTAR=4.758;//12 apr 2019
- Produs::Produs(const char *nume,float pret ) {
- strcpy(this->nume,nume);
- this->pret=pret;
- }
- void Produs::afisare() {
- cout<<"Nume: "<< nume<<endl;
- cout<<"Pret in Euro: "<<pret<<endl;
- cout<<"Pret in lei: "<<getPretLei()<<endl;
- cout<<"-----------------------------"<<endl;
- }
- void Produs::setNume(char *nume) {
- strcpy(this->nume, nume);
- }
- char *Produs::getNume() {
- return nume;
- }
- void Produs::setPret(float pret) {
- if(pret>0)
- this->pret=pret;
- }
- float Produs::getPret() {
- return pret;
- }
- float Produs::getPretLei() { //functie ce calculeaza pretul in lei
- return pret*CURS_VALUTAR;
- }
- class Magazin { //clasa Magazin
- private:
- int capacitate;//nr max de produse din magazin
- int nrProduse;//nr efectiv de produse
- Produs *produse;
- public:
- Magazin(int capacitate);
- Magazin(const Magazin &m);
- void adaugare(Produs p);
- void afisare();
- void eliminare(Produs p);
- };
- Magazin::Magazin(int capacitate) {
- this->capacitate = capacitate;
- this->produse = new Produs[capacitate];
- this->nrProduse=0;
- }
- Magazin::Magazin(const Magazin &m) {
- this->capacitate = m.capacitate;
- this->nrProduse=m.nrProduse;
- this->produse = new Produs[m.capacitate];
- for(int i=0; i<nrProduse; i++) {
- this->produse[i]= m.produse[i];
- }
- }
- void Magazin::adaugare(Produs p) {
- if(nrProduse<capacitate) {
- produse[nrProduse]=p;
- nrProduse++;
- } else {
- cout<<"nu mai am loc"<<endl;
- }
- }
- void Magazin::afisare() {
- cout<<endl;
- cout<<"Lista produselor este:"<<endl;
- for(int i=0; i<nrProduse; i++) {
- produse[i].afisare();
- }
- }
- void Magazin::eliminare(Produs p) {
- int gasit=-1;
- for(int i=0; i<nrProduse; i++){
- if(strcmp(p.getNume(),produse[i].getNume())==0){
- gasit=i;
- cout<<"Produsul a fost gasit, urmeaza a fi eliminat"<<endl;
- break;
- }
- }
- if(gasit>=0){
- for(int i=gasit; i<nrProduse-1; i++){
- produse[i]=produse[i+1];
- }
- nrProduse--;
- }
- }
- int main() {
- Produs p1("vafa",4);
- Produs p2("pufarina",1);
- Produs p3("varza",3);
- Magazin m(5);
- m.adaugare(p1);
- m.adaugare(p2);
- m.afisare();
- m.adaugare(p3);
- m.afisare();
- m.eliminare(p2);
- cout<<endl;
- cout<<"***********";
- m.afisare();
- /*
- Magazin m2=m;
- cout<<"----------"<<endl;
- cout<<"magazinul 2"<<endl;
- m2.afisare();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement