// Project01.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <time.h>
#include <algorithm>
using namespace std;
#define IDMAX 1000
/*
學生類
要求:
1、學生有ID,ID為無符號整型,取值范圍為 1 ~ IDMAX
2、完成該類的三個建構式。默認建構式可隨機生成一個ID
3、多載學生類的賦值運算子
4、多載學生類的==運算子,要求:當兩個學生物件的ID相同時,認為這兩個物件相等
*/
class Student
{
private:
unsigned int m_uiId;
public:
Student();
Student(const Student & student);
Student & operator=(const Student & student);
bool operator==(const Student & student);
};
/*
學生集合類
要求:
1、集合中的元素為Student物件,用vector存盤;
2、實作默認建構式、復制建構式
3、多載賦值運算子和==運算子
4、實作向集合中插入(Insert)和洗掉(Remove)操作
5、實作集合的并(Union)、交(InterSect)、差(Difference)、補(Complement)和對稱差(SymDifference),其中補集運算以{1 ... IDMAX}為全集
6、實作空集的判斷(IsEmpty)
7、實作集合的清空操作(Clear
)
8、實作列印集合所有學生學號的操作(Output)
*/
class StudentSet
{
private:
vector<Student> m_vecData;
public:
StudentSet();
StudentSet(const StudentSet & studentset);
StudentSet & operator=(const StudentSet & studentset);
bool operator==(const StudentSet & studentset);
bool Insert(const Student student);
bool Remove(const int id);
StudentSet Union(const StudentSet & studentset);
StudentSet InterSect(const StudentSet & studentset);
StudentSet Difference(const StudentSet & studentset);
StudentSet Complement();
StudentSet SymDifference(const StudentSet & studentset);
bool IsEmpty();
void Clear();
void Output();
};
int main()
{
srand((unsigned int)time(NULL));
StudentSet set1, set2, set3;
set1.Clear();
set2.Clear();
set3.Clear();
for (unsigned int i = 0; i < 50; i++)
{
Student tmpstudent(i);
set1.Insert(tmpstudent);
}
set1.Output();
Student tmpstudent(10);
cout << set1.Insert(tmpstudent) << endl;
for (unsigned int i = 30; i < 70; i++)
{
Student tmpstudent(i);
set2.Insert(tmpstudent);
}
set2.Output();
set3 = set1.Union(set2);
set3.Output();
set3 = set1.InterSect(set2);
set3.Output();
set3 = set1.Difference(set2);
set3.Output();
set3.Complement();
set3.Output();
set3 = set1.SymDifference(set2);
set3.Output();
system("pause");
return 0;
}
uj5u.com熱心網友回復:
啊這,同求助。咱倆留的這是一道題啊
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/271010.html
標籤:C++ 語言
下一篇:C++圖形題
