Kashub's Code Barn - "Kodzik"

podświetlone jako vbnet (dodał(a) Pingwin @ 2013-06-07 18:00:03)

Twoja wyszukiwarka
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
//*******************************Sekcja bibliotek*********************************************
#include <iostream>
#include <windows.h> //np do uzywania beep xD
#include <string.h>
#include <fstream>
#include <conio.h>
using namespace std;
 
//*******************************Sekcja struktury*********************************************
 
struct BOOKS //struktura wydawnictw
{
string tytul;
string imie;
string nazwisko;
string wydawnictwo;
string rok_wydania;
string isbn;
BOOKS *next;		//tworzy wskaznik next ktory wskazuje na str Book
};
 
 
//*******************************Sekcja Funkcji*********************************************
 
void ADD_BOOK(BOOKS *&head, string Tytul, string Imie, string Nazwisko,
string Wydawnictwo, string Rok_wydania, string Isbn, int Lp)
{
 
BOOKS *temp=new BOOKS;		//Trudna linijka :D Tworzy wskaznik ktory ma wskazywac na NOWA strukture. Stad tez new book
BOOKS *help;		//pomocny wskaznik 
int iteracja=0;
help=head;		//od tej pory help wskazuje na nasza strukture
 
temp->tytul=Tytul;
temp->imie=Imie;
temp->nazwisko=Nazwisko;
temp->wydawnictwo=Wydawnictwo;
temp->rok_wydania=Rok_wydania;
temp->isbn=Isbn;
if(Tytul==""){temp->tytul="-";}
if(Imie==""){temp->imie="-";}
if(Nazwisko==""){temp->nazwisko="-";}
if(Wydawnictwo==""){temp->wydawnictwo="-";}
if(Rok_wydania==""){temp->rok_wydania="-";}
if(Isbn==""){temp->isbn="-";}
if(head==NULL || Lp==0)
{
temp->next=head;	//Wskazniokowi temp przypisujemy nastepna pozycje head - cos takiego. dziffffne to :D 
head=temp;
temp=NULL;	//zerujemy wskaznik temp
}else
{
while(help!=NULL)
{
if(help->next==NULL)
{
temp->next=NULL;
help->next=temp;
break;
}else
{
if(iteracja==Lp-1)
{
temp->next=help->next;
help->next=temp;
break;
}
}
help=help->next;
iteracja++;
}
}
}
void DEL_BOOK(BOOKS *&head, int Lp)
{
if(head!=NULL)		//jesli struktura istnieje
{
BOOKS *temp, *help;
int iteracja=0;
temp=head;		//temp przypiuje head.... zas temp to wskaznik
if(Lp==0)
{
head=temp->next;
delete temp;		//Kasuje temp
}else
{
while(temp->next!=NULL)		//dopoki kolejny element temp nie jest 0 wykonuj:
{
if(iteracja==Lp-1)
{
if(temp->next->next==NULL)		//analogicznie jak wyzej
{
help=temp->next;
temp->next=NULL;
delete help;
break;
}else
{
help=temp->next;
temp->next=temp->next->next;
delete help;
break;
}
}
iteracja++;
temp=temp->next;
}
}
}
}
void DEL_ALL_BOOKS(BOOKS *&head)
{
if(head!=NULL)
{
BOOKS *temp=head;
BOOKS *help=head;
while(help!=NULL)
{
temp=help;
help=temp->next;
head=temp->next;
delete temp;
}
head=NULL;
}
}
void EDIT_BOOK(BOOKS *&head, int Lp)
{
if(head!=NULL)
{
cin.sync();
bool find=false;
BOOKS *temp=head;
int iterator=0;
while(temp!=NULL)
{
if(iterator==Lp)
{
string Tytul;
string Imie;
string Nazwisko;
string Wydawnictwo;
string Rok_wydania;
string Isbn;
cout<<"Tytul: ";getline(cin,Tytul);
cout<<"Imie: ";getline(cin,Imie);
cout<<"Nazwisko: ";getline(cin,Nazwisko);
cout<<"Wydawnictwo: ";getline(cin,Wydawnictwo);
cout<<"Rok_wydania: ";getline(cin,Rok_wydania);
cout<<"Isbn: ";getline(cin,Tytul);
temp->tytul=Tytul;
temp->imie=Imie;
temp->nazwisko=Nazwisko;
temp->wydawnictwo=Wydawnictwo;
temp->rok_wydania=Rok_wydania;
temp->isbn=Isbn;
find=true;
 
break;
}else
find=false;
 
temp=temp->next;
iterator++;
}
}
}
void EXPORT_BOOKS(BOOKS *&head, string Name_fils)
{
fstream file(Name_fils.c_str(), ios::out );
if( file.good() )
{
BOOKS *temp=head;
while(temp!=NULL)
{
file<<temp->tytul<<endl<<temp->imie<<endl<<temp->nazwisko<<endl<<
temp->wydawnictwo<<endl<<temp->rok_wydania<<
endl<<temp->isbn<<endl<<"**************"<<endl;
temp=temp->next;
}
file.close();
}else
cout<<"nie można utworzyc pliku"<<endl;
 
file.close();
}
void INPORT_BOOKS(BOOKS *&head,string Name_fils)
{
system("CLS");
fstream file;
file.open( Name_fils.c_str());
int a;
int iterator=0;
string Tytul;
string Imie;
string Nazwisko;
string Wydawnictwo;
string Rok_wydania;
string Isbn;
string spr;
 
if( file.good() )
{
while(!file.eof())
{
 
getline(file,Tytul);
getline(file,Imie);
getline(file,Nazwisko);
getline(file,Wydawnictwo);
getline(file,Rok_wydania);
getline(file,Isbn);
getline(file,spr);
ADD_BOOK(head, Tytul,Imie, Nazwisko,
Wydawnictwo,Rok_wydania,Isbn,iterator);
iterator++;
}
file.close();
cout<<"Rekordy zostaly zaladowane\n\n";
}else
cout<<"nie ma takiego pliku"<<endl;
 
file.close();
}
void VIEW(BOOKS *&temp)
{
 
if(temp!=NULL){
 
cout<<"TYTUL :\t\t"<<temp->tytul<<endl;
cout<<"AUTOR :\t\t"<<temp->imie<<" "<<temp->nazwisko<<endl;
cout<<"WYDAWNICTWO :\t"<<temp->wydawnictwo<<endl;
cout<<"ROK :\t\t"<<temp->rok_wydania<<endl;
cout<<"ISBN :\t\t"<<temp->isbn<<"\n*********************************************"<<endl;
cout<<endl<<endl;
}
else
cout<<"Brak rekordow do wyswietlenia";
 
}
 
