When I run the following code, and receive the output songs_time.txt file, it doesn't show any of the songs numbers or time remaining in the output table. I have the input songs.txt file path copied into the file_in location but don't know what is wrong.
//headers files
#include <iostream>
#include <iomanip>
#include <fstream>
//using namespace
using namespace std;
//main() function is defined
int main()
{
cout << "Bartleby---xxxxxxx" << endl << endl;
//declaring the variables as per the requirement
int song_min, song_sec, total_min, total_sec, total_time = 0, remain_time, remain_min, remain_sec;
int serial_num, s_sec;
//initialising the holding time of CD to 80 minutes
int hold_time = (100 * 60);
//reading data from the file
fstream file_in("C:\Users\gabri\OneDrive\Desktop\songs.txt", ios::in);
//writing data as output on the file
fstream file_out("songs_time.txt", ios::out);
//displaying the heading of the output table
file_out << "\n " << setw(10) << " Song # " << setw(26)
<< " Song Time " << setw(28) << " Total Time \n";
file_out << setw(40)
<< " Minutes Seconds " << setw(27) << " Minutes Seconds \n";
file_out << "-------------------------------------------------------------------- ";
//using while loop to check the condition repeatedely
while (file_in.good())
{
//reading the data from the input text file
file_in >> serial_num >> s_sec;
//calculating the total time
total_time = total_time + s_sec;
//calculating the total time in minutes
total_min = total_time / 60;
//calculating the total time in seconds
total_sec = total_time % 60;
//calculating the total time in minutes
song_min = s_sec / 60;
//calculating the seconds
song_sec = s_sec % 60;
//displaying the output on the output file
file_out << "\n " << serial_num << setw(22) << song_min
<< setw(12) << song_sec << setw(16) << total_min << setw(10) << total_sec << " \n";
}
//calculating the remaining time
remain_time = hold_time - total_time;
//calculating the remaining time in minutes
remain_min = remain_time / 60;
//calculating the remaining time in seconds
remain_sec = remain_time % 60;
//displaying the message and the remaining time
file_out << "\nThere are " << remain_min << " minutes and "
<< remain_sec << " seconds of space left on the 80-minute CD";
//using the close function
file_out.close();
system("pause");
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 6 steps with 6 images
- Word Puzzle GameIn this assignment is only for individual. You are going to decode the scrambled word into correct orderin this game. One round of play is as follows:1. Computer reads a text file named words.txt2. Computer randomly picks one word in the file and randomly scrambles characters in the wordmany times to hide the word3. Computer displays the scrambled word to user with indexes and gives the user options to1. Swap two letters in word based on index given2. Solve the puzzle directly3. Quit the game4. If a player chooses to swap letters, the computer reads two indexes and swaps the letters. Thegame resume to step 3 with the newly guessed word. If the resulted word after swapping is thesecret word, the game is over.5. If a user chooses to solve directly, computer prompts the user to enter the guessed word. If it’scorrect, the game is over, otherwise goes to step 3.6. After game is over, display how many times the player has tried to solve the puzzle.The following is sample…arrow_forward/** * @file main.cpp * @brief This is the main file for the baseball champions program * @author Connor Melton * @date March 12, 2013 * */// INCLUDE THE HEADER FILES NEEDED FOR THE FUNCTIONS TO WORK#include "baseball.h" int main(){ ifstream teamFile; teamFile.open("./Teams.txt"); string teams[30]; int teams_count = 0; while (getline(teamFile, teams[teams_count])) { teams_count++; } teamFile.close(); ifstream winnersFile; winnersFile.open("./WorldSeriesWinners.txt"); // 1. Check if file opened successfully, if not exit the program // 2a. Declare an array of strings to store data for world series winners // 2. Load data from winnersFile to an array by calling loadWinnersFromFileToArray // 3. Close the file stream // Read the instructions on what else you need to finish this program string winners[65]; int winnersCount = 0; while (getline(winnersFile, winners[winnersCount])) { winnersCount++; }…arrow_forwardTraceback (most recent call last): File "C:/app.py", line 20, in main() File "C:/app.py", line 17, in main print_report() File "C:/app.py", line 12, in print_report print_id() File "C:/app.py", line 6, in print_id message = "Your id is:" + id num TypeError: must be str, not int Process finished with exit code 1 Given this stack trace above, on what line was the exception raised? O Line 17 O Line 12 O Line 6 O Line 20arrow_forward
- C Sharp Random Number File writer and Reader Create an application that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many randome numbers the file will hold and should use a SaveFileDialog control to let the user specify the file's name and Location. Create another application that uses an OpenFileDialog control to let the user select the file that was created above. This application should read the numbers from the file, display the numbers in a ListBox control and display: the total of the numbers and the number of random numbers read from the file.arrow_forward>> classicVinyls.cpp For the following program, you will use the text file called “vinyls.txt” attached to this assignment. The file stores information about a collection of classic vinyls. The records in the file are like the ones on the following sample: Led_Zeppelin Led_Zeppelin 1969 1000.00 The_Prettiest_Star David_Bowie 1973 2000.00 Speedway Elvis_Presley 1968 5000.00 Spirit_in_the_Night Bruce_Springsteen 1973 5000.00 … Write a declaration for a structure named vinylRec that is to be used to store the records for the classic collection system. The fields in the record should include a title (string), an artist (string), the yearReleased (int), and an estimatedPrice(double). Create the following…arrow_forwardC++arrays, c-strings, functions with arrays as parameters 1. Create a file that contains 20 integers or download the attached file twenty_integers.txt Create a program that: 2. Declares a c-style string array that will store a filename. 3. Prompts the user to enter a filename. Store the file name declared in the c-string. 4. Opens the file. Write code to check the file state. If the file fails to open, display a message and exit the program. 5. Declare an array that holds 20 integers. Read the 20 integers from the fileinto the array.6. Write a function that accepts the filled array as a parameter and determines the MAXIMUM value in the array.Return the maximum value from the function (the function will be of type int).7. Print ALL the array values AND print the maximum value in the array using a range-based for loop. Use informational messages.Ensure the output is readable.arrow_forward
- flowchrt for the code below //C++ Code #include<iostream>#include<fstream>using namespace std;/*Create a global variable of type ofstream for the output file*/ofstream outfile; /** This function asks the user for the number of employees in the company. This value should be returned as an int. The function accepts no arguments (No parameter/input).*/int NumOfEmployees();/** accepts an argument of type int for the number of employees in the company and returns the total of missed days as an int. This function should do the following:Asks the user to enter the following information for each employee:The employee number (ID) (Assume the employee number is 4 digits or fewer, but don't validate it).The number of days that employee missed during the past year.Writes each employee number (ID) and the number of days missed to the output file */int TotDaysAbsent(int numberOfEmployees);/* calculates the average number of days absent.The function takes two arguments:the number of…arrow_forwardIn C++ PLEASE Use the text file from Chapter 12, forChap12.txt. SEE BELOW Write a program that opens a specified text file then displays a list of all the unique words found in the file. Addition to the text book specifications, print the total of unique words in the file. Text File = forChap12.txt No one is unaware of the name of that famous English shipowner, Cunard. In 1840 this shrewd industrialist founded a postal service between Liverpool and Halifax, featuring three wooden ships with 400-horsepower paddle wheels and a burden of 1,162 metric tons. Eight years later, the company's assets were increased by four 650-horsepower ships at 1,820 metric tons, and in two more years, by two other vessels of still greater power and tonnage. In 1853 the Cunard Co., whose mail-carrying charter had just been renewed, successively added to its assets the Arabia, the Persia, the China, the Scotia, the Java, and the Russia, all ships of top speed and, after the Great Eastern, the biggest ever…arrow_forwardC programarrow_forward
- Code in C language. Please provide code for 3 different files. One header file and two .C files. I need the code for each file. Please provide photos of the output and source code for each file (3). Please follow All instructions in the photo provided. Use the provided input.txt file provided below. A1, A2 20294 Lorenzana Dr Woodland Hills, CA 91364 B1, B2 19831 Henshaw St Culver City, CA 94023 C1, C2 5142 Dumont Pl Azusa, CA 91112 D1, D2 20636 De Forest St Woodland Hills, CA 91364 A1, A2 20294 Lorenzana Dr Woodland Hills, CA 91364 E1, E2 4851 Poe Ave Woodland Hills, CA 91364 F1, F2 20225 Lorenzana Dr Los Angeles, CA 91111 G1, G2 20253 Lorenzana Dr Los Angeles, CA 90005 H1, H2 5241 Del Moreno Dr Los Angeles, CA 91110 I1, I2 5332 Felice Pl Stevenson Ranch, CA 94135 J1, J2 5135 Quakertown Ave Thousand Oaks, CA 91362 K1, K2 720 Eucalyptus Ave 105 Inglewood, CA 89030 L1, L2 5021 Dumont Pl Woodland Hills, CA 91364 M1, M2 4819 Quedo Pl Westlake Village, CA 91362 I1, I2 5332 Felice Pl…arrow_forwardFiles Class Activity Write a program to write your first name (hard coded) to the screen and possibly to a file whose name is passed into the program from the command line. It can be written in upper or lower case or mixed case as the default. Usage: writer [-f filename] If the -f option is included with a filename, then create a file with that name or overwrite a previously existing file and write your name in on the first line. If the -f option is not included, then only write your name to the screen followed by a newline. Use a copy of the original getopt to parse the command line. Be sure to test whether a file open succeeds or not and close any file you open when done.arrow_forwardWhat header file must be included *Match* 1. to perform a mathematical function like sqrt 2. to use random numbers 3. to use random numbers 4. to use stream manipulators like setprecision A. iostream B. cmath C. iomanip D.cstdlibarrow_forward
- 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