Тема: Помилка у програмі студент.
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
class student
{
char* name = new char[100];
int* mark = new int[5];
int average = 0;
public:
student()
{
for (int i = 0; i < 5; i++) {
mark[i] = 0;
}
}
void fill()
{
cout << "Enter name: ";
(cin >> name).get();
cin.clear(); // тут видає помилку
cout << "Enter marks: " << endl;
for (int i = 0; i < 5; i++) {
cout << "Enter " << i + 1 << " mark: ";
cin >> mark[i];
}
int temp_product = 0;
for (int i = 0; i < 5; i++) {
temp_product += mark[i];
}
average = temp_product / 5;
}
void print()
{
cout << "Students name: " << name << endl << "His/her marks: " << endl;
for (int i = 0; i < 5; i++)
{
cout << mark[i] << endl;
}
cout << "Average: " << average << endl;
}
~student() {
cout << "Data deleted. Program compiled normally";
}
};
class group {
char* gname = new char[100];
int num;
student* students = new student[num];
public:
group(int temp) {
gname == ("No group name!!");
num = temp;
}
void fil()
{
cout << "Enter group 1 name: ";
(cin >> gname).get();
cin.clear();
for (int i = 0; i < num; i++) {
cout << "Enter student " << i + 1 << " data" << endl;
students[i].fill();
}
}
void print() {
for (int i = 0; i < num; i++) {
cout << "Student " << i + 1 << " info" << endl;
students[i].print();
}
}
};
int main() {
group group1(4);
group group2(5);
group1.fil();
group1.print();
group2.fil();
group2.print();
system("pause");
return 0;
}
_Ch 122 'z' char
_Meta 122 int
_Str 0xfdfdfdfd <Error reading characters of string.> char *
Visual Studio 2017