In: Computer Science
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 |
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.