void VIEW2(BOOKS *&temp)		//Moja funkcyja :D
{
 
if(temp!=NULL){
 
cout<<"\t"<<temp->tytul<<endl;
 
}
else
cout<<"Brak rekordow do wyswietlenia";
 
}
 
void TITLE(BOOKS *&head) 		//takie cos napisane przezemnie :P
{
system("CLS");
int iteracja=0;
if(head!=NULL)
{
BOOKS *temp= head;
while(temp!=NULL)
{
cout<<"\t"<<iteracja;// <<endl;
VIEW2(temp);
temp=temp->next;
iteracja++;
}
}
}
 
 
void SHOW_ONE_BOOK(BOOKS *&head, int Which)
{
if(head!=NULL)
{
BOOKS *temp= head;
int iterator=0;
system("CLS");
while(temp!=NULL)
{
if(iterator==Which)
{
VIEW(temp);
}
temp=temp->next;
iterator++;
}
 
}
}
void FIND_BOOKS(BOOKS *&head, string Parametr)
{
 
 
string word;
int iterator=0;
int pozycja=0;
EXPORT_BOOKS(head,"temp.txt");
fstream file("temp.txt");
while(!file.eof())  		//eof to end of file czyli wykonuj dopoki nie ma znaku konca pliku
{
file>>word;
if(word==Parametr)
{
cout<<"slowo znalezione zostalo w pozycji:"<<endl;
SHOW_ONE_BOOK(head, pozycja);
}
if(word=="**************")
{
pozycja++;
}
}
 
 
}
 
void SHOW_ALL_BOOK(BOOKS *&head)
{
int iteracja=0;
if(head!=NULL)
{
BOOKS *temp= head;
while(temp!=NULL)
{
cout<<"ID "<< iteracja <<endl;
VIEW(temp);
temp=temp->next;
iteracja++;
}
}
}
 
int main()
{
BOOKS *head; 	//wskaznik head na strukture
head=NULL;		//ustawiamy wskaznik na zero
int stop=0;
for(;;) //petla for działająca w nieskonczonosc
{
 
cout<<"MENU"<<endl;
cout<<"\n0-Wyczysc\n1-Dodaj\n2-Usun\n3-Edytuj\n4-Eksportuj\n5-Importuj\n6-Znajdz\n7-Pokaz wszystkie\n8-Pokaz pojedynczy rekord\n9-Zakoncz"<<endl;
char choice;
//system("CLS");
choice=getch();		//dzieki temu bajerowi mozna wybrac opcje np 2 bez potwierdzania jej jak w przypadku cin>>
int pozycja=0;
 
switch(choice)
{
 
case '0':
{
system("CLS");
}break;
 
case '1':
{
system("CLS");
cin.sync();
string Tytul;
string Imie;
string Nazwisko;
string Wydawnictwo;
string Rok_wydania;
string Isbn;
cout<<"Tytul: ";getline(cin,Tytul);
cout<<"Imie: ";getline(cin,Imie);
cout<<"Nazwisko: ";getline(cin,Nazwisko);
cout<<"Wydawnictwo: ";getline(cin,Wydawnictwo);
cout<<"Rok_wydania: ";getline(cin,Rok_wydania);
cout<<"Isbn: ";getline(cin,Isbn);
cout<<"Pozycja (typ int)"<<endl;
cin>>pozycja;
ADD_BOOK(head, Tytul, Imie, Nazwisko,
Wydawnictwo, Rok_wydania, Isbn, pozycja);
system("CLS");
}break;
case '2':
{
cin.sync();		//czysci bufor pamieci. Tak na wypadek by nie zaladowalo np 5... bo usunie wtedy pozycje 5 mimo ze tego nie chcemy
 
 
 
system("CLS");
if(*&head==NULL) {	//jesli head (czyli wskaznik do struktury) wskazuje na zero to
cout<<"\nBrak ksiazek\n\n";Beep(300,200);}
else {
SHOW_ALL_BOOK(head);		//wywolanie funkcji
cout<<"\n******************\nPodaj Pozycje ktora chcesz skasowac: ";cin>>pozycja;
char znak;
cout<<"Czy napewno chcesz usunac pozycje t/n\n";
znak=getch();
if(znak=='t' ){
 
SHOW_ONE_BOOK(head, pozycja);
DEL_BOOK(head, pozycja);
}
else {
system("CLS");
cout<<"\nRekord NIE zostal usuniety\n\n";
}
}
}break;
case '3':
{
cin.sync();
int pozycja=0;
cout<<"\n*******************\nPodaj Pozycje ktora chcesz edytowac: ";cin>>pozycja;
EDIT_BOOK(head, pozycja);
}break;
case '4':
{
cin.sync();
string file_name;
//cout<<"Podaj nazwe pliku: ";cin>>file_name;
file_name="Baza_Danych.txt";
INPORT_BOOKS(head,file_name);
}break;
case '5':
{
cin.sync();
string file_name;
file_name="Baza_Danych.txt";
EXPORT_BOOKS(head,file_name);
cout<<"Dane zostaly dodane do pliku oraz bufor pamieci zostal wyczyszczony\n***************************"; Beep(300,200);
DEL_ALL_BOOKS(head);
}break;
case '6':
{
cin.sync();
string parametr;
cout<<"Podaj slowo które wyszukac: ";cin>>parametr;
FIND_BOOKS(head, parametr);
 
}break;
case '7':
{
system("CLS");
if(*&head==NULL) {
cout<<"\nBrak ksiazek do wyswietlenia\n\n";Beep(300,200);}
else {
cout<<"**********Ksiazki**********";
SHOW_ALL_BOOK(head);
}
}break;
case '8':
{
cin.sync();
TITLE(head);
int which;
cout<<"\n********************\nPodaj pozycje do wyswietlenia: ";cin>>which;
SHOW_ONE_BOOK(head, which);
}break;
case '9':
stop=1;
break;
 
 
default:
break;
 
 
}
if(stop==1)
{
break;
}
}
}
| Katalog Sklepów internetowych | | Sklep z oponami | | Opony motocyklowe | | Opony zimowe | | Opony specjalne | | Sklep z artykułami RTV/AGD | | Wklejacz kodów | | Skracacz adresów | | Smutne Opisy |