-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (73 loc) · 1.75 KB
/
main.cpp
File metadata and controls
87 lines (73 loc) · 1.75 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//main.cpp
//elberling, Ace
//elberling
#include <iostream>
#include <string>
#include "video.h"
using namespace std;
int main()
{
string sort_type, title, url, comment;
Video* videos[100];
int rating, i=0;
float length;
//input
getline(cin, sort_type);
if(sort_type != "rating" && sort_type != "length" && sort_type != "title")
{
cerr<<sort_type<<" is not a legal sorting method, giving up.\n";
return 1;
}
while(getline(cin, title))
{
getline(cin, url);
getline(cin, comment);
cin>>length>>rating;
cin.ignore();
videos[i] = new Video(title, url, comment, length, rating);
i++;
if (i>100)
{
cerr<<"Too many videos, giving up.\n";
return 1;
}
}
int num_videos = i;
//sort
if (sort_type=="rating")
{
for (int last = num_videos -1; last>0; last--)
{
for(int cur = 0; cur<last; cur++)
{
if(videos[cur]->rated(videos[cur+1]))
swap(videos[cur+1], videos[cur]);
}
}
}
else if (sort_type=="length")
{
for (int last = num_videos -1; last>0; last--)
{
for(int cur = 0; cur<last; cur++)
{
if(videos[cur]->longer(videos[cur+1]))
swap(videos[cur], videos[cur+1]);
}
}
}
else if (sort_type=="title")
{
for (int last = num_videos -1; last>0; last--)
{
for(int cur = 0; cur<last; cur++)
{
if(videos[cur]->alpha(videos[cur+1]))
swap(videos[cur], videos[cur+1]);
}
}
}
for(i=0;i<num_videos;i++)
videos[i]->print();
return 0;
}