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; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 6PE
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning