Treceți la conținutul principal

clasa activitate cpp

// proiect1.cpp : Defines the entry point for the console application.
//

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>


//clasa activitate
class activitate
{
public:

 int cod;
 char denumire;
 int nr_prec;  //nr de activitati direct precedente
 int prec[50];

 unsigned durata,tmi,tMi,tmt,tMt;


 friend ostream & operator<<(ostream &,activitate);

 friend istream & operator>>(istream &,activitate &);
 
 
 
};

 
//clasa proiect
class proiect
{
public:
  activitate a[50];
  int nr_act;// nr de cativitati din proiect
  int adiac[50][50];
  
  proiect();
  proiect& timp();
  void print();
  void drum();
  void gantt();
  activitate gasit(int);
  void isConditionatDe(activitate,activitate);
  proiect& operator+(activitate);
  proiect& operator-(int);
  friend ifstream& operator>>(ifstream&, proiect &);
  friend ofstream& operator<<(ofstream&, proiect);

};

//constructorul clasei proiect

proiect::proiect()
{
 int i,j;
 for(i=0;i<50;i++)
  for(j=0;j<50;j++)
   adiac[i][j]=0;
 nr_act=0;
 a[0].cod=0;
 a[0].denumire='s';
 a[0].durata=0;
 a[0].nr_prec=0;
}


//calcularea timpului maxim si minm de incepere si timpului maxim si minm de terminare
//pt fiecere activitate a proiectului

proiect& proiect::timp()
{
 int i,j,vb;
 unsigned max,min;

 nr_act++;
 a[nr_act].cod=nr_act;
 a[nr_act].denumire='t';
 a[nr_act].durata=0;
 a[nr_act].nr_prec=0;
 for(i=0;i<nr_act;i++)
   {
    vb=0;
    for(j=1;j<nr_act;j++)
     if (adiac[i][j]==1)
      vb=1;
    if(!vb)
      {
       adiac[i][nr_act]=1;
       a[nr_act].prec[a[nr_act].nr_prec]=i;
       a[nr_act].nr_prec++;
      }
   }
 a[0].tmi=0;
 a[0].tmt=0;
 for(i=1;i<=nr_act;i++)
   {
    max=0;
    for(j=0;j<a[i].nr_prec;j++)
     if(max<a[a[i].prec[j]].tmt)
      max=a[a[i].prec[j]].tmt;
    a[i].tmi=max;
    a[i].tmt=max+a[i].durata;
   }
 
 a[nr_act].tMt=max;
 a[nr_act].tMi=max;
 for(i=nr_act-1;i>=0;i--)
   {
    min=max;
    for(j=0;j<=nr_act;j++)
     if((adiac[i][j]==1)&&(min>a[j].tMi))
      min=a[j].tMi;
    a[i].tMt=min;
    a[i].tMi=min-a[i].durata;
   }
 nr_act--;
 return *this;
}

//afisarea timpului minim si maxim de incepere si a timpului minim si maxim de terminare
//pentru fiecare activitate a proiectului

void proiect::print()
{
 int i;

 cout<<"Timp minim si maxim de incepere si timp minim si maxim de terminare:\n";
 for(i=1;i<=nr_act;i++)
  cout<<"Activitatea "<<a[i].denumire<<": "<<a[i].tmi<<", "<<a[i].tMi<<", "<<a[i].tmt<<", "<<a[i].tMt<<"\n";
 
}

//determinarea duratei minime a proiectului di drumului critic

void proiect::drum()
 {
  int i;
  
  cout<<"Durata minima a proiectului este: "<<a[nr_act].tMt<<"\n";
  cout<<"Drumul critic: ";
  for(i=1;i<=nr_act;i++)
   if((a[i].tmi==a[i].tMi)&&(a[i].tmt==a[i].tMt)) cout<<a[i].denumire<<" ";
  cout<<endl; 
 }

//afisarea graficului Gantt

