Treceți la conținutul principal

studenti cpp

//----------------TOMOZEI LUCIANA MARIA--------------
//----------------1067-------------------------------
//----------------BILET NR 9: CLASA LISTA, CLASA STUDENT 






#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
#include <io.h>



class student
 {
 public:
  char nume_stud[30];
  int nr_matricol;
  int an_studiu;
  int temp;
  int nr_note;
  float note[30];

    //Constructorul contine un vector de note care trebuiesc introduse de la tastatura(Nu am reusit
    //sa initializez elementele vectorului)

  student(char n[30]="Anonim",int nr=0,int as=1,int tm=1,int nrn=1.)
  {strcpy(nume_stud,n);nr_matricol=nr;an_studiu=as;temp=tm;nr_note=nrn;
         if((nr_matricol==0)&&(nr_note==1))note[0]=0;
         else
         {
         for(int i=0;i<nrn;i++)
         {
   cout<<"\nNota "<<i+1<<" pentru "<<nume_stud<<":";
   cin>>note[i];
         }}}

  //Supraincaracari pentru operatii de intrare-iesire la nivel de student

  friend istream &operator>>(istream &i,student &s)
  {
   cout<<"Nume:";i>>s.nume_stud;
   cout<<"\nNumar matricol:";i>>s.nr_matricol;
   cout<<"\nAnul de studiu:";i>>s.an_studiu;
   cout<<"\nObiect temporar(0 sau 1):";
   int vb;
   do
   {
   vb=0;
   i>>s.temp;
   if(s.temp>1)
    {
    cout<<"Data invalida!";
    vb=1;
    }
   }
   while(vb==1);
   cout<<"\nNumarul de note:";i>>s.nr_note;
   for(int j=0;j<s.nr_note;j++)
   {
   cout<<"\nNota "<<j+1<<":";
   i>>s.note[j];}
   return i;
  }

  friend ostream &operator<<(ostream &o,student s)
  {
   cout<<"Nume:";o<<s.nume_stud;
   cout<<"\nNr. matricol:";o<<" "<<s.nr_matricol;
   cout<<"\nAn studiu:";o<<" "<<s.an_studiu;
   cout<<"\nObiect temporar:";o<<" "<<s.temp;
   cout<<"\nNr. note:";o<<" "<<s.nr_note;
   for(int j=0;j<s.nr_note;j++)
   {
   cout<<"\nNota "<<j+1<<":";
   o<<" "<<s.note[j];
   }
   o<<"\n";
   return o;
  }

  void operator<<(float n){nr_note++;note[nr_note-1]=n;}//adaugarea notei n studentului

  void operator++(){an_studiu++;}//promovarea in anul de studiu urmator

  operator float(){float suma=0.0,media=0.0;for(int j=0;j<nr_note;j++)suma+=note[j];media=suma/nr_note;return media;}//cast pentru calcul mediei unui student

  operator char*(){return nume_stud;}//cast pentru extragerea numelui unui student

 };

struct nod
{
 student info;
 nod* next;
};


