Untitled
unknown
c_cpp
3 years ago
1.2 kB
5
Indexable
#include <iostream>
using namespace std;
class Marks {
private:
int* marks;
int len;
public:
//Конструктор
Marks(const int arr[], int size) {
this->len = size;
this->marks = new int[len]; //створення масиву оцінок, довжиною len (size)
//копіювання елементів з arr в this->marks
for (int i = 0; i < size; ++i) {
this->marks[i] = arr[i];
}
}
//Вивід оцінок
void Display() {
for (int i = 0; i < this->len; ++i) {
cout << this->marks[i] << endl;
}
}
//Getter
int *getMarks() const {
return marks;
}
//Setter
void setMarks(int *marks) {
this->marks = marks;
}
};
int main() {
int size = 6;
int* arr = new int[size]; //створення масиву на 6 оцінок
for (int i = 0; i < size; i++) {
cout << "Enter your mark: ";
cin >> arr[i];
}
Marks marks(arr, size); //створення об'єкта класу
marks.Display();
return 0;
}
Editor is loading...