Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <fstream>
  5. #include <iomanip>
  6. using namespace std;
  7. ifstream f("date.in");
  8. struct nod
  9. {
  10.     char nume[99];
  11.     float med;
  12.     nod *pred, *urm;
  13. }*c, *p, *u;
  14. int med=0;
  15.  
  16. void creare()
  17. {
  18.     char x[99];
  19.     float y;
  20.     c = new nod;
  21.     c -> pred = NULL;
  22.     c -> urm = NULL;
  23.     f>>x;
  24.     strcpy(c->nume,x);
  25.     f>>y;
  26.     c->med=y;
  27.     p = c;
  28.     u = c;
  29.  
  30.  
  31.     while(f>>x>>y)
  32.     {
  33.         c = new nod;
  34.         strcpy(c->nume,x);
  35.         c->med=y;
  36.  
  37.         u -> urm = c;
  38.         c -> pred = u;
  39.         c -> urm = NULL;
  40.         u = c;
  41.     }
  42.  
  43. }
  44. void afisare()
  45. {
  46.  
  47.     c = p;
  48.     while(c)
  49.     {
  50.         cout << endl;
  51.         cout << c -> nume << "-"<<c->med;
  52.         c = c -> urm;
  53.     }
  54. }
  55.  
  56. void medmax()
  57. {
  58.     cout<<endl;
  59.     c=p;
  60.     nod *maxi;
  61.     maxi=p;
  62.     while(c)
  63.     {
  64.         if(c->med>maxi->med)
  65.             maxi=c;
  66.         c=c->urm;
  67.     }
  68.     cout<<"Media cea mai mare :"<<maxi->nume<<"-"<<maxi->med;
  69. }
  70. void intreoptsizece()
  71. {
  72.     cout<<endl<<"Mediile intre 8 si 10:";
  73.     c=p;
  74.     while(c)
  75.     {
  76.         if(c->med>8&&c->med<=10)
  77.             cout<<c->nume<<" ";
  78.         c=c->urm;
  79.     }
  80. }
  81. void cautare()
  82. {
  83.     c=p;
  84.     char x[99];
  85.     cout<<endl<<"Cautati:";
  86.     cin>>x;
  87. cout<<"Media lui "
  88.  <<x<< " este ";
  89.     while(c)
  90.     {
  91.         if(strcmp(x,c->nume)==0)
  92.             cout<<c->med<<" ";
  93.         c=c->urm;
  94.     }
  95. }
  96. void mediepeclasa()
  97. {
  98.     float med=0,k=0;
  99.     c=p;
  100.     while(c)
  101.     {
  102.         med=med+c->med;
  103.         k++;
  104.     c=c->urm;
  105.     }
  106.     cout<<endl<<"Media pe clasa:";
  107.     cout<<med/k;
  108. }
  109. int main()
  110. {
  111.     creare();
  112.     afisare();
  113.     medmax();
  114.     intreoptsizece();
  115.     cautare();
  116.     mediepeclasa();
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement