c ++ using the Score class, enter a class n (can not be determined in advance) students of the school number and all subjects, then ask each student's grade point average, and outputs a list of the students' school, all subjects and grade point average.

Score define a class, which includes the private data members and member functions public, i.e.
mNum student number
mMath higher math
mEnglish English achievement
mProgramming programming results
Inscore () and all subjects enter the student number, and the average score is calculated
showScore () output Science number and all subjects
using score category, enter a class n (can not be determined in advance) students of the school number and all subjects, then ask each student's grade point average, and outputs a list of the students' school, all subjects and grade point average .

#include "pch.h"
#include "Score.h"
#include <iostream>
using namespace std;
int main()
{
	int n,a,b,c,d;
	cin >> n;
	Score *m = new Score[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b >> c >> d;
	    m[i].Inscore(a,b,c,d);
	}
	cout << "num" << '\t' << "math" << '\t' << "English" << '\t' << "programming" << '\t' << "average"<<endl;
	for (int i = 0; i < n; i++)
	{
		m[i].Showscore();
	}
	delete[]m;
}
#pragma once
class Score
{
public:
	Score();
	double Inscore(double num, double math, double eng, double pro);
	void Showscore();
private:
	double mNum, mMath, mEnglish, mProgramming;
};
//Score cpp
#include "pch.h"
#include "Score.h"
#include <iostream>
using namespace std;
Score::Score()
{
}
double Score::Inscore(double num, double math, double eng, double pro)
{
	mNum = num;
	mMath = math;
	mEnglish = eng;
	mProgramming=pro;
	return ( math + eng + pro) / 3;
}
void Score::Showscore()
{
	cout << mNum << '\t' << mMath << '\t' << mEnglish << '\t' << mProgramming << '\t' << Score::Inscore(mNum, mMath, mEnglish, mProgramming)<<endl;
}

Guess you like

Origin blog.csdn.net/weixin_43981315/article/details/94758858