-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputerCollection.h
51 lines (43 loc) · 1.13 KB
/
ComputerCollection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// ComputerCollection.h
// pr21
//
// Created by yuqing on 2019/3/16.
// Copyright © 2019 yuqing. All rights reserved.
//
#ifndef ComputerCollection_h
#define ComputerCollection_h
#include "Computer.h"
#include <iostream>
#include <string.h>
using namespace std;
class ComputerCollection{
public:
Computer com[100];
int totalnum = 0;
public:
ComputerCollection(){};
void sortByScore(){
for(int i = 0; i < totalnum; i++){
for(int j = i+1 ; j < totalnum; j++){
if(com[i] < com[j]){
Computer cominst = com[i];
com[i] = com[j];
com[j] = cominst;
}
}
}
return;
}
Computer& operator[](string s){
for(int i = 0; i < totalnum; i++){
if(strcmp(s.c_str(), com[i].name.c_str()) == 0){
return com[i];
}
}
return com[1];
}
friend istream &operator>>(istream& in, ComputerCollection& cc);
friend ostream& operator<<(ostream& out, const ComputerCollection& cc);
};
#endif /* ComputerCollection_h */