Programming and Problem Solving With C++
6th Edition
ISBN: 9781449694265
Author: Nell Dale
Publisher: Jones & Bartlett Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 6PP
Program Plan Intro
Program Plan:
- The file name is inserted in the string s .
- The file is opened with file stream fs.
- A Boolean variable prev is declared to check for a comma.
- A while loop is used to go through the file.
- Inside the loop, conditions are given to encounter the word after a comma.
- The if condition will print the word before a comma.
- The else if condition will print the word after a full stop.
- The first else condition will print the word after a comma.
- The second else will check for a comma.
Program Description:
To print the first word after the comma from the text file whose name is given by the user.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a C++ program that reads lines from a file until the end of file. The program should prompt the user for the file name to read from. The program should open the file for reading, and if the file cannot be opened, print the message “File couldn’t be opened”, followed by a space and the filename, and exit. The program should keep track of the number of lines, the number of non-blank lines, the number of words, and the number of integers read from the file.
Write a C program named toupper.c that reads the contents of a file, and writes to another file after changing all lowercase letters in the input file to uppercase.
The name of the input file and the output file are to be passed as command line arguments.
Assume there are only ASCII characters in the input file.
The length of the input file is not known beforehand. So make sure your program keeps reading bytes until EOF is reached.
Use the library function toupper to concert letters into uppercase.
Example:
The program is run from the command line as follows;
C:\>toupper.exe infile.txt outfile.txt
Suppose the contents of the input file infile.txt is:
AbcdefG
The contents of the output file outfile.txt should be:
ABCDEFG
You are required to write a C++ program that reads several hundreds of movie ratings from an input file, and output a list of Number of times rated (#Rated), sum of ratings (Total Ratings) and average ratings of the movies.The application program reads in several hundreds of movie ratings from an input file“Rating_list.txt”. Each line in the input file represents one review, indicating the title of the movie and a rating (between 0 and 5) separated by a space. Sample lines from the input file is shown below.The output must be formatted as shown below (see the columns and decimal places). In addition, the output must include the total number of unique movie titles and the total number of rating
Chapter 4 Solutions
Programming and Problem Solving With C++
Ch. 4 - Prob. 1PSCSCh. 4 - Prob. 1EPECh. 4 - Prob. 2EPECh. 4 - Prob. 3EPECh. 4 - Prob. 4EPECh. 4 - Prob. 5EPECh. 4 - Prob. 6EPECh. 4 - Prob. 7EPECh. 4 - Prob. 8EPECh. 4 - Prob. 9EPE
Ch. 4 - Prob. 10EPECh. 4 - Prob. 11EPECh. 4 - Prob. 12EPECh. 4 - Prob. 13EPECh. 4 - Prob. 14EPECh. 4 - Prob. 15EPECh. 4 - Prob. 16EPECh. 4 - Prob. 17EPECh. 4 - Prob. 18EPECh. 4 - Prob. 19EPECh. 4 - Prob. 20EPECh. 4 - Prob. 21EPECh. 4 - Prob. 22EPECh. 4 - Prob. 1PWECh. 4 - Prob. 2PWECh. 4 - Prob. 3PWECh. 4 - Prob. 4PWECh. 4 - Prob. 5PWECh. 4 - Prob. 6PWECh. 4 - Prob. 7PWECh. 4 - Prob. 8PWECh. 4 - Prob. 9PWECh. 4 - Prob. 10PWECh. 4 - Prob. 11PWECh. 4 - Prob. 12PWECh. 4 - Prob. 13PWECh. 4 - Prob. 14PWECh. 4 - Prob. 1PPCh. 4 - Prob. 2PPCh. 4 - Prob. 3PPCh. 4 - Prob. 4PPCh. 4 - Prob. 5PPCh. 4 - Prob. 6PPCh. 4 - Prob. 7PPCh. 4 - Prob. 1CSFCh. 4 - Prob. 2CSFCh. 4 - Prob. 3CSFCh. 4 - Prob. 4CSFCh. 4 - Prob. 5CSF
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- You are required to write a C++ program that reads several hundreds of movie ratings from an input file, and output a list of Number of times rated (#Rated), sum of ratings (Total Ratings) and average ratings of the movies.The application program reads in several hundreds of movie ratings from an input file“Rating_list.txt”. Each line in the input file represents one review, indicating the title of the movie and a rating (between 0 and 5) separated by a space. Sample lines from the input file is shown below.arrow_forwardYou are required to write a C++ program that reads several hundreds of movie ratings from an input file, and output a list of Number of times rated (#Rated), sum of ratings (Total Ratings) and average ratings of the movies. The application program reads in several hundreds of movie ratings from an input file "Rating_list.txt". Each line in the input file represents one review, indicating the title of the movie and a rating (between 0 and 5) separated by a space. Sample lines from the input file is shown below. Rating_list - Notepad Eile Edit Format View Help Titanic 5 The_Full_Monty 3 Liar_Liar Apollo 13 3 Liar Liar 3 Titanic 4 4 Windo in 1, C 100% The output must be formatted as shown below (see the columns and decimal places). In addition, the output must include the total number of unique movie titles and the total number of ratings found in the input file as shown in the sample output. CAWindows\system32\cmd.exe Movie Mname #Rated Total Ratings Average Rating Liar_Liar 87…arrow_forwardYou are required to write a C++ program that reads several hundreds of movie ratings from an input file, and output a list of Number of times rated (#Rated), sum of ratings (Total Ratings) and average ratings of the movies.The application program reads in several hundreds of movie ratings from an input file “Rating_list.txt”. Each line in the input file represents one review, indicating the title of the movie and a rating (between 0 and 5) separated by a space. Sample lines from the input file is shown below. Titanic 5 The_Full_Monty 3 Liar_Liar 4 Apollo_13 3 Liar_Liar 3 Titanic 4 The_Silence_of_the_Lambs 2 Star_Wars 1 Men_in_Black 4 Dead_Man_Walking 2 Toy_Story…arrow_forward
- You are required to write a C++ program that reads several hundreds of movie ratings from an input file, and output a list of Number of times rated (#Rated), sum of ratings (Total Ratings) and average ratings of the movies. The application program reads in several hundreds of movie ratings from an input file “Rating_list.txt”. Each line in the input file represents one review, indicating the title of the movie and a rating (between 0 and 5) separated by a space. Sample lines from the input file is shown below. Titanic 5 The_Full_Monty 3 Liar_Liar 4 Apollo_13 3 Liar_Liar 3 Titanic 4 The output must be formatted as shown below (see the columns and decimal places). In addition, the output must include the total number of unique movie titles and the total number of ratings found in the input file as shown in the sample output. Movie Mname #Rated Total Ratings Average…arrow_forwardWrite a C Program which reads the contents of the attached sequential file - customers.txt Print the surname of people who agreed to share their data. This is denoted by the final field in the file (1 for agree, 0 for not agreed). Print the average age of these people (age is the 4th column in the data) Print the average age for people who live in Dublin and have agreed to share their data. This is denoted by the first field in the file. customers.txt New York Dunne 865463389 21 1New York Milford 865438990 22 0New York Mowlds 876765443 24 1New York Wang 873456789 22 1New York Smith 875432234 25 1New York Henry 876654429 22 0New York Gupta 896765443 24 1Los Angeles Monahan 865432245 22 1Los Angeles Brunsdon 865678894 22 1Alabama Tyson 865434566 22 0Alabama Browne 865564766 20 1New York Dunne 890065443 27 1New…arrow_forwardWrite a C++ program to read data from a file “txt”. The contents of numbers.txt are as following. 99 88 77 66 55 44 Read each number from the file “txt” to calculate the sum and average of all the numbers. Save all numbers, sum, and average to a file “txt”. The output of each number and sum is placed in a field-wide enough to 5 places. The average of numbers will be displayed with two decimal places.arrow_forward
- Write a C++ program that reads sales data from a file called sales.txt. Each line of the file contains four data items:1. A product number which is an integer2. A product name which is a string no longer than 12 characters and which does not contain spaces3. A unit price which is a double4. A number of units sold which is an integerThe program will output the two products which generated the highest total revenue (unit price * number sold).Your program must:1. Read each line of the file storing the four items into the members of adynamically allocated structure.2. Store pointers to the structures in an array.3. Sort the array of pointers by total revenue4. Display the product name and total revenue of the top two products5. The program must work for sales.txt files with anywhere from 2 to 100 products ---------- sales.txt file information: 1002 Hammer 23.65 2031024 Nails 6.95 4001276 Screwdriver 13.95 2511385 Elec_Drill 45.69 1321462 Air_Filter 7.95 500 ------- Help me fix my code so…arrow_forwardWrite a C program that, given a text file, constructs Huffman code based on the character frequencies of the file and then encodes the file accordingly. The executable must accept the following command line options:• -i filename for the input file • -o filename for the output file Use the fread function, use FILE, size, etc. Please use the following to write the code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <getopt.h>arrow_forwardWrite a C++program to read a series of product names, count, and price of each item in a file called cart.in to the end. Calculate the cost of each item and the total amount spent before taxes. Assuming the sales tax applied is 5.7%, display the total cost of each item and the total amount after taxes. Output the results to a file called receipts.out. The output must be in the form shown below. Attach the code and screenshot of a successful run on the program. ==== Your receipt Item Count Price/Item Item Total Pens 3 $ 2.99 $ 8.97 Notebook 5 $ 3.00 $15.00 Shoes 1 $ 25.19 $ 25.19 ===================== Subtotal $ 49.16 ===================== Total $ 51.96arrow_forward
- Write a Python program that reads from the user the name of two files (an input file and an output file). The program will then read each line of the input file and save it in the output file preceded with the line number and removing any of the following punctuations (. , ! ? ; :) found at the end of the line. For example, if the input file is:Mary had a little lamb;Whose fleece was white as snow; And everywhere that Mary went; The lamb was sure to go!Then the output file the content of the input file and saves it in the produced output file will beLine 1: Mary had a little lambLine 2: Whose fleece was white as snow Line 3: And everywhere that MaryLine 4: The lamb was sure to goarrow_forwardWrite a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by a space. In addition, you must print to the console “Excellent” if the grade is greater than or equal to 90, “Well Done” if the grade is less than 90 and greater than or equal to 80, “Good” if the grade is less than 80 and greater than or equal to 70, “Need Improvement” if the grade is less than 70 and greater than or equal to 60, and “Fail” if the grade is less than 60.arrow_forwardIn C write a program that takes a file name and two strings as command line arguments, and writes the longer of the two strings to the file with the given name. If the given strings are the same length, write the first string given to the file. If the user does not provide the correct number of command line arguments, print an error message and exit the program with a non-zero exit code.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License