Knowee
Questions
Features
Study Tools

5.15 LAB: Movie show time displayWrite 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: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.csvand the contents of movies.csv are:16:40,Wonders of the World,G20:00,Wonders of the World,G19:00,Journey to Space ,PG-1312:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG10:00,Adventures of Lewis and Clark,PG-1314:30,Adventures of Lewis and Clark,PG-1319:00,Halloween,Rthe output of the program is:Wonders of the World | G | 16:40 20:00Journey to Space | PG-13 | 19:00Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30Adventures of Lewis and Clark | PG-13 | 10:00 14:30Halloween | R | 19:00

Question

5.15 LAB: Movie show time displayWrite 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: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.csvand the contents of movies.csv are:16:40,Wonders of the World,G20:00,Wonders of the World,G19:00,Journey to Space ,PG-1312:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG10:00,Adventures of Lewis and Clark,PG-1314:30,Adventures of Lewis and Clark,PG-1319:00,Halloween,Rthe output of the program is:Wonders of the World | G | 16:40 20:00Journey to Space | PG-13 | 19:00Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30Adventures of Lewis and Clark | PG-13 | 10:00 14:30Halloween | R | 19:00

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a step-by-step guide on how to write a program in C++ to solve this problem:

  1. Include necessary libraries:
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
  1. Declare necessary variables:
std::string fileName, line, title, rating, time, prevTitle = "";
  1. Get the file name from the user:
std::cin >> fileName;
  1. Open the file:
std::ifstream file(fileName);
  1. Check if the file is open:
if (file.is_open()) {
  1. Read the file line by line:
while (getline(file, line)) {
  1. Use std::stringstream to split the line into time, title, and rating:
std::stringstream ss(line);
getline(ss, time, ',');
getline(ss, title, ',');
getline(ss, rating);
  1. If the title is the same as the previous title, just append the time. Otherwise, print the title, rating, and time:
if (title == prevTitle) {
    std::cout << " " << time;
} else {
    if (!prevTitle.empty()) {
        std::cout << std::endl;
    }
    std::cout << std::left << std::setw(44) << title.substr(0, 44) << " | " << std::right << std::setw(5) << rating << " | " << time;
    prevTitle = title;
}
  1. Close the file:
file.close();
  1. If the file could not be opened, print an error message:
} else {
    std::cout << "Unable to open file";
}

This program reads the CSV file line by line, splits each line into time, title, and rating, and prints the title, rating, and time in the required format. If the title is the same as the previous title, it just appends the time.

This problem has been solved

Similar Questions

Fill in the blanks with the correct answer :Text fileComma-separated values (CSV) fileTab-delimited file(Just select the word in BOLD)blank1 - Word AnswerWrite your response here... :  A data file that contains characters, such as letters, numbers, and symbols, including punctuation and spaces.This file is not a Movie, it is not a Word, nor PPTX, etc.blank2 - Word AnswerWrite your response here... :  A file type that uses commas to separate data into columns and a newline character to separate data into rows.blank3 - Word AnswerWrite your response here... : A file type that uses tabs to separate data into columns.

Saran and Dinesh are preparing the release details for their new show 'Galactic Adventures' on their streaming service. To ensure the episode information is accurate, Saran asks Dinesh to create a program to input the episode number and its duration, and then display this information.Your task as a programmer is to assist them in this program.Input format :The input consists of an integer N, representing the episode number and a double value X, representing its duration.Output format :The output prints "Episode [N] is [X] hours long!"Refer to the sample output for the exact text and format.Code constraints :1 ≤ N ≤ 100.1 ≤ X ≤ 60.0Sample test cases :Input 1 :1 2.75Output 1 :Episode 1 is 2.75 hours long!Input 2 :2 3.75Output 2 :Episode 2 is 3.75 hours long!

Not Boring MoviesX city opened a new cinema, many people would like to go to this cinema. Thecinema also gives out a poster indicating the movies’ ratings and descriptions.Please write a SQL query to output movies with an odd numbered ID and adescription that is not 'boring'. Order the result by rating.For example, table cinema:idmoviedescriptionrating1Wargreat 3D8.92Sciencefiction8.53Irishboring6.24Ice SongFantasy8.65House cardInteresting9.1For the example above, the output should be:idmoviedescriptionrating5House cardInteresting9.11Wargreat 3D8.9Optionsselect movie, description, ratingfrom cinemawhere id % 2 != 1 and description <> 'boring'order by rating asc;select id, movie, descriptionfrom moviewhere rating % 2 = 1 and description <> 'boring'order by rating;select id, movie, description, ratingfrom cinemawhere id % 2 = 1 and description <> 'boring'order by rating desc;select id, movie, description, ratingfrom ratingwhere id % 2 = 1 and description <> 'boring'order by cinema desc;

Insert a new field called ‘Movie’ to display the results of concatenating the ‘Title’ and‘Director’ fields. Add a ‘: Directed by ’ text string in the middle of concatenate formulaas well

Aishu wants to develop a program to calculate the total viewing time for a movie marathon of the Deadpool series based on the number of movies and the frequency of breaks.She is provided with the following information:Each movie in the series has a fixed duration of 45 minutes.After watching a certain number of movies, there is a break of 15 minutes.Assist Aishu in creating a program that accepts input for the total number of movies in the series and the number of movies watched before a break. Calculate and output the total viewing time required to watch the entire series, including the breaks. Use the conditional operator for the same.Input format :The first line of input consists of an integer n, representing the total number of movies in the series.The second line consists of an integer k, representing the number of movies watched before a break.Output format :The output displays an integer representing the total viewing time required to watch the entire series, including the breaks, in minutes.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ n ≤ 201 ≤ k ≤ 10Sample test cases :Input 1 :52Output 1 :255 minutesInput 2 :43Output 2 :195 minutesInput 3 :135Output 3 :615 minutes

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.