Skip to content

Instantly share code, notes, and snippets.

@pstachula-dev
Created June 1, 2013 16:15
Show Gist options
  • Save pstachula-dev/5690899 to your computer and use it in GitHub Desktop.
Save pstachula-dev/5690899 to your computer and use it in GitHub Desktop.
Programowanie obiektowe 6 projekt
//
// Projekt nr : 6
// gatunki plyt muzycznych
//Przykład 18 + A2.h +A2.cpp
#include <iostream>
#include <string>
#include <time.h>
#include <fstream>
#include <ctime>
using namespace std;
// Klasa Statyczna
class data_dod
{
protected:
string data_dodania;
public:
data_dod()
{
time_t czas;
data_dodania = ctime( & czas );
}
void get(){ cout << data_dodania << endl; }
};
///////////////////////////////////// DZIEDZICZENIE//////////////////////////////////////
// *********************** ### Klasy ### *********************** //
class muzyka
{
protected:
static data_dod * data_akt;
public:
virtual void wyswietl()const=0;
};
data_dod * muzyka::data_akt = new data_dod;
class album;
// *********************** Wytwornie *********************** //
class wytwornie: virtual public muzyka
{
string nazwa;
int rok;
public:
static int licznik_wytwornie;
wytwornie():nazwa("Beznazwy"),rok(1900) { }
void dodaj(string t_nazwa, int t_rok);
void wyswietl() const;
};
// *********************** Funkcje skladowe klasy - Wytwornie *********************** //
void wytwornie::dodaj(string t_nazwa, int t_rok)
{
nazwa = t_nazwa;
rok = t_rok;
licznik_wytwornie++;
}
void wytwornie::wyswietl() const
{
cout << nazwa << "\t" << rok << endl;
}
// *********************** gatunki *********************** //
class gatunki: virtual public muzyka
{
string rodzaj;
int numer;
int rabat;
const int cena;
friend int zaplata(album album, gatunki **&kat);
public:
static int licznik_gatunki;
gatunki():cena(50),rabat(0)
{
rodzaj = "Bez nazwy";
numer = 0;
}
void dodaj(string t_tytul_utwor, int e_numer, int rabat);
void wyswietl() const;
};
// *********************** UTWOR_DANE *********************** //
class utwor_dane // utwor_wlasciwosci
{
// *********************** UTWOR_CENA *********************** //
class utwor_cena
{
int cena;
public:
utwor_cena():cena(15){}
int getCena(){ return cena; }
};
utwor_cena * cena;
string nazwa;
int dlugosc;
public:
static int licznik_utwor_wlasc;
utwor_dane():nazwa("Bez-nazwy"), dlugosc(0), cena(new utwor_cena){}
void dodaj(string t_nazwa, int t_dlugosc);
string wyswietl_nazwa() const;
int wyswietl_dlugosc() const;
int wyswietl_cena() const;
};
void utwor_dane::dodaj(string t_nazwa, int t_dlugosc)
{
nazwa = t_nazwa;
dlugosc = t_dlugosc;
licznik_utwor_wlasc++;
}
string utwor_dane::wyswietl_nazwa() const
{
return nazwa;
}
int utwor_dane::wyswietl_dlugosc() const
{
return dlugosc;
}
int utwor_dane::wyswietl_cena() const
{
return (cena->getCena());
}
// *********************** ALBUM *********************** //
class album: public wytwornie, public gatunki
{
string tytul_album;
int rok;
int utwor;
int ktory_gatunki;
utwor_dane * dane_utwory;
// Zaprzyjaznione klasy
friend int zaplata(album album, gatunki **&kat);
friend int znajdz_album(album *&nowy, string nazwa, int rok_wyd);
friend bool import(album *&el_album);
friend void duplikat(album *&nowy);
friend class utwor_wlasc;
public:
static int licznik_album;
album()
{
tytul_album = "Bez nazwy";
rok = 1900;
utwor = 0;
ktory_gatunki = 0;
dane_utwory = new utwor_dane[5];
}
void dodaj(string t_tytul_album, int t_rok, int t_utwor, int e_ktory_kat);
void wyswietl() const;
void wyswietl_utwory() const;
// Przeciazenie operatorow
friend ostream & operator<<(ostream &out, album *&tmp);
friend ostream & operator<<(ostream &out, album &tmp); // eksport
friend istream & operator>>(istream &out, album &tmp);
album & operator =(album &nowy);
utwor_dane & operator[](int x);
void operator()(void);
utwor_dane * operator->(void);
bool operator==(album &nowy);
friend bool operator!=(album &nowy, album &nowy2);
};
// *********************** ### Dynamiczne tablice ### *********************** //
int album::licznik_album = 0;
int gatunki::licznik_gatunki = 0;
int wytwornie::licznik_wytwornie = 0;
int utwor_dane::licznik_utwor_wlasc = 5;
album *tab_wsk;
gatunki **tab_gatunki;
wytwornie **tab_wytwornie;
bool czy_zwolniono_pamiec = true;
bool czy_zwolniono_pamiec_kat = true;
void pokaz_roznice()
{
muzyka **kontener;
kontener = new muzyka*[(album::licznik_album)];
for(int i = 0; i < album::licznik_album; i++) {
kontener[i] = &tab_wsk[i];
kontener[i]->wyswietl();
}
}
// *********************** Funkcje skladowe klasy - Album *********************** //
void duplikat(album *&nowy)
{
cout << "1. Albumy z taka sama nazwa \n2. Albumy z danego roku\n";
string temp;
int x, z=0, rok2;
cin >> x;
switch(x) {
case 1:
cout << "Podaj tytul: ";
cin >> temp;
for(int i = 0; i < album::licznik_album; i++)
if(nowy[i].tytul_album == temp)
z = i;
for(int i = 0; i < album::licznik_album; i++) {
if(nowy[z] == nowy[i])
cout << nowy[i];
}
break;
case 2:
cout << "Podaj rok: ";
cin >> rok2;
for(int i = 0; i < album::licznik_album; i++)
if(nowy[i].rok == rok2)
z = i;
for(int i = 0; i < album::licznik_album; i++)
if(!(nowy[z] != nowy[i]))
cout << "Duplikat: " << nowy[i];
break;
}
}
bool eksport(album *&el_album)
{
fstream dane("asdd", fstream::out);
string temp;
if(!dane.is_open()) {
cout << "Blad odczytu\n";
return false;
}
for(int i = 0; i < album::licznik_album; i++)
dane << el_album[i];
dane.close();
return true;
}
bool import(album *&el_album)
{
fstream dane2("asdd", fstream::in);
string temp;
int ile_album;
if(!dane2.is_open()) {
cout << "Blad odczytu\n";
return false;
}
while(!dane2.eof()) {
getline(dane2, temp);
album::licznik_album++;
}
dane2.close();
fstream dane("asdd", fstream::in);
int i = 0;
album::licznik_album--;
el_album = new album[album::licznik_album];
//cout << "Nazwa - \tRok wyd - \tL.utw - \tk.kat\n";
while(!dane.eof()) {
getline(dane, temp, '\t');
el_album[i].tytul_album = temp;
getline(dane, temp, '\t');
el_album[i].rok = atoi(temp.c_str());
getline(dane, temp, '\t');
el_album[i].utwor = atoi(temp.c_str());
getline(dane, temp);
el_album[i++].ktory_gatunki = atoi(temp.c_str());
if(i == album::licznik_album)
break;
}
dane.close();
return true;
}
////////////////
void album::dodaj(string t_tytul_album, int t_rok, int t_utwor, int e_ktory_kat)
{
tytul_album = t_tytul_album;
rok = t_rok;
utwor = t_utwor;
ktory_gatunki = e_ktory_kat;
licznik_album++;
}
void album::wyswietl() const
{
cout << tytul_album << "\t" << rok << "\t" << utwor << "\t" << ktory_gatunki << endl;
cout << "\n Dziedziczone skladniki: \n";
gatunki::wyswietl();
wytwornie::wyswietl();
data_akt->get();
}
void album::wyswietl_utwory() const
{
dane_utwory->wyswietl_nazwa();
}
utwor_dane * album::operator ->(void)
{
if(dane_utwory == 0)
cout << "Blad wskaznik zerowy!";
return dane_utwory;
}
ostream & operator<<(ostream &out, album *&tmp)
{
cout << "Nazwa\tRok wyd\tL.utw\tk.kat\n";
for(int i = 0; i < album::licznik_album; i++) {
out << tmp[i].tytul_album << "\t" << tmp[i].rok << "\t"
<< tmp[i].utwor << "\t" << tmp[i].ktory_gatunki << endl;
}
return out;
}
ostream & operator<<(ostream &out, album &tmp)
{
out << tmp.tytul_album << "\t" << tmp.rok << "\t"
<< tmp.utwor << "\t" << tmp.ktory_gatunki << endl;
return out;
}
istream & operator>>(istream &out, album &tmp)
{
cout << "Podaj tytul albumu: ";
out >> tmp.tytul_album;
cout << "Podaj rok wydania: ";
out >> tmp.rok;
cout << "Podaj liczbe utworow: ";
out >> tmp.utwor;
cout << "Ktory gatunki: ";
out >> tmp.ktory_gatunki;
return out;
}
album & album::operator =(album &nowy)
{
if(this != &nowy) {
delete [] dane_utwory;
tytul_album = nowy.tytul_album;
rok = nowy.rok;
utwor = nowy.utwor;
ktory_gatunki = nowy.ktory_gatunki;
dane_utwory = new utwor_dane[4];
}
return *this;
}
utwor_dane & album::operator [](int x)
{
return dane_utwory[x];
}
void album::operator ()()
{
licznik_album--;
}
bool album::operator==(album &nowy)
{
if(tytul_album == nowy.tytul_album)
return true;
else
return false;
}
bool operator!=(album &nowy, album &nowy2)
{
if(&nowy.rok != &nowy2.rok)
return true;
else
return false;
}
// *********************** Funkcje skladowe klasy - gatunki *********************** //
void gatunki::dodaj(string t_rodzaj, int e_numer, int e_rabat)
{
rodzaj = t_rodzaj;
rabat = e_rabat;
numer = e_numer;
licznik_gatunki++;
}
void gatunki::wyswietl() const
{
cout << rodzaj << "\t" << numer << "\t" << rabat << endl;
}
// *********************** Funkcje Globalne klasy - Album *********************** //
void stworz(album *&nowy, int ile)
{
nowy = new album [ile];
}
void dodaj(album *&nowy, int ile)
{
string temp;
for(int i = 0; i < ile; i++){
temp = rand() % 10 + 65;
nowy[i].dodaj(temp, i+2000, i*4, 0);
}
czy_zwolniono_pamiec = true;
}
void edytuj(album *&nowy, int ile)
{
string e_tytul_album;
int e_rok, e_utwor, e_ktory_kat;
ile--;
cout << "Podaj tytul albumu: ";
cin >> e_tytul_album;
cout << "Podaj rok wydania: ";
cin >> e_rok;
cout << "Podaj liczbe utworow: ";
cin >> e_utwor;
cout << "Ktory gatunki: ";
cin >> e_ktory_kat;
nowy[ile].dodaj(e_tytul_album, e_rok, e_utwor, e_ktory_kat);
(*nowy)();
}
void wyswietl_utwory(album *&nowy, int indeks)
{
cout << "Nazwa\tDlugosc\n";
for(int i = 0; i < 4; i++)
cout << (*(nowy))[i].wyswietl_nazwa() << "\t"
<< (*(nowy))[i].wyswietl_dlugosc() << "\t"
<< nowy[i]->wyswietl_cena() << endl;
}
void wyswietl(album *&nowy, int ile)
{
cout << "Nazwa\tRok wyd\tL.utw\tk.kat\n";
for(int i = 0; i < ile; i++){
nowy[i].wyswietl();
}
}
void usun(album *&nowy, int &ile)
{
delete [] nowy;
ile = 0;
album::licznik_album = 0;
czy_zwolniono_pamiec = false;
}
void przesun(album *&nowy, int ile, int &rozmiar)
{
ile--;
rozmiar++;
int i = 0;
album *temp_album;
stworz(temp_album, rozmiar);
for(i; i < ile; i++){
temp_album[i] = nowy[i];
}
i++;
temp_album[ile].dodaj("Nowy", 8, 99, 0);
for(i; i < rozmiar; i++){
temp_album[i] = nowy[i - 1];
}
if(czy_zwolniono_pamiec)
delete [] nowy;
stworz(nowy, rozmiar);
for(i = 0; i < rozmiar; i++){
nowy[i] = temp_album[i];
}
czy_zwolniono_pamiec = true;
delete [] temp_album;
}
void usun_jeden_element(album *&nowy, int ile, int &rozmiar)
{
ile--;
rozmiar--;
int i = 0;
album *temp_album;
stworz(temp_album, rozmiar);
for(i; i < ile; i++){
temp_album[i] = nowy[i];
}
for(i; i < rozmiar; i++){
temp_album[i] = nowy[i + 1];
}
stworz(nowy, rozmiar);
for(i = 0; i < rozmiar; i++){
nowy[i] = temp_album[i];
}
delete [] temp_album;
(*nowy)(); // zmniejsza licznik
}
int znajdz_album(album *&nowy, string nazwa, int rok_wyd)
{
int j = 0;
for(int i = 0; i < album::licznik_album; i++) {
if(nazwa == nowy[i].tytul_album && rok_wyd == nowy[i].rok) {
cout << "\nZnaleziono album ";
nowy[i].wyswietl();
cout << "\nPrzejdz do nastepnego kroku\n";
j = 0;
return i;
} else
j = 1;
}
if(j) {
cout << "\nBrak wskazanego albumu\n";
return -1;
}
}
// *********************** Funkcje Globalne klasy - wytwornie *********************** //
void stworz(wytwornie **&nowy, int ile)
{
nowy = new wytwornie *[ile];
for(int i = 0; i < ile; i++){
nowy[i] = new wytwornie;
}
}
void dodaj(wytwornie **&nowy, int ile)
{
czy_zwolniono_pamiec_kat = true;
string temp;
for(int i = 0; i < ile; i++){
temp = rand() % 10 + 65;
nowy[i]->dodaj(temp, i + 1);
}
}
void edytuj(wytwornie **&nowy, int ile)
{
string e_tytul_utwor;
int e_numer, e_rabat;
ile--;
cout << "Podaj tytul gatunkiu: ";
cin >> e_tytul_utwor;
cout << "Wprowadz nowy numer:";
cin >> e_numer;
nowy[ile]->dodaj(e_tytul_utwor, e_numer);
wytwornie::licznik_wytwornie--;
}
void wyswietl(wytwornie **&nowy, int ile)
{
cout << "\ngatunki\tId\tRabat\n";
for(int i = 0; i < ile; i++){
nowy[i]->wyswietl();
}
}
void usun(wytwornie **&nowy, int &ile)
{
for(int i = 0; i < ile; i++){
delete nowy[i];
}
delete [] nowy;
ile = 0;
wytwornie::licznik_wytwornie = 0;
czy_zwolniono_pamiec_kat = false;
}
void przesun(wytwornie **&nowy, int ile, int &rozmiar)
{
ile--;
rozmiar++;
int i = 0;
wytwornie **temp_gatunki;
stworz(temp_gatunki, rozmiar);
for(i; i < ile; i++){
temp_gatunki[i] = nowy[i];
}
i++;
temp_gatunki[ile]->dodaj("Wyt", 8);
for(i; i < rozmiar; i++){
temp_gatunki[i] = nowy[i - 1];
}
if(czy_zwolniono_pamiec_kat)
delete [] nowy;
stworz(nowy, rozmiar);
for(i = 0; i < rozmiar; i++){
nowy[i] = temp_gatunki[i];
}
czy_zwolniono_pamiec_kat = true;
delete [] temp_gatunki;
}
void usun_jeden_element(wytwornie **&nowy, int ile, int &rozmiar)
{
ile--;
rozmiar--;
int i = 0;
wytwornie **temp_gatunki;
stworz(temp_gatunki, rozmiar);
for(i; i < ile; i++){
temp_gatunki[i] = nowy[i];
}
for(i; i < rozmiar; i++){
temp_gatunki[i] = nowy[i + 1];
}
delete [] nowy;
stworz(nowy, rozmiar);
for(i = 0; i < rozmiar; i++){
nowy[i] = temp_gatunki[i];
}
delete [] temp_gatunki;
wytwornie::licznik_wytwornie--;
}
// *********************** Funkcje Globalne klasy - gatunki *********************** //
void stworz(gatunki **&nowy, int ile)
{
nowy = new gatunki *[ile];
for(int i = 0; i < ile; i++){
nowy[i] = new gatunki;
}
}
void dodaj(gatunki **&nowy, int ile)
{
czy_zwolniono_pamiec_kat = true;
string temp;
for(int i = 0; i < ile; i++){
temp = rand() % 10 + 65;
nowy[i]->dodaj(temp, i + 1, 0);
}
}
void edytuj(gatunki **&nowy, int ile)
{
string e_tytul_utwor;
int e_numer, e_rabat;
ile--;
cout << "Podaj tytul gatunkiu: ";
cin >> e_tytul_utwor;
cout << "Wprowadz nowy numer:";
cin >> e_numer;
cout << "Wprowadz rabat:";
cin >> e_rabat;
nowy[ile]->dodaj(e_tytul_utwor, e_numer, e_rabat);
gatunki::licznik_gatunki--;
}
void wyswietl(gatunki **&nowy, int ile)
{
cout << "\nNazwa\tRok";
for(int i = 0; i < ile; i++){
nowy[i]->wyswietl();
}
}
void usun(gatunki **&nowy, int &ile)
{
for(int i = 0; i < ile; i++){
delete nowy[i];
}
delete [] nowy;
ile = 0;
gatunki::licznik_gatunki = 0;
czy_zwolniono_pamiec_kat = false;
}
void przesun(gatunki **&nowy, int ile, int &rozmiar)
{
ile--;
rozmiar++;
int i = 0;
gatunki **temp_gatunki;
stworz(temp_gatunki, rozmiar);
for(i; i < ile; i++){
temp_gatunki[i] = nowy[i];
}
i++;
temp_gatunki[ile]->dodaj("Kat", 8, 0);
for(i; i < rozmiar; i++){
temp_gatunki[i] = nowy[i - 1];
}
if(czy_zwolniono_pamiec_kat)
delete [] nowy;
stworz(nowy, rozmiar);
for(i = 0; i < rozmiar; i++){
nowy[i] = temp_gatunki[i];
}
czy_zwolniono_pamiec_kat = true;
delete [] temp_gatunki;
}
void usun_jeden_element(gatunki **&nowy, int ile, int &rozmiar)
{
ile--;
rozmiar--;
int i = 0;
gatunki **temp_gatunki;
stworz(temp_gatunki, rozmiar);
for(i; i < ile; i++){
temp_gatunki[i] = nowy[i];
}
for(i; i < rozmiar; i++){
temp_gatunki[i] = nowy[i + 1];
}
delete [] nowy;
stworz(nowy, rozmiar);
for(i = 0; i < rozmiar; i++){
nowy[i] = temp_gatunki[i];
}
delete [] temp_gatunki;
gatunki::licznik_gatunki--;
}
// *********************** Funkcje Globalne: ROZNE *********************** //
int zaplata(album album, gatunki **&kat)
{
int zaplata = 50;
for(int i = 0; i < gatunki::licznik_gatunki; i++) {
if(album.ktory_gatunki == kat[i]->numer) {
zaplata = kat[i]->cena - kat[i]->rabat;
break;
}
}
return zaplata;
}
// *********************** Funkcje Globalne: pod-menu *********************** //
void menu_album();
void menu_gatunki();
void menu_wytwornie();
void menu_zloz_zamowienie();
// *********************** Zmienne Globalne *********************** //
int i, rozmiar, wybor = 0;
bool wyjscie = true;
int main()
{
srand((unsigned)time(NULL));
while(wyjscie)
{
cout << "\n-----------------------\n";
cout << "1. Zarzadzanie albumami \n2. Zarzadzanie gatunkiami \n3. Wytwornie "
"\n4. Zloz zamowienie \n5. Pokaz kontener \n6. Wyjscie\n";
cin >> wybor;
switch(wybor){
case 1:
import(tab_wsk);
menu_album();
break;
case 2:
menu_gatunki();
break;
case 3:
menu_wytwornie();
break;
case 4:
menu_zloz_zamowienie();
break;
case 5:
pokaz_roznice();
break;
case 6:
wyjscie = false;
break;
default:
cout << "\n-----------------------\n";
cout << "\nZly wybor\n";
break;
}
}
}
// *********************** Pod-menu *********************** //
void menu_album()
{
bool wyjscie = true, imp_exp = true;
int wybor, i, rozmiar = album::licznik_album=0;
while(wyjscie)
{
cout << "\n-----------------------\n";
cout << "Pod-menu: klasy Album\n";
cout << "1. Dodaj Album\n2. Edytuj Album\n3. Zwolnij pamiec Albumy\n4. Wyswietl Album"
<<"\n5. Dodaj obiekt\n6. Usun obiekt \n7. Pokaz utwory danej plyty \n8. Glowne menu \n\n9. Export \n10. Import \n11. Duplikat \n";
cin >> wybor;
switch(wybor){
case 1:
cout << "\n-----------------------\n";
cout << "Ile albumow chcesz dodac? ";
cin >> rozmiar;
if(rozmiar > 0){
stworz(tab_wsk, rozmiar);
dodaj(tab_wsk, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Podales nieprawidlowy wymiar, sproboj ponownie...\n";
}
break;
case 2:
cout << "\n-----------------------\n";
cout << "Ktory gatunki edytowac? ";
cin >> i;
if(rozmiar && i <= rozmiar && i > 0){
cin >> tab_wsk[i];
} else {
cout << "\n-----------------------\n";
cout << "Podales nieprawidlowy wymiar lub tablica jest pusta, sproboj ponownie...\n";
}
break;
case 3:
if(rozmiar){
usun(tab_wsk, rozmiar);
} else {
cout << "Tablica pusta\n";
}
break;
case 4:
if(rozmiar){
cout << "\n-----------------------\n";
cout << tab_wsk;
} else {
cout << "\n-----------------------\n";
cout << "Brak obiektow\n";
}
break;
case 5:
int indeks;
cout << "\n-----------------------\n";
cout << "Podaj indeks nowego obiektu: ";
cin >> indeks;
if(indeks <= rozmiar + 1 && indeks > 0){
przesun(tab_wsk, indeks, rozmiar);
cout << tab_wsk;
} else {
cout << "\n-----------------------\n";
cout << "\n(Zly indeks, lub tablica nie istnieje!)\n\n";
}
break;
case 6:
int i_usun;
cout << "\n-----------------------\n";
cout << "Ktory element usunac: ";
cin >> i_usun;
if((rozmiar) && (i_usun <= rozmiar && i_usun > 0)){
usun_jeden_element(tab_wsk, i_usun, rozmiar);
cout << tab_wsk;
} else {
cout << "\n-----------------------\n";
cout << "\n(Zly indeks, lub tablica nie istnieje!)\n\n";
}
break;
case 7:
int indeks_albumu;
cout << "\n-----------------------\n";
cout << "Ktora plyte pokazac?";
cin >> indeks_albumu;
if(rozmiar)
wyswietl_utwory(tab_wsk, indeks_albumu);
else
cout << "\n-----------------------\n(Zly indeks, lub tablica nie istnieje!)\n";
break;
case 8:
wyjscie = false;
break;
case 9:
if(rozmiar)
imp_exp = eksport(tab_wsk);
if(!imp_exp)
cout << "Blad eksportu!\n";
else
cout << "Eksport sie powiodl!\n";
break;
case 10:
imp_exp = import(tab_wsk);
rozmiar = album::licznik_album;
if(!imp_exp)
cout << "Blad importu!\n";
else
cout << "Import sie powiodl!\n";
break;
default:
cout << "\n-----------------------\n";
cout << "\nZly wybor\n";
break;
case 11:
if(rozmiar)
duplikat(tab_wsk);
break;
}
}
}
void menu_gatunki()
{
bool wyjscie = true;
int wybor, i, rozmiar = gatunki::licznik_gatunki;
while(wyjscie)
{
cout << "\n-----------------------\n";
cout << "Pod-menu: klasy Ktalog\n";
cout << "1. Dodaj gatunki \n2. Edytuj gatunki \n3. Zwolnij pamiec \n4. Wyswietl gatunkii "
<<"\n5. Dodaj obiekt\n6. Usun obiekt \n7. Glowne menu\n";
cin >> wybor;
switch(wybor){
case 1:
cout << "\n-----------------------\n";
cout << "Ile gatunkiow chcesz dodac? ";
cin >> rozmiar;
if(rozmiar > 0){
stworz(tab_gatunki, rozmiar);
dodaj(tab_gatunki, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Podales nieprawidlowy wymiar, sproboj ponownie...\n";
}
break;
case 2:
cout << "\n-----------------------\n";
cout << "Ktory gatunki edytowac? ";
cin >> i;
if(rozmiar && i <= rozmiar && i > 0){
edytuj(tab_gatunki, i);
} else {
cout << "\n-----------------------\n";
cout << "Podales nieprawidlowy wymiar lub tablica jest pusta, sproboj ponownie...\n";
}
break;
case 3:
if(rozmiar){
usun(tab_gatunki, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Tablica pusta\n";
}
break;
case 4:
if(rozmiar){
cout << "\n-----------------------\n";
wyswietl(tab_gatunki, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Brak obiektow\n";
}
break;
case 5:
int indeks;
cout << "\n-----------------------\n";
cout << "Podaj indeks nowego obiektu: ";
cin >> indeks;
if((indeks <= rozmiar + 1) && (indeks > 0)){
przesun(tab_gatunki, indeks, rozmiar);
wyswietl(tab_gatunki, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "\n(Zly indeks, lub tablica nie istnieje!)\n\n";
}
break;
case 6:
int i_usun;
cout << "\n-----------------------\n";
cout << "Ktory element usunac: ";
cin >> i_usun;
if((rozmiar) && (i_usun <= rozmiar && i_usun > 0)){
usun_jeden_element(tab_gatunki, i_usun, rozmiar);
wyswietl(tab_gatunki, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "\n(Zly indeks, lub tablica nie istnieje!)\n\n";
}
break;
case 7:
wyjscie = false;
break;
default:
cout << "\n-----------------------\n";
cout << "\nZly wybor\n";
break;
}
}
}
void menu_wytwornie()
{
bool wyjscie = true;
int wybor, i, rozmiar = wytwornie::licznik_wytwornie;
while(wyjscie)
{
cout << "\n-----------------------\n";
cout << "Pod-menu: klasy wytwornie\n";
cout << "1. Dodaj wytwornie \n2. Edytuj wytwornie \n3. Zwolnij pamiec \n4. Wyswietl wytwornie "
<<"\n5. Dodaj wytwornie\n6. Usun wytwornie \n7. Glowne menu\n";
cin >> wybor;
switch(wybor){
case 1:
cout << "\n-----------------------\n";
cout << "Ile wytworni chcesz dodac? ";
cin >> rozmiar;
if(rozmiar > 0){
stworz(tab_wytwornie, rozmiar);
dodaj(tab_wytwornie, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Podales nieprawidlowy wymiar, sproboj ponownie...\n";
}
break;
case 2:
cout << "\n-----------------------\n";
cout << "Ktory gatunki edytowac? ";
cin >> i;
if(rozmiar && i <= rozmiar && i > 0){
edytuj(tab_wytwornie, i);
} else {
cout << "\n-----------------------\n";
cout << "Podales nieprawidlowy wymiar lub tablica jest pusta, sproboj ponownie...\n";
}
break;
case 3:
if(rozmiar){
usun(tab_wytwornie, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Tablica pusta\n";
}
break;
case 4:
if(rozmiar){
cout << "\n-----------------------\n";
wyswietl(tab_wytwornie, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "Brak obiektow\n";
}
break;
case 5:
int indeks;
cout << "\n-----------------------\n";
cout << "Podaj indeks nowego obiektu: ";
cin >> indeks;
if((indeks <= rozmiar + 1) && (indeks > 0)){
przesun(tab_wytwornie, indeks, rozmiar);
wyswietl(tab_wytwornie, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "\n(Zly indeks, lub tablica nie istnieje!)\n\n";
}
break;
case 6:
int i_usun;
cout << "\n-----------------------\n";
cout << "Ktory element usunac: ";
cin >> i_usun;
if((rozmiar) && (i_usun <= rozmiar && i_usun > 0)){
usun_jeden_element(tab_wytwornie, i_usun, rozmiar);
wyswietl(tab_wytwornie, rozmiar);
} else {
cout << "\n-----------------------\n";
cout << "\n(Zly indeks, lub tablica nie istnieje!)\n\n";
}
break;
case 7:
wyjscie = false;
break;
default:
cout << "\n-----------------------\n";
cout << "\nZly wybor\n";
break;
}
}
}
void menu_zloz_zamowienie()
{
bool wyjscie = true;
int wybor, i, j = -1;
string nazwa;
int rok_wyd;
int koszt;
while(wyjscie)
{
cout << "\n-----------------------\n";
cout << "Menu Zloz zamowienie\n";
cout << "1. Wypelnij formularz \n2. Wyslij zgloszenie\n3. Glowne menu\n";
cin >> wybor;
switch(wybor){
case 1:
if(tab_wsk){
cout << "\n-----------------------\n";
cout << tab_wsk;
cout << "Podaj nazwe: ";
cin >> nazwa;
cout << "Podaj roj wydania: ";
cin >> rok_wyd;
j = znajdz_album(tab_wsk, nazwa, rok_wyd);
} else {
cout << "\n-----------------------\n";
cout << "Brak obiektow\n";
}
break;
case 2:
if(j >= 0) {
cout << "Czy napewno chcesz zamowic ten album? \n "
"Jesli tak wcisnij [1] jesli nie [0]\n";
cin >> i;
if(i) {
koszt = zaplata(tab_wsk[j], tab_gatunki);
cout << "Do zaplaty: " << koszt << endl;
}
} else {
cout << "Brak wskazanego albumu\n";
}
break;
case 3:
wyjscie = false;
break;
default:
cout << "\nZly wybor\n";
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment