Em đinh thống kê số sinh viên theo tổng điểm sum mà không biết làm sao lấy giá trị tổng điểm của từng sinh viên ra được??
#include "Student.h"
#include "Point.h"
Student::Student(){
}
void Student::setId(string ID) {
id = ID;
}
string Student::getId() {
return id;
}
void Student::setName(string NAME) {
name = NAME;
}
string Student::getName() {
return name;
}
void Student::setAddress(string ADDRESS) {
address = ADDRESS;
}
string Student::getAddress() {
return address;
}
void Student::setSex(string SEX) {
sex = SEX;
}
string Student::getSex() {
return sex;
}
void Student::setPoint(Point POINT) {
point = POINT;
}
Point Student::getPoint() {
return point;
}
#include "Point.h"
Point::Point(){
}
void Point::setMath(float MATH) {
math = MATH;
}
float Point::getMath() {
return math;
}
void Point::setPhysical(float PHYSICAL) {
physical = PHYSICAL;
}
float Point::getPhysical(){
return physical;
}
void Point::setChemistry(float CHEMISTRY) {
chemistry = CHEMISTRY;
}
float Point::getChemistry() {
return chemistry;
}
float Point::getSum() {
return (math + physical + chemistry);
}
//Hàm đọc file và viết file
#include "IOFile.h"
#include "Student.h"
#include<fstream>
#include<iostream>
using namespace std;
IOFile::IOFile()
{
}
void IOFile::readFile(string path) {
fstream file(path, ios::in | ios::app);
string data;
string line;
while (!file.eof()) {
getline(file, line);
data = data + line + "\n";
//file >> student.getId() >> student.getName();
//cout << student.getId() << student.getName() << endl; ??? Sao dung cach nay ko dc??
}
cout << data << endl;//in tu file ra man hinh
file.close();
}
void IOFile::writeFile(string path, Student &student) {
ofstream file(path, ios::out | ios::app);
if (!file) {
cout << "File khong ton tai" << endl;
}
else {
file<< "\t" << student.getId() << "\t" << student.getName() << "\t" << student.getAddress() << "\t" << student.getSex() <<
"\t" << student.getMath() << "\t" << student.getPhysical() << "\t" << student.getChemistry()
<<"\t"<< student.getSum()<<"\n";
}
file.close();
}
//Hàm thống kê
#include "StudentController.h"
#include "IOFile.h"
#include "Student.h"
#include "Point.h"
#include<fstream>
#include<iostream>
using namespace std;
StudentController::StudentController()
{
}
void StudentController::statitics(Student &st) {
int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;
ifstream file("sinhvien.txt", ios::in);
ofstream fs("test.txt", ios::out);
string line;
while (getline(file,line)) {
sum1++;
if (st.getSum() < 15) {
sum2++;
}else if ((st.getSum() >= 15) && (st.getSum() < 20) ){
sum3++;
}else if ((st.getSum() >= 20) && (st.getSum() < 25) ){
sum4++;
}else if (st.getSum() >= 25) {
sum5++;
}
}
cout << "Tong so sinh vien: " << sum1 << endl;
cout << "So sinh vien co diem <15: " << sum2 << endl;
cout << "So sinh vien co diem >=15 && <20 : " << sum3 << endl;
cout << "So sinh vien co diem >=25 : " << sum5 << endl;
}