Treceți la conținutul principal

agenda tel cpp

#include<stdio.h>
#include<iostream.h>
#include<malloc.h>
#include<string.h>
#include <conio.h>

//definirea clasei persoana
class persoana
{ public:
 char nume[20],locatie[20];
 int telefon;
    persoana(char num[20]="necunoscut", char loc[20]="necunoscuta", int tel=0) 
 {
  strcpy(nume,num);
  strcpy(locatie,loc);
  telefon=tel;
 };

 friend ostream& operator<<(ostream &iesire, persoana &p)
 {
  iesire<<p.nume<<"  "<<p.locatie<<"  "<<p.telefon<<endl;
  return iesire;
 };

 
 friend istream& operator>>(istream &intrare, persoana &p)
 {
  cout<<"Introduceti informatiile "<<"\n";
  cout<<"Nume:  ";   intrare>>p.nume;
  cout<<"Locatie:  ";   intrare>>p.locatie;
  cout<<"Nr telefon:  ";   intrare>>p.telefon;
  return intrare;
 }
 
 int operator ==(persoana a)
 {
  return strcmp(a.nume,nume)==0?1:0;
 }

};

//definirea clasei nod
template <class tip> class nod
{ public:
 tip info;
 nod *next;
};

//definirea clasei lista
template <class tip> class lista
{ friend class agenda;
  public:
 nod<tip> *cap;
 lista() { cap=NULL; }
 lista(const lista<tip>  &l)
 { nod<tip> *p,*aux;
  if (l.cap)
  {
   cap= new nod<tip>;
   cap->info=l.cap->info;
   cap->next=NULL;

      aux=l.cap->next;
   while (aux)
   {
    p=new nod<tip>;
    p->info=aux->info;
    p->next=cap;
    cap=p;
    aux=aux->next;
   }
  }
  else
   cap=NULL;
 }
 
 ~lista() {
  while(cap)
  {
   nod<tip> *temp=cap;
   cap=temp->next;
   delete(temp);
  }
 };


 void inserare(tip inf);
 
 void stergere(tip inf);
 
 friend ostream& operator <<(ostream& ies, lista<tip> l)
 {
  nod<persoana> *aux;
  aux=l.cap;
  while(aux)
  {
  ies<<aux->info.nume<<"  "<<aux->info.locatie<<"  "<<aux->info.telefon<<endl;
  aux = aux->next;
  }
  return ies;
 }
 nod<tip>* operator[](tip inf);
};
//se incheie definirea

template <class tip> void lista<tip>::inserare(tip inf)
{
 nod<tip> *nou;
 nou = new nod<tip>;
 nou->info=inf;
 nou->next=cap;
 cap=nou;
}


template <class tip> void lista<tip>::stergere(tip inf)
{ nod<tip> *temp, *aux;
 if(cap)
 {   temp = cap;

  if(cap->info==inf)
  {
   cap=temp->next;
   delete(temp);
  }
  else
  { while(temp->next)
   {
    aux=temp->next;
    if (aux->info==inf)
    {
     temp->next=aux->next;
     delete(aux);
    }
    else temp=temp->next;

   }
  }
 }
};

template <class tip> nod<tip>* lista<tip>::operator[](tip inf)
{
 nod<tip> *temp=cap;
 while(temp)
 {
  if(inf==temp->info) return temp;
  temp=temp->next;
 }
 return NULL;
};

//definirea clasei agenda
class agenda
{ public:
  friend class lista<persoana>;
  lista<persoana> lprim,lsortn,lsortl,lsortt;
  bool altalista(lista<persoana> *caps,nod<persoana> *aux);
  void sortnume();
  void sortlocatie();
  void sorttelefon();
     nod<persoana>* operator<<(int tel);
  nod<persoana>* operator>>(int tel);
     friend ostream& operator<<(ostream &ies,agenda a)
  { 
  nod<persoana> *aux;
  aux=a.lsortn.cap;
  while(aux)
  {
  ies<<aux->info.nume<<"  "<<aux->info.locatie<<"  "<<aux->info.telefon<<endl;
  aux = aux->next;
  }
  return ies;
  };