void proiect::gantt()
{
 unsigned i,j;
 cout<<"Graficul Gantt la termene minime de incepere:"<<endl<<endl;
 for(i=nr_act;i>=1;i--)
   {
    cout<<a[i].denumire<<": ";
    for(j=0;j<a[i].tmi;j++) cout<<"  ";
    for(j=0;j<a[i].durata;j++) cout<<"--";
    for(j=0;j<(a[i].tMt-a[i].tmt);j++) cout<<"++";
    cout<<"\n";
   }
 
 cout<<"   ";
 if (a[nr_act].tMt>9)
  {
   for (i=1;i<=9;i++)
    cout<<' '<<i;
   for(i=10;i<=a[nr_act].tMt;i++)
    cout<<i;
  }
 else
  for(i=1;i<a[nr_act].tMt;i++)
   cout<<' '<<i;
 cout<<"\n"; 
}

//cautarea unei activitati in proiect dupa cod

activitate proiect::gasit(int c)
{ 
 for (int i=1;i<=nr_act;i++)
  if(a[i].cod==c)
   return a[i];
}

//test de conditionalitate

void proiect::isConditionatDe(activitate a1,activitate a2)
{
 int i,k,j,v[50];
 bool vb;

 vb=0;
 for(i=0;i<a1.nr_prec;i++)
  if(a2.cod==a1.prec[i])
   vb=1;
 if (vb) 
  cout<<"\nActivitatea "<<a1.denumire<<" este direct conditionata de activitatea "<<a2.denumire<<"\n";
 
 if(!vb)
  {
   k=0;
   i=0;
   for(j=0;j<a1.nr_prec;j++)
    if(a1.prec[j]>a2.cod)
     {
      k++;
      v[k]=a1.prec[j];
     }

   while((i<k)&&(!vb))
    {
     i++;
     for(j=0;j<a[v[i]].nr_prec;j++)
       if(a[v[i]].prec[j]==a2.cod) 
        vb=1;
       else
        if (a2.cod<a[v[i]].prec[j])
         {
          k++;
          v[k]=a[v[i]].prec[j];
         }
    }
   if(vb)
    cout<<"\nActivitatea "<<a1.denumire<<" este indirect conditionata de activitatea "<<a2.denumire<<"\n";
   else
    cout<<"\nActivitatea "<<a1.denumire<<" nu este conditionata de activitatea "<<a2.denumire<<"\n";
    }
}


//adugarea unei activitati in proiect
  
proiect& proiect :: operator + (activitate act)
{
 nr_act++;
 a[nr_act].cod=nr_act;
 a[nr_act].denumire=act.denumire;
 a[nr_act].durata=act.durata;
 a[nr_act].nr_prec=act.nr_prec;

 for(int i=0;i<=nr_act;i++)
  adiac[i][nr_act]=0;

 for(int l=0;l<act.nr_prec;l++)
   {
    a[nr_act].prec[l]=act.prec[l];
    adiac[act.prec[l]][nr_act]=1;
   }

 if (!act.nr_prec)
   {
    adiac[0][nr_act]=1;
    a[nr_act].nr_prec=1;
    a[nr_act].prec[0]=0;
   } 
 
 return *this;
}


//stergerea unei activitati din proiect

proiect& proiect :: operator - (int c)
{
 int j,i,t;

 for(i=0;i<=nr_act;i++)
  for(j=c;j<nr_act;j++)
   adiac[i][j]=adiac[i][j+1];
 
 for(i=0;i<=nr_act;i++)
  for(j=c;j<nr_act;j++)
   adiac[j][i]=adiac[j+1][i];

 for(i=c;i<nr_act;i++)
   {
    a[i].cod=a[i+1].cod;
    a[i].denumire=a[i+1].denumire;
    a[i].durata=a[i+1].durata;
    a[i].nr_prec=a[i+1].nr_prec;
    for(j=0;j<a[i].nr_prec;j++)
      a[i].prec[j]=a[i+1].prec[j];
   }
 
 nr_act=nr_act-1;
 
 for(i=c;i<=nr_act;i++)
   {
    for(j=0;j<a[i].nr_prec;j++)
     if(c==a[i].prec[j]) 
      {
       for(t=j;t<a[i].nr_prec-1;t++)
        a[i].prec[t]=a[i].prec[t+1];
       a[i].nr_prec--;
      }
    if (!a[i].nr_prec)
     {
      adiac[0][i]=1;
      a[i].nr_prec=1;
      a[i].prec[0]=0;
     } 
   }
 return *this;
} 
 
//adfisarea unei activitati
  
