Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; const int MAX _ RATINGS = 1 0 0 0 ; const int MAX _ CATEGORIES = 3 ; const

#include
#include
using namespace std;
const int MAX_RATINGS =1000;
const int MAX_CATEGORIES =3;
const int MAX_AGE_GROUPS =4;
struct Rating {
int category;
int ageGroup;
int value;
};
Rating ratings[MAX_RATINGS];
int numRatings =0;
string categories[MAX_CATEGORIES]={"Horror", "Sci-Fi", "Drama"};
string ageGroups[MAX_AGE_GROUPS]={"Below 18","18-29","30-44","45 and above"};
void displayMenu(){
cout <<"
TV Show Rating Application" << endl;
cout <<"1. Rate a TV show category" << endl;
cout <<"2. Remove a rating" << endl;
cout <<"3. Display ordered lists of ratings" << endl;
cout <<"4. Display average ratings" << endl;
cout <<"5. Search for ratings" << endl;
cout <<"6. Top recent ratings" << endl;
cout <<"7. Categories and age groups with most ratings" << endl;
cout <<"0. Exit" << endl;
cout << "Enter your choice: ";
}
void rateCategory(){
int categoryChoice, ageGroupChoice, rating;
cout << "Choose a category:" << endl;
for (int i =0; i < MAX_CATEGORIES; i++){
cout << i +1<<"."<< categories[i]<< endl;
}
cout << "Enter your choice: ";
cin >> categoryChoice;
if (categoryChoice <1|| categoryChoice > MAX_CATEGORIES){
cout << "Invalid category choice!" << endl;
return;
}
cout << "Choose an age group:" << endl;
for (int i =0; i < MAX_AGE_GROUPS; i++){
cout << i +1<<"."<< ageGroups[i]<< endl;
}
cout << "Enter your choice: ";
cin >> ageGroupChoice;
if (ageGroupChoice <1|| ageGroupChoice > MAX_AGE_GROUPS){
cout << "Invalid age group choice!" << endl;
return;
}
cout << "Enter a rating (1-100): ";
cin >> rating;
if (rating <1|| rating >100){
cout << "Invalid rating value!" << endl;
return;
}
if (numRatings < MAX_RATINGS){
ratings[numRatings].category = categoryChoice;
ratings[numRatings].ageGroup = ageGroupChoice;
ratings[numRatings].value = rating;
numRatings++;
cout << "Rating added successfully!" << endl;
} else {
cout << "Maximum number of ratings reached!" << endl;
}
}
void removeRating(){
int categoryChoice, ageGroupChoice, ratingToRemove;
cout <<"**** Remove Rating ****"<< endl;
// Specify TV show Category
cout <<"**** Specify TV show Category ****"<< endl;
for (int i =0; i < MAX_CATEGORIES; i++){
cout <<" Press ("<< i +1<<") for "<< categories[i]<< endl;
}
cout << "Enter a choice: ";
cin >> categoryChoice;
if (categoryChoice <1|| categoryChoice > MAX_CATEGORIES){
cout << "Invalid category choice!" << endl;
return;
}
// Specify the age category
cout <<"**** Specify the age category ****"<< endl;
for (int i =0; i < MAX_AGE_GROUPS; i++){
cout <<" Press ("<< i +1<<") for age group of "<< ageGroups[i]<< endl;
}
cout << "Enter your choice: ";
cin >> ageGroupChoice;
if (ageGroupChoice <1|| ageGroupChoice > MAX_AGE_GROUPS){
cout << "Invalid age group choice!" << endl;
return;
}
// Enter the rating value to be removed
cout << "Enter the rating value to be removed: ";
cin >> ratingToRemove;
bool removed = false;
for (int i =0; i < numRatings; i++){
if (ratings[i].category == categoryChoice && ratings[i].ageGroup == ageGroupChoice &&
ratings[i].value == ratingToRemove){
ratings[i].value =0; // Mark as removed with a value of 0
removed = true;
cout << "Rating value has been removed successfully!" << endl;
}
}
if (!removed){
cout << "Rating not found!" << endl;
}
if (!removed){
cout << "Rating not found!" << endl;
}
}
void displayOrderedLists(){
// Sort the ratings in ascending order
for (int i =0; i < numRatings -1; i++){
for (int j =0; j < numRatings - i -1; j++){
if (ratings[j].value > ratings[j +1].value){
swap(ratings[j], ratings[j +1]);
}
}
}
cout << "Ascending order of ratings:" << endl;
for (int i =0; i < numRatings; i++){
if (ratings[i].value >0){
cout << "Category: "<< categories[ratings[i].category -1]<<", Age Group: "
<< ageGroups[ratings[i].ageGroup -1]<<", Rating: "<< ratings[i].value << endl;
}
}
cout << "Descending order of ratings:" << endl;
for (int i = numRatings -1; i >=0; i--){
if (ratings[i].value >0){
cout << "Category: "<< categories[ratings[i].category -1]<<", Age Group: "
<< ageGroups[ratings[i].ageGroup -1]<<", Rating: "<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Rin A (0)=90kg Ri Rout = " ds = Min Rout = diA= dt -4A(t) 2000 +4+

Answered: 1 week ago