C++Prywatne metody do wyświetlania wyników

0

Witam, mam prośbę o sprawdzaniu mi kodu, bo nie daję sobie z tym radę, i liczę na was.
Mam zadanie, podana jest funkcja main, i mam tworzyć klassę student , skorzystać z klass string i valarray. no itd. więc napisałem tak jak mi nauczono i coś chyba(raczej na pewno) jest źle. Kompiluje się działa ale na samym końcu nie wiadomo skąd on wyświetla jakiś adres i nie tą kolejność. Oto kod:

#include<iostream>
#include<string>
#include<valarray>

using namespace std;

class student
{
   private:        
      string imie;
      typedef valarray<double>ardb;
      ardb ocena;
//----------główny część zadania--------------------
      ostream & aro(ostream & os)const;    
//--------------------------------------------------        
   public:
     ~student()                       {}     
      student()                       :imie(""),ocena(){}
      student(const string & s)       :imie(s),ocena(){} 
      explicit student(int n)         :imie(""),ocena(n){}
      student(const string & s,int n) :imie(s),ocena(n){}
      student(const string & s,const ardb & a)
                                      :imie(s),ocena(a){}
      student(const char*str,const double & pd,int n)
                                      :imie(str),ocena(pd,n){} 
      double srednia()const;
      const string & name()const      {return imie;}
      double & operator[](int i)      {return ocena[i];}
      double operator[](int i)const     {return ocena[i];} 
      
friend istream & operator>>(istream & is,student & st)
                                 {is>>st.imie;return is;}
friend istream & getline   (istream & is,student & st)
                         {getline(is,st.imie);return is;} 
friend ostream & operator<<(ostream & os,student & st);
};

void set (student & sa,int n);

ostream & operator<<(ostream & os,student & st)
{
        // st.aro(os) w tym miejscu chyba jest źle właśnie
        //zadanie jest takie by tworzyć priwatną metodę
        //do wyświetlania wyników
        os<<endl<<" ocena "<<st.imie<<" "<<st.aro(os);
        return os;
        }
        
ostream &  student::aro(ostream & os)const
{
        int i;
        int lim=ocena.size();
        if(lim>0)
          {
           for(i=0;i<lim;i++)
              {
                  os<<ocena[i]<<" ";
                  if(i%5==4)
                    os<<endl;
              } 
            if(i%5!=0)
              os<<endl;
           }
           else
                os<<" tablica jest pusta ";
                return os;
 }          
                  

double student::srednia()const
{
       if(ocena.size()>0)
          return ocena.sum()/ocena.size();
       else 
           return 0;
       }
   
void set (student & sa,int n)
{
     cout<<"\npodaj imie i nazwisko studenta : ";
     getline (cin,sa);
     cout<<" \npodaj "<<n<<" wynikow testow\n";
    
     for(int i=0;i<n;i++) 
           
             cin>>sa[i];                        
             while(cin.get()!='\n')
                   continue;
        
     }        


const int li_stu=3;  //liczba studentow
const int li_win=5;  //liczba wynikow
       
int main()
{
    int i;
    student ada[li_stu]=
    { student(li_win),student(li_win),student(li_win) };
    
    for(i=0;i<li_stu;i++)
       { 
                       set(ada[i],li_win);          
                       }     
                       
    cout<<"\nlista studentow\n";  
    for(i=0;i<li_stu;i++) 
        {
                        cout<<ada[i].name()<<endl; 
                         }  
                  
     cout<<" wyniki: ";
     for(i=0;i<li_stu;i++)
        {
               //i własnie tu ma zadziałać ale jest kolejnośc nie ta co 
               // oczekuję ada[i] ma wyświetlić ocena: imie i oceny  
               //i do tego jakiś adres jest wyświetlany       
                        cout<<endl<<ada[i];       
                        cout<<" srednia : "<<ada[i].srednia()<<endl;                   
                        }                           
      cout<<" gotowe";
    
    
getchar();
return 0;
}      

I mam takie wyniki

podaj imie i nazwisko studenta : Adam Kowalski

podaj 5 wynikow testow
96
95
58
74
89

podaj imie i nazwisko studenta : Kaczor Donald

podaj 5 wynikow testow
44
58
78
96
65

podaj imie i nazwisko studenta : Piotr Alban

podaj 5 wynikow testow
99
65
32
58
78

lista studentow
Adam Kowalski
Kaczor Donald
Piotr Alban
wyniki: --------------------------
96 95 58 74 89 //tu ma być ocena Adam itd a potem 96 95 itd

ocena Adam Kowalski 0x4463c4 srednia : 82.4 // ten właśnie adres jest niejasne

44 58 78 96 65

ocena Kaczor Donald 0x4463c4 srednia : 68.2

99 65 32 58 78

ocena Piotr Alban 0x4463c4 srednia : 66.4
--------------------------
gotowe

:-/

0

A tak próbowałeś:

ostream & operator<<(ostream & os,student & st)
{
        os<<endl<<" ocena "<<st.imie<<" ";
        st.aro(os);
        return os;
}

0

dzięki ,to było BINGO!! a ja już 2 dni się męcze.
temat można zamknąć. [browar]

1 użytkowników online, w tym zalogowanych: 0, gości: 1