  nod<persoana> * search(char abv[20])
  {
   nod<persoana> *p;
   
   for(p=lsortn.cap; p && !strstr(p->info.nume,abv); p=p->next);

   return p;
  }
    
   

};


nod<persoana>* agenda::operator <<(int tel)
{
 if(tel==lsortt.cap->info.telefon)return NULL;
  else
  {
    nod<persoana> *temp=lsortt.cap->next;
   if(tel==temp->info.telefon) return lsortt.cap;
   else
   {
    nod<persoana> *aux=temp;
    temp=temp->next;

    while(!temp)
     if(tel==temp->info.telefon) return aux;
     else
     {
      aux=temp;
      temp=temp->next;
     }
   }
  }
}


nod<persoana>* agenda::operator >>(int tel)
{
 if (lsortt.cap)
 {
  if(tel==lsortt.cap->info.telefon)
   return lsortt.cap->next;
  else
  {nod<persoana> *temp=lsortt.cap->next;
   while(temp)
   if(tel==temp->info.telefon)
    return temp->next;
   else
    temp=temp->next;
  }
 }
}



void agenda::sortnume()
{
 nod<persoana> *p;

 if(lprim.cap)
 {
  //Daca mai avem inainte o lista, o stergem
  if (lsortn.cap)
   while (lsortn.cap)
   {
    p=lsortn.cap;
    lsortn.cap=lsortn.cap->next;
    delete p;
   }
  else
  //o facem
  {
   nod<persoana> *aux;
   
   for(p=lprim.cap; p; p=p->next)
   {
    aux=new nod<persoana>;//aux este nodul pe care-l copii din lprim in lsortn
    strcpy(aux->info.nume, p->info.nume);
    strcpy(aux->info.locatie, p->info.locatie);
    aux->info.telefon=p->info.telefon;

    nod<persoana> *temp, *trace;
    //asta daca e primul nod
    if (!lsortn.cap)
    {
     lsortn.cap=aux;
     aux->next=NULL;
    }
    else
    {

     temp=lsortn.cap;
     trace=NULL;

     while (temp && (strcmp(aux->info.nume,temp->info.nume)<0))
     {
      trace=temp;
      temp=temp->next;
     }

     if (!temp)
     //adaug la sfarsit
     {
      aux->next=NULL;
      trace->next=aux;
     }
     else
     //adaug in interior
      if (trace)
      {
       aux->next=trace->next;
       trace->next=aux;
      }
      else
      //daca e la inceput
      {
       aux->next=lsortn.cap;
       lsortn.cap=aux;
      }
    }
   }
  }
 }
 else lsortn.cap=NULL;
}


void agenda::sortlocatie()
{

 nod<persoana> *p;

 if(lprim.cap)
 {
  //Daca mai avem inainte o lista, o stergem
  if (lsortl.cap)
   while (lsortl.cap)
   {
    p=lsortl.cap;
    lsortl.cap=lsortl.cap->next;
    delete p;
   }
  else
  //o facem
  {
   nod<persoana> *aux;
   
   for(p=lprim.cap; p; p=p->next)
   {
    aux=new nod<persoana>;//aux este nodul pe care-l copiez din lprim in lsortl
    strcpy(aux->info.nume, p->info.nume);
    strcpy(aux->info.locatie, p->info.locatie);
    aux->info.telefon=p->info.telefon;

    nod<persoana> *temp, *trace;
    //asta daca e primul nod
    if (!lsortl.cap)
    {
     lsortl.cap=aux;
     aux->next=NULL;
    }
    else
    {

     temp=lsortl.cap;
     trace=NULL;

     while (temp && (strcmp(aux->info.locatie,temp->info.locatie)<0))
     {
      trace=temp;
      temp=temp->next;
     }

     if (!temp)
     //adaug la sfarsit
     {
      aux->next=NULL;
      trace->next=aux;
     }
     else
     //adaug in interior
      if (trace)
      {
       aux->next=trace->next;
       trace->next=aux;
      }
      else
      //daca e la inceput
      {
       aux->next=lsortl.cap;
       lsortl.cap=aux;
      }
    }
   }
  }
 }
 else lsortl.cap=NULL;

 }


void agenda::sorttelefon()
{

 nod<persoana> *p;

 if(lprim.cap)
 {
  //Daca mai avem inainte o lista, o stergem
  if (lsortt.cap)
   while (lsortt.cap)
   {
    p=lsortt.cap;
    lsortt.cap=lsortt.cap->next;
    delete p;
   }
  else
  //o facem
  {
   nod<persoana> *aux;
   
   for(p=lprim.cap; p; p=p->next)
   {
    aux=new nod<persoana>;//aux este nodul pe care-l copii din lprim in lsortt
    strcpy(aux->info.nume, p->info.nume);
    strcpy(aux->info.locatie, p->info.locatie);
    aux->info.telefon=p->info.telefon;

    nod<persoana> *temp, *trace;
    //asta daca e primul nod
    if (!lsortt.cap)
    {
     lsortt.cap=aux;
     aux->next=NULL;
    }
    else
    {

     temp=lsortt.cap;
     trace=NULL;

     while (temp && (aux->info.telefon<temp->info.telefon))
     {
      trace=temp;
      temp=temp->next;
     }

     if (!temp)
     //adaug la sfarsit
     {
      aux->next=NULL;
      trace->next=aux;
     }
     else
     //adaug in interior
      if (trace)
      {
       aux->next=trace->next;
       trace->next=aux;
      }
      else
      //daca e la inceput
      {
       aux->next=lsortt.cap;
       lsortt.cap=aux;
      }
    }
   }
  }
 }
 else lsortt.cap=NULL;

 }


void main()
{
 persoana p1,p2("diana","constanta",643321),p3("anca","bucuresti",3215464),p4("ionut","targoviste",344988);
 lista<persoana> list;
 agenda a;
 cin >>p1;
 cout<<"\n\nPersoanele introduse :"<<endl;
 cout <<p1<<p2<<p3<<p4;
 
 a.lprim.inserare(p1);
 a.lprim.inserare(p2);
 a.lprim.inserare(p3);
 a.lprim.inserare(p4);

 //creeaza lista sortata dupa nume
 a.sortnume();
 cout<<"\n\nAfisarea persoanelor sortate dupa nume:"<<endl;
 cout<<a.lsortn;

 //creeaza lista sortata dupa nr de telefon
 a.sortlocatie();
 
    //cauta  o persoana
 nod<persoana> *p;
 p=a.lprim[p1];
    if(p) { cout<<"\n\nPersoana cautata a fost gasita: "<<endl;
      cout<<p->info.nume<<endl; }
 else cout<<"\n\nPersoana cautata nu exista!"<<endl;
 
 //cautarea unei persoane dupa un subsir din nume
 p=a.search("di");
 if(p) { cout<<"\n\nPersoana cu abrevierea data este:"<<endl;
      cout<<p->info.nume<<endl; }
 else cout<<"\n\nPersoana cu abrevierea data nu exista!"<<endl;

 //sterg din lista sortata dupa nume
 a.lsortn.stergere(p3);
 cout<<"\n\nPersoanele ramase in agenda dupa stergere:"<<endl;
 cout<<a;

 getch();
}

Comentarii

Postări populare de pe acest blog

WINDOWS 10 COMPUTER FREEZING PROBLEM SOLVED

good news : a BIOS UPDATE can resolve the problem but just for a Windows 7 on 64 bits o.s. and the system is not stable all the time. even after  bios update the system can freeze.
new info : u can try to low the screen brightness and see if this error appear so often after 
news: last info !!! maybe a virus. scann our system now with an antivirus i generate this error using other device ( a tablet pc) connected in the same network and the laptop i have this problem just freeze  http://thehackernews.com/2013/10/backdoor-found-in-chinese-tenda.html

news : if u use a tenda router this make couse all this problems



what i discover so far :
1.the electric company have many failure and affect the main ISP router/switch for building  also the router/switch installed by the ISP may be affected by overheating and will crash after a long utilisation on heat conditions 2.the router/switch of ISP affect any router of the user between this router and pc/laptop of client 3.the router and any other device of t…

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…