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 #include #include //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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;

 

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 6 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-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education