class lista
 {
  nod* cap;
  nod* creat(nod*);
 public:
  lista()
  {
  cap=NULL;
  }

  lista(lista& lis)
  {
  cap=creat(lis.cap);
  }

  //destructorul asigura atat stergerea listei din memorie,
  //cat si salvarea in fisier a obiectelor student din lista
  //dar doar al ceror care nu exista deja in fisier si care nu
  //sunt temporare

  ~lista()
  {
  nod* temp;
  FILE *f1;
  while(cap)
  {
   temp=cap;
   f1=fopen("STUDENTI.DAT","rb+");
   student s;
   while(!feof(f1))
   {
   fread(&s,sizeof(s),1,f1);
   if(temp->info.nr_matricol==s.nr_matricol)temp->info.temp=1;
   }
   fclose(f1);
   if(temp->info.temp==0)
   {
   f1=fopen("studenti.dat","ab+");
   long t=filelength(fileno(f1));
   fseek(f1,t,SEEK_CUR);
   fwrite(&temp->info,sizeof(temp->info),1,f1);
   fclose(f1);
   cout<<"\nAm salvat in fisier studentul "<<(char*)temp->info;
   }
   cap=cap->next;
   delete temp;
  }
  }

  void operator + (student s) //adaugare de nod
  {
  nod* aux=new nod;
  aux->info=s;
  aux->next=cap;
  cap=aux;
  }

  int operator - (int c)      //stergerea unui nod
  {
  nod* p=cap;
  if(!p) return 0;
  else
   {student s1=p->info;
   if(s1.nr_matricol==c)
   {
    cap=cap->next;
    delete p;
    return 1;
   }
   else
   {
    nod* q=p->next;
    while(q&&q->info.nr_matricol!=c)
    {
     p=q;
     q=q->next;
    }
    if(q)
    {
     p->next=q->next;
     delete q;
     return 1;
    }
    else return 0;
   }
        }
  }

  //afisarea listei

  friend ostream& operator << (ostream& os,lista& lis)
  {
  nod* temp=lis.cap;
  if(!temp)
  {
   os<<" EMPTY";
  }
  else
   printf("NUME     ANUL DE STUDIU    NR. MATRICOL       MEDIA");
   cout<<"\n-------------------------------------------------------------------------------";
   while(temp)
   {
   cout<<temp->info.nume_stud;
   cout<<temp->info.an_studiu;
   cout<<temp->info.nr_matricol;
   cout<<(float)temp->info;
   temp=temp->next;
   }
  os<<endl;
  return os;
  }

  //supraincarcarea operatorului ">>" asigura crearea unei liste
  //cu obiectele salvate in fisier fara a fi temporare

  friend istream& operator >> (istream&is,lista& lis)
  {
  FILE *f1;
  student s;
  f1=fopen("studenti.dat","rb+");
  do
  {
  fread(&s,sizeof(s),1,f1);
  if(s.temp==0)lis+s;
  }
  while(!feof(f1));
  lis-s.nr_matricol;
  fclose(f1);
  return is;
  }

     //functia clasificare ordoneaza studentii pe ani de studiu
     //descrescator dupa medie

  friend void clasificare(lista& lis)
  {
  nod*temp=lis.cap;
  if(!temp||!temp->next)return;
  nod *i,*j;
  student t;
  for(i=temp;i->next;i=i->next)
  for(j=i->next;j;j=j->next)
   if(i->info.an_studiu>j->info.an_studiu)
    {
    t=j->info;
    j->info=i->info;
    i->info=t;
    }
  for(i=temp;i->next;i=i->next)
  for(j=i->next;j;j=j->next)
   if(i->info.an_studiu==j->info.an_studiu)
    if(((float)i->info)<((float)j->info))
    {
    t=j->info;
    j->info=i->info;
    i->info=t;
    }
   }


};



void main()
{
 FILE *f1;
 lista ll,l1;
 system("cls");
 cin>>l1;
 cout<<"Fisierul <studenti.dat> contine urmatoarele date:";
 cout<<l1;
 student s1(" LUCIANA  TOMOZEI",1067,2,0,1);
 student s2("COSMIN TOMOZEI",201,1,1,3);
 student s3,s4,aux;
 cin>>s3;        //introducere date pentru s3
 int y,u=0;
        //Cautarea unui articol student in fisier se face dupa cheia nr_matrico
 cout<<"Introduceti numarul matricol al elevului:";cin>>y;
 if((f1=fopen("studenti.dat","rb+"))==NULL)cout<<"Fisier inexistent!";
 else
 {
 while((u==0)&&!feof(f1))
  {
  fread(&s4,sizeof(s4),1,f1);
  if((s4.nr_matricol==y)&&(s4.temp==0))u=1;
  }
 if(u==0)cout<<"\nInregistrare inexistenta in fisier!";
 else
 {cout<<"\nS-a citit din fisier ";cout<<s4;}
 }
 s3<<7.25;       //adaugarea notei 7.25 studentului s3
 cout<<"\n";
 cout<<s3;cout<<"\n";
 cout<<"\nMedia pentru "<<(char*)s3<<" este "<<(float)s3;    //folosire cast pentru nume student,respectiv medie
 cout<<"\n"<<"Anul de studiu pentru studentul "<<s1.nume_stud<<" este "<<s1.an_studiu;
 cout<<"\n"<<"Anul de studiu pentru studentul "<<s2.nume_stud<<" este "<<s2.an_studiu;
 ++s1;    //promovare student s1 si s2
 ++s2;
 cout<<"\n"<<"Noul an de studiu pentru studentul "<<s1.nume_stud<<" este\n "<<s1.an_studiu;
 cout<<"\n"<<"Noul an de studiu pentru studentul "<<s2.nume_stud<<" este\n "<<s2.an_studiu;
 cout<<"\nApasati o tasta\n";getch();
system("cls");
 ll+s1;ll+s2;ll+s3;     //adaugare in lista a studentilor s1,s2
 if(u==1)ll+s4;         //s3 si s4,daca acesta exista in fisier
 //afisarea listei
 cout<<"Lista este:";
 cout<<ll;
 //stergerea unui nod din lista
 cout<<"Introduceti numarul matricol al studentului pe care doriti \nsa-l eliminati din lista:";
 int a;
 cin>>a;
 ll-a;
system("cls");
 cout<<"\nNoua lista este:"<<ll;
 getch();
 clasificare(ll);
system("cls");
 cout<<"\nLista sortata este:"<<ll;
 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…