Advertisement
Guest User

Seminar c++

a guest
Nov 26th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6.  
  7. using namespace std;//dupa nota duma nume
  8. struct Student{
  9.     char nume[20];
  10.     int nota;
  11.     Student *n_nume, *n_nota;//studenti crescatori si node descrescatoare
  12.  
  13. };
  14. void adaugare(Student *&prim_nume, Student *&prim_nota){
  15.     Student *a= new Student;
  16.     cout<<"Nume: ";
  17.     cin>>a->nume;
  18.     cout<<"Nota: ";
  19.     cin>>a->nota;
  20.     if(prim_nume==NULL){
  21.         prim_nume=a;
  22.         a->n_nume=NULL;
  23.     }
  24.     else{
  25.         if(strcmp(a->nume,prim_nume->nume)<0)
  26.         {
  27.             a->n_nume=prim_nume;
  28.             prim_nume=a;
  29.         }
  30.         else{
  31.             Student *p= prim_nume;
  32.             while(p->n_nume!=NULL&&strcmp(p->n_nume->nume,a->nume)<0){
  33.                 p=p->n_nume;
  34.             }
  35.             a->n_nume=p->n_nume;
  36.             p->n_nume=a;
  37.         }
  38.     }
  39.     if(prim_nota==NULL){
  40.         prim_nota=a;
  41.         a->n_nota=NULL;
  42.     }
  43.     else{
  44.  
  45.             if(a->nota>prim_nota->nota){
  46.                 a->n_nota=prim_nota;
  47.                 prim_nota=a;
  48.             }
  49.             else{
  50.                 Student *p= prim_nota;
  51.  
  52.                     while(p->n_nota!=NULL&&p->n_nota->nota>a->nota){
  53.                         p=p->n_nota;
  54.                     }
  55.                    
  56.                     a->n_nota=p->n_nota;
  57.  
  58.                     p->n_nota=a;
  59.  
  60.                    
  61.  
  62.  
  63.             }
  64. }
  65. }
  66. void afisareNota(Student *prim){
  67.     cout<<"Afisare studenti in functie de nota: \n";
  68.     while(prim!=NULL)
  69.     {
  70.         cout<<prim->nume<<": "<<prim->nota<<endl;
  71.         prim=prim->n_nota;
  72.     }
  73. }
  74. void afisareNume(Student *prim){
  75.     cout<<"Afisare studenti in functie de nume: \n";
  76.     while(prim!=NULL)
  77.     {
  78.         cout<<prim->nume<<": "<<prim->nota<<endl;
  79.         prim=prim->n_nume;
  80.     }
  81. }
  82.  
  83.  
  84. int _tmain(int argc, _TCHAR* argv[])
  85. {
  86.     Student *prim_nota=NULL, *prim_nume=NULL;
  87.     int n;
  88.     cout<<"\nIntroduceti un numar: ";
  89.     cin>>n;
  90.     for (int i = 0; i < n; i++)
  91.     {
  92.         adaugare(prim_nume,prim_nota);
  93.     }
  94.     afisareNota(prim_nota);
  95.     afisareNume(prim_nume);
  96.     system("pause");
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement