Головна‎ > ‎C++‎ > ‎

Класи

Масив об'єктів

#include <iostream>
#include <string>

using namespace std;

class Schoolboy
{
public:
     int point;
     string name;
};

int main()
{
   Schoolboy school[3];

   school[0].point = 5;
   school[0].name = "Dmytro";
   school[1].point = 9;
   school[1].name = "Svitlana";
   school[2].point = 12;
   school[2].name = "Mazepa";
   for (int i = 0; i < 3; i++)
   {
       cout << school[i].name << " - " << school[i].point << endl;
   }

   system("pause");
   return 0;
}



Функція

class Time
{
public:
int hours;
int minutes;
};

void Add(Time a, Time b)
{
cout << a.hours + b.hours << ":" << a.minutes + b.minutes << endl;
}

int main()
{
    ...
    Add(t1, t2);
    ...
}