ostream& operator<<(ostream & iesire,activitate a)
{
 iesire<<"Codul activitatii: "<<a.cod<<endl;
 iesire<<"Denumirea activitatii: "<<a.denumire<<endl;
 iesire<<"Durata activitatii: "<<a.durata<<endl;
 if ((!a.nr_prec)||((a.nr_prec==1)&&(a.prec[0]==0)))
  iesire<<"Activitatea "<<a.denumire<<" nu are activitati direct precedente"<<endl;
 else
  {
   iesire<<"Codurile activitatilor direct precedente sunt:"<<endl;
   for (int i=0;i<a.nr_prec;i++)
    if (a.prec[i])
    iesire<<a.prec[i]<<" ";
   iesire<<"\n";
  }
 return iesire;
}

//citirea unei activitati

istream& operator>>(istream & intrare, activitate & a)
{
 cout<<"Codul activitatii: ";
 intrare>>a.cod;
 cout<<"Denumirea activitatii: ";
 intrare>>a.denumire;
 cout<<"Durata activitatii: ";
 intrare>>a.durata;
 cout<<"Numarul de activitati direct precedente: ";
 intrare>>a.nr_prec;
 for (int i=0;i<a.nr_prec;i++)
 {
  cout<<"Codul activitatii direct precedente "<<i+1<<" :";
  intrare>>a.prec[i];
 }
 return intrare;
}



//restaurare proiect din fisier 

ifstream& operator >> (ifstream& intrare, proiect& p)
{
  intrare>>p.nr_act;
  for(int i=1;i<=p.nr_act;i++)
   {
    intrare>>p.a[i].cod;
    intrare>>p.a[i].denumire;
    intrare>>p.a[i].durata;
    intrare>>p.a[i].nr_prec;
    for(int j=0;j<p.a[i].nr_prec;j++)
     {
      intrare>>p.a[i].prec[j];
      p.adiac[p.a[i].prec[j]][i]=1;
     }
   }
  return intrare;
}


//scriere proiect in fisier

ofstream& operator << (ofstream& iesire, proiect p)
{
  
  iesire<<p.nr_act<<' ';
  for(int i=1;i<=p.nr_act;i++)
   {
    iesire<<p.a[i].cod<<' ';
    iesire<<p.a[i].denumire<<' ';
    iesire<<p.a[i].durata<<' ';
    iesire<<p.a[i].nr_prec<<' ';
    for(int j=0;j<p.a[i].nr_prec;j++)
      iesire<<p.a[i].prec[j]<<' ';
   }
  return iesire;
}
  



void main()
{
 proiect p;
 activitate a;
 int c,c1,c2;
 char ch;

 
 ifstream fisin("oana.dat");
 if (!fisin)
  {
   cout<<"\nFisier negasit!";
   exit(1);
  }
 fisin>>p;
 fisin.close();
do
{
 
 cout<<"\n\n\n";
 cout<<"\t1.Afisare timp minim si maxim de incepere si de terminare"<<endl;
 cout<<"\t2.Afisarea drumului critic si a duratei minime a proiectului"<<endl;
 cout<<"\t3.Afisarea graficului Gantt"<<endl;
 cout<<"\t4.Test de conditionalitate"<<endl;
 cout<<"\t5.Inserare activitate in proiect"<<endl;
 cout<<"\t6.Stergere activitate din proiect"<<endl;
 cout<<"\nDati optiunea(sau 0-Iesire): ";
 cin>>ch;
 system("cls");

switch (ch)
{
case '1':
 p.timp();
 p.print();

 break;
case '2':
 p.timp();
 p.drum();

 break;
case '3':
 p.timp();
 p.gantt();

 break;
case '4':
 cout<<"Dati codul primei activitati: ";
 cin>>c1;
 cout<<"Dati codul celei de-a doua activitati: ";
 cin>>c2;
 p.isConditionatDe(p.gasit(c1),p.gasit(c2));

 break;
case '5':
 cin>>a;
 p+a;

break;

case '6':
 cout<<"Dati codul activitatii pe care doriti sa o stergeti: ";
 cin>>c;
 p-c;

break;
case '0':
 exit(0);
}

}
while (ch!='0');

ofstream fisout("lala.dat");
if(!fisout) 
 {
  cout<<"Nu se poate deschide fisierul";
   exit(1);
 }
fisout<<p;
fisout.close();


} 



Comentarii

Postări populare de pe acest blog

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='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

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…