Question

In: Computer Science

Write a C++ program that summarizes all of the Oscars that a given actor or movie...

Write a C++ program that summarizes all of the Oscars that a given actor or movie has won or been nominated for. You have been provided with a CSV file with all of the Oscar wins and nominations below. Each row of this file contains 4 pieces of information, separated by commas: the year, the award category, whether they won the award (TRUE or FALSE), and the recipient. Note that the award category and the year may have multiple words separated by spaces.

Once you have read in this data, prompt the user to "Enter recipient: ". Then, search your data for all entries with matching recipients, noting which awards the recipient won and which they were only nominated for. Then, print "Won:" on a line, followed by all of the awards they won, one per line, in the form

Category (year)

If they didn't win an award, print "Won: nothing" on a line instead. Then, print "Nominated for:" on a line, followed by all of the awards they didn't win, one per line, in the form

Category (year)

If they weren't nominated for an award or they won everything they were nominated for, print "Nominated for: nothing" on a line instead. Terminate the program afterwards.

Hint: you will want to define a struct for the awards.

Content of: oscars.csv

year category winner entity
1927 ACTOR FALSE Richard Barthelmess
1927 ACTOR TRUE Emil Jannings
1927 ACTRESS FALSE Louise Dresser
1927 ACTRESS TRUE Janet Gaynor
1927 ACTRESS FALSE Gloria Swanson
1927 ART DIRECTION FALSE Rochus Gliese
1927 ART DIRECTION TRUE William Cameron Menzies
1927 ART DIRECTION FALSE Harry Oliver
1927 CINEMATOGRAPHY FALSE George Barnes

Solutions

Expert Solution

Hi.. Please check below program..

Main.cpp

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
struct Person {
int year;
string category;
string result;
string name;
};

using namespace std;

int main()
{
ifstream fin("oscar.csv");
if (!fin)
{
cout << "File not open\n";
return 1;
}
  
vector<Person> persons;
  
string line;
const char delim = ',';
  
while (getline(fin, line))
{
istringstream ss(line);
Person person;
ss >> person.year; ss.ignore(10, delim);
getline(ss, person.category,delim);
getline(ss, person.result,delim);
getline(ss, person.name,delim);
// ss >> person.num;
if (ss)
persons.push_back(person);
}
  
cout<< "Enter recipient:";
string Sname;
getline (cin, Sname);
bool checkresult = false;
for (unsigned int i=0; i< persons.size(); i++){
if(Sname == persons[i].name){
if(persons[i].result == "TRUE"){
cout << "Won: Oscar Award\n";
cout << " Nominated For: " << persons[i].category << "\n";
cout << "Year: "<< persons[i].year << "\n";
checkresult = true;
}else{
cout << "Won: nothing\n";
cout << " Nominated For: " << persons[i].category << "\n";
cout << "Year: "<< persons[i].year << "\n";
checkresult = true;
}
}
}
if(!checkresult){
cout << "Won: nothing\n";
cout << " Nominated For: nothing\n";
cout << "Year: nothing\n";
}
  
}


Input:
Oscar.csv

1927,Actor,FALSE,Richard Barth
1927,Actor,TRUE,Emil Jannings

Output 1:
Enter recipient:Emil Jannings
Won: Oscar Award
Nominated For: Actor
Year: 1927

Output 2:
Enter recipient:test
Won: nothing
Nominated For: nothing
Year: nothing


Please check the above and let me know any issues. Thank you. All the best.



Related Solutions

Write a C program that summarizes an order from a fictitious store. You must have these...
Write a C program that summarizes an order from a fictitious store. You must have these four lines in your program: float bike_cost, surfboard_cost; float tax_rate, tax_amount; int num_bikes, num_surfboards; float total_cost_bikes, total_cost_surfboards; float total_cost, total_amount_with_tax;
Write a C program that summarizes an order from a fictitious store. You must have these...
Write a C program that summarizes an order from a fictitious store. You must have these four lines in your program: float bike_cost, surfboard_cost; float tax_rate, tax_amount; int num_bikes, num_surfboards; float total_cost_bikes, total_cost_surfboards; float total_cost, total_amount_with_tax; You will assign your own unique values for each of the variables, except the totals which are computed. No other variables are needed in the program. For example, you will see the numbers I picked in my program in the sample output below. I...
Write a C++ program to print all the perfect numbers below a certain given number. A...
Write a C++ program to print all the perfect numbers below a certain given number. A perfect number is a number that that is equal too the sum of it's divisors other than itself . For example, 6 and 28 are all perfect numbers. 6 = ( 1+2 +3) 28 = (1+2+4+7+14) Make sure your program conforms to the following requirements: 1. Accept the upper limit from the user (as an integer). 2. Make sure the number is positive (at...
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include...
C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include the following attributes with appropriate types: i. Title ii. Director iii. Release Year iv. Rating (“G”, “PG”, “PG-13”, etc) - Write code that instantiates a movie object using value semantics as text: - Write code that instantiates a movie object using reference semantics: - Write the print_movie method code: - Write Constructor code: - Write Entire Movie class declaration
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage...
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works. 2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum 3. Program to compute the car insurance premium for a person based on their...
Part1: Write a program in C/C++ to find the maximum flow in the given Flow Network...
Part1: Write a program in C/C++ to find the maximum flow in the given Flow Network using (i)Ford -Fulkerson algorithm and (ii) Edmond-Karps algorithm Go through the related text and implement each of these algorithms using the efficient data structure. Show the results of different steps of these algorithms for an instance of the flow network with total number of nodesV=6 (please note down that in a flow network there are two special nodes source and sink) and total number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT