IG
Size: a a a
IG
IG
IG
IG
#include <iostream>
#include <fstream>
using namespace std;
struct Student{
string surname;
int mark[4];
};
bool read_fileandWrite(Student* idk){
ofstream out("text.txt", ios::in);
int n;
cout<<"Введите количество студентов"<<endl;
cin>>n;
cout<<"\n";
idk = new Student[n];
Student x;
for (int i = 0; i < n; ++i)
{
cout << "Студент " << i + 1 << ":\n";
cout << "Введите фамилию: ";
cin >> x.surname;
out << x.surname << "\n";
cout << "Введите оценки: ";
for (int j = 0; j < 4; ++j)
{
cin >> x.mark[i];
out << x.mark[i] << "\n";
}
}
std::cout << "Читаем из файла..." << "\n";
std::ifstream file("text.txt", ios::out);
if (!file.is_open())
{ std::cout << "Ошибка чтения файла!\n";
return false;
}
int i = 0;
while(file >> idk[i].surname >> idk[i].mark[0] >> idk[i].mark[1] >> idk[i].mark[2] >> idk[i].mark[3]) {
cout << idk[i].surname << " " << idk[i].mark[0] << " " << idk[i].mark[1] << " " << idk[i].mark[2] << " " << idk[i].mark[3]
<< " " << "Средний бал студента: " << (idk[i].mark[0] + idk[i].mark[1] + idk[i].mark[2] + idk[i].mark[3]) / 4. << "\n";
i++;
}
return true;
}
int main() {
ifstream in("txt1");
int count = 0;
Student *idk = NULL;
read_fileandWrite(idk);
delete[] idk;
return 0;
}
SI
NK
А
#include <iostream>
#include <fstream>
using namespace std;
struct Student{
string surname;
int mark[4];
};
bool read_fileandWrite(Student* idk){
ofstream out("text.txt", ios::in);
int n;
cout<<"Введите количество студентов"<<endl;
cin>>n;
cout<<"\n";
idk = new Student[n];
Student x;
for (int i = 0; i < n; ++i)
{
cout << "Студент " << i + 1 << ":\n";
cout << "Введите фамилию: ";
cin >> x.surname;
out << x.surname << "\n";
cout << "Введите оценки: ";
for (int j = 0; j < 4; ++j)
{
cin >> x.mark[i];
out << x.mark[i] << "\n";
}
}
std::cout << "Читаем из файла..." << "\n";
std::ifstream file("text.txt", ios::out);
if (!file.is_open())
{ std::cout << "Ошибка чтения файла!\n";
return false;
}
int i = 0;
while(file >> idk[i].surname >> idk[i].mark[0] >> idk[i].mark[1] >> idk[i].mark[2] >> idk[i].mark[3]) {
cout << idk[i].surname << " " << idk[i].mark[0] << " " << idk[i].mark[1] << " " << idk[i].mark[2] << " " << idk[i].mark[3]
<< " " << "Средний бал студента: " << (idk[i].mark[0] + idk[i].mark[1] + idk[i].mark[2] + idk[i].mark[3]) / 4. << "\n";
i++;
}
return true;
}
int main() {
ifstream in("txt1");
int count = 0;
Student *idk = NULL;
read_fileandWrite(idk);
delete[] idk;
return 0;
}
IG
SI
IG
SI
SH
IG
SI
NK
SI
SI
SH
IG
IG