Hej,
Robię zadanka ze studiów i mam problem raz, że z utworzeniem tablicy studentów a dwa z podpunktem o sumie stypendiów.
#include <iostream>
#include <cstdlib>
using namespace std;
class Student{
private:
int index;
int year;
double salary;
double su;
public:
Student(int index, int year, double salary){
this->index = index;
this->year = year;
this->salary = salary;
}
~Student(){
cout << "Usuwam dane studenta o indeksie: " << index << endl;
}
void information(){
cout << index << endl;
cout << year << endl;
cout << salary << endl;
}
void change_salary(){
cout<<"Stypendium przed zmianami: "<<salary<<endl;
cout<<"Podaj wysokosc stypendium: ";
cin>>salary;
cout<<"Stypendium po zmianach: "<<salary<<endl;}
/* void sum(Student students[])
{
for (int i=0; i<3; i++)
{
su += students[i].salary;
};
cout << su;
}*/
};
int main(){
Student student1(383432, 2, 2137.5);
Student student2(352345, 1, 4423.6);
Student student3(343245, 3, 6524.2);
Student students[3] = {student1, student2, student3};
double sum = students[0].salary + students[1].salary + students[2].salary;
return 0;
}
Wcześniej tablicę próbowałem też zrobić tak
Aktualnie tablica działa ale nie wiem jak naprawić poprzedni kod tj. ten ze screena oraz w wysłąnym kodzie nie potrafię zsumować tych stypendiów. Informuje mnie, że pole salary jest prywatne no i takie ma być i jak to zrobić bez zmiany na public?