one error in a program with Class


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include<iostream>
#include<iomanip>
using namespace std;
char q; // proverka na dannite
int n; //broi na u4enicite
int p; // broi na ocenkite

class Student
{
      private:
             
              int number;
              char street[30];
              char city[30];
              double marks[30];
              double average_mark;
      public:
             char name[30];
            Student();
            void sort(Student mas[]);
            double average();
            void output();
            ~Student();
};

//==============================================================================
Student::~Student(){};
//==========================================
        
Student::Student()
{                
                
                do
                 {
                  cout<<"Vuvedi ime na u4enik ";
                  cin>>name;
                  cout<<"Vuvedi nomer na u4enik ";
                  cin>>number;
                  cout<<"Vuvedi ulica na u4enik ";
                  cin>>street;
                  cout<<"Vuvedi grad na u4enik ";
                  cin>>city;
                  
                  for(int i=0;i<p;i++)
                    do
                       {
                                      cout<<"Vuvedi ocenka po Predmet"<<i+1<<" mejdu 2 i 6!!!";
                                      cin>>marks[i];
                       }while((marks[i]<2)||(marks[i]>6));
                  
                   cout<<"Do you want to edit data? y/n";
                   cin>>q;
                  }while(q=='y'); 
};
//===============================================================================
double Student::average()
{
              double sum=0;               
                  for(int i=0;i<p;i++)
                 {
                         sum=sum+marks[i];
                 } 
return sum/p;
};
//===============================================================================
void Student::output()
{
     cout<<name<<setw(10)<<street<<setw(10)<<city<<setw(10)<<number<<setw(10);
     
     for(int i=0;i<p;i++)
    {
     cout<<marks[i]<<setw(10);
    } 

};
char c[20];
 void Student::sort(Student mas[])
{
cout<<"Vuvedi ime za check";
cin>>c;
for(int i=0;i<n;i++)
if((strcmp(mas[i].name,c) ==0))
mas[i].output();
};

//======================================================

int main()
{
   
  
      do
   {
    cout<<"Vuvedi br. predmeti mejdu 3 i 5!";
    cin>>p;
   }while(p<3||p>5);
   
   cout<<"Vuvedi broi u4enici";
   cin>>n; 
    Student students[n];

cout<<"name"<<setw(10)<<"street"<<setw(10)<<"city"<<setw(10)<<"number"<<setw(10);
     
     for(int i=0;i<p;i++)
     cout<<"Predmet"<<i+1<<setw(10);
     cout<<"Sr.Uspeh"<<setw(10)<<"\n";

for(int i=0;i<n;i++)
{
students[i].output();
cout<<" ";
cout<<students[i].average();   
cout<<"\n";
}


cout<<"\n";
// nai visok sr. uspeh
double max ;
max = students[0].average();
int j=0;
for(int i=0;i<n;i++)
{
if( max < students[i].average() )
{
max=students[i].average();
}
}
cout<<"Nai visok sreden uspeh: "<<max<<"\n";
for(int i=0;i<n;i++)  
if(float(max)==float(students[i].average()) )         
students[i].output();  
// sortirovka
char c[20];

sort(students);


 
system("pause");
return 0;
}

              

Okay, guys...this is it and thats what is shows:

no matching function for call to `sort(Student[((unsigned int)((int)n))])'

I'm really desperate to get this working, but i cant fix it ;(
Please help!
Last edited on
Change line number 20 like this

static void sort(Student mas[]);

Change line number 136 like this

Student::sort(students);

Try to compile now.... It will work.


Also I'm not recommending to use Student students[n]; (line no: 100). This will give unexpected behavior. Better go for dynamic allocation new or malloc() if size of class will be defined dynamically. Use static array declaration when array size is constant.
Last edited on
richard, malloc won't call students constructor so new is actually the only thing he should be doing there.
Yeah... You are right.
Topic archived. No new replies allowed.