不足为外人道也

不足为外人道也,第1张

不足为外人道
//a Record Head file
#pragma once
class aRecord
{
public:
	aRecord() {
		sMarks = 0;
	}
	void setMarks(int no) {
		sMarks = no;
	}
	int getMarks()const { return sMarks; }
private:
	int sMarks;
};

//mBManage head file
#pragma once
#include "aRecord.h"
class mBManage
{
public:
	mBManage(unsigned size);
	void addaRec(int);
	int getNoVaRec()const;
	int findSmallest()const;
	aRecord* getmyMB() const;
	~mBManage();
private:
	unsigned maxSize;
	aRecord* myMB;
	unsigned noVaRec;
};

//cpp
#include "aRecord.h"
#include "mBManage.h"
#include
using namespace std;
mBManage::mBManage(unsigned size) {
	maxSize = size;
	myMB = new aRecord[maxSize];
	noVaRec = 0;
}
void mBManage:: addaRec(int newMarks) {
    myMB[noVaRec++].setMarks(newMarks);


}
int mBManage:: getNoVaRec()const {
	return noVaRec;
}
int mBManage::findSmallest()const {
	int smallest=9999999999999999;
	for (int i = 0; i < noVaRec; i++) {
		if (smallest > myMB[i].getMarks()) {
			smallest = myMB[i].getMarks();

		}
		else if (smallest <= myMB[i].getMarks()) {
			smallest = smallest;
		}
	}
	return smallest;

}
aRecord* mBManage::getmyMB() const {
	return myMB;

}
mBManage::~mBManage() {
	unsigned maxSize;
	aRecord* myMB;
	unsigned noVaRec=0;
}
int main() {
	cout << "The size of the mark-book is 5." << endl;
	mBManage* myBook = new mBManage(5);
	cout << "Enter THREE marks with a space in between: ";
	for (int i = 0; i < 3; i++) {
		;
		int newMarks;
		cin >> newMarks;
		myBook->addaRec(newMarks);
	}
	cout << "Number of Records added in markbook= " << myBook->getNoVaRec() << endl;
	cout << "The lowest marks=" << myBook->findSmallest() << endl;
	cout << "The mark-book marks in input order = ";
	for (int i = 0; i < myBook->getNoVaRec(); i++) {
		cout << ((myBook->getmyMB()) + i)->getMarks() << "t";

	}
	cout << endl;
	delete myBook;
	return 0;

}

Above are Part 1

Part 1会做成一个静态库给part2用

#include
using namespace std;
#include "aRecord.h"
#include "mBManage.h"
#pragma comment(lib,"mBLib.lib")
int main() {
	cout << "The size of the mark-book is 3." << endl;
	mBManage* myBook = new mBManage(3);
	cout << "Enter FIVE marks with a space in between: ";
	for (int i = 0; i < 5; i++) {
		int newMarks;
		cin >> newMarks;
		if (myBook->addaRec(newMarks) == false)
		{
			cout << "A record CANNOT be stored!" << endl;
			continue;
		}
	}
	cout << "Number of Records added in markbook= " << myBook->getNoVaRec() << endl;
	cout << "The lowest marks=" << myBook->findSmallest() << endl;
	cout << "The mark-book marks in input order = ";
	for (int i = 0; i < myBook->getNoVaRec(); i++) {
		cout << ((myBook->getmyMB()) + i)->getMarks() << "t";
	}
	cout << endl;
	delete myBook;
	return 0;

}

part 3

cpp:

#include "aRecord.h"
#include "mBManage.h"
#include 
#include
using namespace std;
mBManage::mBManage(unsigned size) {
	maxSize = size;
	myMB = new aRecord[maxSize];
	noVaRec = 0;
}
void mBManage::addaRec(int newMarks) {
	myMB[noVaRec++].setMarks(newMarks);


}
int mBManage::getNoVaRec()const {
	return noVaRec;
}
int mBManage::findSmallest()const {
	int smallest = 9999999999999999;
	for (int i = 0; i < noVaRec; i++) {
		if (smallest > myMB[i].getMarks()) {
			smallest = myMB[i].getMarks();

		}
		else if (smallest <= myMB[i].getMarks()) {
			smallest = smallest;
		}
	}
	return smallest;

}
aRecord* mBManage::getmyMB() const 
{return myMB;

}
mBManage::~mBManage() {
	unsigned maxSize;
	aRecord* myMB;
	unsigned noVaRec = 0;
}
void mBManage::passaRecord(int* pSMk, char* pSName, unsigned aIndex)const {
	*pSMk = myMB[aIndex].getMarks();
	strncpy(pSName, myMB[aIndex].getName(),50);
}
int main() {
	cout << "The size of the mark-book is 5." << endl;
	mBManage* myBook = new mBManage(5);
	cout << "Enter THREE marks with a space in between: ";
	for (int i = 0; i < 3; i++) {
		;
		int newMarks;
		cin >> newMarks;
		myBook->addaRec(newMarks);
	}
	cout << "Enter THREE names with a space in between: ";
	for (int i = 0; i < 3; i++) {
		char rm[80];
		cin >> rm;
		((myBook->getmyMB()) + i)->setName(rm);

	}
	for (int i = 0; i < myBook->getNoVaRec(); i++) {
		int* pSMk = new int;
		char* pSName = new char[50];;
		unsigned aIndex = i;

		myBook->passaRecord(pSMk, pSName,aIndex);
		std::ofstream outFile;
		ofstream ofs("MB.txt", ios::app | ios::out);
		ofs << *pSMk << "t" << pSName << "n";
		outFile.close();

	}
	std::ofstream outFile;
	ofstream ofs("MB.txt", ios::app | ios::out);
	ofs << "For Prog. Test 2" << endl;
	outFile.close();
	cout << "Number of Records added in markbook= " << myBook->getNoVaRec() << endl;
	cout << "The lowest marks=" << myBook->findSmallest() << endl;
	cout << "The mark-book marks in input order = ";
	for (int i = 0; i < myBook->getNoVaRec(); i++) {
		cout << ((myBook->getmyMB()) + i)->getMarks() << "t";

	}
	cout << endl;
	delete myBook;
	return 0;

}

头文件两个

#pragma once
#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include 
using namespace std;
#include "string.h"
class aRecord
{
public:
	aRecord() {
		sMarks = 0;
	}
	void setMarks(int no) {
		sMarks = no;
	}
	int getMarks()const { return sMarks; }
	void setName(char rm[]) { strcpy(sName, rm); }
	char* getName() { return sName; }
private:
	int sMarks;
	char sName[50];
};

#pragma once
#include "aRecord.h"
class mBManage
{
public:
	mBManage(unsigned size);
	void addaRec(int);
	int getNoVaRec()const;
	int findSmallest()const;
	aRecord* getmyMB() const;
	~mBManage();
	void passaRecord(int* pSMk, char* pSName, unsigned aIndex)const;
private:
	unsigned maxSize;
	aRecord* myMB;
	unsigned noVaRec;
};

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5593239.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存