Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
52d53eda0a | |||
a9da63e643 | |||
975daae4ee |
148
indywidualny
Normal file
148
indywidualny
Normal file
@ -0,0 +1,148 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class produkt {
|
||||
private:
|
||||
int id;
|
||||
string nazwa;
|
||||
float cena;
|
||||
int ilosc;
|
||||
public:
|
||||
produkt (int id, string nazwa, float cena, int ilosc) {
|
||||
this->id = id;
|
||||
this->nazwa = nazwa;
|
||||
this->cena = cena;
|
||||
this->ilosc = ilosc;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
int getIle(){
|
||||
return ilosc;
|
||||
}
|
||||
|
||||
void setIle(){
|
||||
this->ilosc=10;
|
||||
}
|
||||
|
||||
string getNazwa(){
|
||||
return nazwa;
|
||||
}
|
||||
|
||||
float getCena(){
|
||||
return cena;
|
||||
}
|
||||
|
||||
void WypiszInformacje ();
|
||||
|
||||
void Kup();
|
||||
};
|
||||
|
||||
void produkt::WypiszInformacje() {
|
||||
cout << "nazwa produktu: " << nazwa << endl;
|
||||
cout << "cena: " << cena << endl;
|
||||
cout << "ilosc: " <<ilosc <<endl;
|
||||
//cout << "data waznosci: " << dat->WypiszDate() << endl;
|
||||
cout << "---------" << endl;
|
||||
};
|
||||
|
||||
void produkt::Kup() {
|
||||
this->ilosc=this->ilosc-1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
produkt *p1 = new produkt(1, "KIT KAT",2.5, 2);
|
||||
produkt *p2 = new produkt(2, "MARS", 2, 10 );
|
||||
produkt *p3 = new produkt(3, "BOUNTY", 3, 3);
|
||||
produkt *p4 = new produkt(4, "KINDER BUENO", 2.5, 4);
|
||||
produkt *p5 = new produkt(5, "WW", 2 , 10);
|
||||
produkt *p6 = new produkt(6, "MILKY WAY", 1.5, 5);
|
||||
produkt *p7 = new produkt(7, "7-DAYS", 4, 8);
|
||||
produkt *p8 = new produkt(8, "TWIX", 2, 10 );
|
||||
produkt *p9 = new produkt(9, "PRINCE POLO", 1.5, 9);
|
||||
|
||||
produkt *tab[9] = {p1, p2, p3, p4, p5, p6, p7, p8, p9};
|
||||
|
||||
while (true){
|
||||
cout<< "AUTOMAT"<<endl<<endl;
|
||||
cout<< "MOZLIWE NOMINALY: 10 gr (0.1), 20 gr (0.2), 50 gr (0.5), 1 zl, 2 zl, 5zl"<<endl<<endl;
|
||||
for (int i=0; i<9; i++){
|
||||
cout<<tab[i]->getId()<< " "<<tab[i]->getNazwa()<<" "<< tab[i]->getCena()<<" zl"<<endl;
|
||||
}
|
||||
cout<<endl;
|
||||
cout<<"podaj numer produktu: ";
|
||||
int n;
|
||||
cin>>n;
|
||||
while (true){
|
||||
if (n!=1 and n!=2 and n!=3 and n!=4 and n!=5 and n!=6 and n!=7 and n!=8 and n!=9){
|
||||
cout<<"bledna wartosc, podaj ponownie: ";
|
||||
cin>>n;
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout<<"oczekiwana zaplata: "<<tab[n-1]->getCena()<<endl;
|
||||
float zaplata=0;
|
||||
float m;
|
||||
cout<<"wprowadz pierwsza monete: ";
|
||||
while (zaplata<tab[n-1]->getCena()){
|
||||
cin>>m;
|
||||
if (m!=0.1 and m!=0.2 and m!=0.5 and m!=1 and m!=2 and m!=5){
|
||||
cout<<"bledy nominal, wprowadz nowa monete: ";
|
||||
}
|
||||
else{
|
||||
zaplata=zaplata+m;
|
||||
if (zaplata<tab[n-1]->getCena()){
|
||||
cout<<"wprowadz kolejna monete: ";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
cout<<"reszta: ";
|
||||
if ((zaplata-tab[n-1]->getCena())<0.09){
|
||||
cout<<"0"<<endl;
|
||||
}
|
||||
else{
|
||||
cout<<zaplata-tab[n-1]->getCena()<<endl;
|
||||
}
|
||||
tab[n-1]->Kup();
|
||||
if (tab[n-1]->getIle()<1){
|
||||
cout<<"BRAK PRODUKTU NR: "<< n << " " <<tab[n-1]->getNazwa()<<endl;
|
||||
cout<<"WEZWANO MAGAZYN, CZEKAM NA UZUPELNIENIE..."<<endl;
|
||||
for (int j=0; j<10; j++){
|
||||
cout<<"PROSZE CZEKAC: "<<10-j<< endl;
|
||||
Sleep(1000);
|
||||
}
|
||||
tab[n-1]->setIle();
|
||||
cout<<"UZUPELNIONO"<<endl;
|
||||
}
|
||||
|
||||
Sleep(5000);
|
||||
system( "cls" );
|
||||
}
|
||||
|
||||
delete p1;
|
||||
delete p2;
|
||||
delete p3;
|
||||
delete p4;
|
||||
delete p5;
|
||||
delete p6;
|
||||
delete p7;
|
||||
delete p8;
|
||||
delete p9;
|
||||
delete tab;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user