-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·110 lines (105 loc) · 3.89 KB
/
main.cpp
File metadata and controls
executable file
·110 lines (105 loc) · 3.89 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <fstream>
#include <string>
#include "Movie.h"
#include "Hash.h"
#include <bits/stdc++.h>
using namespace std;
void printMenu()
{
cout<<"Please enter your choice from given questions"<<endl
<<"1. Which movie has highest rating?"<<endl
<<"2. Which movie has lowest rating?"<<endl
<<"3. How many movies have same rating?(enter the rating you want to search)"<<endl
<<"4. How many movies have average rating?"<<endl
<<"5. Which average rated movie has highest votes?"<<endl
<<"6. Which average rated movie has lowest votes?"<<endl
<<"Enter 0 to exit"<<endl;
}
int main()
{
string id,votes,rating;
ifstream read;
int count = 0, votesToInt;
float maxRating = 0, minRating = 100000, sumOfRating = 0;
int maxVotes = 0, minVotes = 100000, sumOfVotes = 0;
float ratingToFloat;
read.open("data.txt");
Hash table;
if(read.is_open())
{
while(!read.eof())
{
read >> id >> rating >> votes;
stringstream(rating)>>ratingToFloat;
stringstream(votes)>>votesToInt;
Movie obj(id,ratingToFloat,votesToInt);
table.add(obj);
count++;
sumOfRating += ratingToFloat;
sumOfVotes += votesToInt;
if(maxVotes < votesToInt)
maxVotes = votesToInt;
if(minVotes > votesToInt)
minVotes = votesToInt;
if(maxRating < ratingToFloat)
maxRating = ratingToFloat;
if(minRating > ratingToFloat)
minRating = ratingToFloat;
}
read.close();
}
else
cout << "The file is not open" <<endl;
cout<<"Total Number of Entries: " <<count << endl
<<"Average Rating: " <<float(sumOfRating/count)<< endl
<<"Average Votes: "<< float(sumOfVotes/count)<<endl
<<"Highest Rating: "<< maxRating<<endl
<<"Lowest Rating: "<<minRating<<endl
<<"Highest Number of votes: "<<maxVotes<<endl
<<"Lowest Number of Votes: "<<minVotes<<endl;
int choice;
do
{
printMenu();
cin >> choice;
switch (choice)
{
case 1:
cout << table.searchMax(maxRating*10).getData();
break;
case 2:
cout << table.searchMin(minRating*10).getData();
break;
case 3:
cout << "Enter the rating where you want to check the movie count"<<endl;
cin >> ratingToFloat;
if(table.getSize((ratingToFloat) == 0))
cout << "There are no movies with this rating" <<endl;
else
cout << "Number of movies: "<<table.getSize(ratingToFloat*10)<<endl;
break;
case 4:
if(table.getSize((sumOfRating/count)*10) == 0)
cout << "There are no movies with this rating"<<endl;
else
cout << table.getSize((sumOfRating/count)*10)<<endl;
break;
case 5:
if(table.searchMax((sumOfRating/count)*10).getData().getRating() == 0)
cout << "there are no movies with this rating"<<endl;
else
cout << table.searchMax((sumOfRating/count)*10).getData();
break;
case 6:
if(table.searchMin((sumOfRating/count)*10).getData().getRating() == 0)
cout << "there are no movies with this rating"<<endl;
else
cout << table.searchMin((sumOfRating/count)*10).getData();
break;
default:
cout << "Please enter a valid choice";
}
} while (choice != 0);
return 0;
}