Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements in c++ : Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44 characters, output the first 44 characters only. Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Hints: Use the find() function to find the index of a comma in each row of the text file. Use the substr() function to extract texts separated by the commas. Ex: If the input of the program is: movies.csv and the contents of movies.csv are: 16:40,Wonders of the World,G 20:00,Wonders of the World,G 19:00,Journey to Space ,PG-13 12:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 10:00,Adventure of Lewis and Clark,PG-13 14:30,Adventure of Lewis and Clark,PG-13 19:00,Halloween,R the output of the program is: Wonders of the World | G | 16:40 20:00 Journey to Space | PG-13 | 19:00 Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30 Adventure of Lewis and Clark | PG-13 | 10:00 14:30 Halloween | R | 19:00

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements in c++ :

  • Each row contains the title, rating, and all showtimes of a unique movie.
  • A space is placed before and after each vertical separator ('|') in each row.
  • Column 1 displays the movie titles and is left justified with a minimum of 44 characters.
  • If the movie title has more than 44 characters, output the first 44 characters only.
  • Column 2 displays the movie ratings and is right justified with a minimum of 5 characters.
  • Column 3 displays all the showtimes of the same movie, separated by a space.

Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows.

Hints: Use the find() function to find the index of a comma in each row of the text file. Use the substr() function to extract texts separated by the commas.

Ex: If the input of the program is:

movies.csv

and the contents of movies.csv are:

16:40,Wonders of the World,G 20:00,Wonders of the World,G 19:00,Journey to Space ,PG-13 12:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 10:00,Adventure of Lewis and Clark,PG-13 14:30,Adventure of Lewis and Clark,PG-13 19:00,Halloween,R

the output of the program is:

Wonders of the World | G | 16:40 20:00 Journey to Space | PG-13 | 19:00 Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30 Adventure of Lewis and Clark | PG-13 | 10:00 14:30 Halloween | R | 19:00

#include <iostream>
#include <cstring>
#include <iomanip>
#include <fstream>
using namespace std;

int main() {

   /* Type your code here. */

   return 0;
}

Expert Solution
arrow_forward
Step 1

I've taken the user's input in this case and stored it in a variable.

I then opened the CSV file and copied the contents into a dictionary, where the showtime list is the value and the key is the combination of the movie title and rating separated by a comma.

I then looped through the dictionary to get its values.

In response to the inquiry, I have finally printed the extracted values as a table.

arrow_forward
Step 2

import csv

# user input

filename = input("Enter the CSV file name: ")

 

movies_dict = {}

with open(filename,'r') as file: #opening the file

    reader = csv.reader(file)

    for row in reader: #reading the content

        key = row[1] +','+ row[2]

        tempList=[]

        if key in movies_dict: #checking and stroing in form of dictionary

            tempList = movies_dict[key]

        tempList.append(row[0])

        movies_dict[key] = tempList

# looping over the dictionary and printinng the data

for key,value in movies_dict.items():

    # extarcting the values

    tempList = key.split(',')

    movieName = tempList[0]

    movieRating = tempList[1]

    # if the movie title is greater than 44 then snipping it

    if len(movieName) > 44:

        movieName = movieName[:44]

    print(movieName.ljust(44),end=" | ")

    print(movieRating.rjust(5),end=" | ")

    for time in value:

        print(time,end=" ")

    print()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY